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

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

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

  1 /**********
  2  *
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  *
 35  * Program :   TINA
 36  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/tlvision/tlvisCnr_pick.c,v $
 37  * Date    :  $Date: 2003/10/01 16:02:47 $
 38  * Version :  $Revision: 1.2 $
 39  * CVS Id  :  $Id: tlvisCnr_pick.c,v 1.2 2003/10/01 16:02:47 tony Exp $
 40  *
 41  * Notes :
 42  *
 43  *
 44  *
 45  *********
 46 */
 47 
 48 #include "tlvisCnr_pick.h"
 49 
 50 #if HAVE_CONFIG_H
 51 #include <config.h>
 52 #endif
 53 
 54 #include <stdio.h>
 55 #include <limits.h>
 56 
 57 #include <tina/sys/sysDef.h>
 58 #include <tina/sys/sysPro.h>
 59 #include <tina/math/mathDef.h>
 60 #include <tina/math/mathPro.h>
 61 #include <tina/geometry/geomDef.h>
 62 #include <tina/geometry/geomPro.h>
 63 #include <tina/image/imgDef.h>
 64 #include <tina/image/imgPro.h>
 65 #include <tina/vision/visDef.h>
 66 #include <tina/vision/visPro.h>
 67 
 68 #include <tinatool/draw/drawDef.h>
 69 #include <tinatool/draw/drawPro.h>
 70 #include <tinatool/tlbase/tlbasePro.h>
 71 
 72 
 73 
 74 static int SEARCH_RADIUS = 25;
 75 static Edgel *picked_lmatch = NULL;
 76 static Edgel *picked_rmatch = NULL;
 77 
 78 void   *left_pick_closest_corner(Tv * tv, Ipos pos, int *type)
 79 {
 80     Imrect *er = left_corners_get();
 81     int     r, c;
 82     Vec2    v = {Vec2_id};
 83 
 84     *type = CORNER;
 85     v = tv_backproj2(tv, pos);
 86     r = tina_int(vec2_y(v));
 87     c = tina_int(vec2_x(v));
 88     picked_lmatch = er_closest(er, r, c, SEARCH_RADIUS, (void *(*) ()) NULL,
 89                                NULL);
 90     return ((void *) picked_lmatch);
 91 }
 92 
 93 void   *right_pick_closest_corner(Tv * tv, Ipos pos, int *type)
 94 {
 95     Imrect *er = right_corners_get();
 96     int     r, c;
 97     Vec2    v = {Vec2_id};
 98 
 99     *type = CORNER;
100     v = tv_backproj2(tv, pos);
101     r = tina_int(vec2_y(v));
102     c = tina_int(vec2_x(v));
103 
104     picked_rmatch = er_closest(er, r, c, SEARCH_RADIUS, (void *(*) ()) NULL,
105                                NULL);
106 
107     return ((void *) picked_rmatch);
108 }
109 
110 /* ARGSUSED Quieten Lint */
111 void    print_corners(Tv * tv, List * picklist)
112 {
113     List   *p,*left_matches,*right_matches;
114     Match *lmatch,*rmatch;
115 
116     for (p = picklist; p != NULL; p = p->next)
117         edge_format((Edgel *) p->to);
118     if (picked_lmatch!=NULL && picked_rmatch!=NULL)
119     {
120         lmatch = match_alloc(CORNER);
121         lmatch->weight = 1.0;
122         lmatch->to1 = (void *) picked_lmatch;
123         lmatch->to2 = (void *) picked_rmatch;
124         add_match_to_props(picked_lmatch, (void *) lmatch, MLIST);
125 
126 
127         rmatch = match_alloc(CORNER);
128         rmatch->weight = 1.0;
129         rmatch->to1 = (void *) picked_lmatch;
130         rmatch->to2 = (void *) picked_rmatch;
131         add_match_to_props(picked_rmatch, (void *) rmatch, MLIST);
132 
133         left_matches = (List *) prop_get(picked_lmatch->props, MLIST);
134         right_matches = (List *) prop_get(picked_rmatch->props, MLIST);
135         left_matches->type = FIXED_MATCH;
136         right_matches->type = FIXED_MATCH;
137         picked_lmatch = NULL;
138         picked_rmatch = NULL;
139     }
140 }
141 
142 void    pick_corner_draw(Tv * tv, Edgel * edge, int type)
143 {
144     if (edge == NULL || type != CORNER)
145         return;
146 
147     tv_cross2(tv, edge->pos, 7);
148 }
149 
150 /* ARGSUSED Quieten Lint */
151 void    print_cnrmatch(Match *match)
152 {
153     Transform3 rect_unrect = {Transform3_id};
154     Parcam *pcam;
155     Edgel  *edgel;
156     Edgel  *edger;
157     Vec2   *rectl = NULL;
158     Vec2   *rectr = NULL;
159     Vec3    disp = {Vec3_id};
160     Vec3    pos = {Vec3_id};
161     Matrix         *left_patch, *right_patch;
162     int             i, j;
163     char    temp[128];
164 
165     if (match == NULL)
166         return;
167     edgel = (Edgel *) match->to1;
168     edger = (Edgel *) match->to2;
169     if (edgel == NULL || edger == NULL)
170         return;
171     edge_format(edgel);
172     edge_format(edger);
173 /*
174     rectl = (Vec2 *) prop_get(edgel->props, RECTPOS);
175     rectr = (Vec2 *) prop_get(edger->props, RECTPOS);
176     if (rectl && rectr)
177     {
178         (void) sprintf(temp, " rectified positions : %3.1f %3.1f %3.1f %3.1f \n",
179               rectl->el[0], rectl->el[1], rectr->el[0], rectr->el[1]);
180         format(temp);
181         disp.el[0] = rectl->el[0];
182         disp.el[1] = (rectl->el[1] + rectr->el[1]) / 2.0;
183         disp.el[2] = rectr->el[0] - rectl->el[0];
184         pos = vec3_par_proj_3d(disp);
185         (void) sprintf(temp, "rectified 3d location :  %3.1f %3.1f %3.1f \n",
186                        pos.el[0], pos.el[1], pos.el[2]);
187         format(temp);
188         pcam = pcam_get();
189         rect_unrect =           
190 */
191 /* trans3_prod(*(pcam->cam1->transf), */
192 /*
193             trans3_inverse(*(pcam->rcam1->transf));
194         pos = trans3_pos(rect_unrect, pos);
195         (void) sprintf(temp, "world 3d location :  %3.1f %3.1f %3.1f \n",
196                        pos.el[0], pos.el[1], pos.el[2]);
197         format(temp);
198     }
199 */
200     (void) sprintf(temp, "match->weight = %f\n", match->weight);
201     format(temp);
202     if ((left_patch = (Matrix *) prop_get(edgel->props, PATCH)) == NULL)
203         if ((left_patch=(Matrix *)add_patch_to_props(edgel,left_image_get(),3.0))==NULL)
204             return;
205     if ((right_patch = (Matrix *) prop_get(edger->props, PATCH)) == NULL)
206          if ((right_patch=(Matrix *)add_patch_to_props(edger,right_image_get(),3.0))==NULL)
207             return;;
208 
209     for (i=0;i<5;i++)
210     {
211         sprintf(temp," %1.4f %1.4f %1.4f %1.4f %1.4f \n",
212                 left_patch->el.float_v[i][0],
213                 left_patch->el.float_v[i][1],
214                 left_patch->el.float_v[i][2],
215                 left_patch->el.float_v[i][3],
216                 left_patch->el.float_v[i][4]);
217         format(temp);
218     }
219     for (i=0;i<5;i++)
220     {
221         sprintf(temp," %1.4f %1.4f %1.4f %1.4f %1.4f \n",
222                right_patch->el.float_v[i][0],
223                right_patch->el.float_v[i][1],
224                right_patch->el.float_v[i][2],
225                right_patch->el.float_v[i][3],
226                right_patch->el.float_v[i][4]);
227         format(temp);
228     }
229 }
230 
231 void   print_corner_match(Tv * tv, List * picklist)
232 {
233     List   *matchlist;
234     Match  *match;
235 
236     if (picklist == NULL || (matchlist = picklist->to) == NULL)
237     return;
238 
239     match = matchlist->to;
240     print_cnrmatch(match);
241 }
242 
243 void   *mono_pick_corner_matchlist(Tv * tv, Ipos pos, int *type)
244 {
245     Imrect *er = mono_corners_get();
246     int     r, c;
247     Vec2    v = {Vec2_id};
248     int     data = BACKTEMP;
249 
250     *type = LIST;
251     v = tv_backproj2(tv, pos);
252     r = tina_int(vec2_y(v));
253     c = tina_int(vec2_x(v));
254     return ((void *) er_closest(er, r, c, SEARCH_RADIUS, get_matches_list, (void *) &data));
255 }
256 
257 void   *left_pick_corner_matchlist(Tv * tv, Ipos pos, int *type)
258 {
259     Imrect *er = left_corners_get();
260     int     r, c;
261     Vec2    v = {Vec2_id};
262     int     data = MLIST;
263 
264     *type = LIST;
265     v = tv_backproj2(tv, pos);
266     r = tina_int(vec2_y(v));
267     c = tina_int(vec2_x(v));
268     return ((void *) er_closest(er, r, c, SEARCH_RADIUS, get_matches_list, (void *) &data));
269 }
270 
271 void   *right_pick_corner_matchlist(Tv * tv, Ipos pos, int *type)
272 {
273     Imrect *er = right_corners_get();
274     int     r, c;
275     Vec2    v = {Vec2_id};
276     int     data = MLIST;
277 
278     *type = LIST;
279     v = tv_backproj2(tv, pos);
280     r = tina_int(vec2_y(v));
281     c = tina_int(vec2_x(v));
282     return ((void *) er_closest(er, r, c, SEARCH_RADIUS, get_matches_list, (void *) &data));
283 }
284 
285 static void pick_mlist_cordraw(Tv * tv, List * mlist, int type)
286 {
287     Tv     *tvl = left_tv();
288     Tv     *tvr = right_tv();
289     List   *lptr;
290     Match  *match;
291  
292     if (mlist == NULL || type != LIST)
293         return;
294 
295     if (tv == tvl)
296     {
297          tv_set_overlay(tvr);
298          match = (Match *)mlist->to;
299          tv_cross2(tvl, ((Edgel *) match->to1)->pos, 7);
300          for (lptr = mlist; lptr != NULL; lptr = lptr->next)
301          {
302               match = (Match *) lptr->to;
303               tv_cross2(tvr, ((Edgel *) match->to2)->pos, 7);
304          }
305          tv_reset_draw(tvr);
306     }
307     else
308     {
309          tv_set_overlay(tvl);
310          match = (Match *)mlist->to;
311          tv_cross2(tvr, ((Edgel *) match->to2)->pos, 7);
312          for (lptr = mlist; lptr != NULL; lptr = lptr->next)
313          {
314               match = (Match *) lptr->to;
315               tv_cross2(tvl, ((Edgel *) match->to1)->pos, 7);
316          }
317          tv_reset_draw(tvl);
318     }
319 }
320 
321 static void mono_pick_mlist_cordraw(Tv * tv, List * mlist, int type)
322 {
323     List   *lptr;
324     Match  *match;
325  
326     if (mlist == NULL || type != LIST)
327         return;
328 
329     for (lptr = mlist; lptr != NULL; lptr = lptr->next)
330     {
331          match = (Match *) lptr->to;
332          tv_cross2(tv, ((Edgel *) match->to2)->pos, 7);
333     }
334     tv_reset_draw(tv);
335     tv_set_color(tv, green);
336     match = (Match *)mlist->to;
337     tv_cross2(tv, ((Edgel *) match->to1)->pos, 7);
338     tv_set_overlay(tv);
339 }
340 
341 
342 
343 Tv_pick mono_corner_matches(void)
344 {
345     return (pick_define(
346                         PICK_CLOSEST, mono_pick_corner_matchlist,
347                         PICK_DRAW, mono_pick_mlist_cordraw,
348                         PICK_REPAINT, false,
349                         PICK_FUNC, print_corner_match,
350                         NULL));
351 
352 }
353 
354 Tv_pick left_corner_matches(void)
355 {
356     return (pick_define(
357                         PICK_CLOSEST, left_pick_corner_matchlist,
358                         PICK_DRAW, pick_mlist_cordraw,
359                         PICK_REPAINT, false,
360                         PICK_FUNC, print_corner_match,
361                         NULL));
362 }
363 
364 Tv_pick right_corner_matches(void)
365 {
366     return (pick_define(
367                         PICK_CLOSEST, right_pick_corner_matchlist,
368                         PICK_DRAW, pick_mlist_cordraw,
369                         PICK_REPAINT, false,
370                         PICK_FUNC, print_corner_match,
371                         NULL));
372 }
373 
374 Tv_pick left_print_cor(void)
375 {
376     void   *left_pick_closest_corner(Tv * tv, Ipos pos, int *type);
377     void    pick_corner_draw(Tv * tv, Edgel * edge, int type);
378     void    print_corners(Tv * tv, List * picklist);
379 
380     return (pick_define(
381                         PICK_CLOSEST, left_pick_closest_corner,
382                         PICK_DRAW, pick_corner_draw,
383                         PICK_REPAINT, false,
384                         PICK_FUNC, print_corners,
385                         NULL));
386 }
387 
388 Tv_pick right_print_cor(void)
389 {
390     void   *right_pick_closest_corner(Tv * tv, Ipos pos, int *type);
391     void    pick_corner_draw(Tv * tv, Edgel * edge, int type);
392     void    print_corners(Tv * tv, List * picklist);
393 
394     return (pick_define(
395                         PICK_CLOSEST, right_pick_closest_corner,
396                         PICK_DRAW, pick_corner_draw,
397                         PICK_REPAINT, false,
398                         PICK_FUNC, print_corners,
399                         NULL));
400 }
401 

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