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

Linux Cross Reference
Tina4/src/tools/sequence/seq_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/seqvoi.h>
 10 #include "seqvoifuncs.h"
 11 
 12 /*
 13 Allocate a slice with space for NVOI volumes of interest.
 14 */
 15 static Seqslice *seqslice_alloc(double z)
 16 {
 17     Seqslice *slice = (Seqslice *) ralloc(sizeof(Seqslice));
 18     int i;
 19     slice->im = NULL;
 20     for (i = 0; i < NVOI; i++)
 21         slice->voi[i] = svoi_alloc();
 22     slice->z = z;
 23     return (slice);
 24 }
 25 
 26 /*
 27 Free a slice.
 28 */
 29 static void seqslice_free(Seqslice * slice)
 30 {
 31     int i;
 32     if (slice == NULL)
 33         return;
 34     im_free(slice->im);
 35     for (i = 0; i < NVOI; i++)
 36         svoi_free(slice->voi[i]);
 37     rfree(slice);
 38 }
 39 
 40 /*
 41 Find power of 2 greater than x
 42 */
 43 static int above2n(int x)
 44 {
 45     int y = 1;
 46     while (y < x)
 47         y *= 2;
 48     return (y);
 49 }
 50 
 51 /*
 52 Return an image stack of given image variable type (uchar_v etc.)
 53 with slice numbers ranging from lz to uz (excluding uz).
 54 */
 55 Br_imstack *seq_imstack_make(Vartype vtype, int lz, int uz, double zscale)
 56 {
 57     Br_imstack *imstack = (Br_imstack *) ralloc(sizeof(Br_imstack));
 58     int z;
 59 
 60     imstack->vtype = vtype;
 61     imstack->lx = imstack->ux = imstack->x = 0;
 62     imstack->ly = imstack->uy = imstack->y = 0;
 63     imstack->lz = lz;
 64     imstack->uz = uz;
 65     imstack->z = (lz + uz) / 2;
 66     imstack->zmark = 0;
 67     imstack->slice = tvector_alloc(lz, uz, Seqslice *);
 68     imstack->zscale = zscale;
 69     for (z = lz; z < uz; z++)
 70         imstack->slice[z] = seqslice_alloc(seq_imstack_zscaled(imstack, z));
 71     /*    imstack->stats = NULL;
 72           imstack->tube = NULL;*/
 73     return (imstack);
 74 }
 75 
 76 /*
 77 Free an image stack and associated memory
 78 */
 79 void seq_imstack_free(Br_imstack * imstack)
 80 {
 81     int z;
 82 
 83     if (imstack == NULL)
 84         return;
 85     for (z = imstack->lz; z < imstack->uz; z++)
 86         seqslice_free(imstack->slice[z]);
 87     tvector_free(imstack->slice, imstack->lz, Seqslice *);
 88     /*rfree(imstack->stats);
 89       tube_free(imstack->tube);*/
 90     rfree(imstack);
 91 }
 92 
 93 /*
 94 Get true z-coordinate associated with slice number z
 95 */
 96 double seq_imstack_zscaled(Br_imstack * imstack, int z)
 97 {
 98     z -= (imstack->lz + imstack->uz) / 2;
 99     return (imstack->zscale * z);
100 }
101 
102 /*
103 Get slice number associated wth true z-coordinate z
104 */
105 int seq_imstack_zunscaled(Br_imstack * imstack, double z)
106 {
107     int zi;
108     z /= imstack->zscale;
109     z += (imstack->lz + imstack->uz) / 2;
110     zi = ROUND(z);
111     return (zi);
112 }
113 
114 /*
115 Return transverse image in (y, z) plane at current x-cursor position.
116 */
117 Imrect *seq_imstack_xslice(Br_imstack * imstack, int x)
118 {
119     Imrect *im;
120     Imregion *roi;
121     float *row;
122     int z, width, height;
123 
124     if (imstack == NULL)
125         return (NULL);
126 
127     height = above2n(imstack->uz);
128     width = above2n(imstack->uy);
129     roi = roi_alloc(imstack->ly, imstack->lz, imstack->uy, imstack->uz);
130     im = im_alloc(height, width, roi, imstack->vtype);
131     rfree(roi);
132 
133     row = tvector_alloc(imstack->ly, imstack->uy, float);
134     for (z = imstack->lz; z < imstack->uz; z++)
135     {
136         im_get_colf(row, imstack->slice[z]->im, x, imstack->ly, imstack->uy);
137         im_put_rowf(row, im, z, imstack->ly, imstack->uy);
138     }
139     tvector_free(row, imstack->ly, float);
140 
141     return (im);
142 }
143 
144 /*
145 Return transverse image in (x, z) plane at current y-cursor position.
146 */
147 Imrect *seq_imstack_yslice(Br_imstack * imstack, int y)
148 {
149     Imrect *im;
150     Imregion *roi;
151     float *row;
152     int z, width, height;
153 
154     if (imstack == NULL)
155         return (NULL);
156 
157     height = above2n(imstack->uz);
158     width = above2n(imstack->ux);
159     roi = roi_alloc(imstack->lx, imstack->lz, imstack->ux, imstack->uz);
160     im = im_alloc(height, width, roi, imstack->vtype);
161     rfree(roi);
162 
163     row = tvector_alloc(imstack->lx, imstack->ux, float);
164     for (z = imstack->lz; z < imstack->uz; z++)
165     {
166         im_get_rowf(row, imstack->slice[z]->im, y, imstack->lx, imstack->ux);
167         im_put_rowf(row, im, z, imstack->lx, imstack->ux);
168     }
169     tvector_free(row, imstack->lx, float);
170 
171     return (im);
172 }
173 

~ [ 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.