~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/covira/imstack.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * imstack.c
  3  *
  4  * image stack handling
  5  *
  6  */
  7 
  8 #include <tina/all_tina.h>
  9 #include <tina/brain.h>
 10 #include <tina/brainfuncs.h>
 11 
 12 /*
 13 Find power of 2 greater than x
 14 */
 15 static int above2n(int x)
 16 {
 17     int y = 1;
 18     while (y < x)
 19         y *= 2;
 20     return (y);
 21 }
 22 
 23 /*
 24 Return an image stack of given image variable type (uchar_v etc.)
 25 with slice numbers ranging from lz to uz (excluding uz).
 26 */
 27 Imstack *imstack_make(Vartype vtype, int lz, int uz, double zscale)
 28 {
 29     Imstack *imstack = (Imstack *) ralloc(sizeof(Imstack));
 30     int z;
 31 
 32     imstack->vtype = vtype;
 33     imstack->lx = imstack->ux = imstack->x = 0;
 34     imstack->ly = imstack->uy = imstack->y = 0;
 35     imstack->lz = lz;
 36     imstack->uz = uz;
 37     imstack->z = (lz + uz) / 2;
 38     imstack->zmark = 0;
 39     imstack->slice = tvector_alloc(lz, uz, Slice *);
 40     imstack->zscale = zscale;
 41     for (z = lz; z < uz; z++)
 42         imstack->slice[z] = slice_alloc(imstack_zscaled(imstack, z));
 43     imstack->stats = NULL;
 44     imstack->tube = NULL;
 45     return (imstack);
 46 }
 47 
 48 /*
 49 Free an image stack and associated memory
 50 */
 51 void imstack_free(Imstack * imstack)
 52 {
 53     int z;
 54 
 55     if (imstack == NULL)
 56         return;
 57     for (z = imstack->lz; z < imstack->uz; z++)
 58         slice_free(imstack->slice[z]);
 59     tvector_free(imstack->slice, imstack->lz, Slice *);
 60     rfree(imstack->stats);
 61     tube_free(imstack->tube);
 62     rfree(imstack);
 63 }
 64 
 65 /*
 66 Get true z-coordinate associated with slice number z
 67 */
 68 double imstack_zscaled(Imstack * imstack, int z)
 69 {
 70     z -= (imstack->lz + imstack->uz) / 2;
 71     return (imstack->zscale * z);
 72 }
 73 
 74 /*
 75 Get slice number associated wth true z-coordinate z
 76 */
 77 int imstack_zunscaled(Imstack * imstack, double z)
 78 {
 79     int zi;
 80     z /= imstack->zscale;
 81     z += (imstack->lz + imstack->uz) / 2;
 82     zi = ROUND(z);
 83     return (zi);
 84 }
 85 
 86 /*
 87 Return transverse image in (y, z) plane at current x-cursor position.
 88 */
 89 Imrect *imstack_xslice(Imstack * imstack, int x)
 90 {
 91     Imrect *im;
 92     Imregion *roi;
 93     float *row;
 94     int z, width, height;
 95 
 96     if (imstack == NULL)
 97         return (NULL);
 98 
 99     height = above2n(imstack->uz);
100     width = above2n(imstack->uy);
101     roi = roi_alloc(imstack->ly, imstack->lz, imstack->uy, imstack->uz);
102     im = im_alloc(height, width, roi, imstack->vtype);
103     rfree(roi);
104 
105     row = tvector_alloc(imstack->ly, imstack->uy, float);
106     for (z = imstack->lz; z < imstack->uz; z++)
107     {
108         im_get_colf(row, imstack->slice[z]->im, x, imstack->ly, imstack->uy);
109         im_put_rowf(row, im, z, imstack->ly, imstack->uy);
110     }
111     tvector_free(row, imstack->ly, float);
112 
113     return (im);
114 }
115 
116 /*
117 Return transverse image in (x, z) plane at current y-cursor position.
118 */
119 Imrect *imstack_yslice(Imstack * imstack, int y)
120 {
121     Imrect *im;
122     Imregion *roi;
123     float *row;
124     int z, width, height;
125 
126     if (imstack == NULL)
127         return (NULL);
128 
129     height = above2n(imstack->uz);
130     width = above2n(imstack->ux);
131     roi = roi_alloc(imstack->lx, imstack->lz, imstack->ux, imstack->uz);
132     im = im_alloc(height, width, roi, imstack->vtype);
133     rfree(roi);
134 
135     row = tvector_alloc(imstack->lx, imstack->ux, float);
136     for (z = imstack->lz; z < imstack->uz; z++)
137     {
138         im_get_rowf(row, imstack->slice[z]->im, y, imstack->lx, imstack->ux);
139         im_put_rowf(row, im, z, imstack->lx, imstack->ux);
140     }
141     tvector_free(row, imstack->lx, float);
142 
143     return (im);
144 }
145 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.