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

Linux Cross Reference
Tina4/src/tools/nmr-segment/nmr_segment_tool.c

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

  1 /*
  2   nmr_segment_tool.c
  3 
  4   n.thacker
  5   a.lacey   3.2.98
  6 */
  7 
  8 #include <stdio.h>
  9 #include <tina/sys.h>
 10 #include <tina/sysfuncs.h>
 11 #include <tina/math.h>
 12 #include <tina/mathfuncs.h>
 13 #include <tina/vision.h>
 14 #include <tina/visionfuncs.h>
 15 #include <tina/tv.h>
 16 #include <tina/tvfuncs.h>
 17 #include <tina/draw.h>
 18 #include <tina/drawfuncs.h>
 19 #include <tina/seqoral.h>
 20 #include <tina/seqpro.h>
 21 #include <tina/stimdef.h>
 22 #include <tina/hist_funcs.h>
 23 
 24 #define AIFF_FILE       0
 25 #define ANLZ_FILE       1
 26 #define RAD_FILE        2
 27 #define NEMA_FILE       3
 28 #define MIPL_FILE       4
 29 #define AVS_FILE        5
 30 
 31 Tv     *imcalc_tv_get(void);
 32 Tv     *imcal2_tv_get(void);
 33 int param_num = 1;
 34 
 35 double *a =NULL;
 36 void *pcsf_sigma = NULL;
 37 void *pgrey_sigma = NULL;
 38 void *pwhite_sigma = NULL;
 39 void *pcsf_peak = NULL;
 40 void *pgrey_peak = NULL;
 41 void *pwhite_peak = NULL;
 42 void *pcsf_peak1 = NULL;
 43 void *pgrey_peak1 = NULL;
 44 void *pwhite_peak1 = NULL;
 45 void *pcsf_peak2 = NULL;
 46 void *pgrey_peak2 = NULL;
 47 void *pwhite_peak2 = NULL;
 48 double csf_sigma = 15.0;
 49 double grey_sigma = 65.0;
 50 double white_sigma = 15.0;
 51 double csf_peak = -1670.0;
 52 double grey_peak = -600.0;
 53 double white_peak = -100.0;
 54 double csf_min = -1800;
 55 double white_max = 0.0;
 56 double p1c = -500.0;
 57 double p1g = -20.0;
 58 double p1w = 40.0;
 59 double p2c = -1670.0;
 60 double p2g = -600.0;
 61 double p2w = -100.0;
 62 int seg_im;
 63 static double ave_ttp = 7.0;
 64 static double min_t0 = 18.0;
 65 void *pt0 = NULL;
 66 static double scl = 10000.0;
 67 static double recirc_cut = 0.2;
 68 static double recirc_period = 10.0;
 69 
 70 shistogram *peaks = NULL;
 71 
 72 static int        pmap;
 73 static int        hwave = 3;
 74 static int        offset = 0;
 75 static int        phlw = 0, phup = 1;
 76 static int        corr_func_type = 0;
 77 
 78 static Bool       stim_phase_on = false;
 79 static void      *pperiod = NULL;
 80 static void      *poffset = NULL;
 81 static double     iphase = -1.0;
 82 
 83 static char       patient[256];
 84 static char       notes[256];
 85 static char       repname[256];
 86 
 87 
 88 static void stim_phase_choice_proc(int val)
 89 {
 90    if (val > 0)
 91       stim_phase_on = true;
 92    else
 93       stim_phase_on = false;   
 94 }
 95 
 96 
 97 
 98 static void corr_func_choice_proc(int val)
 99 {
100    corr_func_type = val;
101 }
102 
103 static void pmap_func_choice_proc(int val)
104 {
105    Imrect *gfit_get_image(int perf_type);
106    pmap = val;
107    stack_push((void *)gfit_get_image(pmap), IMRECT, im_free);
108 
109    if (imcalc_tv_get()!=NULL) tv_init(imcalc_tv_get());
110    if (imcal2_tv_get()!=NULL) tv_init(imcal2_tv_get());
111    image_choice_reset();
112 }
113 
114 
115 static void     map_choice_proc(int val)
116 {
117     seg_im = val; 
118 }
119 
120 static void stim_acquire_proc(int val)
121 {
122   void    stim_sqrwave_acqu(int *hwave, int offset, float i);
123   void    stim_sinwave_acqu(int *hwave, int offset, float i);
124   void    stim_roi_acqu(Imrect *im, int *hwave);
125 
126   Imrect *tmask = NULL;
127   int     type;
128 
129   switch (val)
130     {
131     case SCORR_SQR:
132       stim_sqrwave_acqu(&hwave, offset, (float)iphase);
133       break;
134     
135     case SCORR_SIN:
136       stim_sinwave_acqu(&hwave, offset, (float)iphase);
137       break;
138 
139     case SCORR_ROI:
140       stim_roi_acqu((Imrect *)NULL, &hwave);
141       break;
142 
143     case SCORR_PREV:
144       if (stack_check_types(IMRECT, NULL) == false)
145         {
146           error("stim_acquire: wrong type on stack", warning);
147           return;
148         }
149       tmask = (Imrect *) stack_pop(&type);
150       stim_roi_acqu(tmask, &hwave);
151       stack_push((void *)tmask, IMRECT, im_free);
152       break;
153     }
154     plot_stimfunc();
155 }
156 
157 
158 void stim_compare_proc(void)
159 {
160    Tv     *imcalc_tv_get(void);
161    Tv     *imcal2_tv_get(void);
162    int     type;
163 
164    stack_push((void *)stim_corr(offset, corr_func_type), IMRECT, im_free);
165    
166    if (imcalc_tv_get()!=NULL) tv_init(imcalc_tv_get());
167    if (imcal2_tv_get()!=NULL) tv_init(imcal2_tv_get());
168    image_choice_reset();
169 }
170 
171 
172 
173 static void     nearest_proc(void)
174 {
175    Imrect  *imf_knn_density(int neighbours, Imregion *test_roi);
176    Imrect         *im;
177    Imregion *roi = tv_get_im_roi(seq_tv_get());
178    int             type;
179 
180    im = imf_knn_density(10, roi);
181    stack_push(im, IMRECT, im_free);
182    if (imcalc_tv_get()!=NULL) tv_init(imcalc_tv_get());
183    if (imcal2_tv_get()!=NULL) tv_init(imcal2_tv_get());
184    image_choice_reset();
185 }
186 
187 
188 
189 static void  gen_art_proc()
190 {
191   Imrect  *im;
192   int      a, i, j;
193   int      b, c;
194   float    mu, mu1, mu2;
195 
196   mu1 = 100.0;
197   mu2 = 0.0;
198   b = 1;
199 
200   for (a = 0; a < 17; a++)
201     {
202       im = im_alloc(256, 256, NULL, float_v);
203       c = 0;
204       for (i = im->region->ly; i < im->region->uy; ++i)
205         {
206           if (c == 10) 
207             { b++; c = 0; }
208           else
209             c++;
210           /*
211           for (j = im->region->lx; j < im->region->ux; ++j)
212             {
213               if (j > (im->region->ux/2))
214                 {
215                   if ((b/hwave)%2)
216                     mu = mu1;
217                   else
218                     mu = mu2;
219                   IM_SHORT(im, i, j) = mu;
220                 }
221               else
222                 IM_SHORT(im, i, j) = 2.0;
223             }
224           
225           */
226           for (j = im->region->lx; j < im->region->ux; ++j)
227             {
228               if (j > (im->region->ux/2))
229                 {
230                   if ((b/hwave)%2)
231                     mu = mu1;
232                   else
233                     mu = mu2;
234                   IM_FLOAT(im, i, j) = rand_normal((double)mu, 10.0);
235                 }
236               else
237                 IM_FLOAT(im, i, j) = rand_normal(0.0, 1.0);
238             }
239           
240         }
241 
242       stack_push((void *)im, IMRECT, im_free);
243     }
244 }
245 
246 static void  mk_report()
247 {
248   void   flow_report(char *p, char *a, char *n);
249   
250   flow_report(repname, patient, notes);
251 }
252 
253 
254 static void  gen_report_proc()
255 {
256   static void *dialog = NULL;
257 
258   if (dialog)
259     {
260       tw_show_dialog(dialog);
261       return;
262     }
263 
264   dialog = (void *)tw_dialog("Flow report generator");
265   tw_sglobal("Report file:", repname, 40);
266   tw_newrow();
267   tw_sglobal("Patient :", patient, 40);
268   tw_newrow();
269   tw_sglobal("Notes:", notes, 40);
270   tw_newrow();
271   tw_button("Go", mk_report, NULL);
272   tw_end_dialog();
273 }
274 
275 
276 static void  plot_stimfunc_proc()
277 {
278   plot_stimfunc();
279 }
280 
281 
282 static void  plot_flow_proc()
283 {
284   void   plot_flow(void);
285   void   pl_measures(void);
286 
287   plot_flow();
288   pl_measures();
289 }
290 
291 
292 
293 static void  plot_ctflow_proc()
294 {
295   void   plot_ct_flow(void);
296   void   pl_measures(void);
297 
298   plot_ct_flow();
299   pl_measures();
300 }
301 
302 void get_perf_params(float *AVE_TTP, float *MIN_T0, float *RECIRC_CUT,
303                      float *RECIRC_PERIOD, float *SCL)
304 {
305    *AVE_TTP = ave_ttp;
306    *MIN_T0 = min_t0;
307    *SCL = scl;
308    *RECIRC_CUT = recirc_cut;
309    *RECIRC_PERIOD = recirc_period;
310 }
311 
312 
313 static void  gfit_pixels_proc()
314 {
315    void gfit_measure_image();
316    Imrect *gfit_get_image(int perf_type);
317 
318    gfit_measure_image();
319    stack_push((void *)gfit_get_image(pmap), IMRECT, im_free);
320 
321    if (imcalc_tv_get()!=NULL) tv_init(imcalc_tv_get());
322    if (imcal2_tv_get()!=NULL) tv_init(imcal2_tv_get());
323    image_choice_reset();
324 }
325 
326 static void gfit_region_proc()
327 {
328      double   pixel_gfit_region(Tv *tv, Ipos pos);
329      Tv *tv = imcalc_tv_get();
330      Ipos pos;
331      min_t0 = pixel_gfit_region(tv,pos) - 4.0;
332      tw_fglobal_reset(pt0);
333 }
334 
335 
336 static void     rusenik_switch(int value)
337 {
338   switch (value)
339     {
340     case 0:
341       p1c = csf_peak;
342       tw_fglobal_reset(pcsf_peak1);
343       break;
344     case 1:
345       p1g = grey_peak;
346       tw_fglobal_reset(pgrey_peak1);
347       break;
348     case 2:
349       p1w = white_peak;
350       tw_fglobal_reset(pwhite_peak1);
351       break;
352     case 3:
353       p2c = csf_peak;
354       tw_fglobal_reset(pcsf_peak2);
355       break;
356     case 4:
357       p2g = grey_peak;
358       tw_fglobal_reset(pgrey_peak2);
359       break;
360     case 5:
361       p2w = white_peak;
362       tw_fglobal_reset(pwhite_peak2);
363       break;
364     }
365 }
366 
367 static void     imcalc_mouse_proc(Tv_mouse(*func)())
368 {
369   Tv *imcalc_tv();
370 
371   tv_set_mouse(imcalc_tv(), (*func) ());
372   tv_set_activity(imcalc_tv(), MOUSE);
373 }
374 
375 
376 static void     seq_mouse_proc(Tv_mouse(*func)())
377 {
378   tv_set_mouse(seq_tv_get(), (*func) ());
379   tv_set_activity(seq_tv_get(), MOUSE);
380 }
381 
382 
383 
384 /*** Paramter dialog callbacks ***/
385 
386 static void     fit_param_dialog(void)
387 {
388   static void *dialog = NULL;
389 
390   if (dialog)
391     {
392       tw_show_dialog(dialog);
393       return;
394     }
395 
396   dialog = (void *)tw_dialog("Fit Parameters");
397 
398   pcsf_peak = (void *)tw_fglobal("csf  : peak ", &csf_peak, 20);
399   tw_newrow();
400   pcsf_sigma = (void *)tw_fglobal("sigma c", &csf_sigma, 20);
401   tw_newrow();
402   pgrey_peak = (void *)tw_fglobal("grey : peak ", &grey_peak, 20);
403   tw_newrow();
404   pgrey_sigma = (void *)tw_fglobal("sigma g", &grey_sigma, 20);
405   tw_newrow();
406   pwhite_peak = (void *)tw_fglobal("white: peak ", &white_peak, 20);
407   tw_newrow();
408   pwhite_sigma = (void *)tw_fglobal("sigma w", &white_sigma, 20);
409   tw_newrow();
410   (void *)tw_fglobal("csf: min ", &csf_min,  20);
411   tw_newrow();
412   (void *)tw_fglobal("white: max ", &white_max, 20);
413 
414   tw_end_dialog();
415 }
416 
417 static void     rusenik_param_dialog(void)
418 {
419     static void *dialog = NULL;
420 
421     if (dialog)
422     {
423         tw_show_dialog(dialog);
424         return;
425     }
426 
427     dialog = (void *)tw_dialog("Rusenik Parameters");
428     tw_choice("Param Reset:",
429               rusenik_switch, 0, "c1", "g1","w1","c2", "g2","w2", NULL);
430 
431     tw_newrow();
432     pcsf_peak1 = (void *)tw_fglobal("csf peak 1  :", &p1c, 20);
433     tw_newrow();
434     pgrey_peak1 = (void *)tw_fglobal("grey peak 1  :", &p1g, 20);
435     tw_newrow();
436     pwhite_peak1 = (void *)tw_fglobal("white peak 1  :", &p1w, 20);
437     tw_newrow();
438     pcsf_peak2 = (void *)tw_fglobal("csf peak 2  :", &p2c, 20);
439     tw_newrow();
440     pgrey_peak2 = (void *)tw_fglobal("grey peak 2  :", &p2g, 20);
441     tw_newrow();
442     pwhite_peak2 = (void *)tw_fglobal("white peak 2  :", &p2w, 20);
443     tw_newrow();
444 
445     tw_end_dialog();
446 }
447 
448 
449 static void     temp_param_dialog(void)
450 {
451     static void *dialog = NULL;
452 
453     if (dialog)
454     {
455         tw_show_dialog(dialog);
456         return;
457     }
458 
459     dialog = (void *)tw_dialog("Temporal Parameters");
460    
461     tw_choice("Sequence  ", corr_func_choice_proc, 2,
462             "GBAM", "STIM", "FRIS", NULL);
463     tw_newrow();
464     pperiod = (void *)tw_iglobal("period/2: ", &hwave, 5);
465     poffset = (void *)tw_iglobal("  offset: ", &offset, 5);
466     tw_newrow();
467     tw_fglobal("  iphase: ", &iphase, 5);
468     tw_end_dialog();
469 }
470 
471 static void     gfit_param_dialog(void)
472 {
473     static void *dialog = NULL;
474 
475     if (dialog)
476     {
477         tw_show_dialog(dialog);
478         return;
479     }
480 
481     dialog = (void *)tw_dialog("Gamma Parameters");
482   
483     tw_fglobal(" average ttp: ", &ave_ttp, 8);
484     tw_newrow();
485     pt0 = (void *)tw_fglobal("  minimum t0: ", &min_t0, 8);
486     tw_button("region fit", gfit_region_proc, NULL);
487     tw_newrow();
488     tw_fglobal("  recirculation cut: ", &recirc_cut, 8);
489     tw_newrow();
490     tw_fglobal("  recirculation period: ", &recirc_period, 8);
491     tw_newrow();
492     tw_fglobal("  rcbv scale: ", &scl, 8);
493 
494     tw_end_dialog();
495 }
496 
497 void         nmrsegment_tool(int x, int y)
498 {
499   Tv_mouse     nmr_linelen_mouse();
500   Tv_mouse     nmr_regsize_mouse();
501   Tv_mouse     nmr_masksize_mouse();
502   Tv_mouse     nmr_flow_mouse();
503   Tv_mouse     nmr_ctflow_mouse();
504   Tv_mouse     nmr_gfit_mouse();
505 
506   static int   tool = 0;
507   void         nmr_reset_proc(void);
508   void         nmr_fit_proc(void);
509   void         gaus_and_tri_proc(void);
510   void         rusenik(void);
511 
512   if (tool)
513     {
514       tw_show_tool(tool);
515       return;
516     }
517 
518   tool = tw_tool("NMR Segment Tool", x, y);
519 
520   tw_menubar("Imcalc Mouse:  ",
521              "measure",
522              "null", imcalc_mouse_proc, null_mouse,
523              "line", imcalc_mouse_proc, nmr_linelen_mouse,
524              "region", imcalc_mouse_proc, nmr_regsize_mouse,
525              "mask", imcalc_mouse_proc, nmr_masksize_mouse,
526              NULL, 
527              "plot",
528              "null", imcalc_mouse_proc, null_mouse,
529              "flow vs T", imcalc_mouse_proc, nmr_flow_mouse,
530              "conc/T2", imcalc_mouse_proc, nmr_ctflow_mouse,
531              "gamma fit", imcalc_mouse_proc, nmr_gfit_mouse,
532              NULL, 
533                                                   NULL);
534   tw_help_button("nmr_segment_tool");
535   tw_newrow();
536   
537   tw_button("fit params", fit_param_dialog, NULL);
538   tw_button("rusenik params", rusenik_param_dialog, NULL);
539   tw_button("stim params", temp_param_dialog, NULL);
540   tw_button("gamma params", gfit_param_dialog, NULL);
541   tw_newrow();
542 
543   tw_choice("Map Push  ", map_choice_proc, 0,
544              "csf", "grey", "white", NULL);
545   tw_button("hfit", nmr_fit_proc, NULL);
546   tw_button("prob", gaus_and_tri_proc,NULL);
547   tw_button("rusenik", rusenik, NULL);
548   tw_newrow();
549 
550   tw_choice("Stimulus   ", stim_acquire_proc, 0,
551             "SQR", "SIN", "ROI", "Mask", NULL);
552 
553   tw_button("compare", stim_compare_proc, NULL);
554   tw_newrow();
555  
556   tw_choice("Perfusion  ", pmap_func_choice_proc, 0,
557             "TTP", "CBV", "MTT", "ERR", "RCC", NULL);
558   tw_button("gamma fit", gfit_pixels_proc, NULL);
559   tw_newrow();
560 
561   tw_label("Test  ");
562   tw_button("flow/t",  plot_flow_proc, NULL);
563   tw_button("conc/t", plot_ctflow_proc, NULL);
564   tw_button("artificial", gen_art_proc, NULL);
565   tw_button("report", gen_report_proc, NULL);
566   tw_button("nearest", nearest_proc, NULL);
567   tw_end_tool();
568 
569 }
570 

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