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

Linux Cross Reference
Tina5/tina-tools/tinatool/tlvision/tlvisEdge_pick.c

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

  1 /**********
  2 *
  3 *
  4  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  5  * University of Manchester, UK.  All rights reserved.
  6  * 
  7  * Redistribution and use in source and binary forms, with or without modification, 
  8  * are permitted provided that the following conditions are met:
  9  * 
 10  *   . Redistributions of source code must retain the above copyright notice, 
 11  *     this list of conditions and the following disclaimer.
 12  *    
 13  *   . Redistributions in binary form must reproduce the above copyright notice,
 14  *     this list of conditions and the following disclaimer in the documentation 
 15  *     and/or other materials provided with the distribution.
 16  * 
 17  *   . Neither the name of the University of Manchester nor the names of its
 18  *     contributors may be used to endorse or promote products derived from this 
 19  *     software without specific prior written permission.
 20  * 
 21  * 
 22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 32  * POSSIBILITY OF SUCH DAMAGE.
 33 **********
 34 *
 35 * Program :   TINA
 36 * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/tlvision/tlvisEdge_pick.c,v $
 37 * Date    :  $Date: 2003/10/01 16:02:47 $
 38 * Version :  $Revision: 1.3 $
 39 * CVS Id  :  $Id: tlvisEdge_pick.c,v 1.3 2003/10/01 16:02:47 tony Exp $
 40 *
 41 * Notes   :
 42 *
 43 *
 44 *
 45 *********
 46 */
 47 
 48 #include "tlvisEdge_pick.h"
 49 
 50 #if HAVE_CONFIG_H
 51   #include <config.h>
 52 #endif
 53 
 54 #include <tina/sys/sysDef.h>
 55 #include <tina/sys/sysPro.h>
 56 #include <tina/math/mathDef.h>
 57 #include <tina/math/mathPro.h>
 58 #include <tina/geometry/geomDef.h>
 59 #include <tina/geometry/geomPro.h>
 60 #include <tina/image/imgDef.h>
 61 #include <tina/image/imgPro.h>
 62 #include <tina/vision/visDef.h>
 63 #include <tina/vision/visPro.h>
 64 
 65 #include <tinatool/draw/drawDef.h>
 66 #include <tinatool/draw/drawPro.h>
 67 #include <tinatool/tlbase/tlbasePro.h>
 68 
 69 static int SEARCH_RADIUS = 25;
 70 
 71 static void *left_pick_closest_edge(Tv * tv, Ipos pos, int *type)
 72 {
 73     Imrect *er = left_edges();
 74     int     r, c;
 75     Vec2    v = {Vec2_id};
 76 
 77     *type = EDGE;
 78     v = tv_backproj2(tv, pos);
 79     r = tina_int(vec2_y(v));
 80     c = tina_int(vec2_x(v));
 81     return (er_closest(er, r, c, SEARCH_RADIUS, (void *(*) ()) NULL, NULL));
 82 }
 83 
 84 static void *left_pick_closest_matchlist(Tv * tv, Ipos pos, int *type)
 85 {
 86     Imrect *er = left_edges();
 87     int     r, c;
 88     Vec2    v = {Vec2_id};
 89 
 90     *type = LIST;
 91     v = tv_backproj2(tv, pos);
 92     r = tina_int(vec2_y(v));
 93     c = tina_int(vec2_x(v));
 94     return (er_closest(er, r, c, SEARCH_RADIUS, edge_sindex_prop_get, (void *) MLIST));
 95 }
 96 
 97 static void *left_pick_closest_corr_match(Tv * tv, Ipos pos, int *type)
 98 {
 99     Imrect *er = left_edges();
100     int     r, c;
101     Vec2    v = {Vec2_id};
102 
103     *type = LIST;
104     v = tv_backproj2(tv, pos);
105     r = tina_int(vec2_y(v));
106     c = tina_int(vec2_x(v));
107     return (er_closest(er, r, c, SEARCH_RADIUS, edge_prop_get, (void *) MATCH));
108 }
109 
110 static void *right_pick_closest_corr_match(Tv * tv, Ipos pos, int *type)
111 {
112     Imrect *er = right_edges();
113     int     r, c;
114     Vec2    v = {Vec2_id};
115 
116     *type = LIST;
117     v = tv_backproj2(tv, pos);
118     r = tina_int(vec2_y(v));
119     c = tina_int(vec2_x(v));
120     return (er_closest(er, r, c, SEARCH_RADIUS, edge_prop_get, (void *) MATCH));
121 }
122 
123 static void *left_pick_closest_string(Tv * tv, Ipos pos, int *type)
124 {
125     Imrect *er = left_edges();
126     Edgel  *edge;
127     int     r, c;
128     Vec2    v = {Vec2_id};
129 
130     *type = EDGE;
131     v = tv_backproj2(tv, pos);
132     r = tina_int(vec2_y(v));
133     c = tina_int(vec2_x(v));
134     edge = er_closest(er, r, c, SEARCH_RADIUS, (void *(*) ()) NULL, NULL);
135     if (edge == NULL)
136         return (NULL);
137 
138     return (prop_get(edge->props, STRING));
139 }
140 
141 static void *right_pick_closest_edge(Tv * tv, Ipos pos, int *type)
142 {
143     Imrect *er = right_edges();
144     int     r, c;
145     Vec2    v = {Vec2_id};
146 
147     *type = EDGE;
148     v = tv_backproj2(tv, pos);
149     r = tina_int(vec2_y(v));
150     c = tina_int(vec2_x(v));
151     return ((void *) er_closest(er, r, c, SEARCH_RADIUS, (void *(*) ()) NULL,
152                                 NULL));
153 }
154 
155 static void *mono_pick_closest_edge(Tv * tv, Ipos pos, int *type)
156 {
157     Imrect *er = mono_edges();
158     int     r, c;
159     Vec2    v = {Vec2_id};
160 
161     *type = EDGE;
162     v = tv_backproj2(tv, pos);
163     r = tina_int(vec2_y(v));
164     c = tina_int(vec2_x(v));
165     return ((void *) er_closest(er, r, c, SEARCH_RADIUS, (void *(*) ()) NULL,
166                                 NULL));
167 }
168 
169 void    pick_edge_draw(Tv * tv, Edgel * edge, int type)
170 {
171     if (edge == NULL || type != EDGE)
172         return;
173 
174     tv_cross2(tv, edge_image_pos(edge), 7);
175 }
176 
177 static void draw_matchable(Tv * tv, void *ptr, int type)
178 {
179   Point2 *point;
180 
181   switch (type)
182     {
183     case CORNER:
184       tv_cross2(tv, ((Edgel *) ptr)->pos, 7);
185       break;
186     case EDGE:
187       point = (Point2 *)prop_get(((Edgel *)ptr)->props, POINT2);
188       tv_pixel2(tv, point->p);
189       break;
190     case STRING:
191       tv_edge_string(tv, (Tstring *) ptr);
192       break;
193     }
194 }
195 
196 void    pick_mlist_draw(Tv * tv, List * mlist, int type)
197 {
198     List   *lptr;
199     Match  *match;
200 
201     if (mlist == NULL || type != LIST)
202         return;
203 
204     for (lptr = mlist; lptr != NULL; lptr = lptr->next)
205     {
206         match = (Match *) lptr->to;
207         draw_matchable(tv, match->to1, match->type);
208     }
209 }
210 
211 void    pick_corr_match_draw(Tv * tv1, Match * match, int type)
212 {
213   Tv     *tv2 = NULL;
214   int     old_color;
215 
216   if (tv1 == left_tv())
217     tv2 = right_tv();
218 
219   if (tv1 == right_tv())
220     tv2 = left_tv();
221 
222   if (match == NULL || tv1 == NULL || tv2 == NULL)
223     return;
224 
225   old_color = tv_get_color(tv2);
226   tv_set_color(tv2, green);
227 
228   draw_matchable(tv2, match->to2, EDGE);
229 
230   tv_set_color(tv2, old_color);
231 
232   old_color = tv_get_color(tv1);
233   tv_set_color(tv1, green);
234 
235   draw_matchable(tv1, match->to1, EDGE);
236 
237   tv_set_color(tv1, old_color);
238 }
239 
240 void    stereo_match_list_draw(List * mlist)
241 {
242     Tv     *tvl = left_tv();
243     Tv     *tvr = right_tv();
244     List   *lptr;
245     Match  *match;
246 
247     if (mlist == NULL)
248         return;
249 
250     for (lptr = mlist; lptr != NULL; lptr = lptr->next)
251     {
252         match = (Match *) lptr->to;
253         draw_matchable(tvl, match->to1, match->type);
254         draw_matchable(tvr, match->to2, match->type);
255     }
256 }
257 
258 void    stereo_corr_match_draw(Tv * tv1, Match * match, int num)
259 {
260   Tv     *tv2 = NULL;
261   Edgel  *edge1, *edge2;
262   Vec2    pos;
263   Point2 *point;
264   char    numstr[10];
265   int     old_color;
266 
267   sprintf(numstr, "%d", num);
268 
269   if (tv1 == left_tv())
270     tv2 = right_tv();
271 
272   if (tv1 == right_tv())
273     tv2 = left_tv();
274 
275   if (match == NULL || tv1 == NULL || tv2 == NULL)
276     return;
277 
278   old_color = tv_get_color(tv2);
279   tv_set_color(tv2, green);
280 
281   edge2 = (Edgel *)match->to2;
282   draw_matchable(tv2, (void *)edge2, EDGE);
283 
284   point = (Point2 *)prop_get(edge2->props, POINT2);
285   pos = point->p;
286   vec2_x(pos) = (float)tina_int(vec2_x(pos));
287   vec2_y(pos) = (float)tina_int(vec2_y(pos)) + 0.5;
288   tv_cltext2(tv2, numstr, pos);
289 
290   tv_set_color(tv2, old_color);
291 
292   old_color = tv_get_color(tv1);
293   tv_set_color(tv1, green);
294 
295   edge1 = (Edgel *)match->to1;
296   draw_matchable(tv1, (void *)edge1, EDGE);
297 
298   point = (Point2 *)prop_get(edge1->props, POINT2);
299   pos = point->p;
300   vec2_x(pos) = (float)tina_int(vec2_x(pos));
301   vec2_y(pos) = (float)tina_int(vec2_y(pos)) + 0.5;
302   tv_cltext2(tv1, numstr, pos);
303 
304   tv_set_color(tv1, old_color);
305 }
306 
307 static void match_string_draw(Tstring * es)
308 {
309     List *ptr;
310     List *end;
311 
312     if (es == NULL)
313         return;
314 
315     end = es->end;
316     for (ptr = es->start;; ptr = ptr->next)
317     {
318         Tstring *sub = prop_get(((Edgel *) (ptr->to))->props, SINDEX);
319 
320         stereo_match_list_draw((List *) prop_get(sub->props, MLIST));
321         ptr = sub->end;
322         if (ptr == end)
323             break;
324     }
325 }
326 
327 static void picklist_match_string_draw(Tv * tv, List * picklist)
328 {
329     List   *p;
330     Tv     *tvl = left_tv();
331     Tv     *tvr = right_tv();
332 
333     tv_save_draw(tvl);
334     tv_save_draw(tvr);
335     tv_set_color(tvl, yellow);
336     tv_set_color(tvr, yellow);
337     for (p = picklist; p != NULL; p = p->next)
338         match_string_draw((Tstring *) p->to);
339     tv_reset_draw(tvl);
340     tv_reset_draw(tvr);
341 }
342 
343 static void print_edges(Tv * tv, List * picklist)
344 {
345     List   *p;
346 
347     for (p = picklist; p != NULL; p = p->next)
348         edge_format((Edgel *) p->to);
349 }
350 
351 /*
352 static void print_es(tv, picklist)
353 Tv     *tv;
354 List   *picklist;
355 {
356     List   *p;
357 
358     for (p = picklist; p != NULL; p = p->next) {
359         Tstring *es = prop_get(((Edgel *) (p->to))->props, SINDEX);
360 
361         str_apply_func(es, edge_format);
362     }
363 }
364 */
365 
366 static void print_matchlist(Tv * tv, List * picklist)
367 {
368     List   *p;
369 
370     for (p = picklist; p != NULL; p = p->next)
371     {
372         stereo_match_list_draw((List *) p->to);
373         em_list_format((List *) p->to);
374     }
375 }
376 
377 static void print_corr_match(Tv * tv, List * picklist)
378 {
379   List   *p, *other_p;
380   int     num = 1;
381   Bool    repeated_pick;
382 
383   for (p = picklist; p != NULL; p = p->next)
384     {
385       repeated_pick = false;
386 
387       /* check for the same edge being picked more than once */
388       for (other_p = p->next; other_p != NULL; other_p = other_p->next)
389         if (other_p->to == p->to)
390           repeated_pick = true;
391       
392       if (repeated_pick)
393         continue;
394 
395       stereo_corr_match_draw(tv, (Match *)p->to, num);
396       num++;
397     }
398 }
399 
400 Tv_pick left_edge_print(void)
401 {
402     return (pick_define(
403                         PICK_NAME, "edge",
404                         PICK_CLOSEST, left_pick_closest_edge,
405                         PICK_DRAW, pick_edge_draw,
406                         PICK_FUNC, print_edges,
407                         NULL));
408 }
409 
410 Tv_pick right_edge_print(void)
411 {
412     return (pick_define(
413                         PICK_NAME, "edge",
414                         PICK_CLOSEST, right_pick_closest_edge,
415                         PICK_DRAW, pick_edge_draw,
416                         PICK_FUNC, print_edges,
417                         NULL));
418 }
419 
420 Tv_pick mono_print(void)
421 {
422     return (pick_define(
423                         PICK_NAME, "edge",
424                         PICK_CLOSEST, mono_pick_closest_edge,
425                         PICK_DRAW, pick_edge_draw,
426                         PICK_FUNC, print_edges,
427                         NULL));
428 }
429 
430 Tv_pick left_edge_matches(void)
431 {
432     return (pick_define(
433                         PICK_NAME, "edge match",
434                         PICK_CLOSEST, left_pick_closest_matchlist,
435                         PICK_DRAW, pick_mlist_draw,
436                         PICK_FUNC, print_matchlist,
437                         PICK_REPAINT, false,
438                         NULL));
439 }
440 
441 Tv_pick left_edge_corr_matches(void)
442 {
443     return (pick_define(
444                         PICK_NAME, "corr match",
445                         PICK_CLOSEST, left_pick_closest_corr_match,
446                         PICK_DRAW, pick_corr_match_draw,
447                         PICK_FUNC, print_corr_match,
448                         PICK_REPAINT, false,
449                         NULL));
450 }
451 
452 Tv_pick right_edge_corr_matches(void)
453 {
454     return (pick_define(
455                         PICK_NAME, "corr match",
456                         PICK_CLOSEST, right_pick_closest_corr_match,
457                         PICK_DRAW, pick_corr_match_draw,
458                         PICK_FUNC, print_corr_match,
459                         PICK_REPAINT, false,
460                         NULL));
461 }
462 
463 Tv_pick left_string_matches(void)
464 {
465     return (pick_define(
466                         PICK_NAME, "string match",
467                         PICK_CLOSEST, left_pick_closest_string,
468                         PICK_DRAW, tv_edge_string,
469                         PICK_FUNC, picklist_match_string_draw,
470                         PICK_REPAINT, false,
471                         NULL));
472 }
473 

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