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

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

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

  1 /*
  2  * sroi_sample.c
  3  *
  4  * Functions for sampling the ploy ROI into the smartROI tool
  5  * as a model either outer or inner
  6  *
  7  */
  8 
  9 #include <stdio.h>
 10 #include <values.h>
 11 #include <math.h>
 12 #include <tina/sys.h>
 13 #include <tina/sysfuncs.h>
 14 #include <tina/math.h>
 15 #include <tina/mathfuncs.h>
 16 #include <tina/vision.h>
 17 #include <tina/visionfuncs.h>
 18 #include <tina/tv.h>
 19 #include <tina/tvfuncs.h>
 20 #include <tina/draw.h>
 21 #include <tina/drawfuncs.h>
 22 #include <tina/infrtoolfuncs.h>
 23 #include <tina/toolsfuncs.h>
 24 #include <tina/sroi_tool.h>
 25 
 26 
 27 
 28 int  new_model_needed(Model *m)
 29 {
 30   Sroi_dparams  *params = sroi_get_dparams();
 31 
 32   if (m == NULL)
 33     return(1);
 34 
 35   if (params->points != m->c)
 36     return(1);
 37     
 38   if (params->rows != m->r)
 39     return(1);
 40 
 41   if (params->outer != m->o)
 42     return(1);
 43 
 44   if (params->vsize != m->vsize)
 45     return(1);
 46 
 47   return(0);
 48 }
 49 
 50 
 51 void sample_markup(List *poly)
 52 {
 53   Sroi_dparams  *params = sroi_get_dparams();
 54   Model  *oldm = NULL, *mdl = NULL;
 55   List *lptr = NULL;
 56   Vec2   *p, *p1, *p2;
 57   double  dx, dy;
 58   int     length = 0, count = 0;
 59 
 60   if ((lptr = poly) == NULL)
 61     return;
 62 
 63   for (lptr = poly; lptr != NULL; lptr = lptr->next)
 64     length++;
 65 
 66   if ((length < 1 ) || (params->rows < 1) || (params->outer < 1) || 
 67       (params->vsize < 1))
 68       return;
 69 
 70   if (params->outer > length)
 71     params->outer = length;
 72 
 73   if ((mdl = model_alloc(params->rows, length, params->outer, 
 74                          params->vsize)) == NULL)
 75       return;
 76       
 77   for (lptr = poly; lptr != NULL; lptr = lptr->next)
 78   {
 79     if ((p = lptr->to) == NULL)
 80       continue;
 81 
 82     if (count == 0)
 83       p1 = lptr->to;
 84     else if (!(length%2) && (count == (int) ((length / 2) + 1)))
 85       p2 = lptr->to;
 86     else if ((length%2) && (count == (int) (length / 2)))
 87       p2 = lptr->to;
 88 
 89     matrix_put(vec2_x(*p), mdl->m, 0, count);
 90     matrix_put(vec2_y(*p), mdl->m, 1, count);
 91     count++;
 92   }
 93 
 94   if (!p1 && !p2)
 95     return;
 96 
 97   dx = vec2_x(*p1) - vec2_x(*p2);
 98   dy = vec2_y(*p1) - vec2_y(*p2);
 99   mdl->tx = (vec2_x(*p1) + vec2_x(*p2)) / 2.0;
100   mdl->ty = (vec2_y(*p1) + vec2_y(*p2)) / 2.0;
101   mdl->theta = atan2(dy, dx);
102   mdl->s = sqrt(dx * dx + dy * dy);
103 
104   if (oldm != mdl)
105     set_model(mdl);
106 }
107 
108 
109 void sample_outer(List *poly)
110 {
111   Sroi_dparams  *params = sroi_get_dparams();
112   Model  *oldm = NULL, *mdl = NULL;
113   List *lptr = NULL;
114   Vec2   *p, *p1, *p2;
115   double  dx, dy;
116   int     length = 0, count = 0;
117 
118   if ((lptr = poly) == NULL)
119     return;
120 
121   for (lptr = poly; lptr != NULL; lptr = lptr->next)
122     length++;
123 
124   if (((oldm = get_model()) != NULL) && !new_model_needed(oldm))
125     mdl = oldm;
126   else   
127     if ((mdl = model_alloc(params->rows, length, length, params->vsize)) == NULL)
128       return;
129       
130   for (lptr = poly; lptr != NULL; lptr = lptr->next)
131   {
132     if ((p = lptr->to) == NULL)
133       continue;
134 
135     if (count == 0)
136       p1 = lptr->to;
137     else if (!(length%2) && (count == (int) ((length / 2) + 1)))
138       p2 = lptr->to;
139     else if ((length%2) && (count == (int) (length / 2)))
140       p2 = lptr->to;
141 
142     matrix_put(vec2_x(*p), mdl->m, 0, count);
143     matrix_put(vec2_y(*p), mdl->m, 1, count);
144     count++;
145   }
146 
147   if (!p1 && !p2)
148     return;
149 
150   dx = vec2_x(*p1) - vec2_x(*p2);
151   dy = vec2_y(*p1) - vec2_y(*p2);
152   mdl->tx = (vec2_x(*p1) + vec2_x(*p2)) / 2.0;
153   mdl->ty = (vec2_y(*p1) + vec2_y(*p2)) / 2.0;
154   mdl->theta = atan2(dy, dx);
155   mdl->s = sqrt(dx * dx + dy * dy);
156 
157   if (oldm != mdl)
158     set_model(mdl);
159 }
160 
161 
162 void export_outer()
163 {
164   Model   *mdl;
165   List  *poly = NULL;
166   Vec2     v;
167   double **el;
168   int      i;
169 
170   if ((mdl = get_model()) == NULL)
171     return;
172 
173   if ((el = mdl->m->el.double_v) == NULL)
174     return;
175 
176   vec2_x(v) = el[0][0];
177   vec2_y(v) = el[1][0];
178   poly = dd_ref_addtostart(poly, (void *)vec2_copy(&v), VEC2);
179   for(i = 1; i < mdl->o; i++)
180   {
181     vec2_x(v) = el[0][i];
182     vec2_y(v) = el[1][i];
183     poly = dd_ref_addtoend(poly, (void *)vec2_copy(&v), VEC2);
184   }
185 
186   tv_poly_set(poly);
187 }
188 
189 
190 void sample_inner(List *poly)
191 {
192   Model   *mdl;
193   List  *lptr;
194   Vec2    *p;
195   int      count, length;
196 
197   length = 0;
198 
199   if ((poly == NULL) || (mdl = get_model()) == NULL)
200     return;
201   
202   count = mdl->o; 
203 
204   if ((lptr = poly) == NULL)
205     return;
206 
207   for (lptr = poly; lptr != NULL; lptr = lptr->next)
208     length++;
209 
210   if ((mdl = model_alloc_inner(mdl, length)) == NULL)
211     return;
212  
213   for (lptr = poly; lptr != NULL; lptr = lptr->next)
214   {
215     if ((p = lptr->to) == NULL)
216       continue;
217     matrix_put(vec2_x(*p), mdl->m, 0, count);
218     matrix_put(vec2_y(*p), mdl->m, 1, count);
219     count++;
220   }
221 
222 }
223 
224 void export_inner()
225 {
226   Model   *mdl;
227   List  *poly = NULL;
228   Vec2     v;
229   double **el;
230   int      i, start;
231 
232   if ((mdl = get_model()) == NULL)
233     return;
234 
235   start = mdl->o;
236   if (mdl->c == start)
237     return;
238 
239   if ((el = mdl->m->el.double_v) == NULL)
240     return;
241 
242   vec2_x(v) = el[0][start];
243   vec2_y(v) = el[1][start];
244   poly = dd_ref_addtostart(poly, (void *)vec2_copy(&v), VEC2);
245   for(i = ++start; i < mdl->c; i++)
246   {
247     vec2_x(v) = el[0][i];
248     vec2_y(v) = el[1][i];
249     poly = dd_ref_addtoend(poly, (void *)vec2_copy(&v), VEC2);
250   }
251 
252   tv_poly_set(poly);
253 }
254 
255 

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