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

Linux Cross Reference
Tina4/src/tools/edge/edge_pick.c

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

  1 #include <stdio.h>
  2 #include <math.h>
  3 #include <tina/sys.h>
  4 #include <tina/sysfuncs.h>
  5 #include <tina/math.h>
  6 #include <tina/mathfuncs.h>
  7 #include <tina/vision.h>
  8 #include <tina/visionfuncs.h>
  9 #include <tina/tv.h>
 10 #include <tina/tvfuncs.h>
 11 #include <tina/draw.h>
 12 #include <tina/drawfuncs.h>
 13 #include <tina/toolsfuncs.h>
 14 
 15 static int SEARCH_RADIUS = 25;
 16 
 17 static void *left_pick_closest_edge(Tv * tv, Ipos pos, int *type)
 18 {
 19     Imrect *er = left_edges();
 20     int     r, c;
 21     Vec2    v = {Vec2_id};
 22 
 23     *type = EDGE;
 24     v = tv_backproj2(tv, pos);
 25     r = tina_int(vec2_y(v));
 26     c = tina_int(vec2_x(v));
 27     return (er_closest(er, r, c, SEARCH_RADIUS, (void *(*) ()) NULL, NULL));
 28 }
 29 
 30 static void *left_pick_closest_matchlist(Tv * tv, Ipos pos, int *type)
 31 {
 32     Imrect *er = left_edges();
 33     int     r, c;
 34     Vec2    v = {Vec2_id};
 35 
 36     *type = LIST;
 37     v = tv_backproj2(tv, pos);
 38     r = tina_int(vec2_y(v));
 39     c = tina_int(vec2_x(v));
 40     return (er_closest(er, r, c, SEARCH_RADIUS, edge_sindex_prop_get, (void *) MLIST));
 41 }
 42 
 43 static void *left_pick_closest_corr_match(Tv * tv, Ipos pos, int *type)
 44 {
 45     Imrect *er = left_edges();
 46     int     r, c;
 47     Vec2    v = {Vec2_id};
 48 
 49     *type = LIST;
 50     v = tv_backproj2(tv, pos);
 51     r = tina_int(vec2_y(v));
 52     c = tina_int(vec2_x(v));
 53     return (er_closest(er, r, c, SEARCH_RADIUS, edge_prop_get, (void *) MATCH));
 54 }
 55 
 56 static void *right_pick_closest_corr_match(Tv * tv, Ipos pos, int *type)
 57 {
 58     Imrect *er = right_edges();
 59     int     r, c;
 60     Vec2    v = {Vec2_id};
 61 
 62     *type = LIST;
 63     v = tv_backproj2(tv, pos);
 64     r = tina_int(vec2_y(v));
 65     c = tina_int(vec2_x(v));
 66     return (er_closest(er, r, c, SEARCH_RADIUS, edge_prop_get, (void *) MATCH));
 67 }
 68 
 69 static void *left_pick_closest_string(Tv * tv, Ipos pos, int *type)
 70 {
 71     Imrect *er = left_edges();
 72     Edgel  *edge;
 73     int     r, c;
 74     Vec2    v = {Vec2_id};
 75 
 76     *type = EDGE;
 77     v = tv_backproj2(tv, pos);
 78     r = tina_int(vec2_y(v));
 79     c = tina_int(vec2_x(v));
 80     edge = er_closest(er, r, c, SEARCH_RADIUS, (void *(*) ()) NULL, NULL);
 81     if (edge == NULL)
 82         return (NULL);
 83 
 84     return (prop_get(edge->props, STRING));
 85 }
 86 
 87 static void *right_pick_closest_edge(Tv * tv, Ipos pos, int *type)
 88 {
 89     Imrect *er = right_edges();
 90     int     r, c;
 91     Vec2    v = {Vec2_id};
 92 
 93     *type = EDGE;
 94     v = tv_backproj2(tv, pos);
 95     r = tina_int(vec2_y(v));
 96     c = tina_int(vec2_x(v));
 97     return ((void *) er_closest(er, r, c, SEARCH_RADIUS, (void *(*) ()) NULL,
 98                                 NULL));
 99 }
100 
101 static void *mono_pick_closest_edge(Tv * tv, Ipos pos, int *type)
102 {
103     Imrect *er = mono_edges();
104     int     r, c;
105     Vec2    v = {Vec2_id};
106 
107     *type = EDGE;
108     v = tv_backproj2(tv, pos);
109     r = tina_int(vec2_y(v));
110     c = tina_int(vec2_x(v));
111     return ((void *) er_closest(er, r, c, SEARCH_RADIUS, (void *(*) ()) NULL,
112                                 NULL));
113 }
114 
115 void    pick_edge_draw(Tv * tv, Edgel * edge, int type)
116 {
117     if (edge == NULL || type != EDGE)
118         return;
119 
120     tv_cross2(tv, edge_image_pos(edge), 7);
121 }
122 
123 static void draw_matchable(Tv * tv, void *ptr, int type)
124 {
125   Point2 *point;
126 
127   switch (type)
128     {
129     case CORNER:
130       tv_cross2(tv, ((Edgel *) ptr)->pos, 7);
131       break;
132     case EDGE:
133       point = (Point2 *)prop_get(((Edgel *)ptr)->props, POINT2);
134       tv_pixel2(tv, point->p);
135       break;
136     case STRING:
137       tv_edge_string(tv, (Tstring *) ptr);
138       break;
139     }
140 }
141 
142 void    pick_mlist_draw(Tv * tv, List * mlist, int type)
143 {
144     List   *lptr;
145     Match  *match;
146 
147     if (mlist == NULL || type != LIST)
148         return;
149 
150     for (lptr = mlist; lptr != NULL; lptr = lptr->next)
151     {
152         match = (Match *) lptr->to;
153         draw_matchable(tv, match->to1, match->type);
154     }
155 }
156 
157 void    pick_corr_match_draw(Tv * tv1, Match * match, int type)
158 {
159   Tv     *tv2 = NULL;
160   int     old_color;
161 
162   if (tv1 == left_tv())
163     tv2 = right_tv();
164 
165   if (tv1 == right_tv())
166     tv2 = left_tv();
167 
168   if (match == NULL || tv1 == NULL || tv2 == NULL)
169     return;
170 
171   old_color = tv_get_color(tv2);
172   tv_set_color(tv2, green);
173 
174   draw_matchable(tv2, match->to2, EDGE);
175 
176   tv_set_color(tv2, old_color);
177 
178   old_color = tv_get_color(tv1);
179   tv_set_color(tv1, green);
180 
181   draw_matchable(tv1, match->to1, EDGE);
182 
183   tv_set_color(tv1, old_color);
184 }
185 
186 void    stereo_match_list_draw(List * mlist)
187 {
188     Tv     *tvl = left_tv();
189     Tv     *tvr = right_tv();
190     List   *lptr;
191     Match  *match;
192 
193     if (mlist == NULL)
194         return;
195 
196     for (lptr = mlist; lptr != NULL; lptr = lptr->next)
197     {
198         match = (Match *) lptr->to;
199         draw_matchable(tvl, match->to1, match->type);
200         draw_matchable(tvr, match->to2, match->type);
201     }
202 }
203 
204 void    stereo_corr_match_draw(Tv * tv1, Match * match, int num)
205 {
206   Tv     *tv2 = NULL;
207   Edgel  *edge1, *edge2;
208   Vec2    pos;
209   Point2 *point;
210   char    numstr[10];
211   int     old_color;
212 
213   sprintf(numstr, "%d", num);
214 
215   if (tv1 == left_tv())
216     tv2 = right_tv();
217 
218   if (tv1 == right_tv())
219     tv2 = left_tv();
220 
221   if (match == NULL || tv1 == NULL || tv2 == NULL)
222     return;
223 
224   old_color = tv_get_color(tv2);
225   tv_set_color(tv2, green);
226 
227   edge2 = (Edgel *)match->to2;
228   draw_matchable(tv2, (void *)edge2, EDGE);
229 
230   point = (Point2 *)prop_get(edge2->props, POINT2);
231   pos = point->p;
232   vec2_x(pos) = (float)tina_int(vec2_x(pos));
233   vec2_y(pos) = (float)tina_int(vec2_y(pos)) + 0.5;
234   tv_cltext2(tv2, numstr, pos);
235 
236   tv_set_color(tv2, old_color);
237 
238   old_color = tv_get_color(tv1);
239   tv_set_color(tv1, green);
240 
241   edge1 = (Edgel *)match->to1;
242   draw_matchable(tv1, (void *)edge1, EDGE);
243 
244   point = (Point2 *)prop_get(edge1->props, POINT2);
245   pos = point->p;
246   vec2_x(pos) = (float)tina_int(vec2_x(pos));
247   vec2_y(pos) = (float)tina_int(vec2_y(pos)) + 0.5;
248   tv_cltext2(tv1, numstr, pos);
249 
250   tv_set_color(tv1, old_color);
251 }
252 
253 static void match_string_draw(Tstring * es)
254 {
255     List *ptr;
256     List *end;
257 
258     if (es == NULL)
259         return;
260 
261     end = es->end;
262     for (ptr = es->start;; ptr = ptr->next)
263     {
264         Tstring *sub = prop_get(((Edgel *) (ptr->to))->props, SINDEX);
265 
266         stereo_match_list_draw((List *) prop_get(sub->props, MLIST));
267         ptr = sub->end;
268         if (ptr == end)
269             break;
270     }
271 }
272 
273 static void picklist_match_string_draw(Tv * tv, List * picklist)
274 {
275     List   *p;
276     Tv     *tvl = left_tv();
277     Tv     *tvr = right_tv();
278 
279     tv_save_draw(tvl);
280     tv_save_draw(tvr);
281     tv_set_color(tvl, yellow);
282     tv_set_color(tvr, yellow);
283     for (p = picklist; p != NULL; p = p->next)
284         match_string_draw((Tstring *) p->to);
285     tv_reset_draw(tvl);
286     tv_reset_draw(tvr);
287 }
288 
289 static void print_edges(Tv * tv, List * picklist)
290 {
291     List   *p;
292 
293     for (p = picklist; p != NULL; p = p->next)
294         edge_format((Edgel *) p->to);
295 }
296 
297 /*
298 static void print_es(tv, picklist)
299 Tv     *tv;
300 List   *picklist;
301 {
302     List   *p;
303 
304     for (p = picklist; p != NULL; p = p->next) {
305         Tstring *es = prop_get(((Edgel *) (p->to))->props, SINDEX);
306 
307         str_apply_func(es, edge_format);
308     }
309 }
310 */
311 
312 static void print_matchlist(Tv * tv, List * picklist)
313 {
314     List   *p;
315 
316     for (p = picklist; p != NULL; p = p->next)
317     {
318         stereo_match_list_draw((List *) p->to);
319         em_list_format((List *) p->to);
320     }
321 }
322 
323 static void print_corr_match(Tv * tv, List * picklist)
324 {
325   List   *p, *other_p;
326   int     num = 1;
327   Bool    repeated_pick;
328 
329   for (p = picklist; p != NULL; p = p->next)
330     {
331       repeated_pick = false;
332 
333       /* check for the same edge being picked more than once */
334       for (other_p = p->next; other_p != NULL; other_p = other_p->next)
335         if (other_p->to == p->to)
336           repeated_pick = true;
337       
338       if (repeated_pick)
339         continue;
340 
341       stereo_corr_match_draw(tv, (Match *)p->to, num);
342       num++;
343     }
344 }
345 
346 Tv_pick left_edge_print(void)
347 {
348     return (pick_define(
349                         PICK_NAME, "edge",
350                         PICK_CLOSEST, left_pick_closest_edge,
351                         PICK_DRAW, pick_edge_draw,
352                         PICK_FUNC, print_edges,
353                         NULL));
354 }
355 
356 Tv_pick right_edge_print(void)
357 {
358     return (pick_define(
359                         PICK_NAME, "edge",
360                         PICK_CLOSEST, right_pick_closest_edge,
361                         PICK_DRAW, pick_edge_draw,
362                         PICK_FUNC, print_edges,
363                         NULL));
364 }
365 
366 Tv_pick mono_print(void)
367 {
368     return (pick_define(
369                         PICK_NAME, "edge",
370                         PICK_CLOSEST, mono_pick_closest_edge,
371                         PICK_DRAW, pick_edge_draw,
372                         PICK_FUNC, print_edges,
373                         NULL));
374 }
375 
376 Tv_pick left_edge_matches(void)
377 {
378     return (pick_define(
379                         PICK_NAME, "edge match",
380                         PICK_CLOSEST, left_pick_closest_matchlist,
381                         PICK_DRAW, pick_mlist_draw,
382                         PICK_FUNC, print_matchlist,
383                         PICK_REPAINT, false,
384                         NULL));
385 }
386 
387 Tv_pick left_edge_corr_matches(void)
388 {
389     return (pick_define(
390                         PICK_NAME, "corr match",
391                         PICK_CLOSEST, left_pick_closest_corr_match,
392                         PICK_DRAW, pick_corr_match_draw,
393                         PICK_FUNC, print_corr_match,
394                         PICK_REPAINT, false,
395                         NULL));
396 }
397 
398 Tv_pick right_edge_corr_matches(void)
399 {
400     return (pick_define(
401                         PICK_NAME, "corr match",
402                         PICK_CLOSEST, right_pick_closest_corr_match,
403                         PICK_DRAW, pick_corr_match_draw,
404                         PICK_FUNC, print_corr_match,
405                         PICK_REPAINT, false,
406                         NULL));
407 }
408 
409 Tv_pick left_string_matches(void)
410 {
411     return (pick_define(
412                         PICK_NAME, "string match",
413                         PICK_CLOSEST, left_pick_closest_string,
414                         PICK_DRAW, tv_edge_string,
415                         PICK_FUNC, picklist_match_string_draw,
416                         PICK_REPAINT, false,
417                         NULL));
418 }
419 

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