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 interface
30 * $Log: imgproc_interface.c,v $
31 * Revision 1.1 2008-09-16 10:16:08 gerber
32 * added imgproc routines
41 #include "imgproc_interface.h"
49 create_filter_var (gint filter_id
,
51 gchar
*label_filtervar_label
,
54 gchar
*label_step_filter_label
,
59 static ImgfilterInterface
*
60 create_filter_interface (GnomeApp
*main_window
,
66 create_imgproc(GnomeApp
*main_window
,
68 /*-----------------------------------------------------------------------------
69 * Image processing window
72 GpivConsole
* gpiv
= gtk_object_get_data (GTK_OBJECT (main_window
), "gpiv");
73 Imgprocess
* imgproc
= g_new0 (Imgprocess
, 1);
79 gpiv_var
->imgproc_count
= 0;
81 imgproc
->vbox_label
= gtk_vbox_new (FALSE
,
83 gtk_widget_ref (imgproc
->vbox_label
);
84 gtk_object_set_data_full (GTK_OBJECT (main_window
),
85 "imgproc__vbox_label",
87 (GtkDestroyNotify
) gtk_widget_unref
);
88 gtk_widget_show (imgproc
->vbox_label
);
89 gtk_container_add (GTK_CONTAINER (container
),
94 imgproc
->label_title
= gtk_label_new(_("Image processing"));
95 gtk_widget_ref(imgproc
->label_title
);
96 gtk_object_set_data_full(GTK_OBJECT(main_window
),
97 "imgproc__label_title",
99 (GtkDestroyNotify
) gtk_widget_unref
);
100 gtk_widget_show (imgproc
->label_title
);
101 gtk_box_pack_start (GTK_BOX (imgproc
->vbox_label
),
102 imgproc
->label_title
,
110 imgproc
->vbox_scroll
= gtk_vbox_new (FALSE
,
112 gtk_widget_ref (imgproc
->vbox_scroll
);
113 gtk_object_set_data_full (GTK_OBJECT (main_window
),
114 "imgproc__vbox_scroll",
115 imgproc
->vbox_scroll
,
116 (GtkDestroyNotify
) gtk_widget_unref
);
117 gtk_widget_show (imgproc
->vbox_scroll
);
118 gtk_box_pack_start (GTK_BOX (imgproc
->vbox_label
),
119 imgproc
->vbox_scroll
,
126 imgproc
->scrolledwindow
= gtk_scrolled_window_new (NULL
,
128 gtk_widget_ref (imgproc
->scrolledwindow
);
129 gtk_object_set_data_full (GTK_OBJECT (main_window
),
130 "imgproc__scrolledwindow",
131 imgproc
->scrolledwindow
,
132 (GtkDestroyNotify
) gtk_widget_unref
);
133 gtk_widget_show (imgproc
->scrolledwindow
);
134 gtk_box_pack_start (GTK_BOX (imgproc
->vbox_scroll
),
135 imgproc
->scrolledwindow
,
139 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW
140 (imgproc
->scrolledwindow
),
142 GTK_POLICY_AUTOMATIC
);
146 imgproc
->viewport
= gtk_viewport_new (NULL
,
148 gtk_widget_ref (imgproc
->viewport
);
149 gtk_object_set_data_full (GTK_OBJECT (main_window
),
152 (GtkDestroyNotify
) gtk_widget_unref
);
153 gtk_widget_show (imgproc
->viewport
);
154 gtk_container_add (GTK_CONTAINER (imgproc
->scrolledwindow
),
158 * main vbox and table for image processing table/window
160 imgproc
->vbox
= gtk_vbox_new (FALSE
,
162 gtk_widget_ref (imgproc
->vbox
);
163 gtk_object_set_data_full (GTK_OBJECT (main_window
),
166 (GtkDestroyNotify
) gtk_widget_unref
);
167 gtk_widget_show (imgproc
->vbox
);
168 gtk_container_add (GTK_CONTAINER (imgproc
->viewport
),
173 imgproc
->table
= gtk_table_new (6,
176 gtk_widget_ref (imgproc
->table
);
177 gtk_object_set_data_full (GTK_OBJECT (main_window
),
180 (GtkDestroyNotify
) gtk_widget_unref
);
181 gtk_widget_show (imgproc
->table
);
182 gtk_box_pack_start (GTK_BOX (imgproc
->vbox
),
188 * Create filter buttons and attributes
190 /* g_message ("create imgproc tab of zo:: window = %d threshold = %d", */
191 /* gl_imgproc_par->window, gl_imgproc_par->threshold); */
193 create_filter_var (GPIV_IMGFI_SUBACK
,
194 N_("Subtract background"),
200 N_("Subtracts background from current image")
204 create_filter_var (GPIV_IMGFI_HILO
,
205 N_("High/low filter"),
207 gl_imgproc_par
->window
,
208 GPIV_IMGPROCPAR_MAX__WINDOW
,
211 N_("High/low filtering: expands local contrast")
215 create_filter_var (GPIV_IMGFI_CLIP
,
218 gl_imgproc_par
->threshold
,
219 GPIV_IMGPROCPAR_MAX__THRESHOLD
,
220 /* img_top = (img_top << gl_image_par->depth) - 1, */
223 N_("Set image intensity below threshold to zero")
225 /* g_message ("create_imgproc or so:: depth = %d top = %d", gl_image_par->depth, img_top); */
228 create_filter_var (GPIV_IMGFI_SMOOTH
,
231 gl_imgproc_par
->window
,
232 GPIV_IMGPROCPAR_MAX__WINDOW
,
235 N_("Averages over window")
239 create_filter_var (GPIV_IMGFI_HIGHPASS
,
240 N_("High-pass filter"),
242 gl_imgproc_par
->threshold
,
243 GPIV_IMGPROCPAR_MAX__THRESHOLD
,
246 N_("High-pass filter")
250 for (i
= 0; i
< IMG_FILTERS
; i
++) {
251 /* g_message(":: val[%d] = %f upper[%d] = %f", */
252 /* i, imgproc->ivar[i]->value, */
253 /* i, imgproc->ivar[i]->upper); */
254 imgproc
->imf_inf
[i
] =
255 create_filter_interface (main_window
,
260 gtk_object_set_data(GTK_OBJECT(imgproc
->imf_inf
[i
]->button_filter
),
263 gtk_table_attach (GTK_TABLE (imgproc
->table
),
264 imgproc
->imf_inf
[i
]->button_filter
,
269 (GtkAttachOptions
) (GTK_EXPAND
| GTK_FILL
),
270 (GtkAttachOptions
) (0),
275 gtk_table_attach (GTK_TABLE (imgproc
->table
),
276 imgproc
->imf_inf
[i
]->label_filtervar
,
281 (GtkAttachOptions
) (GTK_EXPAND
| GTK_FILL
),
282 (GtkAttachOptions
) (0),
287 gtk_table_attach (GTK_TABLE (imgproc
->table
),
288 imgproc
->imf_inf
[i
]->spinbutton_filtervar
,
293 (GtkAttachOptions
) (GTK_EXPAND
| GTK_FILL
),
294 (GtkAttachOptions
) (0),
299 gtk_table_attach (GTK_TABLE (imgproc
->table
),
300 imgproc
->imf_inf
[i
]->label_step_filter
,
305 (GtkAttachOptions
) (GTK_EXPAND
| GTK_FILL
),
306 (GtkAttachOptions
) (0),
312 * Button to execute image processing
314 imgproc
->button
= gtk_button_new_with_label ( _("process image"));
315 gtk_widget_ref (imgproc
->button
);
316 gtk_object_set_data_full (GTK_OBJECT (main_window
),
319 (GtkDestroyNotify
) gtk_widget_unref
);
320 gtk_widget_show (imgproc
->button
);
321 gtk_box_pack_start (GTK_BOX (imgproc
->vbox
),
327 gtk_tooltips_set_tip(gpiv
->tooltips
,
329 _("Executes the image process sequence in the order of the step numbers"),
332 gtk_object_set_data (GTK_OBJECT (imgproc
->button
),
335 g_signal_connect (GTK_OBJECT (imgproc
->button
),
337 G_CALLBACK (on_button_imgproc_enter
),
339 g_signal_connect (GTK_OBJECT (imgproc
->button
),
341 G_CALLBACK (on_widget_leave
),
343 g_signal_connect (GTK_OBJECT (imgproc
->button
),
345 G_CALLBACK (on_button_imgproc
),
349 * End of create_imgproc
356 static ImgfilterVar
*
357 create_filter_var (gint filter_id
,
359 gchar
*label_filtervar_label
,
362 gchar
*label_step_filter_label
,
366 /*-----------------------------------------------------------------------------
369 ImgfilterVar
*ivar
= g_new0 (ImgfilterVar
, 1);
371 ivar
->filter_id
= filter_id
;
372 ivar
->button_label
= button_label
;
373 ivar
->label_filtervar_label
= label_filtervar_label
;
376 ivar
->label_step_filter_label
= label_step_filter_label
;
377 ivar
->count_nr
= count_nr
;
378 ivar
->appbar_msg
= appbar_msg
;
385 static ImgfilterInterface
*
386 create_filter_interface (GnomeApp
*main_window
,
389 /*-----------------------------------------------------------------------------
392 ImgfilterInterface
*imf_inf
= g_new0 (ImgfilterInterface
, 1);
395 imf_inf
->button_filter
=
396 gtk_check_button_new_with_label(ivar
->button_label
);
397 gtk_widget_ref(imf_inf
->button_filter
);
398 gtk_object_set_data_full(GTK_OBJECT(main_window
),
399 "imf_inf__button_filter",
400 imf_inf
->button_filter
,
401 (GtkDestroyNotify
) gtk_widget_unref
);
402 gtk_object_set_data (GTK_OBJECT (imf_inf
->button_filter
),
405 gtk_object_set_data (GTK_OBJECT (imf_inf
->button_filter
),
408 gtk_widget_show(imf_inf
->button_filter
);
411 g_signal_connect(GTK_OBJECT(imf_inf
->button_filter
),
413 G_CALLBACK (on_button_filter_enter
),
414 (gchar
*) ivar
->appbar_msg
);
415 g_signal_connect(GTK_OBJECT(imf_inf
->button_filter
),
417 G_CALLBACK (on_widget_leave
),
419 g_signal_connect(GTK_OBJECT(imf_inf
->button_filter
),
421 G_CALLBACK (on_button_filter
),
422 (int *) ivar
->filter_id
);
423 /* gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON */
424 /* imf_inf->button_filter), */
425 /* gpiv_par->process_subtract); */
429 imf_inf
->label_filtervar
= gtk_label_new(ivar
->label_filtervar_label
);
430 gtk_widget_ref(imf_inf
->label_filtervar
);
431 gtk_object_set_data_full(GTK_OBJECT (main_window
),
432 "imf_inf__label_filtervar",
433 imf_inf
->label_filtervar
,
434 (GtkDestroyNotify
) gtk_widget_unref
);
435 gtk_widget_show(imf_inf
->label_filtervar
);
436 gtk_misc_set_padding(GTK_MISC(imf_inf
->label_filtervar
),
442 imf_inf
->spinbutton_adj_filtervar
=
443 gtk_adjustment_new ((gdouble
) ivar
->value
,
445 (gdouble
) ivar
->upper
,
450 imf_inf
->spinbutton_filtervar
=
451 gtk_spin_button_new (GTK_ADJUSTMENT (imf_inf
->spinbutton_adj_filtervar
),
454 gtk_widget_ref (imf_inf
->spinbutton_filtervar
);
455 gtk_object_set_data_full (GTK_OBJECT (main_window
),
456 "imf_inf__spinbutton_filtervar",
457 imf_inf
->spinbutton_filtervar
,
458 (GtkDestroyNotify
) gtk_widget_unref
);
459 gtk_widget_show (imf_inf
->spinbutton_filtervar
);
460 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (imf_inf
->spinbutton_filtervar
),
462 gtk_object_set_data (GTK_OBJECT (imf_inf
->spinbutton_filtervar
),
465 g_signal_connect (GTK_OBJECT (imf_inf
->spinbutton_filtervar
),
467 G_CALLBACK (on_spinbutton_filtervar
),
468 imf_inf
->spinbutton_filtervar
);
471 * Step number or pass
473 imf_inf
->label_step_filter
=
474 gtk_label_new(ivar
->label_step_filter_label
);
475 gtk_widget_ref(imf_inf
->label_step_filter
);
476 gtk_object_set_data_full(GTK_OBJECT (main_window
),
477 "imf_inf__step_label_filter",
478 imf_inf
->label_step_filter
,
479 (GtkDestroyNotify
) gtk_widget_unref
);
480 gtk_widget_show(imf_inf
->label_step_filter
);
481 gtk_misc_set_padding(GTK_MISC(imf_inf
->label_step_filter
),
487 #endif /* ENABLE_IMGPROC */