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

Linux Cross Reference
Tina5/tina-tools/tinatool/tlvision/tlvisSmm_tool.c

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

  1 /**********
  2  *
  3  * This file is part of the TINA Open Source Image Analysis Environment
  4  * henceforth known as TINA
  5  *
  6  * TINA is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU Lesser General Public License as
  8  * published by the Free Software Foundation.
  9  *
 10  * TINA is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  * GNU Lesser General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU Lesser General Public License
 16  * along with TINA; if not, write to the Free Software Foundation, Inc.,
 17  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  *
 19  **********
 20  *
 21  * Program :   TINA
 22  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/tlvision/tlvisSmm_tool.c,v $
 23  * Date    :  $Date: 2009/03/27 16:01:50 $
 24  * Version :  $Revision: 1.6 $
 25  * CVS Id  :  $Id: tlvisSmm_tool.c,v 1.6 2009/03/27 16:01:50 paul Exp $
 26  *
 27  * Notes :
 28  *
 29  *
 30  *
 31  *********
 32 */
 33 
 34 #include "tlvisSmm_tool.h"
 35 
 36 #if HAVE_CONFIG_H
 37 #include <config.h>
 38 #endif
 39 
 40 #include <stdio.h>
 41 
 42 #include <tina/sys/sysDef.h>
 43 #include <tina/sys/sysPro.h>
 44 #include <tina/math/mathDef.h>
 45 #include <tina/math/mathPro.h>
 46 #include <tina/file/fileDef.h>
 47 #include <tina/file/filePro.h>
 48 #include <tina/geometry/geomDef.h>
 49 #include <tina/geometry/geomPro.h>
 50 #include <tina/vision/visDef.h>
 51 #include <tina/vision/visPro.h>
 52 
 53 #include <tinatool/wdgts/wdgtsDef.h>
 54 #include <tinatool/wdgts/wdgtsPro.h>
 55 #include <tinatool/draw/drawDef.h>
 56 #include <tinatool/draw/drawPro.h>
 57 #include <tinatool/tlbase/tlbaseDef.h>
 58 #include <tinatool/tlbase/tlbasePro.h>
 59 
 60 #include <tinatool/tlvision/tlvisSmm_mouse.h>
 61 #include <tinatool/tlvision/tlvisSmm_matcher.h>
 62 #include <tinatool/tlvision/tlvisSmm_pick.h>
 63 #include <tinatool/tlvision/tlvisSmm_view.h>
 64 #include <tinatool/tlvision/tlvisSmm_draw.h>
 65 
 66 int *matcher_get_mlsize();
 67 
 68 /* Tv selection */
 69 
 70 static Tv      *tvs;
 71 static Tv      *tvm;
 72 static void *pcliche=NULL;
 73 
 74 static void     match_tv_proc(void)
 75 {
 76         scene_tv_set(tvs = scene_tv_make());
 77         model_tv_set(tvm = model_tv_make());
 78 
 79         tv_set_next(tvm);
 80         tv_set_mouse(tvm, matcher_model_mouse());
 81         tv_set_mouse(tvs, matcher_scene_mouse());
 82 }
 83 
 84 static void     tv_choice_proc(int val)
 85 {
 86         switch (val)
 87         {
 88                 case 0:
 89                 tv_set_next(tvm);
 90                 break;
 91         case 1:
 92                 tv_set_next(tvs);
 93                 break;
 94         }
 95 }
 96 
 97 /* file code */
 98 
 99 static char     base_name[100];
100 static char     dir_name[100];
101 
102 #define MODEL 0
103 #define SCENE 1
104 #define CLICHES_OLD 2
105 #define CLICHES_NEW 3
106 #define CLICHES_2
107 
108 static int      file_type = MODEL;
109 int go_to_match = 1, mlist_size = 30, cliche_size = 8;
110 
111 static void     file_choice_proc(int val)
112 {
113         file_type = val;
114 }
115 
116 void init_cliches( int cliche_size )
117 {
118     matcher_set_cliches(NULL);
119     free_globalMem_list();
120 }
121 
122 static void     input_proc(void)
123 {
124         char            fname[256];
125         List   *ffg_read_file(char *pathname, List * list);
126 
127         switch (file_type)
128         {
129         case MODEL:
130                 (void) string_append(fname, dir_name, "/", base_name, ".poly", NULL);
131                 model_set(line3_read_geom(fname, RIGHT));
132                 break;
133         case SCENE:
134                 (void) string_append(fname, dir_name, "/", base_name, ".poly", NULL);
135                 scene_set(line3_read_geom(fname, RIGHT));
136                 break;
137         case CLICHES_OLD:
138                 (void) string_append(fname, dir_name, "/", base_name, ".ffgnn", NULL);
139                 matcher_set_cliches(ffg_read_file(fname, model_get())); 
140                 break;
141         case CLICHES_NEW:
142                 (void) string_append(fname, dir_name, "/", base_name, ".ffg", NULL);
143                 matcher_set_cliches(ffg_new_read_file(fname, model_get()));
144                 break;
145         
146         default:
147                 error("unable to input that file type", non_fatal);
148                 break;
149         }
150 }
151 
152 static void     output_proc(void)
153 {
154         char            fname[256];
155 
156         switch (file_type)
157         {
158         case MODEL:
159                 (void) string_append(fname, dir_name, "/", base_name, ".poly", NULL);
160                 line3_write_geom(fname, model_get(), RIGHT);
161                 break;
162         case SCENE:
163                 (void) string_append(fname, dir_name, "/", base_name, ".poly", NULL);
164                 line3_write_geom(fname, scene_get(), RIGHT);
165                 break;
166         case CLICHES_OLD:
167                 (void) string_append(fname, dir_name, "/", base_name, ".ffg", NULL);
168                 ffg_write_file(fname, matcher_get_cliches());
169                 break;
170         case CLICHES_NEW:
171                 (void) string_append(fname, dir_name, "/", base_name, ".ffg", NULL);
172                 ffg_new_write_file(fname, matcher_get_cliches());
173                 break;
174         default:
175                 error("unable to output that file type", non_fatal);
176         }
177 }
178 
179 /* mouse pick selection */
180 
181 static void     model_pick_proc(Tv_pick(*func) ( /* ??? */ ))
182 {
183         tv_set_pick(tvm, (*func) ());
184         (void) tv_set_activity(tvm, PICK);
185 }
186 
187 static void     scene_pick_proc(Tv_pick(*func) ( /* ??? */ ))
188 {
189         tv_set_pick(tvs, (*func) ());
190         (void) tv_set_activity(tvs, PICK);
191 }
192 
193 /*** match functions ***/
194 
195 void     trans_model_proc(void)
196 {
197         List           *geom;
198         Transform3      trans = {Transform3_id};
199         trans = matcher_get_trans();
200         geom = list_copy(model_get(), (void *(*) ()) geom_copy, NULL);
201         reclist_list_apply(geom, geom_transform, 0, (void *) &trans);
202         tv_set_color(tvs, red);
203         reclist_list_draw(tvs, geom, 0, geom_draw, NULL);
204         (void) reclist_list_free(geom, geom_free, 0, NULL);
205 }
206 
207 static void     match_choice_proc(int value)
208 {
209         matcher_set_use_transf_thres((Bool) value);
210 }
211 
212 static void     get_scene_proc(void)
213 {
214         /* get scene geometry data from 3D tool */
215         scene_set(reclist_list_flat(threed_geom_get(), geom_update_copy, 0, NULL));
216 }
217 
218 static void     get_model_proc(void)
219 {
220         /* get model geometry from 3D tool (for scene to scene matching) */
221         model_set(reclist_list_flat(threed_geom_get(), geom_update_copy, 0, NULL));
222 }
223 
224 static void     init_cliches_proc(void)
225 {
226 /*
227         matcher_set_cliches((List *) NULL);
228 */
229         init_cliches(cliche_size);
230 }
231 
232 static void     init_matches_proc(void)
233 {
234         matcher_matches_init();
235 }
236 
237 static void     add_cliche_proc(void)
238 {
239      matcher_add_cliche();
240 }
241 
242 void            transform_proc(void)
243 {
244     int    tvm_width, tvs_width;
245 
246     if ( matcher_compute_transform() )
247     {
248         tv_repaint(tvm);
249         tv_repaint(tvs);
250 
251         tvm_width = tv_get_linewidth(tvm);
252         tvs_width = tv_get_linewidth(tvs);
253         (void) tv_set_linewidth(tvm, tvm_width * 2);
254         (void) tv_set_linewidth(tvs, tvs_width * 2);
255 
256         match_list_cycle_draw(matcher_matches_get(), tvm, tvs);
257 
258         (void) tv_set_linewidth(tvm, tvm_width);
259         (void) tv_set_linewidth(tvs, tvs_width);
260     }
261 }
262 
263 void     build_tables_proc(void)
264 {
265       matcher_build_tables();
266 }
267 
268  void     smm_matcher_proc(void)
269 {
270         int     tvm_width, tvs_width;
271         List   *cliche_list;
272 
273         cliche_list = cliches_from_ffg(model_get(), cliche_size);
274         matcher_set_cliches(cliche_list);
275 
276         matcher_run_smm( cliche_size );
277 
278         tv_repaint(tvm);
279         tv_repaint(tvs);
280 
281         tvm_width = tv_get_linewidth(tvm);
282         tvs_width = tv_get_linewidth(tvs);
283         (void) tv_set_linewidth(tvm, tvm_width * 2);
284         (void) tv_set_linewidth(tvs, tvs_width * 2);
285 
286         match_list_cycle_draw(matcher_matches_get(), tvm, tvs);
287 
288         (void) tv_set_linewidth(tvm, tvm_width);
289         (void) tv_set_linewidth(tvs, tvs_width);
290 }
291 
292 void smm_go_to_proc( void )
293 {
294      int             tvm_width, tvs_width;
295      smm_go_to( go_to_match );
296      tv_repaint(tvm);
297      tv_repaint(tvs);
298 
299      /* make the matched lines thicker */
300      tvm_width = tv_get_linewidth(tvm);
301      tvs_width = tv_get_linewidth(tvs);
302      (void) tv_set_linewidth(tvm, tvm_width * 2);
303      (void) tv_set_linewidth(tvs, tvs_width * 2);
304 
305      match_list_cycle_draw(matcher_matches_get(), tvm, tvs);
306      /* reset line widths */
307      (void) tv_set_linewidth(tvm, tvm_width);
308      (void) tv_set_linewidth(tvs, tvs_width);
309 }
310 
311 /********** Paramter dialog callbacks **********/
312 
313 static void     pwr_dialog_proc(void)
314 {
315         static void    *dialog = NULL;
316 
317         if (dialog)
318         {
319                 tw_show_dialog(dialog);
320                 return;
321         }
322         dialog = tw_dialog("PWR Parameters");
323 
324         pcliche = tw_iglobal("cliche size", &cliche_size, 2 );
325         tw_newrow();
326         (void) tw_ivalue("clique size:", matcher_get_csize, matcher_set_csize, 2);
327         tw_newrow();
328         (void) tw_fvalue("pos error  :", matcher_get_pos_error, matcher_set_pos_error, 10);
329         tw_newrow();
330         (void) tw_fvalue("rot error  :", matcher_get_rot_error, matcher_set_rot_error, 10);
331         tw_newrow();
332         (void) tw_fvalue("Lenh thres :", matcher_get_lthres, matcher_set_lthres, 10);
333 
334         tw_end_dialog();
335 }
336 
337 static void     match_dialog_proc(void)
338 {
339         static void    *dialog = NULL;
340 
341         if (dialog)
342         {
343                 tw_show_dialog(dialog);
344                 return;
345         }
346         dialog = tw_dialog("Match Parameters");
347 
348         (void) tw_fvalue("Max rot   :", matcher_get_max_rot, matcher_set_max_rot, 20);
349         tw_newrow();
350         (void) tw_fvalue("Max trans :", matcher_get_max_trans, matcher_set_max_trans, 20);
351         tw_newrow();
352         (void) tw_fvalue("Len ratio :", matcher_get_length_ratio, matcher_set_length_ratio, 20);
353         tw_newrow();
354         tw_iglobal("Max matches :", matcher_get_mlsize(), 2 );
355 
356         tw_end_dialog();
357 }
358 
359 /********** Tool creation **********/
360 
361 void            matcher_tool(int x, int y)
362 {
363         static void    *tv_screen = NULL;
364 
365         if (tv_screen)
366         {
367                 tw_show_tool(tv_screen);
368                 return;
369         }
370         match_tv_proc();
371         tv_screen = tw_tool("Matcher Tool", x, y);
372 
373         tw_choice("Tv: ", tv_choice_proc, 0, "model", "scene", NULL);
374         tw_menubar("Pick: ",
375                    "Model",
376                    "null", model_pick_proc, null_pick,
377                    "choose", model_pick_proc, model_choose,
378                    "delete", model_pick_proc, model_delete,
379                    "direct", model_pick_proc, model_direct,
380                    "matches", model_pick_proc, model_matches,
381                    "focus", model_pick_proc, model_focus,
382                    "group", model_pick_proc, model_group,
383                    NULL,
384                    "Scene",
385                    "null", scene_pick_proc, null_pick,
386                    "choose", scene_pick_proc, scene_choose,
387                    "delete", scene_pick_proc, scene_delete,
388                    "direct", scene_pick_proc, scene_direct,
389                    "matches", scene_pick_proc, scene_matches,
390                    "pairs", scene_pick_proc, scene_pwr,
391                    NULL,
392                    NULL);
393         tw_newrow();
394         tw_choice("File:", file_choice_proc, 0,
395                   "Model", "Scene", "Cliches Old", "Cliches New",  NULL);
396         tw_newrow();
397         tw_button("input", input_proc, NULL);
398         tw_button("output", output_proc, NULL);
399         tw_button("get model", get_model_proc, NULL);
400         tw_button("get scene", get_scene_proc, NULL);
401         tw_newrow();
402         (void) tw_sglobal("Directory Name:", dir_name, 32);
403         tw_newrow();
404         (void) tw_sglobal("Base Name:     ", base_name, 32);
405         tw_newrow();
406 
407         (void) tw_label("Initialisation");
408         tw_button("init matches", init_matches_proc, NULL);
409         tw_button("init cliches", init_cliches_proc, NULL);
410         tw_button("add cliche", add_cliche_proc, NULL);
411         tw_newrow();
412 
413         (void) tw_label("Automatic");
414         tw_button("build tables", build_tables_proc, NULL);
415         tw_button("smm matcher", smm_matcher_proc, NULL);
416         tw_newrow();
417 
418         (void) tw_label("Interactive");
419         tw_button("go to", smm_go_to_proc, NULL);
420         tw_iglobal(" ", &go_to_match, 2 );
421         tw_button("comp trans", transform_proc, NULL);
422         tw_button("trans model", trans_model_proc, NULL);
423         tw_newrow();
424 
425         tw_choice("Limit Trans:", match_choice_proc, 0,
426                   "No", "Yes", NULL);
427         tw_button("PWR Params", pwr_dialog_proc, NULL);
428         tw_button("Match Params", match_dialog_proc, NULL);
429 
430         tw_end_tool();
431 }
432 

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