1 /* -*- Mode: 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) 2007 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 * Image processing window/tabulator callbacks
31 * Revision 1.1 2008-09-16 11:04:47 gerber
32 * added imgproc routines
38 /* #include "imgproc_interface.h" */
44 exec_imgproc_smooth (void);
47 exec_imgproc_hilo (void);
50 exec_imgproc_clip (void);
56 on_button_filter_enter(GtkWidget
*widget
,
59 /*-----------------------------------------------------------------------------
62 GpivConsole
* gpiv
= gtk_object_get_data (GTK_OBJECT (widget
), "gpiv");
64 gnome_appbar_set_status (GNOME_APPBAR (gpiv
->appbar
), data
);
69 on_button_filter(GtkWidget
*widget
,
72 /*-----------------------------------------------------------------------------
73 Adjust/ sets variables for a image processing button, its relatives and
74 variables of other imgproc buttons if adeqaute.
76 imf_inf: current widget which is calling the callback function
77 imgproc->imf_inf[]: (element of) array widgets belonging to imgproc
80 Imgprocess
*imgproc
= gtk_object_get_data (GTK_OBJECT (widget
), "imgproc");
81 ImgfilterInterface
*imf_inf
= gtk_object_get_data (GTK_OBJECT (widget
),
83 ImgfilterVar
*ivar
= gtk_object_get_data (GTK_OBJECT (widget
), "ivar");
84 /* gint filter_id = (int) data; */
85 gchar label
[GPIV_MAX_CHARS
];
88 if (GTK_TOGGLE_BUTTON(widget
)->active
== TRUE
) {
89 gpiv_var
->imgproc_count
++;
90 g_snprintf (label
, GPIV_MAX_CHARS
,
91 "Step #: %d", gpiv_var
->imgproc_count
);
92 ivar
->label_step_filter_label
= label
;
93 gtk_label_set_text (GTK_LABEL (imf_inf
->label_step_filter
),
94 (char *) ivar
->label_step_filter_label
);
95 ivar
->count_nr
= gpiv_var
->imgproc_count
;
98 for (i
= 0; i
< IMG_FILTERS
; i
++) {
99 if (imgproc
->ivar
[i
]->count_nr
> ivar
->count_nr
) {
100 imgproc
->ivar
[i
]->count_nr
--;
101 g_snprintf(label
, GPIV_MAX_CHARS
, "Step #: %d",
102 imgproc
->ivar
[i
]->count_nr
);
103 imgproc
->ivar
[i
]->label_step_filter_label
= label
;
104 gtk_label_set_text (GTK_LABEL (imgproc
->imf_inf
[i
]->label_step_filter
),
105 (char *) imgproc
->ivar
[i
]->label_step_filter_label
);
109 gpiv_var
->imgproc_count
--;
111 g_snprintf(label
, GPIV_MAX_CHARS
, "Step #: %d", ivar
->count_nr
);
112 ivar
->label_step_filter_label
= label
;
113 gtk_label_set_text (GTK_LABEL (imf_inf
->label_step_filter
),
114 (char *) ivar
->label_step_filter_label
);
121 on_spinbutton_filtervar (GtkSpinButton
*widget
,
124 /* ----------------------------------------------------------------------------
127 ImgfilterVar
*ivar
= gtk_object_get_data (GTK_OBJECT (widget
), "ivar");
129 ivar
->value
= gtk_spin_button_get_value_as_int (widget
);
131 if (ivar
->filter_id
== GPIV_IMGFI_SUBACK
) {
132 /* gpiv_var->imgproc_smooth_window = gtk_spin_button_get_value_as_int (widget);*/
133 /* g_message ("on_spinbutton_filtervar:: GPIV_IMGFI_SUBACK val = %d", */
135 } else if (ivar
->filter_id
== GPIV_IMGFI_HILO
) {
136 /* g_message ("on_spinbutton_filtervar:: GPIV_IMGFI_HILO val = %d", */
138 } else if (ivar
->filter_id
== GPIV_IMGFI_SMOOTH
) {
139 /* g_message ("on_spinbutton_filtervar:: GPIV_IMGFI_SMOOTH val = %d", */
141 } else if (ivar
->filter_id
== GPIV_IMGFI_CLIP
) {
142 /* g_message ("on_spinbutton_filtervar:: GPIV_IMGFI_CLIP val = %d", */
144 } else if (ivar
->filter_id
== GPIV_IMGFI_HIGHPASS
) {
145 /* g_message ("on_spinbutton_filtervar:: GPIV_IMGFI_HIGHPASS val = %d", */
152 on_button_imgproc_enter (GtkWidget
*widget
,
155 /*-----------------------------------------------------------------------------
158 GpivConsole
*gpiv
= gtk_object_get_data (GTK_OBJECT (widget
), "gpiv");
159 gchar
*msg
= _("Processes image");
160 gnome_appbar_set_status (GNOME_APPBAR (gpiv
->appbar
), msg
);
165 on_button_imgproc (GtkWidget
*widget
,
168 /* ----------------------------------------------------------------------------
171 /* Imgprocess *imgproc = gtk_object_get_data (GTK_OBJECT (widget), "imgproc"); */
172 GpivConsole
*gpiv
= gtk_object_get_data (GTK_OBJECT (widget
), "gpiv");
174 cancel_process
= FALSE
;
182 set_imgproc_filtervar (GpivConsole
*gpiv
,
185 /* ----------------------------------------------------------------------------
188 gchar
*err_msg
= NULL
;
192 for (i
= 0; i
< IMG_FILTERS
; i
++) {
193 if (gpiv
->imgproc
->ivar
[i
]->filter_id
== id
/* GPIV_IMGFI_SUBACK */ ) {
194 gpiv
->imgproc
->ivar
[i
]->value
= value
;
195 gtk_spin_button_set_value
196 (GTK_SPIN_BUTTON (gpiv
->imgproc
->imf_inf
[i
]->spinbutton_filtervar
),
198 if (gpiv_par
->verbose
) g_message ("set_imgproc_filtervar:: i = %d id = %d value = %d",
209 exec_imgproc_subtract (ImgfilterVar
*ivar
)
210 /*-----------------------------------------------------------------------------
213 gchar
*err_msg
= NULL
;
215 if (gpiv_par
->verbose
) g_message ("exec_imgproc_subtract:: value = %d", ivar
->value
);
216 if (ivar
->value
> nbufs
- 1) {
217 err_msg
= "exec_imgproc_subtract: unvalid value: larger than number of buffers";
218 warning_gpiv ("%s", err_msg
);
222 if (ivar
->value
== display_act
->id
) {
223 err_msg
= "exec_imgproc_subtract: subtracting intensities from own buffer image";
228 gpiv_imgproc_subtractimg (display
[ivar
->value
]->img
->image
,
229 display_act
->img
->image
232 g_message("exec_imgproc_subtract: %s", err_msg
);
243 exec_imgproc_hilo (void)
244 /*-----------------------------------------------------------------------------
247 gchar
*err_msg
= NULL
;
250 /* BUGFIX: there is an error in the procedure? */
251 if (gpiv_par
->verbose
) g_message ("exec_imgproc_hilo:: 0");
253 gpiv_imgproc_highlow (display_act
->img
->image
, gl_imgproc_par
))
254 != NULL
) gpiv_warning ("exec_imgproc_hilo: %s", err_msg
);
255 if (gpiv_par
->verbose
) g_message ("exec_imgproc_hilo:: 1");
258 if (gpiv_par
->verbose
) g_message ("exec_imgproc_hilo:: 2/2");
265 exec_imgproc_clip (void)
266 /*-----------------------------------------------------------------------------
269 gchar
*err_msg
= NULL
;
273 gpiv_imgproc_clip (display_act
->img
->image
, gl_imgproc_par
))
274 != NULL
) gpiv_warning ("exec_imgproc_clip: %s", err_msg
);
283 exec_imgproc_smooth (void)
284 /*-----------------------------------------------------------------------------
287 gchar
*err_msg
= NULL
;
291 gpiv_imgproc_smooth (display_act
->img
->image
, gl_imgproc_par
))
292 != NULL
) gpiv_warning ("exec_imgproc_smooth: %s", err_msg
);
301 exec_imgproc_highpass (void)
302 /*-----------------------------------------------------------------------------
305 gchar
*err_msg
= NULL
;
309 gpiv_imgproc_highpass (display_act
->img
->image
, gl_imgproc_par
))
310 != NULL
) gpiv_warning ("exec_imgproc_highpass: %s", err_msg
);
319 exec_imgproc (GpivConsole
* gpiv
320 /* Imgprocess *imgproc */
322 /*-----------------------------------------------------------------------------
325 gchar
*err_msg
= NULL
;
328 for (i
= 1; i
<= gpiv_var
->imgproc_count
; i
++) {
329 for (j
= 0; j
< IMG_FILTERS
; j
++) {
330 if (gpiv
->imgproc
->ivar
[j
]->count_nr
== i
) {
331 if (gpiv
->imgproc
->ivar
[j
]->filter_id
== GPIV_IMGFI_SUBACK
) {
332 if ((err_msg
= exec_imgproc_subtract (gpiv
->imgproc
->ivar
[j
]))
334 g_warning ("exec_imgproc: %s", err_msg
);
336 } else if (gpiv
->imgproc
->ivar
[j
]->filter_id
== GPIV_IMGFI_HILO
) {
337 gl_imgproc_par
->window
= gpiv
->imgproc
->ivar
[j
]->value
;
338 exec_imgproc_hilo ();
339 } else if (gpiv
->imgproc
->ivar
[j
]->filter_id
== GPIV_IMGFI_CLIP
) {
340 gl_imgproc_par
->threshold
= gpiv
->imgproc
->ivar
[j
]->value
;
341 exec_imgproc_clip ();
342 } else if (gpiv
->imgproc
->ivar
[j
]->filter_id
== GPIV_IMGFI_SMOOTH
) {
343 exec_imgproc_smooth ();
344 } else if (gpiv
->imgproc
->ivar
[j
]->filter_id
== GPIV_IMGFI_HIGHPASS
) {
345 gl_imgproc_par
->window
= gpiv
->imgproc
->ivar
[j
]->value
;
346 exec_imgproc_highpass ();
353 /* #ifdef IMGPROC_SAVE_IMG */
354 if (display_act
!= NULL
) {
355 destroy_img (display_act
);
356 create_img (display_act
);
357 if (gpiv_par
->verbose
) g_message ("EXEC_IMGPROC:: img.saved_img = FALSE");
358 display_act
->img
->saved_img
= FALSE
;