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

Linux Cross Reference
Tina4/src/tools/coreg/csf_count12.c

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

  1 #include <stdio.h>
  2 #include <values.h>
  3 #include <tina/sys.h>
  4 #include <tina/sysfuncs.h>
  5 #include <tina/math.h>
  6 #include <tina/mathfuncs.h>
  7 #include <tina/vision.h>
  8 #include <tina/visionfuncs.h>
  9 #include <tina/tv.h>
 10 #include <tina/tvfuncs.h>
 11 #include <tina/draw.h>
 12 #include <tina/drawfuncs.h>
 13 #include <tina/temporal.h>
 14 extern void init_interp(int nblx, int nbux, int nbly, int nbuy,
 15                         int nblz, int nbuz);
 16 extern void ***coreg_slice_init(Vec3 *ptr);
 17 extern void ***coreg_limits(int *lz, int *uz, int *ly,
 18                          int *uy, int *lx, int *ux);
 19 extern void coreg_coords(Vec3 *ex, Vec3 *ey, Vec3 *ez);
 20 extern void coreg_centre(double *x,double *y,double *z, Vec3 *c);
 21 extern void coreg_scales(double *x, double *y, double *z,
 22                          double *nx, double *ny, double *nz);
 23 Vec3 coreg_bproj(double x, double y, double z);
 24 Vec3 coreg_proj(double x, double y, double z);
 25 extern Tv *xcoreg_tv_get();
 26 extern Tv *ycoreg_tv_get();
 27 extern Tv *zcoreg_tv_get();
 28 extern Imrect *get_xcoreg_im();
 29 extern get_iscales(double *iscx, double *iscy, double *iscz);
 30 static void ***imptrs=NULL;
 31 static Vec3 coreg_ex, coreg_ey, coreg_ez, coreg_c;
 32 
 33 char pat_name[30];
 34 char pat_diag[30];
 35 double pat_age;
 36 char directory[64];
 37 
 38 static FILE *patient;
 39 
 40 csf_count12_proc()
 41 {
 42   char fullname[128];
 43 
 44     Vec3 ex,ey,ez,posi,post;
 45     int i,j,k;
 46     Imrect *im, *xcoreg_im;
 47     Imregion roi,xroi;
 48     double count[12];
 49     double scale;
 50     int imptrlx, imptrux,imptrly, imptruy, imptrlz, imptruz;
 51     int nimptrlx, nimptrux, nimptrly, nimptruy, nimptrlz, nimptruz;
 52     Vec3 iimptrlx, iimptrux, iimptrly, iimptruy, iimptrlz, iimptruz;
 53     float timptrlx, timptrux, timptrly, timptruy, timptrlz, timptruz;
 54     double xcentre = 128.0;
 55     double ycentre = 128.0;
 56     double zcentre = 40.0;
 57     double xtest,ytest,ytest1,ytest2,ztest,ztest1,ztest2;
 58     double xscale = 1.0;
 59     double yscale = 1.0;
 60     double zscale = 2.0;
 61     double nxscale = 1.0;
 62     double nyscale = 1.0;
 63     double nzscale = 2.0;
 64     float nearest_pixel(void ***rasptrs, Vec3 pos);
 65     float xdist, ydist, zdist;
 66 
 67 
 68     imptrs = coreg_limits(&imptrlz,&imptruz,&imptrly,&imptruy,&imptrlx,&imptrux);
 69     init_interp(imptrlx,imptrux, imptrly,imptruy, imptrlz,imptruz);
 70     coreg_scales(&xscale,&yscale,&zscale,&nxscale,&nyscale,&nzscale);
 71     coreg_centre(&xcentre,&ycentre,&zcentre,&coreg_c);
 72 
 73     count[0] = 0.0; count[1] = 0.0; count[2] = 0.0;
 74     count[3] = 0.0; count[4] = 0.0; count[5] = 0.0;
 75     count[6] = 0.0; count[7] = 0.0; count[8] = 0.0;
 76     count[9] = 0.0; count[10] = 0.0; count[11] = 0.0;
 77 
 78     tv_get_roi( xcoreg_tv_get(), &timptrlz, &timptrly, &timptruz, &timptruy);
 79     nimptrlz =  MAXINT;
 80     nimptruz = -MAXINT;
 81     nimptrly =  MAXINT;
 82     nimptruy = -MAXINT;
 83     nimptrlx =  MAXINT;
 84     nimptrux = -MAXINT;
 85 
 86 /* loop over reslice coordinates locating maximal extent of CSF */
 87     for (k=imptrlz;k<imptruz;k++)
 88     {
 89     for (i=imptrly;i<imptruy;i++)
 90     {
 91        for (j=imptrlx;j<imptrux;j++)
 92        {
 93            posi.el[0] = ((float)j+0.5 );
 94            posi.el[1] = ((float)i+0.5 );
 95            posi.el[2] = ((float)k+0.5 );
 96            
 97            if(nearest_pixel(imptrs,posi)>0.0)
 98            {
 99               post = coreg_proj((double)posi.el[0],(double)posi.el[1],(double)posi.el[2]);
100               if (tina_int(post.el[2])<nimptrlz)
101               {
102                  nimptrlz = tina_int(post.el[2]);
103                  iimptrlz = coreg_bproj(0.0,0.0,post.el[2]);
104               }
105               if (tina_int(post.el[2])>nimptruz)
106               {
107                  nimptruz = tina_int(post.el[2]);
108                  iimptruz = coreg_bproj(0.0,0.0,post.el[2]);
109               }
110               if (tina_int(post.el[1])<nimptrly)
111               {
112                  nimptrly = tina_int(post.el[1]);
113                  iimptrly = coreg_bproj(0.0,post.el[1],0.0);
114               }
115               if (tina_int(post.el[1])>nimptruy) 
116               {
117                  nimptruy = tina_int(post.el[1]);
118                  iimptruy = coreg_bproj(0.0,post.el[1],0.0);
119               }
120               if (tina_int(post.el[0])<nimptrlx)
121               {
122                  nimptrlx = tina_int(post.el[0]);
123                  iimptrlx = coreg_bproj(post.el[0],0.0,0.0);
124               }
125               if (tina_int(post.el[0])>nimptrux)
126               {
127                  nimptrux = tina_int(post.el[0]);
128                  iimptrux = coreg_bproj(post.el[0],0.0,0.0);
129               }
130            }
131        }
132     }
133     }
134     xcoreg_im = get_xcoreg_im();
135 /*    xroi = &(Imregion *)(xcoreg_im->region);
136 */
137     if (xcoreg_im==NULL) 
138         nimptruy = (int)((timptruy-ycentre)*yscale)/nyscale + ycentre;
139     xtest = (double)(nimptrlx+nimptrux+1.0)/2.0;
140     ytest = (double)(nimptrly+nimptruy+1.0)/2.0;
141     ztest = (double)(nimptrlz+nimptruz+1.0)/2.0;
142     ztest1 = ztest - (double)(nimptruz-nimptrlz)/6.0;
143     ztest2 = ztest + (double)(nimptruz-nimptrlz)/6.0;
144 /* now divide up the volume and count the contents */
145     for (k=imptrlz;k<imptruz;k++)
146     {
147     for (i=imptrly;i<imptruy;i++)
148     {
149        for (j=imptrlx;j<imptrux;j++)
150        {
151            posi.el[0] = ((float)j+0.5 );
152            posi.el[1] = ((float)i+0.5 );
153            posi.el[2] = ((float)k+0.5 );
154 
155            if (nearest_pixel(imptrs,posi)!=0.0)
156            {
157            post = coreg_proj((double)posi.el[0],(double)posi.el[1],(double)posi.el[2]);
158 /*
159               post = coreg_bproj((double)posi.el[0],(double)posi.el[1],(double)posi.el[2]);
160 */
161            if (post.el[0]<xtest)
162            {
163                if (post.el[1]<ytest)
164                {
165                     if (post.el[2]<ztest1)
166                        count[0] += nearest_pixel(imptrs,posi);
167                     else if (post.el[2]<ztest2)
168                        count[1] += nearest_pixel(imptrs,posi);
169                     else
170                        count[2] += nearest_pixel(imptrs,posi);
171                }
172                else if(post.el[1]<nimptruy)
173                {
174                     if (post.el[2]<ztest1)
175                        count[3] += nearest_pixel(imptrs,posi);
176                     else if (post.el[2]<ztest2)
177                        count[4] += nearest_pixel(imptrs,posi);
178                     else
179                        count[5] += nearest_pixel(imptrs,posi); 
180                }
181            }
182            else
183            {
184                if (post.el[1]<ytest)
185                {
186                     if (post.el[2]<ztest1)
187                        count[6] += nearest_pixel(imptrs,posi);
188                     else if (post.el[2]<ztest2)
189                        count[7] += nearest_pixel(imptrs,posi);
190                     else
191                        count[8] += nearest_pixel(imptrs,posi); 
192                }
193                else if(post.el[1]<nimptruy)
194                {
195                     if (post.el[2]<ztest1)
196                        count[9] += nearest_pixel(imptrs,posi);
197                     else if (post.el[2]<ztest2)
198                        count[10] += nearest_pixel(imptrs,posi);
199                     else
200                        count[11] += nearest_pixel(imptrs,posi); 
201                }
202            }
203            }
204        }
205     }
206     }
207     /* now multiply numbers of voxels by voxel sizes (of brain loaded in as 'reslice', since this gives the original voxel sizes now that the air file has been swapped)  to get volumes in cubic
208 mm */
209     get_iscales(&xscale, &yscale, &zscale);
210     scale = xscale*yscale*zscale;
211     format(" absolute volumes and distances in cubic mm \n");
212     format(" --a %f --b %f  --c %f \n",count[0]*scale,count[1]*scale,count[2]*scale);
213     format(" -+a %f -+b %f  -+c %f \n",count[3]*scale,count[4]*scale,count[5]*scale);
214     format(" +-a %f +-b %f  +-c %f \n",count[6]*scale,count[7]*scale,count[8]*scale);
215     format(" ++a %f ++b %f  ++c %f \n",count[9]*scale,count[10]*scale,count[11]*scale);
216     /* In order to be able to scale these volumes into the standard brain space we need to know the total dimensions of the brain being analyzed in mm - measured as the distance between extreme csf voxels */ 
217     /* distance measured in the standard frame, scaled back into the frame of data being analyzed, to give absolute distance in mm */
218     xdist = sqrt(xscale*xscale*
219                 (iimptrux.el[0]-iimptrlx.el[0])*(iimptrux.el[0]-iimptrlx.el[0])
220                + yscale*yscale*
221                 (iimptrux.el[1]-iimptrlx.el[1])*(iimptrux.el[1]-iimptrlx.el[1])
222                + zscale*zscale*
223                 (iimptrux.el[2]-iimptrlx.el[2])*(iimptrux.el[2]-iimptrlx.el[2]));
224     ydist = sqrt(xscale*xscale*
225                 (iimptruy.el[0]-iimptrly.el[0])*(iimptruy.el[0]-iimptrly.el[0])
226                + yscale*yscale*
227                 (iimptruy.el[1]-iimptrly.el[1])*(iimptruy.el[1]-iimptrly.el[1])
228                + zscale*zscale*
229                 (iimptruy.el[2]-iimptrly.el[2])*(iimptruy.el[2]-iimptrly.el[2]));
230     zdist = sqrt(xscale*xscale*
231                 (iimptruz.el[0]-iimptrlz.el[0])*(iimptruz.el[0]-iimptrlz.el[0])
232                + yscale*yscale*
233                 (iimptruz.el[1]-iimptrlz.el[1])*(iimptruz.el[1]-iimptrlz.el[1])
234                + zscale*zscale*
235                 (iimptruz.el[2]-iimptrlz.el[2])*(iimptruz.el[2]-iimptrlz.el[2]));
236     format(" x extent mm %f, y extent mm %f, z extent mm %f \n", 
237            xdist, ydist, zdist );
238 
239         string_append(fullname, directory, pat_name, ".tvs", NULL);
240     patient = fopen(fullname, "w");
241     if(patient!=NULL)
242       { 
243         /* stuff to print the data to a file as well */
244         fprintf(patient, " %s %s %f\n", pat_name, pat_diag, pat_age);
245         fprintf(patient, " --a %f --b %f  --c %f \n",count[0]*scale,count[1]*scale,count[2]*scale);
246         fprintf(patient, " -+a %f -+b %f  -+c %f \n",count[3]*scale,count[4]*scale,count[5]*scale);
247         fprintf(patient, " +-a %f +-b %f  +-c %f \n",count[6]*scale,count[7]*scale,count[8]*scale);
248         fprintf(patient, " ++a %f ++b %f  ++c %f \n",count[9]*scale,count[10]*scale,count[11]*scale);
249         fprintf(patient, " x mm %f, y mm %f, z mm %f \n", xdist,ydist,zdist);
250         
251         fclose(patient);
252       }
253 
254 }
255 

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