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

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

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