Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

tlvisEdge_pick.c

Go to the documentation of this file.
00001 /**********
00002 *
00003 *
00004  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
00005  * University of Manchester, UK.  All rights reserved.
00006  * 
00007  * Redistribution and use in source and binary forms, with or without modification, 
00008  * are permitted provided that the following conditions are met:
00009  * 
00010  *   . Redistributions of source code must retain the above copyright notice, 
00011  *     this list of conditions and the following disclaimer.
00012  *    
00013  *   . Redistributions in binary form must reproduce the above copyright notice,
00014  *     this list of conditions and the following disclaimer in the documentation 
00015  *     and/or other materials provided with the distribution.
00016  * 
00017  *   . Neither the name of the University of Manchester nor the names of its
00018  *     contributors may be used to endorse or promote products derived from this 
00019  *     software without specific prior written permission.
00020  * 
00021  * 
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00023  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
00026  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00027  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
00028  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00029  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00030  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00031  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00032  * POSSIBILITY OF SUCH DAMAGE.
00033 **********
00034 *
00035 * Program :   TINA
00036 * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/tlvision/tlvisEdge_pick.c,v $
00037 * Date    :  $Date: 2003/10/01 16:02:47 $
00038 * Version :  $Revision: 1.3 $
00039 * CVS Id  :  $Id: tlvisEdge_pick.c,v 1.3 2003/10/01 16:02:47 tony Exp $
00040 *
00041 * Notes   :
00042 *
00043 *
00044 *
00045 *********
00046 */
00047 
00048 #include "tlvisEdge_pick.h"
00049 
00050 #if HAVE_CONFIG_H
00051   #include <config.h>
00052 #endif
00053 
00054 #include <tina/sys/sysDef.h>
00055 #include <tina/sys/sysPro.h>
00056 #include <tina/math/mathDef.h>
00057 #include <tina/math/mathPro.h>
00058 #include <tina/geometry/geomDef.h>
00059 #include <tina/geometry/geomPro.h>
00060 #include <tina/image/imgDef.h>
00061 #include <tina/image/imgPro.h>
00062 #include <tina/vision/visDef.h>
00063 #include <tina/vision/visPro.h>
00064 
00065 #include <tinatool/draw/drawDef.h>
00066 #include <tinatool/draw/drawPro.h>
00067 #include <tinatool/tlbase/tlbasePro.h>
00068 
00069 static int SEARCH_RADIUS = 25;
00070 
00071 static void *left_pick_closest_edge(Tv * tv, Ipos pos, int *type)
00072 {
00073     Imrect *er = left_edges();
00074     int     r, c;
00075     Vec2    v = {Vec2_id};
00076 
00077     *type = EDGE;
00078     v = tv_backproj2(tv, pos);
00079     r = tina_int(vec2_y(v));
00080     c = tina_int(vec2_x(v));
00081     return (er_closest(er, r, c, SEARCH_RADIUS, (void *(*) ()) NULL, NULL));
00082 }
00083 
00084 static void *left_pick_closest_matchlist(Tv * tv, Ipos pos, int *type)
00085 {
00086     Imrect *er = left_edges();
00087     int     r, c;
00088     Vec2    v = {Vec2_id};
00089 
00090     *type = LIST;
00091     v = tv_backproj2(tv, pos);
00092     r = tina_int(vec2_y(v));
00093     c = tina_int(vec2_x(v));
00094     return (er_closest(er, r, c, SEARCH_RADIUS, edge_sindex_prop_get, (void *) MLIST));
00095 }
00096 
00097 static void *left_pick_closest_corr_match(Tv * tv, Ipos pos, int *type)
00098 {
00099     Imrect *er = left_edges();
00100     int     r, c;
00101     Vec2    v = {Vec2_id};
00102 
00103     *type = LIST;
00104     v = tv_backproj2(tv, pos);
00105     r = tina_int(vec2_y(v));
00106     c = tina_int(vec2_x(v));
00107     return (er_closest(er, r, c, SEARCH_RADIUS, edge_prop_get, (void *) MATCH));
00108 }
00109 
00110 static void *right_pick_closest_corr_match(Tv * tv, Ipos pos, int *type)
00111 {
00112     Imrect *er = right_edges();
00113     int     r, c;
00114     Vec2    v = {Vec2_id};
00115 
00116     *type = LIST;
00117     v = tv_backproj2(tv, pos);
00118     r = tina_int(vec2_y(v));
00119     c = tina_int(vec2_x(v));
00120     return (er_closest(er, r, c, SEARCH_RADIUS, edge_prop_get, (void *) MATCH));
00121 }
00122 
00123 static void *left_pick_closest_string(Tv * tv, Ipos pos, int *type)
00124 {
00125     Imrect *er = left_edges();
00126     Edgel  *edge;
00127     int     r, c;
00128     Vec2    v = {Vec2_id};
00129 
00130     *type = EDGE;
00131     v = tv_backproj2(tv, pos);
00132     r = tina_int(vec2_y(v));
00133     c = tina_int(vec2_x(v));
00134     edge = er_closest(er, r, c, SEARCH_RADIUS, (void *(*) ()) NULL, NULL);
00135     if (edge == NULL)
00136         return (NULL);
00137 
00138     return (prop_get(edge->props, STRING));
00139 }
00140 
00141 static void *right_pick_closest_edge(Tv * tv, Ipos pos, int *type)
00142 {
00143     Imrect *er = right_edges();
00144     int     r, c;
00145     Vec2    v = {Vec2_id};
00146 
00147     *type = EDGE;
00148     v = tv_backproj2(tv, pos);
00149     r = tina_int(vec2_y(v));
00150     c = tina_int(vec2_x(v));
00151     return ((void *) er_closest(er, r, c, SEARCH_RADIUS, (void *(*) ()) NULL,
00152                                 NULL));
00153 }
00154 
00155 static void *mono_pick_closest_edge(Tv * tv, Ipos pos, int *type)
00156 {
00157     Imrect *er = mono_edges();
00158     int     r, c;
00159     Vec2    v = {Vec2_id};
00160 
00161     *type = EDGE;
00162     v = tv_backproj2(tv, pos);
00163     r = tina_int(vec2_y(v));
00164     c = tina_int(vec2_x(v));
00165     return ((void *) er_closest(er, r, c, SEARCH_RADIUS, (void *(*) ()) NULL,
00166                                 NULL));
00167 }
00168 
00169 void    pick_edge_draw(Tv * tv, Edgel * edge, int type)
00170 {
00171     if (edge == NULL || type != EDGE)
00172         return;
00173 
00174     tv_cross2(tv, edge_image_pos(edge), 7);
00175 }
00176 
00177 static void draw_matchable(Tv * tv, void *ptr, int type)
00178 {
00179   Point2 *point;
00180 
00181   switch (type)
00182     {
00183     case CORNER:
00184       tv_cross2(tv, ((Edgel *) ptr)->pos, 7);
00185       break;
00186     case EDGE:
00187       point = (Point2 *)prop_get(((Edgel *)ptr)->props, POINT2);
00188       tv_pixel2(tv, point->p);
00189       break;
00190     case STRING:
00191       tv_edge_string(tv, (Tstring *) ptr);
00192       break;
00193     }
00194 }
00195 
00196 void    pick_mlist_draw(Tv * tv, List * mlist, int type)
00197 {
00198     List   *lptr;
00199     Match  *match;
00200 
00201     if (mlist == NULL || type != LIST)
00202         return;
00203 
00204     for (lptr = mlist; lptr != NULL; lptr = lptr->next)
00205     {
00206         match = (Match *) lptr->to;
00207         draw_matchable(tv, match->to1, match->type);
00208     }
00209 }
00210 
00211 void    pick_corr_match_draw(Tv * tv1, Match * match, int type)
00212 {
00213   Tv     *tv2 = NULL;
00214   int     old_color;
00215 
00216   if (tv1 == left_tv())
00217     tv2 = right_tv();
00218 
00219   if (tv1 == right_tv())
00220     tv2 = left_tv();
00221 
00222   if (match == NULL || tv1 == NULL || tv2 == NULL)
00223     return;
00224 
00225   old_color = tv_get_color(tv2);
00226   tv_set_color(tv2, green);
00227 
00228   draw_matchable(tv2, match->to2, EDGE);
00229 
00230   tv_set_color(tv2, old_color);
00231 
00232   old_color = tv_get_color(tv1);
00233   tv_set_color(tv1, green);
00234 
00235   draw_matchable(tv1, match->to1, EDGE);
00236 
00237   tv_set_color(tv1, old_color);
00238 }
00239 
00240 void    stereo_match_list_draw(List * mlist)
00241 {
00242     Tv     *tvl = left_tv();
00243     Tv     *tvr = right_tv();
00244     List   *lptr;
00245     Match  *match;
00246 
00247     if (mlist == NULL)
00248         return;
00249 
00250     for (lptr = mlist; lptr != NULL; lptr = lptr->next)
00251     {
00252         match = (Match *) lptr->to;
00253         draw_matchable(tvl, match->to1, match->type);
00254         draw_matchable(tvr, match->to2, match->type);
00255     }
00256 }
00257 
00258 void    stereo_corr_match_draw(Tv * tv1, Match * match, int num)
00259 {
00260   Tv     *tv2 = NULL;
00261   Edgel  *edge1, *edge2;
00262   Vec2    pos;
00263   Point2 *point;
00264   char    numstr[10];
00265   int     old_color;
00266 
00267   sprintf(numstr, "%d", num);
00268 
00269   if (tv1 == left_tv())
00270     tv2 = right_tv();
00271 
00272   if (tv1 == right_tv())
00273     tv2 = left_tv();
00274 
00275   if (match == NULL || tv1 == NULL || tv2 == NULL)
00276     return;
00277 
00278   old_color = tv_get_color(tv2);
00279   tv_set_color(tv2, green);
00280 
00281   edge2 = (Edgel *)match->to2;
00282   draw_matchable(tv2, (void *)edge2, EDGE);
00283 
00284   point = (Point2 *)prop_get(edge2->props, POINT2);
00285   pos = point->p;
00286   vec2_x(pos) = (float)tina_int(vec2_x(pos));
00287   vec2_y(pos) = (float)tina_int(vec2_y(pos)) + 0.5;
00288   tv_cltext2(tv2, numstr, pos);
00289 
00290   tv_set_color(tv2, old_color);
00291 
00292   old_color = tv_get_color(tv1);
00293   tv_set_color(tv1, green);
00294 
00295   edge1 = (Edgel *)match->to1;
00296   draw_matchable(tv1, (void *)edge1, EDGE);
00297 
00298   point = (Point2 *)prop_get(edge1->props, POINT2);
00299   pos = point->p;
00300   vec2_x(pos) = (float)tina_int(vec2_x(pos));
00301   vec2_y(pos) = (float)tina_int(vec2_y(pos)) + 0.5;
00302   tv_cltext2(tv1, numstr, pos);
00303 
00304   tv_set_color(tv1, old_color);
00305 }
00306 
00307 static void match_string_draw(Tstring * es)
00308 {
00309     List *ptr;
00310     List *end;
00311 
00312     if (es == NULL)
00313         return;
00314 
00315     end = es->end;
00316     for (ptr = es->start;; ptr = ptr->next)
00317     {
00318         Tstring *sub = prop_get(((Edgel *) (ptr->to))->props, SINDEX);
00319 
00320         stereo_match_list_draw((List *) prop_get(sub->props, MLIST));
00321         ptr = sub->end;
00322         if (ptr == end)
00323             break;
00324     }
00325 }
00326 
00327 static void picklist_match_string_draw(Tv * tv, List * picklist)
00328 {
00329     List   *p;
00330     Tv     *tvl = left_tv();
00331     Tv     *tvr = right_tv();
00332 
00333     tv_save_draw(tvl);
00334     tv_save_draw(tvr);
00335     tv_set_color(tvl, yellow);
00336     tv_set_color(tvr, yellow);
00337     for (p = picklist; p != NULL; p = p->next)
00338         match_string_draw((Tstring *) p->to);
00339     tv_reset_draw(tvl);
00340     tv_reset_draw(tvr);
00341 }
00342 
00343 static void print_edges(Tv * tv, List * picklist)
00344 {
00345     List   *p;
00346 
00347     for (p = picklist; p != NULL; p = p->next)
00348         edge_format((Edgel *) p->to);
00349 }
00350 
00351 /*
00352 static void print_es(tv, picklist)
00353 Tv     *tv;
00354 List   *picklist;
00355 {
00356     List   *p;
00357 
00358     for (p = picklist; p != NULL; p = p->next) {
00359         Tstring *es = prop_get(((Edgel *) (p->to))->props, SINDEX);
00360 
00361         str_apply_func(es, edge_format);
00362     }
00363 }
00364 */
00365 
00366 static void print_matchlist(Tv * tv, List * picklist)
00367 {
00368     List   *p;
00369 
00370     for (p = picklist; p != NULL; p = p->next)
00371     {
00372         stereo_match_list_draw((List *) p->to);
00373         em_list_format((List *) p->to);
00374     }
00375 }
00376 
00377 static void print_corr_match(Tv * tv, List * picklist)
00378 {
00379   List   *p, *other_p;
00380   int     num = 1;
00381   Bool    repeated_pick;
00382 
00383   for (p = picklist; p != NULL; p = p->next)
00384     {
00385       repeated_pick = false;
00386 
00387       /* check for the same edge being picked more than once */
00388       for (other_p = p->next; other_p != NULL; other_p = other_p->next)
00389         if (other_p->to == p->to)
00390           repeated_pick = true;
00391       
00392       if (repeated_pick)
00393         continue;
00394 
00395       stereo_corr_match_draw(tv, (Match *)p->to, num);
00396       num++;
00397     }
00398 }
00399 
00400 Tv_pick left_edge_print(void)
00401 {
00402     return (pick_define(
00403                         PICK_NAME, "edge",
00404                         PICK_CLOSEST, left_pick_closest_edge,
00405                         PICK_DRAW, pick_edge_draw,
00406                         PICK_FUNC, print_edges,
00407                         NULL));
00408 }
00409 
00410 Tv_pick right_edge_print(void)
00411 {
00412     return (pick_define(
00413                         PICK_NAME, "edge",
00414                         PICK_CLOSEST, right_pick_closest_edge,
00415                         PICK_DRAW, pick_edge_draw,
00416                         PICK_FUNC, print_edges,
00417                         NULL));
00418 }
00419 
00420 Tv_pick mono_print(void)
00421 {
00422     return (pick_define(
00423                         PICK_NAME, "edge",
00424                         PICK_CLOSEST, mono_pick_closest_edge,
00425                         PICK_DRAW, pick_edge_draw,
00426                         PICK_FUNC, print_edges,
00427                         NULL));
00428 }
00429 
00430 Tv_pick left_edge_matches(void)
00431 {
00432     return (pick_define(
00433                         PICK_NAME, "edge match",
00434                         PICK_CLOSEST, left_pick_closest_matchlist,
00435                         PICK_DRAW, pick_mlist_draw,
00436                         PICK_FUNC, print_matchlist,
00437                         PICK_REPAINT, false,
00438                         NULL));
00439 }
00440 
00441 Tv_pick left_edge_corr_matches(void)
00442 {
00443     return (pick_define(
00444                         PICK_NAME, "corr match",
00445                         PICK_CLOSEST, left_pick_closest_corr_match,
00446                         PICK_DRAW, pick_corr_match_draw,
00447                         PICK_FUNC, print_corr_match,
00448                         PICK_REPAINT, false,
00449                         NULL));
00450 }
00451 
00452 Tv_pick right_edge_corr_matches(void)
00453 {
00454     return (pick_define(
00455                         PICK_NAME, "corr match",
00456                         PICK_CLOSEST, right_pick_closest_corr_match,
00457                         PICK_DRAW, pick_corr_match_draw,
00458                         PICK_FUNC, print_corr_match,
00459                         PICK_REPAINT, false,
00460                         NULL));
00461 }
00462 
00463 Tv_pick left_string_matches(void)
00464 {
00465     return (pick_define(
00466                         PICK_NAME, "string match",
00467                         PICK_CLOSEST, left_pick_closest_string,
00468                         PICK_DRAW, tv_edge_string,
00469                         PICK_FUNC, picklist_match_string_draw,
00470                         PICK_REPAINT, false,
00471                         NULL));
00472 }

Generated on Thu Nov 12 02:20:52 2009 for Tools by doxygen 1.3.6