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

Linux Cross Reference
Tina4/src/tools/smartROI/sroi_polygon.c

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

  1 /*
  2  * sroi_polygon.c
  3  *
  4  * affine transfer code
  5  *
  6  */
  7 
  8 #include <stdio.h>
  9 #include <values.h>
 10 #include <math.h>
 11 #include <tina/sys.h>
 12 #include <tina/sysfuncs.h>
 13 #include <tina/math.h>
 14 #include <tina/mathfuncs.h>
 15 #include <tina/vision.h>
 16 #include <tina/visionfuncs.h>
 17 #include <tina/tv.h>
 18 #include <tina/tvfuncs.h>
 19 #include <tina/draw.h>
 20 #include <tina/drawfuncs.h>
 21 #include <tina/infrtoolfuncs.h>
 22 #include <tina/toolsfuncs.h>
 23 #include <tina/vector.h>
 24 #include <tina/sroi_tool.h>
 25 
 26 
 27 static char getfromfile(FILE * fp)
 28 {
 29   char k = getc(fp);
 30 
 31   while ((k == ' ') || (k == '\t') || (k == '\n'))
 32     k = getc(fp);
 33 
 34   return (k);
 35 }
 36 
 37 
 38 static int read_poly_points(FILE * fp, double **el, int m, int n)
 39 {
 40   Vec2    p;
 41   List *roi_poly = NULL;
 42   float   weight;
 43   int     i, j, size;
 44   int     run = 1;
 45   char    c;
 46 
 47   fscanf(fp, "%d", &size);
 48 
 49   for (i = 0; i < size; i++)
 50   {
 51     p.el[0] = 0;
 52     p.el[1] = 0;
 53     while (run == 1)
 54     {
 55       if (fscanf(fp, "%f", &weight) == EOF)
 56       {
 57         run = 2;
 58         continue;
 59       }
 60       if ((c = getfromfile(fp)) != ',')
 61       {
 62         run = 3;
 63         continue;
 64       }
 65       if (fscanf(fp, "%d", &j) == EOF || j < 0 || j > n)
 66       {
 67         run = 4;
 68         continue;
 69       }
 70       if ((c = getfromfile(fp)) == ';')
 71         run = 0;
 72       else if (c != ',')
 73       {
 74         run = 5;
 75         continue;
 76       }
 77       p.el[0] += weight * el[0][j];
 78       p.el[1] += weight * el[1][j];
 79     }
 80 
 81     if (run == 0)
 82     {
 83       roi_poly = dd_ref_addtoend(roi_poly, (void *)vec2_copy(&p), VEC2);
 84       run = 1;
 85     } else
 86     {
 87       format("read_poly_points: error %d\n", run);
 88       continue;
 89     }
 90   }
 91 
 92   tv_poly_set(roi_poly);
 93 
 94   return (0);
 95 }
 96 
 97 
 98 static int sroi_roi_readpnts(FILE * fp, double **pos, int m, int n)
 99 {
100   char comm;
101 
102   if ((comm = getfromfile(fp)) == EOF)
103     return (0);
104 
105   switch (comm)
106   {
107   case 'p':
108     read_poly_points(fp, pos, m, n);
109     break;
110 
111   default:
112     break;
113   }
114 
115   return (1);
116 }
117 
118 
119 void sroi_polygon(double **pos, int m, int n, char *config_file)
120 {
121   FILE *fp = NULL;
122 
123   if (pos == NULL || m < 2 || config_file == NULL)
124     return;
125 
126   if ((fp = fopen((const char *)config_file, "r")) == NULL)
127   {
128     error("sroi_polygon: its all gone wrong\n", warning);
129     return;
130   }
131   sroi_roi_readpnts(fp, pos, m, n);
132 
133   fclose(fp);
134 }
135 
136 
137 void sroi_polygon_label(double **pos, int m, int n, Tv * tv)
138 {
139   Vec2  loc;
140   int   i;
141   char  num[4];
142 
143   if (pos == NULL || tv == NULL || m < 2)
144     return;
145 
146   tv_set_color(tv, red);
147 
148   for (i = 0; i < n; i++)
149   {
150     vec2_x(loc) = pos[0][i] + 5.0;
151     vec2_y(loc) = pos[1][i] + 5.0;
152     sprintf(num, "%d", i);
153     tv_text2(tv, num, loc);
154   }
155 }
156 

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