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

Linux Cross Reference
Tina6/tina-tools/tinatool/tlbase/tlbaseImc_graph.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    :  $Source: /home/tina/cvs/tina-tools/tinatool/tlbase/tlbaseImc_graph.c,v $
 37  * Date    :  $Date: 2005/02/07 23:29:19 $
 38  * Version :  $Revision: 1.3 $
 39  * CVS Id  :  $Id: tlbaseImc_graph.c,v 1.3 2005/02/07 23:29:19 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes :
 44  *
 45  *********
 46 */
 47 
 48 #include "tlbaseImc_graph.h"
 49 
 50 #if HAVE_CONFIG_H
 51 #include <config.h>
 52 #endif
 53 
 54 #include <stdio.h>
 55 #include <string.h>
 56 #include <math.h>
 57 #include <float.h>
 58 #include <tina/sys/sysDef.h>
 59 #include <tina/sys/sysPro.h>
 60 #include <tina/math/mathDef.h>
 61 #include <tina/math/mathPro.h>
 62 #include <tinatool/draw/drawDef.h>
 63 #include <tinatool/draw/drawPro.h>
 64 #include <tina/image/imgDef.h>
 65 #include <tina/image/imgPro.h>
 66 #include <tinatool/tlbase/tlbase_InfrDef.h>
 67 #include <tinatool/tlbase/tlbase_InfrPro.h> 
 68 #include <tinatool/tlbase/tlbaseImc_imc.h>
 69 
 70 #define ROIPLOT 0
 71 #define CIRCPLOT 1
 72 #define LINEPLOT 2
 73 
 74 Tv     *tv_create();
 75 
 76 static char title[64];
 77 static double xmin, xmax, xinc;
 78 static int ndata = 0;
 79 static float *xdata = NULL, *ydata = NULL ,*zdata = NULL;
 80 static float max_pixel, min_pixel;
 81 static int plot_type = PL_GRAPH_DATA;
 82 static int data_type = ROIPLOT;
 83 static Vec2 start_plot;
 84 static Vec2 end_plot;
 85 
 86 void    graph_set_type(int type)
 87 {
 88     plot_type = type;
 89 }
 90 
 91 void    graph_set_title(char *title0)
 92 {
 93     (void) strcpy(title, title0);
 94 }
 95 
 96 void    graph_set_xrange(double xmin0, double xmax0, double xinc0)
 97 {
 98     xmin = xmin0;
 99     xmax = xmax0;
100     xinc = xinc0;
101 }
102 
103 void    graph_set_data(int ndata0, float *xdata0, float *ydata0)
104 {
105     ndata = ndata0;
106     xdata = xdata0;
107     ydata = ydata0;
108 }
109 
110 static void fulldraw(Tv * tv)
111 {
112     switch (plot_type)
113     {
114         case PL_GRAPH_DATA:
115         if (zdata != NULL && data_type != ROIPLOT)
116         {
117           plot(PL_INIT, PL_TV, tv,
118              PL_AXIS_COLOR, black,
119              PL_TITLE, "Intensity Plot",
120              PL_COLOR, red,
121              PL_GRAPH_DATA, ndata, xdata, zdata,
122              PL_COLOR, blue,
123              PL_GRAPH_DATA, ndata, xdata, ydata,
124              PL_PLOT,
125              NULL);
126         }
127         else if (data_type != ROIPLOT)
128         {
129           plot(PL_INIT, PL_TV, tv,
130              PL_AXIS_COLOR, black,
131              PL_TITLE, "Intensity Plot",
132              PL_COLOR, red,
133              PL_GRAPH_DATA, ndata, xdata, ydata,
134              PL_PLOT,
135              NULL);
136         }
137         break;
138     case PL_HIST_DATA:
139         if (max_pixel - min_pixel == 0.0) max_pixel += (float)1.0;
140         if (zdata != NULL)
141         {
142         plot(PL_INIT, PL_TV, tv,
143              PL_AXIS_COLOR, black,
144              PL_TITLE, "Intensity Histogram",
145              PL_COLOR, red,
146              PL_HIST_RANGE, (double)min_pixel, (double) max_pixel, 
147                             (double)(max_pixel - min_pixel )/50.0,
148              PL_HIST_DATA, ndata, zdata,
149              PL_COLOR, blue,
150              PL_HIST_RANGE, (double)min_pixel, (double) max_pixel, 
151                             (double)(max_pixel - min_pixel )/50.0,
152              PL_HIST_DATA, ndata, ydata,
153              PL_PLOT,
154              NULL);
155         }
156         else
157         {
158         plot(PL_INIT, PL_TV, tv,
159              PL_AXIS_COLOR, black,
160              PL_TITLE, "Intensity Histogram",
161              PL_COLOR, red,
162              PL_HIST_RANGE, (double)min_pixel, (double) max_pixel, 
163                             (double)(max_pixel - min_pixel )/50.0,
164              PL_HIST_DATA, ndata, ydata,
165              PL_PLOT,
166              NULL);
167         }
168         break;
169     }
170 }
171 
172 /* ARGSUSED quieten lint */
173 static void skeldraw(Tv * tv)
174 {
175 }
176 
177 static void init(Tv * tv)
178 {
179     start_plot.el[0] =  (float)0.0;
180     start_plot.el[1] =  (float)0.0;
181     end_plot.el[0] =  (float)0.0;
182     end_plot.el[1] =  (float)0.0;
183 }
184 
185 Tv     *imcalc_graph_tv_make(void)
186 {
187     Tv     *tv;
188 
189     tv = tv_create("imcalc graph");
190     tv_named_font_set(tv, "6x10");
191     (void) tv_set_fulldraw(tv, fulldraw);
192     (void) tv_set_skeldraw(tv, skeldraw);
193     tv_set_init(tv, init);
194     (void) tv_set_zoomlevel(tv, IMZOOM);
195     return (tv);
196 }
197 
198 static void set_start_down(Tv * tv, Ipos pos)
199 {
200     Vec2    tv_backproj2();
201     start_plot = tv_backproj2(tv, pos);
202     end_plot = tv_backproj2(tv, pos);
203     tv_set_overlay(tv);
204 }
205 
206 static void draw_line_drag(Tv * tv, Ipos pos)
207 {
208     Vec2    tv_backproj2();
209 
210     tv_line2(tv, start_plot, end_plot);
211     end_plot = tv_backproj2(tv, pos);
212     tv_line2(tv, start_plot, end_plot);
213 }
214 
215 static void draw_circle_drag(Tv * tv, Ipos pos)
216 {
217     Vec2    tv_backproj2();
218     double  radius;
219 
220     radius = vec2_dist(start_plot, end_plot);
221     tv_circle2(tv, start_plot, radius);
222     end_plot = tv_backproj2(tv, pos);
223     radius = vec2_dist(start_plot, end_plot);
224     tv_circle2(tv, start_plot, radius);
225 }
226 
227 static void draw_roi_drag(Tv * tv, Ipos pos)
228 {
229     Vec2    tv_backproj2();
230 
231     tv_rect2(tv, start_plot, end_plot);
232     end_plot = tv_backproj2(tv, pos);
233     tv_rect2(tv, start_plot, end_plot);
234 }
235 
236 static void draw_line_plot(Tv * tv)
237 {
238     Imrect *im;
239     int     type;
240     Imregion *roi;
241     int     i,length;
242     double xscale,yscale;
243     double x,y;
244     float  *xvector, *yvector;
245     Complex pix;
246 
247     tv_set_overlay(tv);
248     tv_line2(tv, start_plot, end_plot);
249     tv_reset_draw(tv);
250     im = (Imrect *) stack_inspect(&type);
251     if (type != IMRECT || im == NULL)
252     {
253         error("draw_line_up: no image on stack", warning);
254         return;
255     }
256     roi = im->region;
257     if (roi == NULL)
258         return;
259 
260     if (xdata != NULL)
261         rfree((void *) xdata);
262     if (zdata !=NULL)
263         rfree((void *) zdata);
264     zdata = NULL;
265     if (ydata != NULL)
266         rfree((void *) ydata);
267 
268     length = tina_int(vec2_dist(start_plot,end_plot));
269     xdata = fvector_alloc(0, length);
270     ydata = fvector_alloc(0, length);
271     if (im->vtype == complex_v) zdata =  fvector_alloc(0, length);
272     xscale = (end_plot.el[0] - start_plot.el[0])/(float)length;
273     yscale = (end_plot.el[1] - start_plot.el[1])/(float)length;
274 
275     max_pixel = -FLT_MAX;
276     min_pixel = FLT_MAX;
277     for (i=0;i<length;i++)
278     {
279        x = start_plot.el[0] + (double)i*xscale;
280        y = start_plot.el[1] + (double)i*yscale;
281        xdata[i] =  (float)i;
282        if (zdata!=NULL)
283        {
284            pix = im_sub_pixz(im, y , x);
285            ydata[i] = pix.y;
286            zdata[i] = pix.x;
287            if ( zdata[i]>max_pixel && zdata[i]<FLT_MAX)
288                max_pixel = zdata[i];
289            if ( zdata[i]<min_pixel && zdata[i]>-FLT_MAX)
290                min_pixel = zdata[i];
291        }
292        else
293        {
294           ydata[i] = im_sub_pixqf(im, y, x);
295        }
296        if ( ydata[i]>max_pixel && ydata[i]<FLT_MAX)
297                max_pixel = ydata[i];
298        if ( ydata[i]<min_pixel && ydata[i]>-FLT_MAX)
299                min_pixel = ydata[i];
300     }
301     ndata = length;
302 
303     tv_repaint(imcalc_graph_tv_get());
304 }
305  
306 static void draw_line_up(Tv *tv, Ipos pos)
307 {
308     tv_line2(tv, start_plot, end_plot);
309     end_plot = tv_backproj2(tv, pos);
310     tv_reset_draw(tv);
311     data_type = LINEPLOT;
312     draw_line_plot(tv);
313 }
314 
315 static void draw_circle_plot(Tv * tv)
316 {
317     Vec2    tv_backproj2();
318     Imrect *im;
319     int     type;
320     Imregion *roi;
321     int     i,j,k;
322     double radius,delta_theta = 2.0*3.141592/360.0;
323     double x,y;
324     float  *xvector, *yvector;
325     Complex pix;
326 
327     tv_set_overlay(tv);
328     radius = vec2_dist(end_plot,start_plot);
329     tv_circle2(tv, start_plot, radius);
330     tv_reset_draw(tv);
331     im = (Imrect *) stack_inspect(&type);
332     if (type != IMRECT || im == NULL)
333     {
334         error("draw_circle_up: no image on stack", warning);
335         return;
336     }
337     roi = im->region;
338     if (roi == NULL)
339         return;
340 
341 
342     max_pixel = -FLT_MAX;
343     min_pixel = FLT_MAX;
344 
345     if(plot_type == PL_GRAPH_DATA)
346     {
347         if (xdata != NULL) rfree((void *) xdata);
348         if (ydata != NULL) rfree((void *) ydata);
349         if (zdata != NULL) rfree((void *) zdata);
350         zdata = NULL;
351         ndata = 360;
352         xdata = fvector_alloc(0, 360);
353         ydata = fvector_alloc(0, 360);
354         if (im->vtype == complex_v) zdata = fvector_alloc(0, 360);
355         for (i=0;i<360;i++)
356         {
357            x = start_plot.el[0] + radius*sin(i*delta_theta);
358            y = start_plot.el[1] - radius*cos(i*delta_theta);
359            xdata[i] =  (float)i;
360            if (zdata !=NULL)
361            {
362               pix = im_sub_pixz(im , y, x);
363               ydata[i] = pix.y;
364               zdata[i] = pix.x;
365               if ( zdata[i]>max_pixel && zdata[i]< FLT_MAX) max_pixel = zdata[i];
366               if ( zdata[i]<min_pixel && zdata[i]> -FLT_MAX) min_pixel = zdata[i];
367            }
368            else
369            {
370               ydata[i] = (float)im_sub_pixqf(im, y, x);
371            }
372            if ( ydata[i]>max_pixel && ydata[i]< FLT_MAX) max_pixel = ydata[i];
373            if ( ydata[i]<min_pixel && ydata[i]> -FLT_MAX) min_pixel = ydata[i];
374         }
375     }
376     else
377     {
378         if (ydata != NULL) rfree((void *) ydata);
379         if (zdata != NULL) rfree((void *) zdata);
380         zdata = NULL;
381         ndata = tina_int(3.141592*radius*radius);
382         if (im->vtype == complex_v) zdata = fvector_alloc(0, ndata);
383         ydata = fvector_alloc(0, ndata);
384 
385         for (j = tina_int(start_plot.el[0] - radius),k=0;
386              j < 1 + tina_int(start_plot.el[0] + radius); j++)
387             for (i = tina_int(start_plot.el[1] - radius);
388                  i < 1 + tina_int(start_plot.el[1] + radius); i++)
389             {
390                 if ((start_plot.el[0]-j-0.5)*(start_plot.el[0]-j-0.5)
391                    +(start_plot.el[1]-i-0.5)*(start_plot.el[1]-i-0.5) < radius*radius
392                     && k<ndata)
393                 {
394                     if (j<roi->ux&&j>roi->lx && i<roi->uy&&i>roi->ly)
395                     {
396                        if (zdata != NULL)
397                        {
398                           IM_PIX_GETZ(im, i, j, pix);
399                           ydata[k] = pix.y;
400                           zdata[k] = pix.x;
401                           if ( zdata[k]>max_pixel) max_pixel = zdata[k];
402                           if ( zdata[k]<min_pixel) min_pixel = zdata[k];
403                           if ( ydata[k]>max_pixel) max_pixel = ydata[k];
404                           if ( ydata[k]<min_pixel) min_pixel = ydata[k];
405                           if (zdata[k]!=0.0) k++;
406                        }
407                        else
408                        {
409                           IM_PIX_GET(im, i, j, ydata[k]);
410                           if ( ydata[k]>max_pixel) max_pixel = ydata[k];
411                           if ( ydata[k]<min_pixel) min_pixel = ydata[k];
412                           if (ydata[k]!=0.0) k++;
413                        }
414                     }
415                 }
416             }
417         ndata = k; /* suppress zero entries*/
418     }
419 
420     tv_repaint(imcalc_graph_tv_get());
421 } 
422 
423 static void draw_circle_up(Tv *tv, Ipos pos)
424 {
425     double radius;
426 
427     radius = vec2_dist(end_plot,start_plot);
428     tv_circle2(tv, start_plot, radius);
429     end_plot = tv_backproj2(tv, pos);
430     tv_reset_draw(tv);
431     data_type = CIRCPLOT;
432     draw_circle_plot(tv);
433 }
434 
435 static void draw_roi_plot(Tv * tv)
436 {
437     int     i, j, k, type;
438     Imrect *im;
439     Imregion roi,*inter_roi;
440     Complex pix;
441 
442     tv_set_overlay(tv);
443     tv_rect2(tv, start_plot, end_plot);
444     tv_reset_draw(tv);
445 
446     im = (Imrect *) stack_inspect(&type);
447     if (type != IMRECT || im == NULL)
448     {
449         error("draw_roi_up: no image on stack", warning);
450         return;
451     }
452     if (im->region==NULL) return;
453 
454 
455     if (start_plot.el[0]<end_plot.el[0])
456     {
457         roi.lx = start_plot.el[0];
458         roi.ux = end_plot.el[0];
459     }
460     else
461     {
462         roi.lx = end_plot.el[0];
463         roi.ux = start_plot.el[0];
464     }
465     if (start_plot.el[1]<end_plot.el[1])
466     {
467         roi.ly = start_plot.el[1];
468         roi.uy = end_plot.el[1];
469     }
470     else
471     {
472         roi.ly = end_plot.el[1];
473         roi.uy = start_plot.el[1];
474     }
475     inter_roi = roi_inter(&roi, im->region);
476     if (inter_roi==NULL) return;
477     tv_set_roi(imcalc_tv_get(),inter_roi);
478 
479     if (plot_type == PL_GRAPH_DATA)
480     {
481         error("draw_roi_up: can't graph a region",warning);
482         rfree(inter_roi);
483         return;
484     }
485 
486     if (ydata != NULL)
487         fvector_free(ydata, 0);
488     ydata = NULL;
489     if (zdata !=NULL)
490         fvector_free(zdata, 0);
491     zdata = NULL;
492 
493     ndata = (inter_roi->ux - inter_roi->lx) * (inter_roi->uy - inter_roi->ly);
494     ydata = fvector_alloc(0, ndata);
495 
496     max_pixel = -FLT_MAX;
497     min_pixel = FLT_MAX;
498     if (im->vtype== complex_v)
499     {
500         zdata = fvector_alloc(0, ndata);
501         for (j = inter_roi->lx,k=0; j < inter_roi->ux; j++)
502            for (i = inter_roi->ly; i < inter_roi->uy; i++)
503            {
504               IM_PIX_GETZ(im, i, j, pix);
505               ydata[k] = pix.y;
506               zdata[k] = pix.x;
507               
508               if ( zdata[k]>max_pixel && zdata[k] <FLT_MAX) max_pixel = zdata[k];
509               if ( zdata[k]<min_pixel&& zdata[k] >-FLT_MAX) min_pixel = zdata[k];
510               if ( ydata[k]>max_pixel && ydata[k] <FLT_MAX) max_pixel = ydata[k];
511               if ( ydata[k]<min_pixel&& ydata[k] >-FLT_MAX) min_pixel = ydata[k];
512               if(zdata[k]!=0.0) k++;
513            }
514     }
515     else
516     {
517        for (j = inter_roi->lx,k=0; j < inter_roi->ux; j++)
518           for (i = inter_roi->ly; i < inter_roi->uy; i++)
519           {
520              IM_PIX_GET(im, i, j, ydata[k]);
521              if ( ydata[k]>max_pixel && ydata[k] <FLT_MAX) max_pixel = ydata[k];
522              if ( ydata[k]<min_pixel&& ydata[k] >-FLT_MAX) min_pixel = ydata[k];
523              if(ydata[k]!=0.0) k++;
524           }
525     }
526     ndata = k; /* suppress zero entries*/
527     tv_repaint(imcalc_graph_tv_get());
528     rfree(inter_roi);
529 }
530 
531 static void draw_roi_up(Tv *tv, Ipos pos)
532 {
533     tv_rect2(tv, start_plot, end_plot);
534     end_plot = tv_backproj2(tv, pos);
535     tv_reset_draw(tv);
536     data_type = ROIPLOT;
537     draw_roi_plot(tv);
538 }
539 
540 Tv_mouse imcalc_prof_mouse(void)
541 {
542     return (mouse_define(MOUSE_NAME, "Prof",
543                          RIGHT_NAME, "line",
544                          RIGHT_DOWN, set_start_down,
545                          RIGHT_DRAG, draw_line_drag,
546                          RIGHT_UP, draw_line_up,
547                          MIDDLE_NAME, "circle",
548                          MIDDLE_DOWN, set_start_down,
549                          MIDDLE_DRAG, draw_circle_drag,
550                          MIDDLE_UP, draw_circle_up,
551                          LEFT_NAME, "roi",
552                          LEFT_DOWN, set_start_down,
553                          LEFT_DRAG, draw_roi_drag,
554                          LEFT_UP, draw_roi_up,
555                          NULL));
556 }
557 
558 void redraw_graph_plot(Tv *tv)
559 {
560     if (tv == NULL) return;
561     if (plot_type == PL_HIST_DATA || plot_type == PL_GRAPH_DATA)
562     {
563         if (data_type == ROIPLOT)
564         {
565             draw_roi_plot(tv);
566         }
567         if (data_type == CIRCPLOT)
568         {
569             draw_circle_plot(tv);
570         }
571         if (data_type == LINEPLOT)
572         {
573             draw_line_plot(tv);
574         }
575         fulldraw(imcalc_graph_tv_get());
576     }
577 }
578 

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