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

Linux Cross Reference
Tina5/tina-tools/tinatool/tlvision/tlvisEdge_geom_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/tlvisEdge_geom_pick.c,v $
 37 * Date    :  $Date: 2008/12/02 22:04:19 $
 38 * Version :  $Revision: 1.5 $
 39 * CVS Id  :  $Id: tlvisEdge_geom_pick.c,v 1.5 2008/12/02 22:04:19 paul Exp $
 40 *
 41 * Notes   :
 42 *
 43 *
 44 *
 45 *********
 46 */
 47 
 48 #include "tlvisEdge_geom_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/vision/visDef.h>
 61 #include <tina/vision/visPro.h>
 62 
 63 #include <tinatool/draw/drawDef.h>
 64 #include <tinatool/draw/drawPro.h>
 65 #include <tinatool/tlbase/tlbasePro.h>
 66 #include <tinatool/tlvision/tlvisEdge_pick.h>
 67 
 68 static List            *picked_geom = NULL;
 69 
 70 List *mono_picked_geom_get(void)
 71 {
 72     return picked_geom;
 73 }
 74 
 75 void mono_picked_geom_set(List *geom)
 76 {
 77     picked_geom = geom;
 78 }
 79 
 80 static void  *geom2_pick_closest(Tv *tv, Ipos pos, int *type)
 81 {
 82     Tv_closest      tvc;
 83 
 84     tvc.tv = tv;
 85     tvc.pos = pos;
 86     tvc.ptr = NULL;
 87 
 88     reclist_list_apply(mono_geom_get(), geom_pick_closest, 0, &tvc);
 89 
 90     if (tvc.ptr != NULL)
 91         *type = tvc.type;
 92     return (tvc.ptr);
 93 }
 94 
 95 static void geom2_pick_choose(Tv *tv, List *picklist)
 96 {
 97     List *picked_geom;
 98     List *pairs_picked_geom_get();
 99 
100     picked_geom = mono_picked_geom_get();
101 
102     if (picked_geom!=NULL)
103         reclist_list_free(picked_geom, geom_free, 0, NULL);
104 
105     picked_geom = list_copy(picklist, geom_copy, NULL); /* cp list elemets */
106 
107     mono_picked_geom_set(picked_geom);
108 }
109 
110 void   *geom3_pick_closest(Tv * tv, Ipos pos, int *type)
111 {
112     Tv_closest tvc = {Tv_closest_id};
113 
114     tvc.tv = tv;
115     tvc.pos = pos;
116     tvc.ptr = NULL;
117 
118     reclist_list_apply(threed_geom_get(), geom_pick_closest, 0, (void *) &tvc);
119 
120     if (tvc.ptr != NULL)
121         *type = tvc.type;
122     return (tvc.ptr);
123 }
124 
125 void   *geoml_pick_closest(Tv * tv, Ipos pos, int *type)
126 {
127     Tv_closest tvc = {Tv_closest_id};
128 
129     tvc.tv = tv;
130     tvc.pos = pos;
131     tvc.ptr = NULL;
132 
133     reclist_list_apply(left_geom_get(), geom_pick_closest, 0, (void *) &tvc);
134 
135     if (tvc.ptr != NULL)
136         *type = tvc.type;
137     return (tvc.ptr);
138 }
139 
140 void    geoml_pick_print(Tv * tv, List * picklist)
141 {
142     list_apply_func(picklist, geom_format, NULL);
143 }
144 
145 void    geoml_pick_delete(Tv * tv, List * picklist)
146 {
147     List   *domain = left_geom_get();
148     List   *p;
149 
150     for (p = picklist; p != NULL; p = p->next)
151         domain = reclist_list_rm_entry(domain, p->to, geom_free);
152     left_geom_null();
153     left_geom_set(domain);
154 }
155 
156 void    geoml_pick_choose(Tv * tv, List * picklist)
157 {
158     List   *domain = left_geom_get();
159     List   *p;
160 
161     for (p = picklist; p != NULL; p = p->next)  /* rm chosen from domain */
162         domain = reclist_list_rm_entry(domain, p->to, (void (*) ()) NULL);
163     domain = list_copy(picklist, geom_copy, NULL);      /* cp list elemets */
164     left_geom_set(domain);
165 }
166 
167 void    geom3_pick_print(Tv * tv, List * picklist)
168 {
169     list_apply_func(picklist, geom_format, NULL);
170 }
171 
172 void    geom3_pick_delete(Tv * tv, List * picklist)
173 {
174     List   *domain = threed_geom_get();
175     List   *p;
176 
177     for (p = picklist; p != NULL; p = p->next)
178         domain = reclist_list_rm_entry(domain, p->to, geom_free);
179     threed_geom_null();
180     threed_geom_set(domain);
181 }
182 
183 void draw_corr_match_edgels(Point3 *geompoint, int num)
184 {
185   Tv     *tvl = left_tv(), *tv3d = threed_tv();
186   Edgel  *ledgel;
187   Match  *match;
188   Imrect *ledges = left_edges_get();
189   Vec2    pos;
190   Point2 *point;
191   char    numstr[10];
192   int     old_color;
193 
194   sprintf(numstr, "%d", num);
195 
196   if (geompoint == NULL)
197     return;
198 
199   old_color = tv_get_color(tv3d);
200   tv_set_color(tv3d, green);
201   tv_cltext3(tv3d, numstr, geompoint->p);
202   tv_set_color(tv3d, old_color);
203 
204   /* find the location in the left that the geom point came from */
205   point = (Point2 *)prop_get(geompoint->props, POINT2);
206   if (point==NULL)
207     return;
208   pos = point->p;
209 
210   ledgel = (Edgel *)IM_PTR(ledges, (int)vec2_y(pos), (int)vec2_x(pos));
211   if (ledgel == NULL)
212     return;
213 
214   match = (Match *)prop_get(ledgel->props, MATCH);
215 
216   stereo_corr_match_draw(tvl, match, num);
217 }
218 
219 void    geom3_pick_corr_match(Tv * tv, List * picklist)
220 {
221   List   *p, *other_p;
222   int     num = 1;
223   Bool    repeated_pick;
224 
225   for (p = picklist; p != NULL; p = p->next)
226     {
227       repeated_pick = false;
228 
229       /* check for the same geom point being picked more than once */
230       for (other_p = p->next; other_p != NULL; other_p = other_p->next)
231         if (other_p->to == p->to)
232           repeated_pick = true;
233       
234       if (repeated_pick || p->type!=POINT3)
235         continue;
236 
237       draw_corr_match_edgels((Point3 *)p->to, num);
238       num++;
239     }
240 }
241 
242 void    geom3_pick_choose(Tv * tv, List * picklist)
243 {
244     List   *domain = threed_geom_get();
245     List   *p;
246 
247     for (p = picklist; p != NULL; p = p->next)  /* rm chosen from domain */
248         domain = reclist_list_rm_entry(domain, p->to, (void (*) ()) NULL);
249     domain = list_copy(picklist, (void *(*) ()) NULL, NULL);    /* cp list elemets */
250     threed_geom_set(domain);
251 }
252 
253 void    geom3_pick_plane(Tv * tv, List * picklist)
254 {
255     Plane  *p;
256     Vec3    c = {Vec3_id};
257     List   *domain;
258     float   resid;
259 
260     p = plane_lsq(picklist, &resid);
261 
262     if (p == NULL)
263         return;
264 
265     c = geom3_centroid(picklist);
266     p->p = vec3_proj_on_plane(c, p->p, p->n);
267 
268     domain = threed_geom_get();
269     domain = ref_addtostart(domain, (void *) p, PLANE);
270     threed_geom_null();
271     threed_geom_set(domain);
272 }
273 
274 void    geom3_pick_cone(Tv * tv, List * picklist)
275 {
276     Cone   *cone;
277     List   *domain;
278     Conic3 *c1;
279     Conic3 *c2;
280     double  offset = 0;
281     Plane  *p;
282 
283     if (picklist == NULL || picklist->next == NULL)
284         return;
285 
286     switch (OPAIR(picklist->type, picklist->next->type))
287     {
288     case OPAIR(CONIC3, CONIC3):
289         c1 = conic3_copy((Conic3 *) picklist->to);
290         c2 = conic3_copy((Conic3 *) picklist->next->to);
291         break;
292     case OPAIR(CONIC3, PLANE):
293         c1 = conic3_copy((Conic3 *) picklist->to);
294         p = (Plane *) picklist->next->to;
295         c2 = conic3_copy(c1);
296         c2->origin = vec3_proj_on_plane(c2->origin, p->p, p->n);
297         (void) list_addtoend(threed_geom_get(), link_alloc((void *) c2, CONIC3));
298         c2 = conic3_copy(c2);
299         break;
300     case OPAIR(PLANE, CONIC3):
301         c1 = conic3_copy((Conic3 *) picklist->next->to);
302         p = (Plane *) picklist->to;
303         c2 = conic3_copy(c1);
304         c2->origin = vec3_proj_on_plane(c2->origin, p->p, p->n);
305         (void) list_addtoend(threed_geom_get(), link_alloc((void *) c2, CONIC3));
306         c2 = conic3_copy(c2);
307         break;
308     default:
309         return;
310     }
311 
312     offset = conic3_parameter_offset(c1, c2);
313     c1->conic->t1 = c2->conic->t1 = 0.0;
314     c1->conic->t2 = c2->conic->t2 = TWOPI;
315     cone = cone_make(c1, c2, offset, 0);
316 
317     domain = threed_surface_get();
318     domain = ref_addtostart(domain, (void *) cone, CONE);
319     threed_surface_set(domain);
320 }
321 
322 Tv_pick    mono_geom_choose(void)
323 {
324     Tv_pick         pick;
325 
326     pick = pick_define(
327         PICK_NAME, "choose",
328         PICK_CLOSEST, geom2_pick_closest,
329         PICK_DRAW, geom_draw,
330         PICK_FUNC, geom2_pick_choose,
331         NULL);
332     return (pick);
333 }
334 
335 Tv_pick left_geom_print(void)
336 {
337     Tv_pick pick = {Tv_pick_id};
338 
339     pick = pick_define(
340                        PICK_NAME, "print",
341                        PICK_CLOSEST, geoml_pick_closest,
342                        PICK_DRAW, geom_draw,
343                        PICK_FUNC, geoml_pick_print,
344                        NULL);
345     return (pick);
346 }
347 
348 Tv_pick left_geom_delete(void)
349 {
350     Tv_pick pick = {Tv_pick_id};
351 
352     pick = pick_define(
353                        PICK_NAME, "delete",
354                        PICK_CLOSEST, geoml_pick_closest,
355                        PICK_DRAW, geom_draw,
356                        PICK_FUNC, geoml_pick_delete,
357                        NULL);
358     return (pick);
359 }
360 
361 Tv_pick left_geom_choose(void)
362 {
363     Tv_pick pick = {Tv_pick_id};
364 
365     pick = pick_define(
366                        PICK_NAME, "add",
367                        PICK_CLOSEST, geoml_pick_closest,
368                        PICK_DRAW, geom_draw,
369                        PICK_FUNC, geoml_pick_choose,
370                        NULL);
371     return (pick);
372 }
373 
374 Tv_pick threed_print(void)
375 {
376     Tv_pick pick = {Tv_pick_id};
377 
378     pick = pick_define(
379                        PICK_NAME, "print",
380                        PICK_CLOSEST, geom3_pick_closest,
381                        PICK_DRAW, geom_draw,
382                        PICK_FUNC, geom3_pick_print,
383                        NULL);
384     return (pick);
385 }
386 
387 Tv_pick threed_delete(void)
388 {
389     Tv_pick pick = {Tv_pick_id};
390 
391     pick = pick_define(
392                        PICK_NAME, "delete",
393                        PICK_CLOSEST, geom3_pick_closest,
394                        PICK_DRAW, geom_draw,
395                        PICK_FUNC, geom3_pick_delete,
396                        NULL);
397     return (pick);
398 }
399 
400 Tv_pick threed_choose(void)
401 {
402     Tv_pick pick = {Tv_pick_id};
403 
404     pick = pick_define(
405                        PICK_NAME, "choose",
406                        PICK_CLOSEST, geom3_pick_closest,
407                        PICK_DRAW, geom_draw,
408                        PICK_FUNC, geom3_pick_choose,
409                        NULL);
410     return (pick);
411 }
412 
413 Tv_pick threed_plane(void)
414 {
415     Tv_pick pick = {Tv_pick_id};
416 
417     pick = pick_define(
418                        PICK_NAME, "choose",
419                        PICK_CLOSEST, geom3_pick_closest,
420                        PICK_DRAW, geom_draw,
421                        PICK_FUNC, geom3_pick_plane,
422                        NULL);
423     return (pick);
424 }
425 
426 Tv_pick threed_cone(void)
427 {
428     Tv_pick pick = {Tv_pick_id};
429 
430     pick = pick_define(
431                        PICK_NAME, "choose",
432                        PICK_CLOSEST, geom3_pick_closest,
433                        PICK_DRAW, geom_draw,
434                        PICK_FUNC, geom3_pick_cone,
435                        NULL);
436     return (pick);
437 }
438 
439 Tv_pick threed_corr_match(void)
440 {
441     Tv_pick pick = {Tv_pick_id};
442 
443     pick = pick_define(
444                        PICK_NAME, "src edges",
445                        PICK_CLOSEST, geom3_pick_closest,
446                        PICK_DRAW, geom_draw,
447                        PICK_FUNC, geom3_pick_corr_match,
448                        PICK_REPAINT, false,
449                        NULL);
450     return (pick);
451 }
452 

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