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

Linux Cross Reference
Tina6/tina-tools/tinatool/tlvision/tlvisEdge_stest_tool.c

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

  1 /**********
  2 *
  3 *
  4  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  5  * University of Manchester, UK.  All rights reserved.
  6  * 
  7  * Redistribution and use in source and binary forms, with or without modification, 
  8  * are permitted provided that the following conditions are met:
  9  * 
 10  *   . Redistributions of source code must retain the above copyright notice, 
 11  *     this list of conditions and the following disclaimer.
 12  *    
 13  *   . Redistributions in binary form must reproduce the above copyright notice,
 14  *     this list of conditions and the following disclaimer in the documentation 
 15  *     and/or other materials provided with the distribution.
 16  * 
 17  *   . Neither the name of the University of Manchester nor the names of its
 18  *     contributors may be used to endorse or promote products derived from this 
 19  *     software without specific prior written permission.
 20  * 
 21  * 
 22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 32  * POSSIBILITY OF SUCH DAMAGE.
 33 **********
 34 *
 35 * Program :   TINA
 36 * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/tlvision/tlvisEdge_stest_tool.c,v $
 37 * Date    :  $Date: 2009/03/27 16:01:50 $
 38 * Version :  $Revision: 1.7 $
 39 * CVS Id  :  $Id: tlvisEdge_stest_tool.c,v 1.7 2009/03/27 16:01:50 paul Exp $
 40 *
 41 * Notes   :
 42 *
 43 *
 44 *
 45 *********
 46 */
 47 
 48 #include "tlvisEdge_stest_tool.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/image/imgDef.h>
 61 #include <tina/image/imgPro.h>
 62 #include <tina/vision/visDef.h>
 63 #include <tina/vision/visPro.h>
 64 
 65 #include <tinatool/wdgts/wdgtsDef.h>
 66 #include <tinatool/wdgts/wdgtsPro.h>
 67 #include <tinatool/draw/drawDef.h>
 68 #include <tinatool/draw/drawPro.h>
 69 #include <tinatool/tlbase/tlbasePro.h>
 70 #include <tinatool/tlvision/tlvisEdge_pick.h>
 71 #include <tinatool/tlvision/tlvisEdge_geom_pick.h>
 72 
 73 
 74 static Tv *tvl;
 75 static Tv *tvr;
 76 
 77 /*
 78  * interface controlled match function selection
 79  */
 80 static double (*match_cost_func) ();
 81 static  Bool(*match_func) () = es_match_orandcon;
 82 static  Bool(*wta_compat_func) () = matches_not_unique;
 83 
 84 /** parameter handling **/
 85 
 86 static double lowd = -0.5, upd = 0.5;   /* image disparity */
 87 static float lowdisp, updisp;   /* rectified pixel disparity */
 88 static int vdisp = 0;           /* allowable rasters disparity */
 89 static double fit_thres3 = 2.0;
 90 static void *ft3;
 91 static void *dps;
 92 static unsigned int block_label = 0;
 93 static int use_disp_histogram = 1;
 94 
 95 double  stest_lowdisp(void)
 96 {
 97     return (lowdisp);
 98 }
 99 
100 double  stest_updisp(void)
101 {
102     return (updisp);
103 }
104 
105 static void param_dialog(void)
106 {
107     static void *dialog = NULL;
108 
109     if (dialog)
110     {
111         tw_show_dialog(dialog);
112         return;
113     }
114     dps = tw_ivalue("DP table max:", stereo_dp_max_size_get,
115                     stereo_dp_max_size_set, 20);
116     dialog = tw_dialog("Segment Params");
117     (void) tw_fglobal("Low disp  :", &lowd, 16);
118     tw_newrow();
119     (void) tw_fglobal("Up disp   :", &upd, 16);
120     tw_newrow();
121     (void) tw_iglobal("Vert disp :", &vdisp, 16);
122     tw_end_dialog();
123 }
124 
125 static void geom_param_dialog(void)
126 {
127     static void *dialog = NULL;
128 
129     if (dialog)
130     {
131         tw_show_dialog(dialog);
132         return;
133     }
134     dialog = tw_dialog("Geom Parameters");
135 
136     ft3 = tw_fglobal("3D  fit thres :", &fit_thres3, 20);
137 
138     tw_end_dialog();
139 }
140 
141 /* Tv pick function selection */
142 
143 static void left_pick_proc(Tv_pick(*func) ( /* ??? */ ))
144 {
145     tv_set_pick(left_tv(), (*func) ());
146 }
147 
148 static void right_pick_proc(Tv_pick(*func) ( /* ??? */ ))
149 {
150     tv_set_pick(right_tv(), (*func) ());
151 }
152 
153 static void left_mouse_proc(Tv_mouse(*func) ( /* ??? */ ))
154 {
155     tv_set_mouse(left_tv(), (*func) ());
156 }
157 
158 static void right_mouse_proc(Tv_mouse(*func) ( /* ??? */ ))
159 {
160     tv_set_mouse(right_tv(), (*func) ());
161 }
162 
163 void match_func_choice_proc(int value)
164 {
165     switch (value)
166     {
167         case 0:
168         match_func = NULL;
169         break;
170     case 1:
171         match_func = es_match_abs_orient;
172         break;
173     case 2:
174         match_func = es_match_orient;
175         break;
176     case 3:
177         match_func = es_match_orandcon;
178         break;
179     }
180 }
181 
182 void match_cost_choice_proc(int value)
183 {
184     switch (value)
185     {
186         case 0:
187         match_cost_func = NULL;
188         break;
189     case 1:
190         match_cost_func = match_strength;
191         break;
192     case 2:
193         match_cost_func = match_total_string_strength;
194         break;
195     case 3:
196         match_cost_func = match_local_string_strength;
197         break;
198     case 4:
199         match_cost_func = match_local_area_strength;
200         break;
201     }
202 }
203 
204 static void wta_compat_choice_proc(int value)
205 {
206     Bool    matches_not_unique();
207     Bool    matches_not_ordered();
208 
209     switch (value)
210     {
211     case 0:
212         wta_compat_func = matches_not_unique;
213         break;
214     case 1:
215         wta_compat_func = matches_not_ordered;
216         break;
217     }
218 }
219 
220 
221 #if 0
222 static void draw_es_list(Tv * tv, List * list)
223 {
224     for (; list != NULL; list = list->next)
225         tv_edge_string(tv, (Tstring *) list->to);
226 }
227 
228 static void draw_match_list(List * mlist)
229 {
230     List   *lptr;
231 
232     for (lptr = mlist; lptr != NULL; lptr = lptr->next)
233         tv_match(tvl, tvr, (Match *) lptr->to);
234 }
235 
236 #endif
237 
238 static void draw_match_list_col(List * mlist)
239 {
240     List   *lptr;
241     int     col = wheat;
242 
243     for (lptr = mlist; lptr != NULL; lptr = lptr->next)
244     {
245         tv_set_color(tvl, col);
246         tv_set_color(tvr, col);
247         tv_match(tvl, tvr, (Match *) lptr->to);
248         col = (col == baby_pink) ? wheat : col + 1;
249     }
250 }
251 
252 void    stest_order_match(int raster)
253 {
254     Imrect *ler;
255     Imrect *rer;
256     Rindex *lsx;
257     Rindex *rsx;
258     List   *mlist;
259 
260     ler = left_edges();
261     rer = right_edges();
262     if (ler == NULL && rer == NULL)
263         return;
264 
265     lsx = (Rindex *) prop_get(ler->props, SINDEX);
266     rsx = (Rindex *) prop_get(rer->props, SINDEX);
267     if (lsx == NULL && rsx == NULL)
268         return;
269 
270     if (raster < lsx->region->ly || raster > lsx->region->uy ||
271         raster < rsx->region->ly || raster > rsx->region->uy)
272         return;
273 
274     mlist = match_epi_dprog((List *) lsx->index[raster], match_cost_func);
275     tv_repaint(tvl);
276     tv_repaint(tvr);
277     draw_match_list_col(mlist);
278     list_rm_links(mlist);
279 }
280 
281 static void choose_wta_proc(void)
282 {
283     Imrect *left_er;
284 
285     if ( (left_er = left_edges()) == NULL)
286         return;
287 
288     choose_wta_matches(left_er, match_cost_func, wta_compat_func);
289     er_apply_through_sindex(left_er, es_select_fix_matches, NULL);
290 }
291 
292 void choose_ordered_proc(void)
293 {
294     Imrect *left_er;
295 
296     if ( (left_er = left_edges()) == NULL)
297         return;
298 
299     choose_ordered_matches(left_er, match_cost_func);
300     er_apply_through_sindex(left_er, es_select_fix_matches, NULL);
301 }
302 
303 static void choose_string_proc(void)
304 {
305     Imrect *left_er;
306 
307     if ( (left_er = left_edges()) == NULL)
308         return;
309 
310     er_apply_to_all_strings(left_er, es_choose_string_matches, NULL);
311     er_apply_through_sindex(left_er, es_select_fix_matches, NULL);
312 }
313 
314 static void figural_supp_proc(void)
315 {
316     er_apply_to_all_strings(left_edges(), es_figural_supp, (void *) match_cost_func);
317 }
318 
319 void string_supp_proc(void)
320 {
321     Imrect *left_er = left_edges();
322 
323     er_apply_to_all_strings(left_er, es_match_string_init, (void *) match_cost_func);
324     er_apply_to_all_strings(left_er, es_match_string, (void *) match_cost_func);
325     er_apply_to_all_strings(left_er, es_mlist_set_total_string_sup, NULL);
326 }
327 
328 static void ordered_supp_proc(void)
329 {
330     Imrect *left_er = left_edges();
331 
332     support_ordered_matches(left_er, match_cost_func);
333     er_apply_through_sindex(left_er, es_supp_good_matches_only, NULL);
334 }
335 
336 static void st_index_proc(void)
337 {
338     Imrect *left_er;
339     Imrect *right_er;
340 
341     tvl = left_tv();
342     tvr = right_tv();
343 
344     left_er = left_edges();
345     right_er = right_edges();
346 
347     if (left_er == NULL || right_er == NULL)
348         return;
349 
350     er_reference_strings(left_er);
351     er_set_sindex(left_er);
352     er_reference_strings(right_er);
353     er_set_sindex(right_er);
354 
355 }
356 
357 static void st_hist_proc(void)
358 {
359     Imrect *left_er;
360     Imrect *right_er;
361     double  Disp, edge_Disp_get();
362     Windex *disp_range;
363 
364     left_er = left_edges();
365     right_er = right_edges();
366 
367     if (left_er == NULL || right_er == NULL)
368         return;
369 
370     Disp = edge_Disp_get();
371     lowdisp = Disp + lowd * left_er->width;
372     updisp = Disp + upd * left_er->width;
373 
374 
375     if (use_disp_histogram)
376     {
377         disp_range = er_disp_hist(left_er, right_er,
378                                   lowdisp, updisp,
379                                   es_match_orandcon);
380     } else
381     {
382         disp_range = er_disp_range_build(left_er, 16, 16);
383         disp_range_fix_disparity(disp_range, lowdisp, updisp);
384     }
385     disp_range_set(disp_range);
386 }
387 
388 void st_matches_proc(void)
389 {
390     Imrect *left_er;
391     Imrect *right_er;
392 
393     left_er = left_edges();
394     right_er = right_edges();
395 
396     if (left_er == NULL || right_er == NULL)
397         return;
398 
399 /*
400     pcam = pcam_get();
401 */
402 
403     er_apply_through_sindex(left_er, es_init_mlist, NULL);
404     er_set_matches(left_er, right_er, vdisp, match_func);
405 }
406 
407 void st_support_proc(void)
408 {
409     Imrect *left_er;
410 
411 
412     if ((left_er = left_edges()) == NULL)
413         return;
414 
415     er_apply_through_sindex(left_er, es_add_supp_prop, NULL);   /* add support prop */
416 }
417 
418 
419 static void   *point3_of_dvec3(Vec3 * vp, int *type)
420 {
421     Vec3    v =
422     {Vec3_id};
423 
424     v = vec3_par_proj_3d(*vp);
425     *type = POINT3;
426     return ((void *) point3_make(v, POINT3));
427 }
428 
429 static List   *es2_depth_points(List * es_list)
430 {
431     List   *list3 = NULL;
432     List   *ptr;
433 
434     for (ptr = es_list; ptr != NULL; ptr = ptr->next)
435     {
436         Tstring *es3, *es2 = (Tstring *) ptr->to;
437 
438         es3 = es_build_string3(es2, es2);
439         list3 = ref_addtostart(list3, (void *) es3, STRING);
440     }
441     return (list_reverse(list3));
442 }
443 
444 static void geom3_init(void)
445 {
446     threed_geom_set((List *) NULL);
447 }
448 
449 static void geom3_proc(void)
450 {
451     int edge_stereo_method(void);
452     List   *geom = left_geom_get();
453     List   *threed_list_get();
454 
455     if (geom != NULL)
456     {
457         geom = reclist_list_update(geom, geom3_from_geom2, 0, (void *) &fit_thres3);
458     }
459     else                        /* use raw edges */
460     {
461         Imrect *er=left_edges_get();
462         List *geom2;
463 
464         geom2 = (List *) prop_get(er->props, STRING);
465         geom2 = es2_depth_points(geom2);
466         geom = reclist_list_update(geom2, point3_of_dvec3, 0, NULL);
467         reclist_list_free(geom2, rfree, 0, NULL);
468     }
469 /* transform to base coordinate frame for combination of head data NAT
470     trans = trans3_inverse(*(pcam->rcam1->transf));
471     reclist_list_apply(geom, geom_transform, NULL, &trans);
472 */
473     geom = list_append(geom, threed_list_get());
474     threed_geom_null();
475     threed_geom_set(geom);
476 }
477 
478 static void left_proc(void)
479 {
480     Parcam *pcam = pcam_get();
481     Transform3 trans =
482     {Transform3_id};
483 
484     if (pcam == NULL || pcam->cam1 == NULL || pcam->rcam1 == NULL ||
485         pcam->cam1->transf == NULL || pcam->rcam1->transf == NULL)
486         return;
487 
488     trans = trans3_inverse(*(pcam->rcam1->transf));
489     trans = trans3_prod(*(pcam->cam1->transf), trans);
490 
491     reclist_list_apply(threed_geom_get(), geom_transform, 0, (void *) &trans);
492 }
493 
494 /*
495 void stereo_default_proc(void)
496 {
497     match_func_choice_proc(3);
498     match_cost_choice_proc(1); 
499     st_index_proc();  no options 
500     st_hist_proc();  match_func 
501     st_matches_proc();  match_func 
502     st_support_proc();  no options 
503     string_supp_proc();  match_cost_func 
504     choose_ordered_proc();  match_cost_func 
505 }
506 */
507 
508 static void stereo_proc(void)
509 {
510     double  edge_Disp_get(void);
511     int edge_stereo_method();
512     Imrect *left_er;
513     Imrect *right_er;
514     void match_func_choice_proc(int val);
515     void match_cost_choice_proc(int val);
516     void st_matches_proc(void);
517     void st_support_proc(void);
518     void string_supp_proc(void);
519     void choose_ordered_proc(void);
520 
521     if (edge_stereo_method())
522     {
523         error("edge tool: stereo in stretch correlation mode", warning);
524         return;
525     }
526 
527     left_er = left_edges_get();
528     right_er = right_edges_get();
529 
530     if (left_er == NULL || right_er == NULL)
531     {
532         error("edge tool: no edges available", warning);
533         return;
534     }
535 
536     match_func_choice_proc(3);
537     match_cost_choice_proc(1);
538 
539     (void) ralloc_start_blocked(block_label);
540     st_index_proc(); 
541     (void) ralloc_end_blocked();
542     st_hist_proc();
543 
544 /*  quick version not reliable NAT 1/1/00
545     could it be it requires a unique block lablel?
546     (void) ralloc_start_blocked(block_label);
547     er_string_matcher(left_er, right_er, es_match_abs_orient);
548     (void) ralloc_end_blocked();
549 */
550 
551     st_matches_proc(); /* match_func */
552     st_support_proc(); /* no options */
553     string_supp_proc(); /* match_cost_func */
554     choose_ordered_proc(); /* match_cost_func */
555 }
556 
557 static void disp_range_choice_proc(int val)
558 {
559     use_disp_histogram = val;
560 }
561 
562 static void left_edge_pick_proc(Tv_pick(*func) ( /* ??? */ ))
563 {
564     Tv     *tv = left_tv_get();
565 
566     tv_set_pick(tv, (*func) ());
567     (void) tv_set_activity(tv, PICK);
568 }
569 
570 static void threed_pick_proc(Tv_pick(*func) ( /* ??? */ ))
571 {
572     Tv     *tv = threed_tv_get();
573 
574     tv_set_pick(tv, (*func) ());
575     (void) tv_set_activity(tv, PICK);
576 }
577 
578 void    stereo_test_tool(int x, int y)
579 {
580     static void *tv_screen = NULL;
581     Tv_mouse left_order_mouse();
582     Tv_mouse right_order_mouse();
583 
584     if (tv_screen)
585     {
586         tw_show_tool(tv_screen);
587         return;
588     }
589     tv_screen = tw_tool("PMF Stereo Tool", x, y);
590 
591     tw_menubar("Pick: ",
592                "Left",
593                "null", left_pick_proc, null_pick,
594                "e mat", left_edge_pick_proc, left_edge_matches,
595                "s mat", left_edge_pick_proc, left_string_matches,
596                NULL,
597                "Right",
598                "null", right_pick_proc, null_pick,
599                NULL,
600                "Threed",
601                "null", threed_pick_proc, null_pick,
602                "print", threed_pick_proc, threed_print,
603                "choose", threed_pick_proc, threed_choose,
604                "delete", threed_pick_proc, threed_delete,
605                "plane", threed_pick_proc, threed_plane,
606 #ifndef lint                    /* lint fails on > 49 arguments */
607                "cone", threed_pick_proc, threed_cone,
608                NULL,
609 #endif                          /* lint */
610                NULL);
611 
612     tw_newrow();
613     tw_menubar("Mouse: ",
614                "Left",
615                "null", left_mouse_proc, null_mouse,
616                "order", left_mouse_proc, left_order_mouse,
617                NULL,
618                "Right",
619                "null", right_mouse_proc, null_mouse,
620                "order", right_mouse_proc, right_order_mouse,
621                NULL,
622                NULL);
623     tw_help_button("pmf_stereo_tool");
624 
625     tw_newrow();
626     tw_choice("Match", match_func_choice_proc, 3,
627               "all mats", "abs or", "orient", "or+con", NULL);
628 
629     tw_newrow();
630     tw_choice("Cost", match_cost_choice_proc, 1,
631               "null", "match", "string", "sub str", "area", NULL);
632 
633     tw_newrow();
634     tw_choice("WTA", wta_compat_choice_proc, 0,
635               "unique", "ordered", NULL);
636 
637     tw_newrow();
638     tw_choice("Disparity range:",
639               disp_range_choice_proc, 1, "uniform", "histogram", NULL);
640 
641     tw_newrow();
642     tw_button("index edges", st_index_proc, NULL);
643     tw_button("disp hist", st_hist_proc, NULL);
644     tw_button("set matches", st_matches_proc, NULL);
645     tw_button("set support", st_support_proc, NULL);
646 
647     tw_newrow();
648     (void) tw_label("Support : ");
649     tw_button("ordered", ordered_supp_proc, NULL);
650     tw_button("string tot", string_supp_proc, NULL);
651     tw_button("figural tot", figural_supp_proc, NULL);
652 
653     tw_newrow();
654     (void) tw_label("Choose  : ");
655     tw_button("wta", choose_wta_proc, NULL);
656     tw_button("DP order", choose_ordered_proc, NULL);
657     tw_button("string tot", choose_string_proc, NULL);
658 
659     tw_newrow();
660     (void) tw_label("Default : ");
661     tw_button("stereo", stereo_proc, NULL);
662     tw_button("init geom3", geom3_init, NULL);
663     tw_button("geom3", geom3_proc, NULL);
664     tw_button("left", left_proc, NULL);
665 
666     tw_newrow();
667     tw_button("stereo params", param_dialog, NULL);
668     tw_button("geom params", geom_param_dialog, NULL);
669 
670     tw_end_tool();
671 }
672 

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