1 /* -*- Mode1: C; indent-tabs-mode: nil; c-basic-offset: 4 c-style: "K&R" -*- */
3 /*----------------------------------------------------------------------
5 gpiv - Graphic program for Particle Image Velocimetry, based on gtk/gnome
8 Copyright (C) 2002 Gerber van der Graaf
10 This file is part of gpiv.
12 Gpiv is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2, or (at your option)
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 ----------------------------------------------------------------------*/
29 * main routines of gpiv
31 * Revision 1.2 2003-06-27 13:47:26 gerber
32 * display ruler, line/point evaluation
34 * Revision 1.1.1.1 2003/06/17 17:10:52 gerber
40 /* ---------- some header inclusions for gtk/gnome (by glade) --*/
47 #include "gpiv_gtk.h" /* all variables are read by a header */
49 /* #include "console_interface.h" */
54 Usage: gpiv-gui [-f filename][-s N][-t] \n\
57 -f filename: loads project \n\
58 -s N: vector scale N \n\
62 /* -p: print parameters and other info to stdout \n\ */
65 gpiv processes and analyzes images for (Digital) Particle Image \n\
66 Velocimetry, post-processes the PIV data and visualizes its \n\
67 results in a graphical way. \n"
69 /*-- General variables */
73 /*-- Function prototypes ---------------------------------------*/
74 /*-- General functions (only called by main) -----------------*/
76 int main(int argc
, char *argv
[])
77 /*-------------------------------------------------------------------------*/
78 /*---- Main program of gpiv-gui -------------------------------------------*/
81 gboolean used_default
= 0;
82 gchar
*msg
= "Welcome to gpiv.";
83 GtkWidget
*menu_gpiv_popup
= NULL
;
84 GpivConsole
*gpiv
= NULL
;
86 static const struct poptOption options
[] = {
87 /* {NULL, 'q', POPT_ARG_NONE, &q, 0, */
88 /* N_("Explain gpiv"), NULL}, */
90 {"bins", 'b', POPT_ARG_INT
, &gpiv_par
.nbins
, 0,
91 N_("number of bins for histograms"), N_("BINS")},
93 {"columns", 'c', POPT_ARG_INT
, &gpiv_par
.img_width
, 0,
94 N_("number of columns in image"), N_("NCOLUMNS")},
96 {"rows", 'r', POPT_ARG_INT
, &gpiv_par
.img_height
, 0,
97 N_("number of rows in image"), N_("NROWS")},
99 {"display_img1", '\0', POPT_ARG_NONE
, &gpiv_par
.display_img1
, 0,
100 N_("enables displaying of the first image of a PIV image pair"),
103 {"display_img2", '\0', POPT_ARG_NONE
, &gpiv_par
.display_img2
, 0,
104 N_("enables displaying of the second image of a PIV image pair"),
107 {"display_intregs", '\0', POPT_ARG_NONE
, &gpiv_par
.display_intregs
, 0,
108 N_("enables displaying of interrogation regions"), NULL
},
110 {"display_piv", '\0', POPT_ARG_NONE
, &gpiv_par
.display_piv
, 0,
111 N_("enables displaying of PIV data"), NULL
},
113 {"display_vor", '\0', POPT_ARG_NONE
, &gpiv_par
.display_vor
, 0,
114 N_("enables displaying of vorticity data"), NULL
},
116 {"display_sstrain", '\0', POPT_ARG_NONE
, &gpiv_par
.display_sstrain
, 0,
117 N_("enables displaying of shear strain data"), NULL
},
119 {"display_nstrain", '\0', POPT_ARG_NONE
, &gpiv_par
.display_nstrain
, 0,
120 N_("enables displaying of normal strain data"), NULL
},
122 {"hdf", '\0', POPT_ARG_NONE
, &gpiv_par
.hdf
, 0,
123 N_("save data in HDF5 format with .gpi extension"), NULL
},
124 {"hdf_img", '\0', POPT_ARG_NONE
, &gpiv_par
.hdf_img
, 0,
125 N_("include image data in .gpi file (HDF5 format)"), NULL
},
127 {"print", 'p', POPT_ARG_NONE
, &print_par
, 0,
128 N_("print parameters and other info to stdout"), NULL
},
130 {"proc_piv", '\0', POPT_ARG_NONE
, &gpiv_par
.process_piv
, 0,
131 N_("includes piv in the chain-proces"), NULL
},
133 {"proc_gradient", '\0', POPT_ARG_NONE
, &gpiv_par
.process_gradient
, 0,
134 N_("includes gradient in the chain-proces"), NULL
},
136 {"proc_resstats", '\0', POPT_ARG_NONE
, &gpiv_par
.process_resstats
, 0,
137 N_("includes resstats in the chain-proces"), NULL
},
139 {"proc_errvec", '\0', POPT_ARG_NONE
, &gpiv_par
.process_errvec
, 0,
140 N_("includes validate in the chain-proces"), NULL
},
142 {"proc_peaklock", '\0', POPT_ARG_NONE
, &gpiv_par
.process_peaklock
, 0,
143 N_("includes peaklock in the chain-proces"), NULL
},
145 {"proc_average", '\0', POPT_ARG_NONE
, &gpiv_par
.process_average
, 0,
146 N_("includes average in the chain-proces"), NULL
},
148 {"proc_scale", '\0', POPT_ARG_NONE
, &gpiv_par
.process_scale
, 0,
149 N_("includes scaling in the chain-proces"), NULL
},
151 {"proc_substract", '\0', POPT_ARG_NONE
, &gpiv_par
.process_substract
, 0,
152 N_("includes substract in the chain-proces"), NULL
},
154 {"proc_vorstra", '\0', POPT_ARG_NONE
, &gpiv_par
.process_vorstra
, 0,
155 N_("includes vorticity in the chain-proces"), NULL
},
157 {"zoomscale", 'z', POPT_ARG_INT
, &gpiv_par
.zoom_index
, 0,
158 N_("display zoom index: 0:0.5, 1:0.83, 2:1.0, 3:1.3, 4:1.6, 5:2.0"),
161 {"vectorscale", 's', POPT_ARG_INT
, &gpiv_par
.vector_scale
, 0,
162 N_("vector length scale"), N_("SCALE")},
164 /* {"stretch_window", '\0', POPT_ARG_NONE, &gpiv_par.stretch_window, 0, */
165 /* N_("stretch display window to fit image area "), NULL}, */
167 {"tooltips", 't', POPT_ARG_NONE
, &gpiv_par
.show_tooltips
, 0,
168 N_("show tooltips"), NULL
},
170 {"view_gpivbuttons", '\0', POPT_ARG_NONE
, &gpiv_par
.view_gpivbuttons
, 0,
171 N_("view the GPIV buttons of the application"), NULL
},
173 {"view_tabulator", '\0', POPT_ARG_NONE
, &gpiv_par
.view_tabulator
, 0,
174 N_("view the tabulator of the application"), NULL
},
176 {NULL
, '\0', 0, NULL
, 0}
180 setlocale (LC_ALL
, "");
181 bindtextdomain(PACKAGE
, PACKAGE_LOCALE_DIR
);
186 * parameter initializing of gpiv-gtk
192 * Reading paramenters from gnome parameter file (~/.gnome/gpiv)
193 * See: http://developer.gnome.org/doc/GGAD/z79.html
196 gnome_config_push_prefix("/gpiv/General/");
199 gnome_config_get_bool_with_default("print_par=TRUE", &used_default
);
201 g_warning("print_par = %d from default", print_par
);
202 gnome_config_set_bool("print_par", print_par
);
205 default_par
.show_tooltips
=
206 gnome_config_get_bool_with_default("show_tooltips=TRUE", &used_default
);
208 g_warning("show_tooltips = %d from default", default_par
.show_tooltips
);
209 gnome_config_set_bool("show_tooltips", default_par
.show_tooltips
);
212 default_par
.view_gpivbuttons
=
213 gnome_config_get_bool_with_default("view_gpivbuttons=TRUE",
216 g_warning("view_gpivbuttons = %d from default", default_par
.view_gpivbuttons
);
217 gnome_config_set_bool("view_gpivbuttons", default_par
.view_gpivbuttons
);
220 default_par
.view_tabulator
=
221 gnome_config_get_bool_with_default("view_tabulator=TRUE", &used_default
);
223 g_warning("view_tabulator = %d from default", default_par
.view_tabulator
);
224 gnome_config_set_bool("view_tabulator", default_par
.view_tabulator
);
228 gnome_config_get_int_with_default("nbins=10", &used_default
);
230 g_warning("nbins = %d from default", default_par
.nbins
);
231 gnome_config_set_int("nbins", default_par
.nbins
);
234 default_par
.img_width
=
235 gnome_config_get_int_with_default("columns=256", &used_default
);
237 g_warning("img_width = %d from default", default_par
.img_width
);
238 gnome_config_set_int("columns", default_par
.img_width
);
241 default_par
.img_height
=
242 gnome_config_get_int_with_default("rows=256", &used_default
);
244 g_warning("img_height = %d from default", default_par
.img_height
);
245 gnome_config_set_int("rows", default_par
.img_height
);
249 gnome_config_get_bool_with_default("hdf=FALSE", &used_default
);
251 g_warning("hdf = %d from default ??", default_par
.hdf
);
252 gnome_config_set_bool("hdf", default_par
.hdf
);
255 default_par
.hdf_img
=
256 gnome_config_get_bool_with_default("hdf_img=FALSE", &used_default
);
258 g_warning("hdf_img = %d from default ??", default_par
.hdf_img
);
259 gnome_config_set_bool("hdf_img", default_par
.hdf_img
);
264 gnome_config_push_prefix("/gpiv/Processes/");
266 default_par
.process_piv
=
267 gnome_config_get_bool_with_default("process_piv=TRUE", &used_default
);
269 g_warning("process_piv = %d from default", default_par
.process_piv
);
270 gnome_config_set_bool("process_piv", default_par
.process_piv
);
273 default_par
.process_gradient
=
274 gnome_config_get_bool_with_default("process_gradient=FALSE", &used_default
);
276 g_warning("process_gradient = %d from default", default_par
.process_gradient
);
277 gnome_config_set_bool("process_gradient", default_par
.process_gradient
);
280 default_par
.process_resstats
=
281 gnome_config_get_bool_with_default("process_resstats=FALSE", &used_default
);
283 g_warning("process_resstats = %d from default", default_par
.process_resstats
);
284 gnome_config_set_bool("process_resstats", default_par
.process_resstats
);
287 default_par
.process_errvec
=
288 gnome_config_get_bool_with_default("process_errvec=FALSE", &used_default
);
290 g_warning("process_errvec = %d from default", default_par
.process_errvec
);
291 gnome_config_set_bool("process_errvec", default_par
.process_errvec
);
294 default_par
.process_peaklock
=
295 gnome_config_get_bool_with_default("process_peaklock=FALSE", &used_default
);
297 g_warning("process_peaklock = %d from default", default_par
.process_peaklock
);
298 gnome_config_set_bool("process_peaklock", default_par
.process_peaklock
);
301 default_par
.process_average
=
302 gnome_config_get_bool_with_default("process_average=FALSE", &used_default
);
304 g_warning("process_average = %d from default", default_par
.process_average
);
305 gnome_config_set_bool("process_average", default_par
.process_average
);
308 default_par
.process_scale
=
309 gnome_config_get_bool_with_default("process_scale=FALSE", &used_default
);
311 g_warning("process_scale = %d from default", default_par
.process_scale
);
312 gnome_config_set_bool("process_scale", default_par
.process_scale
);
315 default_par
.process_substract
=
316 gnome_config_get_bool_with_default("process_substract=FALSE", &used_default
);
318 g_warning("process_substract = %d from default", default_par
.process_substract
);
319 gnome_config_set_bool("process_substract", default_par
.process_substract
);
322 default_par
.process_vorstra
=
323 gnome_config_get_bool_with_default("process_vorstra=FALSE", &used_default
);
325 g_warning("process_vorstra = %d from default", default_par
.process_vorstra
);
326 gnome_config_set_bool("process_vorstra", default_par
.process_vorstra
);
331 gnome_config_push_prefix("/gpiv/Display/");
333 default_par
.zoom_index
=
334 gnome_config_get_int_with_default("zoom_index=0", &used_default
);
336 g_warning("zoom_index = %d from default", default_par
.zoom_index
);
337 gnome_config_set_int("zoom_index", default_par
.zoom_index
);
340 default_par
.vector_scale
=
341 gnome_config_get_int_with_default("vector_scale=8", &used_default
);
343 g_warning("vector_scale = %d from default", default_par
.vector_scale
);
344 gnome_config_set_int("vector_scale", default_par
.vector_scale
);
347 /* default_par.stretch_window = */
348 /* gnome_config_get_int_with_default("stretch_window=0", &used_default); */
349 /* if (used_default) { */
350 /* g_warning("stretch_window = %d from default", */
351 /* default_par.stretch_window); */
352 /* gnome_config_set_int("stretch_window", default_par.stretch_window); */
355 default_par
.display_img1
=
356 gnome_config_get_bool_with_default("display_img1=FALSE",
359 g_warning("display_img1 = %d from default",
360 default_par
.display_img1
);
361 gnome_config_set_bool("display_img1", default_par
.display_img1
);
364 default_par
.display_img2
=
365 gnome_config_get_bool_with_default("display_img2=FALSE",
368 g_warning("display_img2 = %d from default",
369 default_par
.display_img2
);
370 gnome_config_set_bool("display_img2", default_par
.display_img1
);
373 default_par
.display_intregs
=
374 gnome_config_get_bool_with_default("display_intregs=TRUE", &used_default
);
376 g_warning("display_intregs = %d from default", default_par
.display_intregs
);
377 gnome_config_set_bool("display_intregs", default_par
.display_intregs
);
380 default_par
.display_piv
=
381 gnome_config_get_bool_with_default("display_piv=TRUE", &used_default
);
383 g_warning("display_piv = %d from default", default_par
.display_piv
);
384 gnome_config_set_bool("display_piv", default_par
.display_piv
);
387 default_par
.display_vor
=
388 gnome_config_get_bool_with_default("display_vor=TRUE", &used_default
);
390 g_warning("display_vor = %d from default", default_par
.display_vor
);
391 gnome_config_set_bool("display_vor", default_par
.display_vor
);
394 default_par
.display_sstrain
=
395 gnome_config_get_bool_with_default("display_sstrain=TRUE", &used_default
);
397 g_warning("display_sstrain = %d from default", default_par
.display_sstrain
);
398 gnome_config_set_bool("display_sstrain", default_par
.display_sstrain
);
401 default_par
.display_nstrain
=
402 gnome_config_get_bool_with_default("display_nstrain=TRUE", &used_default
);
404 g_warning("display_nstrain = %d from default", default_par
.display_nstrain
);
405 gnome_config_set_bool("display_nstrain", default_par
.display_nstrain
);
408 gnome_config_pop_prefix();
410 gpiv_par
.show_tooltips
= default_par
.show_tooltips
;
411 gpiv_par
.view_tabulator
= default_par
.view_tabulator
;
412 gpiv_par
.view_gpivbuttons
= default_par
.view_gpivbuttons
;
413 gpiv_par
.nbins
= default_par
.nbins
;
414 gpiv_par
.img_width
= default_par
.img_width
;
415 gpiv_par
.img_height
= default_par
.img_height
;
416 gpiv_par
.process_piv
= default_par
.process_piv
;
417 gpiv_par
.process_gradient
= default_par
.process_gradient
;
418 gpiv_par
.process_resstats
= default_par
.process_resstats
;
419 gpiv_par
.process_errvec
= default_par
.process_errvec
;
420 gpiv_par
.process_peaklock
= default_par
.process_peaklock
;
421 gpiv_par
.process_average
= default_par
.process_average
;
422 gpiv_par
.process_scale
= default_par
.process_scale
;
423 gpiv_par
.process_substract
= default_par
.process_substract
;
424 gpiv_par
.process_vorstra
= default_par
.process_vorstra
;
425 gpiv_par
.zoom_index
= default_par
.zoom_index
;
426 gpiv_par
.vector_scale
= default_par
.vector_scale
;
427 /* gpiv_par.stretch_window = default_par.stretch_window; */
428 gpiv_par
.display_img1
= default_par
.display_img1
;
429 gpiv_par
.display_img2
= default_par
.display_img2
;
430 gpiv_par
.display_intregs
= default_par
.display_intregs
;
431 gpiv_par
.display_piv
= default_par
.display_piv
;
432 gpiv_par
.display_vor
= default_par
.display_vor
;
433 gpiv_par
.display_sstrain
= default_par
.display_sstrain
;
434 gpiv_par
.display_nstrain
= default_par
.display_nstrain
;
435 gpiv_par
.hdf
= default_par
.hdf
;
436 gpiv_par
.hdf_img
= default_par
.hdf_img
;
440 /* piv_data.nx = MAX_DATA; */
441 /* piv_data.ny = MAX_DATA; */
444 * variables initializing of gpiv-gui
447 gnome_config_push_prefix("/gpiv/RuntimeVariables/");
449 /* HOME_DIR=getenv("HOME"); */
451 gnome_config_get_string_with_default("fname_last=./", &used_default
);
453 g_warning("fname_last = %s from default", fname_last
);
454 gnome_config_set_string("fname_last", fname_last
);
460 exec_process
= FALSE
;
461 cancel_process
= FALSE
;
465 memset(graybuf_int1
, 215,
466 (sizeof(guchar
)) * (MAX_INTERR_SIZE
* MAX_INTERR_SIZE
));
467 memset(graybuf_int2
, 215,
468 (sizeof(guchar
)) * (MAX_INTERR_SIZE
* MAX_INTERR_SIZE
));
469 memset(graybuf_cov
, 215,
470 (sizeof(guchar
)) * (MAX_INTERR_SIZE
* MAX_INTERR_SIZE
));
471 /* memset( graybuf_cov, 255, (sizeof (guchar)) *(MAX_INTERR_SIZE * MAX_INTERR_SIZE)); */
476 gci_vector_piv_disprocess
= NULL
;
481 g_snprintf(IMAGE_WIDTH_LABEL
, MAX_CHARS
, "%d", gpiv_par
.img_width
);
482 g_snprintf(IMAGE_HEIGHT_LABEL
,MAX_CHARS
, "%d", gpiv_par
.img_height
);
485 * parameter initializing of image
487 image_par
.nbits_logic
= 0;
488 image_par
.ncolumns_logic
= 0;
489 image_par
.nrows_logic
= 0;
490 image_par
.x_corr_logic
= 0;
491 image_par
.s_scale_logic
= 0;
492 image_par
.t_scale_logic
= 0;
493 image_par
.z_off_logic
= 0;
494 image_par
.project_logic
= 0;
495 image_par
.creation_date_logic
= 0;
496 image_par
.location_logic
= 0;
497 image_par
.comment_logic
= 0;
501 * parameter initializing of piv_eval
503 piv_eval_par
.autokey_logic
= 0;
504 piv_eval_par
.col_start_logic
= 0;
505 piv_eval_par
.col_end_logic
= 0;
506 piv_eval_par
.int_geo_logic
= 0;
507 piv_eval_par
.ifit_logic
= 0;
508 piv_eval_par
.int_line_row_logic
= 0;
509 piv_eval_par
.int_line_row_start_logic
= 0;
510 piv_eval_par
.int_line_row_end_logic
= 0;
511 piv_eval_par
.int_line_col_logic
= 0;
512 piv_eval_par
.int_line_col_start_logic
= 0;
513 piv_eval_par
.int_line_col_end_logic
= 0;
514 piv_eval_par
.int_point_col_logic
= 0;
515 piv_eval_par
.int_point_row_logic
= 0;
516 piv_eval_par
.int_size
= 0;
517 piv_eval_par
.int_size_1_logic
= 0;
518 piv_eval_par
.int_size_2_logic
= 0;
519 piv_eval_par
.int_shift_logic
= 0;
520 piv_eval_par
.old_piv_logic
= 0;
521 piv_eval_par
.pre_shift_col_logic
= 0;
522 piv_eval_par
.peak_logic
= 0;
523 piv_eval_par
.pre_shift_row_logic
= 0;
524 piv_eval_par
.print_par_logic
= 0;
525 piv_eval_par
.print_piv_logic
= 0;
526 piv_eval_par
.print_cov_logic
= 0;
527 piv_eval_par
.row_start_logic
= 0;
528 piv_eval_par
.row_end_logic
= 0;
529 piv_eval_par
.weight_logic
= 0;
530 piv_eval_par
.zero_off_logic
= 0;
531 piv_eval_par
.central_diff_logic
= 0;
535 * parameter initializing of piv_valid
537 piv_valid_par
.auto_thresh_logic
= 0;
538 piv_valid_par
.residu_max_logic
= 0;
539 piv_valid_par
.res_stats_logic
= 0;
540 piv_valid_par
.data_yield_logic
= 0;
541 piv_valid_par
.residu_type_logic
= 0;
542 piv_valid_par
.subst_type_logic
= 0;
543 piv_valid_par
.histo_type_logic
= 0;
546 * parameter initializing of piv_post
548 piv_post_par
.z_off_d_logic
= 0;
550 piv_post_par
.diff_type_logic
= 0;
551 piv_post_par
.operator_vorstra_logic
= 0;
554 * command line keys: using POPT
557 gnome_init_with_popt_table("GPIV", VERSION
, argc
, argv
,
561 gpiv_scan_resourcefiles(IMAGE_PAR_KEY
, &image_par
, print_par
);
562 gpiv_scan_resourcefiles(EVAL_PAR_KEY
, &piv_eval_par
, print_par
);
563 gpiv_scan_resourcefiles(VALID_PAR_KEY
, &piv_valid_par
, print_par
);
564 gpiv_scan_resourcefiles(POST_PAR_KEY
, &piv_post_par
, print_par
);
566 /* checking image_par is done in open_img (concole.c) */
567 /* gpiv_img_check_header_read(image_par); */
568 gpiv_piv_check_parameters_read(piv_eval_par
);
569 gpiv_valid_check_parameters_read(piv_valid_par
);
570 gpiv_post_check_parameters_read(piv_post_par
);
573 if(gpiv_par
.img_width
<= IMAGE_WIDTH_MAX
574 && gpiv_par
.img_height
<= IMAGE_HEIGHT_MAX
) {
575 image_par
.ncolumns
= gpiv_par
.img_width
;
576 image_par
.ncolumns_logic
= 1;
577 image_par
.nrows
= gpiv_par
.img_height
;
578 image_par
.nrows_logic
= 1;
581 gtk_warning(_("image width = %d image height = %d"),
582 gpiv_par
.img_width
, gpiv_par
.img_height
);
583 gpiv
= create_gpiv();
584 gtk_widget_show(gpiv
->console
);
586 menu_gpiv_popup
= create_menu_gpiv_popup(gpiv
);
587 gtk_signal_connect_object(GTK_OBJECT(gpiv
->console
),
588 "button_press_event",
589 GTK_SIGNAL_FUNC (on_my_popup_handler
),
590 GTK_OBJECT(menu_gpiv_popup
));
592 gnome_appbar_set_default(GNOME_APPBAR(gpiv
->appbar
), msg_default
);
593 gnome_appbar_push(GNOME_APPBAR(gpiv
->appbar
), msg
);
595 if(gpiv_par
.show_tooltips
) {
596 gtk_tooltips_enable(gpiv
->tooltips
);
598 gtk_tooltips_disable(gpiv
->tooltips
);
602 sensitive(gpiv
, IMG
, TRUE
);
603 sensitive(gpiv
, EVAL
, TRUE
);
604 sensitive(gpiv
, INTREGS
, FALSE
);
605 sensitive(gpiv
, VALID
, TRUE
);
606 sensitive(gpiv
, POST
, TRUE
);
610 gtk_error(_("Image dimensions are larger then the allowed maxima (%dx%d)."),
611 (int)IMAGE_WIDTH_MAX
, (int)IMAGE_HEIGHT_MAX
);