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

Linux Cross Reference
Tina6/tina-tools/tinatool/tlmedical/tlmedAnl_ct_mouse.c

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

  1 /**********
  2  *
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  *
 35  * Program :    TINA
 36  * File    : 
 37  * Date    : 
 38  * Version : 
 39  * CVS Id  : 
 40  *
 41  * Notes : 
 42  *
 43  *********
 44 */
 45 
 46 #include "tlmedAnl_ct_mouse.h"
 47 
 48 #if HAVE_CONFIG_H
 49 #   include <config.h>
 50 #endif
 51 
 52 #include <stdio.h>
 53 #include <math.h>
 54 #include <float.h>
 55 
 56 #include <tina/sys/sysDef.h>
 57 #include <tina/sys/sysPro.h>
 58 #include <tina/math/mathDef.h>
 59 #include <tina/math/mathPro.h>
 60 #include <tina/image/imgDef.h>
 61 #include <tina/image/imgPro.h>
 62 #include <tina/medical/medDef.h>
 63 #include <tina/medical/medPro.h>
 64 #include <tinatool/draw/drawDef.h>
 65 #include <tinatool/draw/drawPro.h>
 66 #include <tinatool/tlbase/tlbaseDef.h>
 67 #include <tinatool/tlbase/tlbasePro.h>
 68 
 69 static void ***imptrs = NULL;
 70 static Vec2 start_line;
 71 static Vec2 end_line;
 72 static Vec2 p1 = {Vec2_id};
 73 static Vec2 p2 = {Vec2_id};
 74 static List *roi_poly = NULL;
 75 
 76 
 77 static void   ct_pixel_gfit_plot(Tv *tv, Ipos pos)
 78 {
 79   Perfusion *p = NULL;
 80   Vec2       loc = {Vec2_id};  
 81   Sequence *seq = seq_get_current();
 82   Tv        *tv_g = (Tv *)imcalc_graph_tv();
 83   float     *time, *x, *y1, *y2;
 84   void    ***imptrs;
 85   int        length, i;
 86   float      single_time;
 87   
 88   if ((tv_g == NULL) || (tv_g->tv_screen == NULL))
 89     return;
 90 
 91   loc = tv_backproj2(tv, pos);
 92   p = perfusion_alloc();
 93   seq = (Sequence *)seq_get_current();
 94 
 95   if ((single_time = seq->dim[3]) == 0.0)
 96     {
 97       error("gamma_fit_proc: timing info may be missing", warning);
 98       return;
 99     }
100 
101   imptrs = seq_slice_init(seq);
102   ct_gamma_fit_pixel(p, loc, imptrs);
103   length = (p->n2 -  p->n1);
104   time = (float *)fvector_alloc(0, length);
105   for (i = 0; i < length; i++)
106     {
107       time[i] = i * single_time;
108     }
109 
110   x = time;
111   if (p->r2 != NULL && p->r2_ther !=NULL)
112   {
113     y1 = &(p->r2[p->n1]);
114     y2 = &(p->r2_ther[p->n1]);
115       
116     tv_erase(tv_g);
117     plot(PL_INIT, PL_TV, tv_g,
118          PL_AXIS_COLOR, black,
119          PL_X_TEXT, true, 
120          PL_Y_TEXT, true, 
121          PL_TITLE, "Gamma Fit",
122          PL_STYLE, PL_CROSS,
123          PL_COLOR, red,
124          PL_GRAPH_DATA, length, x, y1,
125          PL_STYLE, PL_CROSS,
126          PL_COLOR, blue,
127          PL_GRAPH_DATA, length, x, y2,
128          PL_STYLE, PL_LINE, 
129          PL_GRAPH_DATA, length, x, y2,
130          PL_PLOT,
131          NULL);
132 
133   }
134   return;
135 }
136 
137 
138 static void   ct_pixel_pfit_plot(Tv *tv, Ipos pos)
139 {
140   Permeability *p = NULL;
141   Vec2       loc = {Vec2_id};  
142   Sequence *seq = seq_get_current();
143   Imrect    *im = NULL;
144    Tv        *tv_g = imcalc_graph_tv();
145   float     *time, *x, *y1, *y2;
146   int        imptrlx, imptrux, imptrly, imptruy, imptrlz, imptruz;
147   void    ***imptrs;
148   int        length, i;
149   float     single_time; 
150 
151   if ((tv_g == NULL) || (tv_g->tv_screen == NULL))
152     return;
153 
154   loc = tv_backproj2(tv, pos);
155   p = permeability_alloc();
156 
157 
158 
159 
160   if ((single_time = seq->dim[3]) == 0.0)
161     {
162       error("gamma_fit_proc: timing info may be missing", warning);
163       return;
164     }
165 
166   imptrs = seq_slice_init(seq);
167                 
168   if (ct_perm_fit_pixel(p, loc, imptrs) == -1)
169   {
170       permeability_free(p);
171       return;
172   }
173   format("vp = %4.3f k = %4.7f t = %3.1f \n",
174           p->vp, p->kin, p->tt*p->tscale);
175 
176   imptrs = seq_limits(&imptrlz, &imptruz, &imptrly, &imptruy, &imptrlx, 
177                         &imptrux);
178 
179   length =  imptruz - imptrlz;
180   time = fvector_alloc(0, length); 
181   for (i=0; i<length; i++)
182     {
183       time[i] = i * single_time;
184     }
185   x = time;
186   if ((p->conc1 != NULL) && (p->conc1_ther !=NULL))
187   {
188    
189     y1 = &(p->conc1[imptrlz]);
190     y2 = &(p->conc1_ther[imptrlz]);
191     
192     tv_erase(tv_g);
193     pl_free_set(false);
194     plot(PL_INIT, PL_TV, tv_g,
195          PL_AXIS_COLOR, black,
196          PL_X_TEXT, true, 
197          PL_Y_TEXT, true, 
198          PL_TITLE, "Permeability Fit",
199          PL_STYLE, PL_CROSS,
200          PL_COLOR, red,
201          PL_GRAPH_DATA, length, x, y1,
202          PL_STYLE, PL_CROSS,
203          PL_COLOR, blue,
204          PL_GRAPH_DATA, length, x, y2,
205          PL_STYLE, PL_LINE, 
206          PL_GRAPH_DATA, length, x, y2,
207          PL_PLOT,
208          NULL);
209 
210   }
211   permeability_free(p);
212   return;
213 }
214 
215 
216 /*
217  *   Altered to improve lib / tool separation - GAB 19 Feb 2003
218  *   Stack manipulation from gamma_fit_region moved here.
219  */
220 double   ct_pixel_gfit_region(Tv *tv, Ipos pos)
221 {
222   Perfusion *p = NULL;
223   Vec2       loc = {Vec2_id};
224   Sequence  *seq = seq_get_current();
225   Imrect    *im = NULL, *mask = NULL;
226   Tv        *tv_g = imcalc_graph_tv();
227   float      single_time, *time, *x, *y1, *y2;
228   int        i;
229   void    ***imptrs;
230   int        length, type;
231   double     t0;
232  
233 
234   p = perfusion_alloc();
235 
236   if ((single_time = seq->dim[3]) == 0.0)
237     {
238       error("gamma_fit_proc: timing info may be missing", warning);
239       return(0.0);
240     }
241 
242   imptrs = seq_slice_init(seq);
243 
244   if (stack_check_types(IMRECT, NULL) == false)
245   {
246      error("gamma_fit: wrong type on stack", warning);
247      t0 = 0.0;
248   }
249   else
250   {
251      mask = (Imrect *) stack_pop(&type);
252      t0 = ct_gamma_fit_region(p, mask);
253      format("tzero: %f\n", t0);
254      stack_push((void *)mask, IMRECT, im_free);
255   }
256 
257 
258   length = (p->n2 -  p->n1);
259   time = (float *)fvector_alloc(0, length);
260   for (i = 0; i < length; i++)
261     {
262       time[i] = i * single_time;
263     }
264 
265   x = time;
266   if (p->r2 != NULL && p->r2_ther !=NULL)
267   {
268     y1 = &(p->r2[p->n1]);
269     y2 = &(p->r2_ther[p->n1]);
270 
271     tv_erase(tv_g);
272     plot(PL_INIT, PL_TV, tv_g,
273          PL_AXIS_COLOR, black,
274          PL_X_TEXT, true, 
275          PL_Y_TEXT, true,
276          PL_TITLE, "Gamma Fit",
277          PL_STYLE, PL_CROSS,
278          PL_COLOR, red,
279          PL_GRAPH_DATA, length, x, y1,
280          PL_STYLE, PL_CROSS,
281          PL_COLOR, blue,
282          PL_GRAPH_DATA, length, x, y2,
283          PL_STYLE, PL_LINE,
284          PL_GRAPH_DATA, length, x, y2,
285          PL_PLOT,
286          NULL);
287 
288   }
289   
290   return(t0);
291 }
292 
293 Tv_mouse     ct_gfit_mouse(void)
294 {
295     return (mouse_define(MOUSE_NAME, "gamma fit",
296                          LEFT_NAME, "pixel",
297                          LEFT_DOWN, ct_pixel_gfit_plot,
298                          NULL));
299 }
300 
301 Tv_mouse     ct_permfit_mouse(void)
302 {
303     return (mouse_define(MOUSE_NAME, "permeability fit",
304                          LEFT_NAME, "pixel",
305                          LEFT_DOWN, ct_pixel_pfit_plot,
306                          NULL));
307 }
308 
309 

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