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

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

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

  1 #include <stdio.h>
  2 #include <tina/sys.h>
  3 #include <tina/sysfuncs.h>
  4 #include <tina/math.h>
  5 #include <tina/mathfuncs.h>
  6 #include <tina/tv.h>
  7 #include <tina/vision.h>
  8 #include <tina/visionfuncs.h>
  9 #include <tina/image.h>
 10 #include <tina/seqdefs.h>
 11 #include <tina/seqoral.h>
 12 #include <tina/seqpro.h>
 13 #include <tina/AIR.h>
 14 
 15 extern parse_fname(char *bnam,char*fname,int fnum);
 16 extern void ***coreg_limits(int *lz, int *uz, int *ly, int *uy, int *lx, int *ux);
 17 static double xcentre=128.0, ycentre=128.0, zcentre=40.0;
 18 static double threshold=600.0, bscale = 0.75, border = 2.0;
 19 static int fnum=0, tnum=0;
 20 static struct air16 air1;
 21 static void *ape1, *ape2, *ape3;
 22 static void *ape4, *ape5, *ape6;
 23 static void *ape7, *ape8, *ape9;
 24 static void *ate1, *ate2, *ate3;
 25 static void *af1, *af2;
 26 static void *avs1, *avs2, *avs3;
 27 static void *avr1, *avr2, *avr3;
 28 static void *ads1,*ads2,*ads3;
 29 static void *adr1,*adr2,*adr3;
 30 static void *pfnum;
 31 /* mjs age pointer */
 32 static void *age, *nam, *dia, *pdir;
 33 
 34 extern double xscale;
 35 extern double yscale;
 36 extern double zscale;
 37 extern double nxscale;
 38 extern double nyscale;
 39 extern double nzscale;
 40 extern double ex[3], ey[3], ez[3], ec[3];
 41 static double zoomfac =1.0;
 42 static void *psx,*psy,*psz;
 43 static char datafile[128];
 44 static char cpfile[128];
 45 /* mjs name of patient, age and diagnosis */
 46 /* I think these have to be extern so they can be read by csf_count12 */
 47 
 48 extern char pat_name[30];
 49 extern char pat_diag[30];
 50 extern double pat_age;
 51 extern char directory[64];
 52 
 53 /* end */
 54 static int coreg_im;
 55 static int mask = 3;
 56 
 57 /* Modified 12/10/01 PAB: batch reslicing along z axis and transfer of threshold to coreg_view.c */
 58 
 59 extern Imrect *get_xcoreg_im();
 60 extern Imrect *get_ycoreg_im();
 61 extern Imrect *get_zcoreg_im();
 62 extern seq_free_proc();
 63 extern List *get_stack_ptr();
 64 
 65 double transfer_threshold_to_coreg_view()
 66 {
 67         return threshold;
 68 }
 69 
 70 static void par_choice_notify_proc(int value)
 71 {
 72    extern void set_coreg_zoom(double zfac, int mask);
 73    mask = value;
 74    set_coreg_zoom(zoomfac,mask);
 75 }
 76 
 77 reset_air()
 78 {
 79     tw_fglobal_reset(ape1);
 80     tw_fglobal_reset(ape2);
 81     tw_fglobal_reset(ape3);
 82     tw_fglobal_reset(ape4);
 83     tw_fglobal_reset(ape5);
 84     tw_fglobal_reset(ape6);
 85     tw_fglobal_reset(ape7);
 86     tw_fglobal_reset(ape8);
 87     tw_fglobal_reset(ape9);
 88     tw_fglobal_reset(ate1);
 89     tw_fglobal_reset(ate2);
 90     tw_fglobal_reset(ate3);
 91     tw_sglobal_reset(af1);
 92     tw_sglobal_reset(af2);
 93     tw_fglobal_reset(avs1);
 94     tw_fglobal_reset(avs2);
 95     tw_fglobal_reset(avs3);
 96     tw_fglobal_reset(avr1);
 97     tw_fglobal_reset(avr2);
 98     tw_fglobal_reset(avr3);
 99     tw_iglobal_reset(ads1);
100     tw_iglobal_reset(ads2);
101     tw_iglobal_reset(ads3);
102     tw_iglobal_reset(adr1);
103     tw_iglobal_reset(adr2);
104     tw_iglobal_reset(adr3);
105 }
106 
107 reset_centre(double new_x, double new_y, double new_z)
108 {
109     xcentre = new_x;
110     ycentre = new_y;
111     zcentre = new_z;
112     tw_fglobal_reset(psx);
113     tw_fglobal_reset(psy);
114     tw_fglobal_reset(psz);
115 }
116 
117 static void inc_fnum_proc(void)
118 {
119   void set_replay_break();
120   fnum++;
121   tw_iglobal_reset(pfnum);
122   if (fnum == tnum) set_replay_break();
123 }
124 
125 static void dec_fnum_proc(void)
126 {
127   void set_replay_break();
128   fnum--;
129   tw_iglobal_reset(pfnum);
130   if (fnum == tnum) set_replay_break();
131 }
132 
133 static void read_air_proc()
134 {
135   int read_air16(char* inputfile, struct air16* air);
136   void set_coreg_trans(struct air16 air1);
137   void set_coreg_centre(double slicex, double slicey, double slicez);
138 
139   strcpy(cpfile,datafile);
140   parse_fname(NULL,cpfile,fnum);
141   read_air16(cpfile,&air1);
142   set_coreg_centre(xcentre,ycentre,zcentre);
143   set_coreg_trans(air1);
144   reset_air();
145 }
146 
147 static void write_air_proc()
148 {
149   void get_coreg_trans(struct air16 *air1);
150   int write_air16(char *outputfile,int permission, struct air16 *air1);
151 
152   get_coreg_trans(&air1);
153   parse_fname(NULL,datafile,fnum);
154   write_air16(datafile,0,&air1);
155 }
156 
157 static void     tv_choice_proc(int val)
158 {
159     Tv *xcoreg_tv_get();
160     Tv *ycoreg_tv_get();
161     Tv *zcoreg_tv_get();
162 
163     coreg_im = val; 
164 
165     switch (val)
166     {
167         case 0:
168           if (!zcoreg_tv_get()) zcoreg_tv_make();
169           tv_set_next(zcoreg_tv_get());
170         break;
171         case 1:
172           if (!ycoreg_tv_get()) ycoreg_tv_make();
173           tv_set_next(ycoreg_tv_get());
174         break;
175         case 2:
176           if (!xcoreg_tv_get()) xcoreg_tv_make();
177           tv_set_next(xcoreg_tv_get());
178         break;
179     }
180 
181 }
182 
183 static void     reslice_choice_proc(int val)
184 {
185    extern void set_interp_choice(int choice);
186    set_interp_choice(val);
187 }
188 
189 static void air_invert_proc()
190 {
191     void get_coreg_trans(struct air16 *air1);
192     void set_coreg_trans(struct air16 air1);
193     char swapf[128];
194     struct key_info key;
195     double new_e[4][4];
196     double min_size;
197 
198     get_coreg_trans(&air1);
199     strcpy(swapf,air1.r_file);
200     strcpy(air1.r_file,air1.s_file);
201     strcpy(air1.s_file,swapf);
202     key = air1.r;
203     air1.r = air1.s;
204     air1.s = key;
205 /* rescale back to cubic coordinates */
206     min_size = MIN(MIN(air1.r.x_size,air1.r.y_size),air1.r.z_size);
207     new_e[0][0] = air1.e[0][0]*air1.r.x_size/min_size; 
208     new_e[0][1] = air1.e[1][0]*air1.r.x_size/min_size; 
209     new_e[0][2] = air1.e[2][0]*air1.r.x_size/min_size; 
210     new_e[0][3] = air1.e[3][0]*air1.r.x_size/min_size; 
211     new_e[1][0] = air1.e[0][1]*air1.r.y_size/min_size; 
212     new_e[1][1] = air1.e[1][1]*air1.r.y_size/min_size; 
213     new_e[1][2] = air1.e[2][1]*air1.r.y_size/min_size; 
214     new_e[1][3] = air1.e[3][1]*air1.r.y_size/min_size; 
215     new_e[2][0] = air1.e[0][2]*air1.r.z_size/min_size;
216     new_e[2][1] = air1.e[1][2]*air1.r.z_size/min_size;
217     new_e[2][2] = air1.e[2][2]*air1.r.z_size/min_size;
218     new_e[2][3] = air1.e[3][2]*air1.r.z_size/min_size;
219 
220 /*  translation of coordinates */
221     new_e[3][0] = -(new_e[0][3]*new_e[0][0] 
222                   + new_e[1][3]*new_e[1][0] 
223                   + new_e[2][3]*new_e[2][0]);
224     new_e[3][1] = -(new_e[0][3]*new_e[0][1] 
225                   + new_e[1][3]*new_e[1][1]
226                   + new_e[2][3]*new_e[2][1]);
227     new_e[3][2] = -(new_e[0][3]*new_e[0][2] 
228                   + new_e[1][3]*new_e[1][2]
229                   + new_e[2][3]*new_e[2][2]);
230 
231     min_size = MIN(MIN(air1.s.x_size,air1.s.y_size),air1.s.z_size);
232 /* back to non cubic pixel coordinates */
233     air1.e[0][0] = new_e[0][0]*min_size/air1.s.x_size;
234     air1.e[1][0] = new_e[1][0]*min_size/air1.s.x_size;
235     air1.e[2][0] = new_e[2][0]*min_size/air1.s.x_size;
236     air1.e[3][0] = new_e[3][0]*min_size/air1.s.x_size;
237     air1.e[0][1] = new_e[0][1]*min_size/air1.s.y_size;
238     air1.e[1][1] = new_e[1][1]*min_size/air1.s.y_size;
239     air1.e[2][1] = new_e[2][1]*min_size/air1.s.y_size;
240     air1.e[3][1] = new_e[3][1]*min_size/air1.s.y_size;
241     air1.e[0][2] = new_e[0][2]*min_size/air1.s.z_size;
242     air1.e[1][2] = new_e[1][2]*min_size/air1.s.z_size;
243     air1.e[2][2] = new_e[2][2]*min_size/air1.s.z_size;
244     air1.e[3][2] = new_e[3][2]*min_size/air1.s.z_size;
245     set_coreg_trans(air1);
246     reset_air();
247 }
248 
249 static void zoom_proc()
250 {
251    extern void coreg_redraw();
252    extern void set_coreg_zoom(double zfac, int mask);
253    extern void reset_tv_coords();
254    void set_coreg_centre(double slicex, double slicey, double slicez);
255    set_coreg_centre(xcentre,ycentre,zcentre);
256    set_coreg_zoom(zoomfac,mask);
257    reset_tv_coords();
258    coreg_redraw();
259 }
260 
261 static void air_load_proc()
262 {
263 }
264 
265 static void coreg_push_proc()
266 {
267    Imregion *roi;
268    extern Imregion *tv_get_im_roi();
269    extern Tv *zcoreg_tv_get();
270    extern Tv *ycoreg_tv_get();
271    extern Tv *xcoreg_tv_get();
272    extern Imrect *coreg_slicez(float zslice, Imregion *within);
273    extern Imrect *coreg_slicey(float yslice, Imregion *within);
274    extern Imrect *coreg_slicex(float xslice, Imregion *within);
275    Imrect *im = NULL;
276 
277    if (coreg_im == 0)
278    {
279        roi = tv_get_im_roi(zcoreg_tv_get());
280        im = coreg_slicez((float)zcentre,roi);
281        rfree(roi);
282    }
283    if (coreg_im == 1)
284    {
285        roi = tv_get_im_roi(ycoreg_tv_get());
286        im = coreg_slicey((float)ycentre,roi);
287        rfree(roi);
288    }
289    if (coreg_im == 2)
290    {
291        roi = tv_get_im_roi(xcoreg_tv_get());
292        im = coreg_slicex((float)xcentre,roi);
293        rfree(roi);
294    }
295    if (im!=NULL) stack_push((void *)im, IMRECT,im_free);
296    imcalc_draw(imcalc_tv_get());
297    imcalc_draw(imcal2_tv_get());
298    image_choice_reset();
299 }
300 
301 static void coreg_auto_proc()
302 {
303    extern void reset_tv_coords();
304    extern void coreg_redraw();
305    extern coreg_auto(double threshold, double bscale, double border , int mask);
306    coreg_auto(threshold,bscale,border,mask);
307    reset_air();
308    reset_tv_coords();
309    coreg_redraw();
310 }
311 
312 static void     coreg_check_proc(int val)
313 {
314     extern void latch_slices(int im_type);
315     extern void latch_clear();
316     static int old_val=0;
317     Sequence *seq = get_seq_ptr();
318     
319     if (val==0) latch_clear();
320     if(val>0) 
321     {
322        if (old_val <1) strcpy(air1.s_file,seq->filename);
323        latch_slices(val);
324     }
325     old_val = val;
326 }
327 
328 static void last_slice_proc()
329 {
330     if(coreg_im == 0) reset_centre(xcentre,ycentre,zcentre-1.0);
331     if(coreg_im == 1) reset_centre(xcentre,ycentre-1.0,zcentre);
332     if(coreg_im == 2) reset_centre(xcentre-1.0,ycentre,zcentre);
333 }
334 
335 static void next_slice_proc()
336 {
337     if(coreg_im == 0) reset_centre(xcentre,ycentre,zcentre+1.0);
338     if(coreg_im == 1) reset_centre(xcentre,ycentre+1.0,zcentre);
339     if(coreg_im == 2) reset_centre(xcentre+1.0,ycentre,zcentre);
340 }
341 
342 
343 static void batch_reslice()
344 {
345         /* Reslice whole volume at once along the z axis. PAB 12/10/01 */
346 
347         int i, old_coreg_im, uy, ly;
348         Imrect *y_im; 
349         Imregion *roi;
350         void ***imptrs=NULL;
351         float old_zslice;
352 
353         y_im = get_ycoreg_im();
354         if(y_im==NULL) return;
355         roi = y_im->region;
356 
357         ly = roi->ly;
358         uy = roi->uy;   
359 
360         old_zslice=zcentre;
361         old_coreg_im=coreg_im;
362         coreg_im=0;
363 
364         for(i=ly; i<uy; i++)
365         {
366                 zcentre = (float)i+0.5;
367                 reset_centre(xcentre, ycentre, zcentre);
368                 coreg_push_proc();
369         }
370 
371         zcentre = old_zslice;
372         reset_centre(xcentre, ycentre, zcentre);
373         coreg_im=old_coreg_im;
374 }
375 
376 
377 static void batch_seq_proc()
378 {
379         Vec3 *iscale=NULL;
380         void stack_seq(Vec3 *iscale);   
381 
382         /* Delete and replace sequence with results of batch reslicing */
383 
384         iscale = vec3_alloc();
385         iscale->el[0] = nxscale;
386         iscale->el[1] = nyscale;
387         iscale->el[2] = nzscale;
388 
389         stack_seq(iscale);
390 }
391 
392 
393 static void set_rfile_proc(struct air16 *rair)
394 {
395     void set_rfile(struct air16 *air1, int num);
396     set_rfile(rair,fnum);
397 }
398 
399 static void air_param_dialog_proc()
400 {
401     static void *dialog = NULL;
402     void set_sfile(struct air16 *air1);
403 
404     if (dialog)
405     {
406         tw_show_dialog(dialog);
407         return;
408     }
409     dialog = (void *)tw_dialog("AIR Parameters");
410 
411     af1 = (void *) tw_sglobal("Standard:",&air1.s_file,42); 
412     tw_newrow();
413     ads1 = (void *) tw_iglobal("dimensions :",&air1.s.x_dim,10);
414     ads2 = (void *) tw_iglobal("",&air1.s.y_dim,10);
415     ads3 = (void *) tw_iglobal("",&air1.s.z_dim,10);
416     tw_button("set S",set_sfile,&air1);
417     tw_newrow();
418     avs1 = (void *) tw_fglobal("Scale:", &nxscale, 12);
419     avs2 = (void *) tw_fglobal("", &nyscale, 12);
420     avs3 = (void *) tw_fglobal("", &nzscale, 12);
421     tw_newrow();
422     af2 = (void *) tw_sglobal("Reslice :",&air1.r_file,42); 
423     tw_newrow();
424     adr1 = (void *) tw_iglobal("dimensions :",&air1.r.x_dim,10);
425     adr2 = (void *) tw_iglobal("",&air1.r.y_dim,10);
426     adr3 = (void *) tw_iglobal("",&air1.r.z_dim,10);
427     tw_button("set R",set_rfile_proc,&air1);
428     tw_newrow();
429     avr1 = (void *) tw_fglobal("Scale:", &xscale, 12);
430     avr2 = (void *) tw_fglobal("", &yscale, 12);
431     avr3 = (void *) tw_fglobal("", &zscale, 12);
432     tw_newrow();
433     ape1 = (void *) tw_fglobal("Er :", &ex[0], 16);
434     ape2 = (void *) tw_fglobal("", &ex[1], 16);
435     ape3 = (void *) tw_fglobal("", &ex[2], 16);
436     tw_newrow();
437     ape4 = (void *) tw_fglobal("   :", &ey[0], 16);
438     ape5 = (void *) tw_fglobal("", &ey[1], 16);
439     ape6 = (void *) tw_fglobal("", &ey[2], 16);
440     tw_newrow();
441     ape7 = (void *) tw_fglobal("   :", &ez[0], 16);
442     ape8 = (void *) tw_fglobal("", &ez[1], 16);
443     ape9 = (void *) tw_fglobal("", &ez[2], 16);
444     tw_newrow();
445     ate1 = (void *) tw_fglobal("Et :", &ec[0], 16);
446     ate2 = (void *) tw_fglobal("", &ec[1], 16);
447     ate3 = (void *) tw_fglobal("", &ec[2], 16);
448     tw_newrow();
449     tw_fglobal("threshold:",&threshold,8);
450     tw_fglobal("blur scale:",&bscale,8);
451     tw_fglobal("border:",&border,8);
452 
453     tw_end_dialog();
454 }
455 
456 static air_init()
457 {
458    air1.r.x_dim = air1.s.x_dim = 256;
459    air1.r.y_dim = air1.s.y_dim = 256;
460    air1.r.z_dim = air1.s.z_dim = 40;
461 
462    air1.r.x_size = air1.s.x_size = 1.0;
463    air1.r.y_size = air1.s.y_size = 1.0;
464    air1.r.z_size = air1.s.z_size = 1.0;
465 
466    air1.e[0][0] = 1.0;
467    air1.e[0][1] = 0.0;
468    air1.e[0][2] = 0.0;
469    air1.e[1][0] = 0.0;
470    air1.e[1][1] = 1.0;
471    air1.e[1][2] = 0.0;
472    air1.e[2][0] = 0.0;
473    air1.e[2][1] = 0.0;
474    air1.e[2][2] = 1.0;
475    air1.e[3][0] = 0.0;
476    air1.e[3][1] = 0.0;
477    air1.e[3][2] = 0.0;  
478 }
479 
480 void         coreg_tool(int x, int y)
481 {
482    static int   tool = 0;
483    void csf_count12_proc();
484    void dump_proc(struct air16 *air1);
485 
486    if (tool)
487      {
488        tw_show_tool(tool);
489        return;
490      }
491 
492    air_init();
493 
494    tool = tw_tool("Coreg Tool", x, y);
495  
496    tw_choice("Tv : ", tv_choice_proc, 0,
497              "z coreg", "y coreg", "x coreg", NULL);
498    tw_fglobal("factor",&zoomfac,8);
499    tw_button("zoom", zoom_proc, NULL);
500    tw_help_button("coreg_tool");
501    tw_newrow();
502    psx = (void *) tw_fglobal("Centre x :", &xcentre, 9);
503    psy = (void *) tw_fglobal(" y :", &ycentre, 9);
504    psz = (void *) tw_fglobal(" z :", &zcentre, 9);
505    tw_button("<", last_slice_proc, NULL);
506    tw_button(">", next_slice_proc, NULL);
507    tw_newrow();
508    tw_choice("Reslice : ", reslice_choice_proc, 0,
509              "nearest", "linear","sinc5","sinc7",
510              NULL);
511 
512    tw_button("push", coreg_push_proc, NULL);
513    tw_button("z reslice", batch_reslice, NULL);
514    tw_newrow();
515  
516    tw_choice("Latch Display : ", coreg_check_proc, 0,
517            "image","anaglyph", "edges", "chequer",  NULL);
518 
519    tw_newrow();
520    tw_button("params", air_param_dialog_proc, NULL);
521    tw_check("Model", par_choice_notify_proc, mask,
522             "Trans", "Rot", "Scale", NULL);
523    tw_button("auto",coreg_auto_proc,NULL);
524    tw_newrow();
525 
526    (void *)tw_sglobal("Air File:", datafile, 36);
527    tw_button("input", read_air_proc, NULL);
528    tw_button("output", write_air_proc, NULL);
529    tw_newrow();
530    pfnum = (void *) tw_iglobal("data",&fnum,3);
531    tw_button("dec", dec_fnum_proc, NULL);
532    tw_button("inc", inc_fnum_proc, NULL);
533    tw_iglobal("break",&tnum,3);
534  
535  
536    tw_newrow();
537    tw_button("swap",air_invert_proc,NULL);
538    tw_button("dump",dump_proc,&air1);
539    tw_button("12 way",csf_count12_proc,NULL);
540    tw_button("Stack->seq", batch_seq_proc, NULL);
541    tw_newrow();
542    pdir = (void *) tw_sglobal("Directory: ", directory, 40);
543    tw_newrow();
544    age = (void *)tw_fglobal("Age: ", &pat_age, 8);
545    tw_newrow();
546    nam = (void *)tw_sglobal("Name: ", pat_name, 30);
547    tw_newrow();
548    dia = (void *)tw_sglobal("Diagnosis: ", pat_diag, 25);
549 
550    tw_end_tool();
551 }
552 
553 

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