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

Linux Cross Reference
Tina4/src/tools/imcalc/imc_graph.c

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

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

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