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

Linux Cross Reference
Tina4/src/tools/edge/geom_pick.c

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

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

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