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

Linux Cross Reference
Tina4/src/tools/segment/seg_pick.c

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

  1 /**@(#)
  2 **/
  3 #include <math.h>
  4 #include <tina/sys.h>
  5 #include <tina/sysfuncs.h>
  6 #include <tina/math.h>
  7 #include <tina/mathfuncs.h>
  8 #include <tina/vision.h>
  9 #include <tina/visionfuncs.h>
 10 #include <tina/tv.h>
 11 #include <tina/tvfuncs.h>
 12 #include <tina/draw.h>
 13 #include <tina/drawfuncs.h>
 14 #include <tina/toolsfuncs.h>
 15 #include <tina/toolsfuncs.h>
 16 
 17 double  conic_var_get();
 18 
 19 #define LEFT_DATA       0
 20 #define RIGHT_DATA      1
 21 #define MONO_DATA       2
 22 
 23 /**
 24 pick on rectified position for rectified data
 25 **/
 26 
 27 static Vec2 pos2_in_rectified(Vec2 v)
 28 {
 29     Parcam *pcam;
 30     int     image_data = seg_image_data_get();
 31 
 32     if (image_data == MONO_DATA ||
 33         edge_edges_rectified_get() == false ||
 34         (pcam = pcam_get()) == NULL)
 35         return (v);
 36 
 37     switch (image_data)
 38     {
 39     case LEFT_DATA:
 40         return (rectify_pos(pcam->rect1, v));
 41     case RIGHT_DATA:
 42         return (rectify_pos(pcam->rect2, v));
 43     default:
 44         return (v);
 45     }
 46 }
 47 
 48 /**
 49 some pick closest functions
 50 **/
 51 
 52 static void *seg_pick_closest_pos(Tv * tv, Ipos pos, int *type)
 53 {
 54     List   *seg_es_get_from_index();
 55     Vec2    v1 = {Vec2_id};
 56     Vec2    v2 = {Vec2_id};
 57 
 58     v1 = tv_backproj2(tv, pos); /* image coordinates */
 59     v2 = pos2_in_rectified(v1); /* rectified coordinates */
 60     return (es_closest_pos2(seg_es_get_from_index(v1), v2, type));
 61 }
 62 
 63 static Tstring *seg_pick_closest_es(Tv * tv, Ipos pos, int *type)
 64 {
 65     List   *seg_es_get_from_index();
 66     Vec2    v1 = {Vec2_id};
 67     Vec2    v2 = {Vec2_id};
 68 
 69     *type = STRING;
 70     v1 = tv_backproj2(tv, pos); /* image coordinates */
 71     v2 = pos2_in_rectified(v1); /* rectified coordinates */
 72     return (es_closest2(seg_es_get_from_index(v1), v2));
 73 }
 74 
 75 static void *seg_pick_closest_geom(Tv * tv, Ipos pos, int *type)
 76 {
 77     Tv_closest tvc = {Tv_closest_id};
 78 
 79     tvc.tv = tv;
 80     tvc.pos = pos;
 81     tvc.ptr = NULL;
 82 
 83     reclist_list_apply(seg_geom_get(), geom_pick_closest, (int)NULL, (void *) &tvc);
 84 
 85     if (tvc.ptr != NULL)
 86         *type = tvc.type;
 87     return (tvc.ptr);
 88 }
 89 
 90 /**
 91 some pick draw functions
 92 **/
 93 
 94 static void seg_pos_draw(Tv * tv, void *ptr, int type)
 95 {
 96     Vec2    pos = {Vec2_id};
 97 
 98     if (ptr == NULL)
 99         return;
100 
101     switch (type)
102     {
103     case VEC2:
104         pos = *(Vec2 *) ptr;
105         break;
106     case EDGE:
107         pos = edge_image_pos((Edgel *) ptr);
108         break;
109     default:
110         return;
111     }
112     tv_cross2(tv, pos, 7);
113 }
114 
115 static void seg_es_draw(Tv * tv, Tstring * es, int type)
116 {
117     if (es == NULL || type != STRING)
118         return;
119 
120     tv_string2(tv, es);
121 }
122 
123 /**
124 delete edge strings pick function
125 **/
126 
127 void    seg_es_delete(Tv * tv, List * picklist)
128 {
129     List   *p;
130     List   *es;
131     List   *seg_es_get();
132 
133     es = seg_es_get();          /* current list of edge strings */
134 
135     for (p = picklist; p != NULL; p = p->next)
136         es = list_rm_ref(es, p->to, (void (*) ()) NULL);
137 
138     seg_es_index_delete(picklist);
139     list_free_refs(picklist, str_rm_links);
140     seg_es_set(es);
141 }
142 
143 Tv_pick seg_pick_delete(void)
144 {
145     return (pick_define(
146                         PICK_NAME, "delete",
147                         PICK_CLOSEST, seg_pick_closest_es,
148                         PICK_DRAW, seg_es_draw,
149                         PICK_FUNC, seg_es_delete,
150                         NULL));
151 }
152 
153 /**
154 choose edge strings pick function
155 **/
156 
157 void    seg_es_choose(Tv * tv, List * picklist)
158 {
159     List   *es;
160     List   *p;
161     List   *seg_es_get();
162 
163     es = seg_es_get();          /* current list of edge strings */
164 
165     picklist = list_copy(picklist, (void *(*) ()) NULL, NULL);
166     for (p = picklist; p != NULL; p = p->next)
167         es = list_rm_ref(es, p->to, (void (*) ()) NULL);
168 
169     seg_es_index_delete(es);
170     list_rm(es, str_rm_links);
171 
172     seg_es_set(picklist);
173 }
174 
175 Tv_pick seg_pick_choose(void)
176 {
177     return (pick_define(
178                         PICK_NAME, "choose",
179                         PICK_CLOSEST, seg_pick_closest_es,
180                         PICK_DRAW, seg_es_draw,
181                         PICK_FUNC, seg_es_choose,
182                         NULL));
183 }
184 
185 /**
186 combine edge strings pick function
187 **/
188 
189 void    seg_es_combine(Tv * tv, List * picklist)
190 {
191     List   *p;
192     List   *new;
193     List   *es;
194     List   *seg_es_get();
195     Tstring *str, *es_list_cat();
196 
197     es = seg_es_get();          /* current list of edge strings */
198 
199     for (p = picklist; p != NULL; p = p->next)
200         es = list_rm_ref(es, p->to, (void (*) ()) NULL);
201 
202     str = es_list_cat(picklist);
203 
204     if (str != NULL)
205         new = link_alloc((void *) str, STRING);
206 
207     seg_es_index_replace(picklist, new);
208     es = link_addtostart(es, new);
209     list_free_refs(picklist, str_rm_links);
210     seg_es_set(es);
211 }
212 
213 Tv_pick seg_pick_combine(void)
214 {
215     return (pick_define(
216                         PICK_NAME, "combine",
217                         PICK_CLOSEST, seg_pick_closest_es,
218                         PICK_DRAW, seg_es_draw,
219                         PICK_FUNC, seg_es_combine,
220                         NULL));
221 }
222 
223 /**
224 segment edge strings pick function
225 **/
226 
227 void    seg_es_segment(Tv * tv, List * picklist)
228 {
229     List   *p;
230     List   *es;
231     List   *seg_es_get();
232     Tstring *str, *new, *str_list_get_by_ref();
233     List *ddptr;
234     List *str_link_get_by_ref();
235 
236     es = seg_es_get();          /* current list of edge strings */
237 
238     for (p = picklist; p != NULL; p = p->next)
239     {
240         str = str_list_get_by_ref(es, p->to);
241         ddptr = str_link_get_by_ref(str, p->to);
242         if (str->type == LOOP)
243     /* BUG in next line: statement with no effect */
244             str->type == STRING;
245         new = str_segment(str, ddptr);
246         if (new != NULL)
247         {
248             seg_es_index_duplicate(str, new);
249             es = ref_addtostart(es, (void *) new, STRING);
250         }
251     }
252     seg_es_set(es);
253 }
254 
255 Tv_pick seg_pick_segment(void)
256 {
257     return (pick_define(
258                         PICK_NAME, "segment",
259                         PICK_CLOSEST, seg_pick_closest_pos,
260                         PICK_DRAW, seg_pos_draw,
261                         PICK_FUNC, seg_es_segment,
262                         NULL));
263 }
264 
265 /**
266 segment edge string curvature pick function
267 **/
268 
269 void    seg_es_curvature(Tv * tv, List * picklist)
270 {
271     List   *p;
272     List   *es;
273     List   *seg_es_get();
274 
275     es = seg_es_get();          /* current list of edge strings */
276 
277     for (p = picklist; p != NULL; p = p->next)
278     {
279         Tstring *str, *str_list_get_by_ref();
280         List *ddptr;
281         List *str_link_get_by_ref();
282         double  k, es_curvature(), dds_curvature();
283 
284         str = str_list_get_by_ref(es, p->to);
285         ddptr = str_link_get_by_ref(str, p->to);
286         if (str == NULL || ddptr == NULL)
287             continue;
288         k = es_curvature(str, ddptr, 0.4, 10.0, 30.0);
289         format("k = %12.6f r = %12.6f\n", k, 1.0 / k);
290         k = dds_curvature(ddptr, 5);
291         format("k = %12.6f r = %12.6f\n", k, 1.0 / k);
292     }
293 }
294 
295 Tv_pick seg_pick_curvature(void)
296 {
297     return (pick_define(
298                         PICK_NAME, "curvature",
299                         PICK_CLOSEST, seg_pick_closest_pos,
300                         PICK_DRAW, seg_pos_draw,
301                         PICK_FUNC, seg_es_curvature,
302                         PICK_REPAINT, false,
303                         NULL));
304 }
305 
306 /**
307 select edge positions pick function
308 **/
309 
310 static void pick_select_pos(Tv * tv, List * picklist)
311 {
312     picklist = list_copy(picklist, (void *(*) ()) NULL, NULL);
313     seg_select_pos_set(picklist);
314 }
315 
316 Tv_pick seg_pick_select_pos(void)
317 {
318     return (pick_define(
319                         PICK_NAME, "select pos",
320                         PICK_CLOSEST, seg_pick_closest_pos,
321                         PICK_DRAW, seg_pos_draw,
322                         PICK_FUNC, pick_select_pos,
323                         PICK_REPAINT, false,
324                         NULL));
325 }
326 
327 /**
328 select edge strings pick function
329 **/
330 
331 static void pick_select_es(Tv * tv, List * picklist)
332 {
333     picklist = list_copy(picklist, (void *(*) ()) NULL, NULL);
334     seg_select_es_set(picklist);
335 }
336 
337 Tv_pick seg_pick_select_es(void)
338 {
339     return (pick_define(
340                         PICK_NAME, "select es",
341                         PICK_CLOSEST, seg_pick_closest_es,
342                         PICK_DRAW, seg_es_draw,
343                         PICK_FUNC, pick_select_es,
344                         PICK_REPAINT, false,
345                         NULL));
346 }
347 
348 /**
349 select geometry pick function
350 **/
351 
352 static void pick_select_geom(Tv * tv, List * picklist)
353 {
354     picklist = list_copy(picklist, (void *(*) ()) NULL, NULL);
355     seg_select_geom_set(picklist);
356 }
357 
358 Tv_pick seg_pick_select_geom(void)
359 {
360     return (pick_define(
361                         PICK_NAME, "select geom",
362                         PICK_CLOSEST, seg_pick_closest_geom,
363                         PICK_DRAW, geom_draw,
364                         PICK_FUNC, pick_select_geom,
365                         PICK_REPAINT, false,
366                         NULL));
367 }
368 
369 /**
370 draw whole conic function
371 **/
372 
373 static void pick_draw_whole(Tv * tv, List * picklist)
374 {
375     List   *ptr;
376 
377     for (ptr = picklist; ptr != NULL; ptr = ptr->next)
378     {
379         if (ptr->type == CONIC2)
380         {
381             Conic  *conic = (Conic *) ptr->to;
382 
383             if (conic->type == ELLIPSE)
384                 conic2_draw_seg(tv, conic, 0.0, TWOPI);
385             else if (conic->type == HYPERBOLA)
386             {
387                 int     branch = conic->branch;
388 
389                 conic2_draw_seg(tv, conic, -3.0, 3.0);
390                 conic->branch *= -1;    /** draw both branches **/
391                 conic2_draw_seg(tv, conic, -3.0, 3.0);
392                 conic->branch = branch;
393             }
394         }
395     }
396 }
397 
398 Tv_pick seg_pick_draw_whole(void)
399 {
400     return (pick_define(
401                         PICK_NAME, "select geom",
402                         PICK_CLOSEST, seg_pick_closest_geom,
403                         PICK_DRAW, geom_draw,
404                         PICK_FUNC, pick_draw_whole,
405                         PICK_REPAINT, false,
406                         NULL));
407 }
408 
409 /**
410 print conic function
411 **/
412 
413 static void pick_geom_print(Tv * tv, List * picklist)
414 {
415     List   *ptr;
416 
417     for (ptr = picklist; ptr != NULL; ptr = ptr->next)
418     {
419         if (ptr->type == CONIC2)
420         {
421             Conic  *conic = (Conic *) ptr->to;
422 
423             geom_format((void *) conic, CONIC2);
424         }
425     }
426 }
427 
428 Tv_pick seg_pick_geom_print(void)
429 {
430     return (pick_define(
431                         PICK_NAME, "select geom",
432                         PICK_CLOSEST, seg_pick_closest_geom,
433                         PICK_DRAW, geom_draw,
434                         PICK_FUNC, pick_geom_print,
435                         PICK_REPAINT, false,
436                         NULL));
437 }
438 
439 /**
440 draw string of conic
441 **/
442 
443 static void pick_draw_geom_string(Tv * tv, List * picklist)
444 {
445     List   *ptr;
446 
447     tv_set_color(tv, magenta);
448     for (ptr = picklist; ptr != NULL; ptr = ptr->next)
449     {
450         if (ptr->type == CONIC2)
451         {
452             Conic  *conic = (Conic *) ptr->to;
453             Tstring *str;
454 
455             str = (Tstring *) prop_get(conic->props, STRING);
456             tv_string2(tv, str);
457         }
458     }
459 }
460 
461 Tv_pick seg_pick_draw_geom_string(void)
462 {
463     return (pick_define(
464                         PICK_NAME, "select geom",
465                         PICK_CLOSEST, seg_pick_closest_geom,
466                         PICK_DRAW, geom_draw,
467                         PICK_FUNC, pick_draw_geom_string,
468                         PICK_REPAINT, false,
469                         NULL));
470 }
471 
472 /**
473 join picked geometry
474 **/
475 
476 static void pick_geom_join(Tv * tv, List * picklist)
477 {
478     List   *ptr;
479     Conic  *conic;
480     Conic_stat *stats;
481     double  (*filter) () = conic_filter_get();  /* fn ptr type made to
482                                                  * agree with prototype.
483                                                  * JB 7/9/93 */
484     double  var = conic_var_get();
485 
486 
487     if (picklist == NULL || filter == NULL)
488         return;
489 
490     conic = (Conic *) picklist->to;
491     stats = (Conic_stat *) prop_get(conic->props, STATS);
492 
493     if (stats == NULL)
494         return;
495 
496     tv_set_color(tv, white);
497     for (ptr = picklist->next; ptr != NULL; ptr = ptr->next)
498     {
499         if (ptr->type == CONIC2)
500         {
501             Conic  *conic2 = (Conic *) ptr->to;
502             Tstring *str;
503             List *dptr;
504 
505             str = prop_get(conic2->props, STRING);
506             for (dptr = str->start;; dptr = dptr->next)
507             {
508                 Vec2    p = {Vec2_id};
509 
510                 DD_GET_POS2(dptr, p);
511                 filter(conic, stats, p, var);
512                 if (dptr == str->end)
513                     break;
514             }
515         }
516     }
517 
518     conic_correct(conic, stats->x);
519     conic_setup(conic);
520     conic2_draw_seg(tv, conic, 0.0, TWOPI);
521 }
522 
523 Tv_pick seg_pick_geom_join(void)
524 {
525     return (pick_define(
526                         PICK_NAME, "select geom",
527                         PICK_CLOSEST, seg_pick_closest_geom,
528                         PICK_DRAW, geom_draw,
529                         PICK_FUNC, pick_geom_join,
530                         PICK_REPAINT, false,
531                         NULL));
532 }
533 
534 /**
535 line stats pick function
536 **/
537 
538 static void seg_line_test(Tv * tv, List * picklist)
539 {
540     double  sum1 = 0.0;
541     double  sum2 = 0.0;
542 
543     if (picklist == NULL)
544         return;
545 
546     if (picklist->type != LINE2)
547         return;
548 
549     line_errors_check((Line2 *) picklist->to, &sum1, &sum2);
550     format("sum1 = %f sum2 = %f sratio = %f\n", sum1, sum2, sum1 / sqrt(sum2));
551 }
552 
553 Tv_pick seg_pick_line_test(void)
554 {
555     return (pick_define(
556                         PICK_NAME, "line test",
557                         PICK_CLOSEST, seg_pick_closest_geom,
558                         PICK_DRAW, geom_draw,
559                         PICK_FUNC, seg_line_test,
560                         NULL));
561 }
562 
563 /**
564 ellipse invariant pick function
565 **/
566 
567 void    seg_es_etest(Tv * tv, List * picklist)
568 {
569     List   *ptr;
570     List   *es;
571     List   *seg_es_get();
572     Tstring *s1, *s2, *str_list_get_by_ref();
573     List *d1;
574     List *d2;
575     List *str_link_get_by_ref();
576     double  k1, k2;
577     Vec2    p1 = {Vec2_id};
578     Vec2    p2 = {Vec2_id};
579     Vec2    t1 = {Vec2_id};
580     Vec2    t2 = {Vec2_id};
581     double  theta1, theta2, r;
582 
583     if (picklist == NULL || picklist->next == NULL)
584     {
585         error("pick at least 2 points\n", warning);
586         return;
587     }
588     es = seg_es_get();          /* current list of edge strings */
589 
590     s1 = str_list_get_by_ref(es, picklist->to);
591     d1 = str_link_get_by_ref(s1, picklist->to);
592     es_diffgeom(s1, d1, 0.4, 5.0, 25.0, &p1, &t1, &k1);
593 
594     for (ptr = picklist->next; ptr != NULL; ptr = ptr->next)
595     {
596         s2 = str_list_get_by_ref(es, ptr->to);
597         d2 = str_link_get_by_ref(s2, ptr->to);
598         es_diffgeom(s2, d2, 0.4, 5.0, 25.0, &p2, &t2, &k2);
599 
600         theta1 = vec2_angle(t1, vec2_diff(p1, p2));
601         theta2 = vec2_angle(t2, vec2_diff(p2, p1));
602         r = sin(theta1) / sin(theta2);
603         r = r * r * r;
604 
605         format("kratio = %10.6f aratio = %10.6f ratio = %12.6f\n",
606                k1 / k2, r, k1 / k2 / r);
607     }
608 }
609 
610 Tv_pick seg_pick_etest(void)
611 {
612     return (pick_define(
613                         PICK_NAME, "etest",
614                         PICK_CLOSEST, seg_pick_closest_pos,
615                         PICK_DRAW, seg_pos_draw,
616                         PICK_FUNC, seg_es_etest,
617                         PICK_REPAINT, false,
618                         NULL));
619 }
620 

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