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

Linux Cross Reference
Tina6/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 static Vec2 picked_lpos = {Vec2_id};
 78 static Vec2 picked_rpos = {Vec2_id};
 79 
 80 void   *left_pick_pos(Tv * tv, Ipos pos, int *type)
 81 {
 82     Imrect *er = left_corners_get();
 83     int     r, c;
 84     Vec2    v = {Vec2_id};
 85 
 86     *type = CORNER;
 87     picked_lpos = tv_backproj2(tv, pos);
 88 
 89 
 90     return ((void *) &picked_lpos);
 91 }
 92 
 93 void   *right_pick_pos(Tv * tv, Ipos pos, int *type)
 94 {
 95     Imrect *er = left_corners_get();
 96     int     r, c;
 97     Vec2    v = {Vec2_id};
 98 
 99     *type = CORNER;
100     picked_rpos = tv_backproj2(tv, pos);
101 
102 
103     return ((void *) &picked_rpos);
104 }
105 
106 void   *left_pick_closest_corner(Tv * tv, Ipos pos, int *type)
107 {
108     Imrect *er = left_corners_get();
109     int     r, c;
110     Vec2    v = {Vec2_id};
111 
112     *type = CORNER;
113     v = tv_backproj2(tv, pos);
114     r = tina_int(vec2_y(v));
115     c = tina_int(vec2_x(v));
116     picked_lmatch = er_closest(er, r, c, SEARCH_RADIUS, (void *(*) ()) NULL,
117                                NULL);
118     return ((void *) picked_lmatch);
119 }
120 
121 void   *right_pick_closest_corner(Tv * tv, Ipos pos, int *type)
122 {
123     Imrect *er = right_corners_get();
124     int     r, c;
125     Vec2    v = {Vec2_id};
126 
127     *type = CORNER;
128     v = tv_backproj2(tv, pos);
129     r = tina_int(vec2_y(v));
130     c = tina_int(vec2_x(v));
131 
132     picked_rmatch = er_closest(er, r, c, SEARCH_RADIUS, (void *(*) ()) NULL,
133                                NULL);
134 
135     return ((void *) picked_rmatch);
136 }
137 
138 void pick_pos_draw(Tv * tv, Vec2 * pos, int type)
139 {
140     tv_cross2(tv, *pos, 7);
141 }
142 
143 
144 void    print_pos(Tv * tv, List * picklist)
145 {
146     Transform3 rect_unrect = {Transform3_id};
147     Tv     *tv3D = threed_tv();
148     Parcam         *pcam = pcam_get();;
149     Mat3 lrect;
150     Mat3 rrect;
151     Vec2 lpos_rec, rpos_rec;
152     Vec3 disp, pos;
153 
154     /* calculations do not correct for radial distortion NAT 10/6/11 */
155     format("left %f %f right %f %f \n",  picked_lpos.el[0], picked_lpos.el[1], picked_rpos.el[0], picked_rpos.el[1]);
156     if (pcam !=NULL)
157     {
158        lrect = pcam->rect1;
159        rrect = pcam->rect2;
160        lpos_rec = rectify_pos(lrect, picked_lpos);
161        rpos_rec = rectify_pos(rrect, picked_rpos);
162 
163        disp.el[0] = lpos_rec.el[0];
164        disp.el[1] = (lpos_rec.el[1] + rpos_rec.el[1]) / 2.0;
165        disp.el[2] = rpos_rec.el[0] - lpos_rec.el[0];
166        pos = vec3_par_proj_3d(disp);
167        tv_set_overlay(tv3D);
168        tv_bigdot3(tv3D, pos,3);
169        tv_reset_draw(tv3D);
170 
171        rect_unrect =            
172 /* trans3_prod(*(pcam->cam1->transf), */
173           trans3_inverse(*(pcam->rcam1->transf));
174         pos = trans3_pos(rect_unrect, pos);
175         format("world 3d location :  %3.1f %3.1f %3.1f \n",
176                        pos.el[0], pos.el[1], pos.el[2]);
177     }
178 
179 }
180 
181 /* ARGSUSED Quieten Lint */
182 void    print_corners(Tv * tv, List * picklist)
183 {
184     List   *p,*left_matches,*right_matches;
185     Match *lmatch,*rmatch;
186 
187     for (p = picklist; p != NULL; p = p->next)
188         edge_format((Edgel *) p->to);
189     if (picked_lmatch!=NULL && picked_rmatch!=NULL)
190     {
191         lmatch = match_alloc(CORNER);
192         lmatch->weight = 1.0;
193         lmatch->to1 = (void *) picked_lmatch;
194         lmatch->to2 = (void *) picked_rmatch;
195         add_match_to_props(picked_lmatch, (void *) lmatch, MLIST);
196 
197 
198         rmatch = match_alloc(CORNER);
199         rmatch->weight = 1.0;
200         rmatch->to1 = (void *) picked_lmatch;
201         rmatch->to2 = (void *) picked_rmatch;
202         add_match_to_props(picked_rmatch, (void *) rmatch, MLIST);
203 
204         left_matches = (List *) prop_get(picked_lmatch->props, MLIST);
205         right_matches = (List *) prop_get(picked_rmatch->props, MLIST);
206         left_matches->type = FIXED_MATCH;
207         right_matches->type = FIXED_MATCH;
208         picked_lmatch = NULL;
209         picked_rmatch = NULL;
210     }
211 }
212 
213 void    pick_corner_draw(Tv * tv, Edgel * edge, int type)
214 {
215     if (edge == NULL || type != CORNER)
216         return;
217 
218     tv_cross2(tv, edge->pos, 7);
219 }
220 
221 /* ARGSUSED Quieten Lint */
222 void    print_cnrmatch(Match *match)
223 {
224     Transform3 rect_unrect = {Transform3_id};
225     Parcam *pcam;
226     Edgel  *edgel;
227     Edgel  *edger;
228     Vec2   *rectl = NULL;
229     Vec2   *rectr = NULL;
230     Vec3    disp = {Vec3_id};
231     Vec3    pos = {Vec3_id};
232     Matrix         *left_patch, *right_patch;
233     int             i, j;
234     char    temp[128];
235 
236     if (match == NULL)
237         return;
238     edgel = (Edgel *) match->to1;
239     edger = (Edgel *) match->to2;
240     if (edgel == NULL || edger == NULL)
241         return;
242     edge_format(edgel);
243     edge_format(edger);
244 /*
245     rectl = (Vec2 *) prop_get(edgel->props, RECTPOS);
246     rectr = (Vec2 *) prop_get(edger->props, RECTPOS);
247     if (rectl && rectr)
248     {
249         (void) sprintf(temp, " rectified positions : %3.1f %3.1f %3.1f %3.1f \n",
250               rectl->el[0], rectl->el[1], rectr->el[0], rectr->el[1]);
251         format(temp);
252         disp.el[0] = rectl->el[0];
253         disp.el[1] = (rectl->el[1] + rectr->el[1]) / 2.0;
254         disp.el[2] = rectr->el[0] - rectl->el[0];
255         pos = vec3_par_proj_3d(disp);
256         (void) sprintf(temp, "rectified 3d location :  %3.1f %3.1f %3.1f \n",
257                        pos.el[0], pos.el[1], pos.el[2]);
258         format(temp);
259         pcam = pcam_get();
260         rect_unrect =           
261 */
262 /* trans3_prod(*(pcam->cam1->transf), */
263 /*
264             trans3_inverse(*(pcam->rcam1->transf));
265         pos = trans3_pos(rect_unrect, pos);
266         (void) sprintf(temp, "world 3d location :  %3.1f %3.1f %3.1f \n",
267                        pos.el[0], pos.el[1], pos.el[2]);
268         format(temp);
269     }
270 */
271     (void) sprintf(temp, "match->weight = %f\n", match->weight);
272     format(temp);
273 /*
274     if ((left_patch = (Matrix *) prop_get(edgel->props, PATCH)) == NULL)
275         if ((left_patch=(Matrix *)add_patch_to_props(edgel,left_image_get(),3.0))==NULL)
276             return;
277     if ((right_patch = (Matrix *) prop_get(edger->props, PATCH)) == NULL)
278          if ((right_patch=(Matrix *)add_patch_to_props(edger,right_image_get(),3.0))==NULL)
279             return;;
280 
281     for (i=0;i<5;i++)
282     {
283         sprintf(temp," %1.4f %1.4f %1.4f %1.4f %1.4f \n",
284                 left_patch->el.float_v[i][0],
285                 left_patch->el.float_v[i][1],
286                 left_patch->el.float_v[i][2],
287                 left_patch->el.float_v[i][3],
288                 left_patch->el.float_v[i][4]);
289         format(temp);
290     }
291     for (i=0;i<5;i++)
292     {
293         sprintf(temp," %1.4f %1.4f %1.4f %1.4f %1.4f \n",
294                right_patch->el.float_v[i][0],
295                right_patch->el.float_v[i][1],
296                right_patch->el.float_v[i][2],
297                right_patch->el.float_v[i][3],
298                right_patch->el.float_v[i][4]);
299         format(temp);
300     }
301 */
302 }
303 
304 void   print_corner_match(Tv * tv, List * picklist)
305 {
306     List   *matchlist;
307     Match  *match;
308 
309     if (picklist == NULL || (matchlist = picklist->to) == NULL)
310     return;
311 
312     match = matchlist->to;
313     print_cnrmatch(match);
314 }
315 
316 void   *mono_pick_corner_matchlist(Tv * tv, Ipos pos, int *type)
317 {
318     Imrect *er = mono_corners_get();
319     int     r, c;
320     Vec2    v = {Vec2_id};
321     int     data = BACKTEMP;
322 
323     *type = LIST;
324     v = tv_backproj2(tv, pos);
325     r = tina_int(vec2_y(v));
326     c = tina_int(vec2_x(v));
327     return ((void *) er_closest(er, r, c, SEARCH_RADIUS, get_matches_list, (void *) &data));
328 }
329 
330 void   *left_pick_corner_matchlist(Tv * tv, Ipos pos, int *type)
331 {
332     Imrect *er = left_corners_get();
333     int     r, c;
334     Vec2    v = {Vec2_id};
335     int     data = MLIST;
336 
337     *type = LIST;
338     v = tv_backproj2(tv, pos);
339     r = tina_int(vec2_y(v));
340     c = tina_int(vec2_x(v));
341     return ((void *) er_closest(er, r, c, SEARCH_RADIUS, get_matches_list, (void *) &data));
342 }
343 
344 void   *right_pick_corner_matchlist(Tv * tv, Ipos pos, int *type)
345 {
346     Imrect *er = right_corners_get();
347     int     r, c;
348     Vec2    v = {Vec2_id};
349     int     data = MLIST;
350 
351     *type = LIST;
352     v = tv_backproj2(tv, pos);
353     r = tina_int(vec2_y(v));
354     c = tina_int(vec2_x(v));
355     return ((void *) er_closest(er, r, c, SEARCH_RADIUS, get_matches_list, (void *) &data));
356 }
357 
358 static void pick_mlist_cordraw(Tv * tv, List * mlist, int type)
359 {
360     Tv     *tvl = left_tv();
361     Tv     *tvr = right_tv();
362     Tv     *tv3D = threed_tv();
363     Vec3   *pos;
364     List   *lptr;
365     Match  *match;
366  
367     if (mlist == NULL || type != LIST)
368         return;
369 
370     if (tv == tvl)
371     {
372          tv_set_overlay(tvl);
373          tv_set_overlay(tvr);
374          match = (Match *)mlist->to;
375          tv_cross2(tvl, ((Edgel *) match->to1)->pos, 5);
376          for (lptr = mlist; lptr != NULL; lptr = lptr->next)
377          {
378               match = (Match *) lptr->to;
379               if (lptr->type == FIXED_MATCH)
380               {                
381                   tv_cross2(tvr, ((Edgel *) match->to2)->pos, 5);
382                   if (tv3D !=NULL)
383                   {
384                       tv_set_overlay(tv3D); 
385                       pos = (Vec3 *)prop_get(((Edgel *) match->to1)->props, POINT3);
386                       if (pos !=NULL)
387                       {
388                          tv_bigdot3(tv3D, *pos,3);
389                       }
390                       tv_reset_draw(tv3D);
391                   }
392               }
393          }
394          tv_reset_draw(tvl);
395          tv_reset_draw(tvr);
396     }
397     else
398     {
399          tv_set_overlay(tvl);
400          tv_set_overlay(tvr);
401          match = (Match *)mlist->to;
402          tv_cross2(tvr, ((Edgel *) match->to2)->pos, 5);
403          for (lptr = mlist; lptr != NULL; lptr = lptr->next)
404          {
405               match = (Match *) lptr->to;
406               if (lptr->type == FIXED_MATCH)
407               {
408                   tv_cross2(tvl, ((Edgel *) match->to1)->pos, 5);
409                   if (tv3D !=NULL)
410                   {
411                       tv_set_overlay(tv3D); 
412                       pos = (Vec3 *)prop_get(((Edgel *) match->to1)->props, POINT3);
413                       if (pos !=NULL)
414                       {
415                          tv_bigdot3(tv3D, *pos,3);
416                       }
417                       tv_reset_draw(tv3D);
418                   }
419               }
420          }
421          tv_reset_draw(tvl);
422          tv_reset_draw(tvr);
423     }
424 }
425 
426 static void mono_pick_mlist_cordraw(Tv * tv, List * mlist, int type)
427 {
428     List   *lptr;
429     Match  *match;
430  
431     if (mlist == NULL || type != LIST)
432         return;
433 
434     for (lptr = mlist; lptr != NULL; lptr = lptr->next)
435     {
436          match = (Match *) lptr->to;
437          tv_cross2(tv, ((Edgel *) match->to2)->pos, 7);
438     }
439     tv_reset_draw(tv);
440     tv_set_color(tv, green);
441     match = (Match *)mlist->to;
442     tv_cross2(tv, ((Edgel *) match->to1)->pos, 7);
443     tv_set_overlay(tv);
444 }
445 
446 
447 
448 Tv_pick mono_corner_matches(void)
449 {
450     return (pick_define(
451                         PICK_CLOSEST, mono_pick_corner_matchlist,
452                         PICK_DRAW, mono_pick_mlist_cordraw,
453                         PICK_REPAINT, false,
454                         PICK_FUNC, print_corner_match,
455                         NULL));
456 
457 }
458 
459 Tv_pick left_corner_matches(void)
460 {
461     return (pick_define(
462                         PICK_CLOSEST, left_pick_corner_matchlist,
463                         PICK_DRAW, pick_mlist_cordraw,
464                         PICK_REPAINT, false,
465                         PICK_FUNC, print_corner_match,
466                         NULL));
467 }
468 
469 Tv_pick right_corner_matches(void)
470 {
471     return (pick_define(
472                         PICK_CLOSEST, right_pick_corner_matchlist,
473                         PICK_DRAW, pick_mlist_cordraw,
474                         PICK_REPAINT, false,
475                         PICK_FUNC, print_corner_match,
476                         NULL));
477 }
478 
479 Tv_pick left_manual_cor(void)
480 {
481     void   *left_pick_pos(Tv * tv, Ipos pos, int *type);
482     void    pick_pos_draw(Tv * tv, Vec2 * pos, int type);
483     void    print_pos(Tv * tv, List * picklist);
484 
485     return (pick_define(
486                         PICK_CLOSEST, left_pick_pos,
487                         PICK_DRAW, pick_pos_draw,
488                         PICK_REPAINT, false,
489                         PICK_FUNC, print_pos,
490                         NULL));
491 }
492 
493 Tv_pick right_manual_cor(void)
494 {
495     void   *right_pick_pos(Tv * tv, Ipos pos, int *type);
496     void    pick_pos_draw(Tv * tv, Vec2 * pos, int type);
497     void    print_pos(Tv * tv, List * picklist);
498 
499     return (pick_define(
500                         PICK_CLOSEST, right_pick_pos,
501                         PICK_DRAW, pick_pos_draw,
502                         PICK_REPAINT, false,
503                         PICK_FUNC, print_pos,
504                         NULL));
505 }
506 
507 
508 Tv_pick left_print_cor(void)
509 {
510     void   *left_pick_closest_corner(Tv * tv, Ipos pos, int *type);
511     void    pick_corner_draw(Tv * tv, Edgel * edge, int type);
512     void    print_corners(Tv * tv, List * picklist);
513 
514     return (pick_define(
515                         PICK_CLOSEST, left_pick_closest_corner,
516                         PICK_DRAW, pick_corner_draw,
517                         PICK_REPAINT, false,
518                         PICK_FUNC, print_corners,
519                         NULL));
520 }
521 
522 Tv_pick right_print_cor(void)
523 {
524     void   *right_pick_closest_corner(Tv * tv, Ipos pos, int *type);
525     void    pick_corner_draw(Tv * tv, Edgel * edge, int type);
526     void    print_corners(Tv * tv, List * picklist);
527 
528     return (pick_define(
529                         PICK_CLOSEST, right_pick_closest_corner,
530                         PICK_DRAW, pick_corner_draw,
531                         PICK_REPAINT, false,
532                         PICK_FUNC, print_corners,
533                         NULL));
534 }
535 

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