updated copyright statement
[gpiv.git] / src / imgproc_interface.c
blob988c63f3b9213f38273c0c55f171eecd64679907
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
6 libraries.
8 Copyright (C) 2007, 2008 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)
15 any later version.
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
35 #ifdef HAVE_CONFIG_H
36 # include <config.h>
37 #endif
39 #include "gpiv_gui.h"
40 #include "console.h"
41 #include "imgproc_interface.h"
42 #include "imgproc.h"
43 #include "utils.h"
45 #ifdef ENABLE_IMGPROC
48 static ImgfilterVar *
49 create_filter_var (gint filter_id,
50 gchar *button_label,
51 gchar *label_filtervar_label,
52 gdouble value,
53 gdouble upper,
54 gchar *label_step_filter_label,
55 gint step,
56 gchar *appbar_msg
59 static ImgfilterInterface *
60 create_filter_interface (GnomeApp *main_window,
61 ImgfilterVar *ivar
65 Imgprocess *
66 create_imgproc(GnomeApp *main_window,
67 GtkWidget *container)
68 /*-----------------------------------------------------------------------------
69 * Image processing window
72 GpivConsole * gpiv = gtk_object_get_data (GTK_OBJECT (main_window), "gpiv");
73 Imgprocess * imgproc = g_new0 (Imgprocess, 1);
75 gint i;
76 gchar *bufno;
79 gpiv_var->imgproc_count = 0;
81 imgproc->vbox_label = gtk_vbox_new (FALSE,
82 0);
83 gtk_widget_ref (imgproc->vbox_label);
84 gtk_object_set_data_full (GTK_OBJECT (main_window),
85 "imgproc__vbox_label",
86 imgproc->vbox_label,
87 (GtkDestroyNotify) gtk_widget_unref);
88 gtk_widget_show (imgproc->vbox_label);
89 gtk_container_add (GTK_CONTAINER (container),
90 imgproc->vbox_label);
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",
98 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,
103 FALSE,
104 FALSE,
108 * Scrolled window
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,
120 TRUE,
121 TRUE,
126 imgproc->scrolledwindow = gtk_scrolled_window_new (NULL,
127 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,
136 TRUE,
137 TRUE,
139 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW
140 (imgproc->scrolledwindow),
141 GTK_POLICY_NEVER,
142 GTK_POLICY_AUTOMATIC);
146 imgproc->viewport = gtk_viewport_new (NULL,
147 NULL);
148 gtk_widget_ref (imgproc->viewport);
149 gtk_object_set_data_full (GTK_OBJECT (main_window),
150 "imgproc__viewport",
151 imgproc->viewport,
152 (GtkDestroyNotify) gtk_widget_unref);
153 gtk_widget_show (imgproc->viewport);
154 gtk_container_add (GTK_CONTAINER (imgproc->scrolledwindow),
155 imgproc->viewport);
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),
164 "imgproc__vbox",
165 imgproc->vbox,
166 (GtkDestroyNotify) gtk_widget_unref);
167 gtk_widget_show (imgproc->vbox);
168 gtk_container_add (GTK_CONTAINER (imgproc->viewport),
169 imgproc->vbox);
173 imgproc->table = gtk_table_new (6,
175 FALSE);
176 gtk_widget_ref (imgproc->table);
177 gtk_object_set_data_full (GTK_OBJECT (main_window),
178 "imgproc__table",
179 imgproc->table,
180 (GtkDestroyNotify) gtk_widget_unref);
181 gtk_widget_show (imgproc->table);
182 gtk_box_pack_start (GTK_BOX (imgproc->vbox),
183 imgproc->table,
184 TRUE,
185 FALSE,
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); */
192 imgproc->ivar[0] =
193 create_filter_var (GPIV_IMGFI_SUBACK,
194 N_("Subtract background"),
195 N_("Buffer #:"),
197 MAX_BUFS,
198 _("Step #: 0"),
200 N_("Subtracts background from current image")
203 imgproc->ivar[1] =
204 create_filter_var (GPIV_IMGFI_HILO,
205 N_("High/low filter"),
206 N_("Window:"),
207 gl_imgproc_par->window,
208 GPIV_IMGPROCPAR_MAX__WINDOW,
209 _("Step #: 0"),
211 N_("High/low filtering: expands local contrast")
214 imgproc->ivar[2] =
215 create_filter_var (GPIV_IMGFI_CLIP,
216 N_("Clip"),
217 N_("Threshold:"),
218 gl_imgproc_par->threshold,
219 GPIV_IMGPROCPAR_MAX__THRESHOLD,
220 /* img_top = (img_top << gl_image_par->depth) - 1, */
221 _("Step #: 0"),
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); */
227 imgproc->ivar[3] =
228 create_filter_var (GPIV_IMGFI_SMOOTH,
229 N_("Smooth"),
230 N_("Window:"),
231 gl_imgproc_par->window,
232 GPIV_IMGPROCPAR_MAX__WINDOW,
233 _("Step #: 0"),
235 N_("Averages over window")
238 imgproc->ivar[4] =
239 create_filter_var (GPIV_IMGFI_HIGHPASS,
240 N_("High-pass filter"),
241 N_("Window:"),
242 gl_imgproc_par->threshold,
243 GPIV_IMGPROCPAR_MAX__THRESHOLD,
244 _("Step #: 0"),
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,
256 imgproc->ivar[i]
260 gtk_object_set_data(GTK_OBJECT(imgproc->imf_inf[i]->button_filter),
261 "imgproc",
262 imgproc);
263 gtk_table_attach (GTK_TABLE (imgproc->table),
264 imgproc->imf_inf[i]->button_filter,
268 i+1,
269 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
270 (GtkAttachOptions) (0),
275 gtk_table_attach (GTK_TABLE (imgproc->table),
276 imgproc->imf_inf[i]->label_filtervar,
280 i+1,
281 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
282 (GtkAttachOptions) (0),
287 gtk_table_attach (GTK_TABLE (imgproc->table),
288 imgproc->imf_inf[i]->spinbutton_filtervar,
292 i+1,
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,
304 i+1,
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),
317 "button",
318 imgproc->button,
319 (GtkDestroyNotify) gtk_widget_unref);
320 gtk_widget_show (imgproc->button);
321 gtk_box_pack_start (GTK_BOX (imgproc->vbox),
322 imgproc->button,
323 TRUE,
324 FALSE,
327 gtk_tooltips_set_tip(gpiv->tooltips,
328 imgproc->button,
329 _("Executes the image process sequence in the order of the step numbers"),
330 NULL);
332 gtk_object_set_data (GTK_OBJECT (imgproc->button),
333 "imgproc",
334 imgproc);
335 g_signal_connect (GTK_OBJECT (imgproc->button),
336 "enter",
337 G_CALLBACK (on_button_imgproc_enter),
338 NULL);
339 g_signal_connect (GTK_OBJECT (imgproc->button),
340 "leave",
341 G_CALLBACK (on_widget_leave),
342 NULL);
343 g_signal_connect (GTK_OBJECT (imgproc->button),
344 "clicked",
345 G_CALLBACK (on_button_imgproc),
346 NULL);
349 * End of create_imgproc
351 return imgproc;
356 static ImgfilterVar *
357 create_filter_var (gint filter_id,
358 gchar *button_label,
359 gchar *label_filtervar_label,
360 gdouble value,
361 gdouble upper,
362 gchar *label_step_filter_label,
363 gint count_nr,
364 gchar *appbar_msg
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;
374 ivar->value = value;
375 ivar->upper = upper;
376 ivar->label_step_filter_label = label_step_filter_label;
377 ivar->count_nr = count_nr;
378 ivar->appbar_msg = appbar_msg;
380 return ivar;
385 static ImgfilterInterface *
386 create_filter_interface (GnomeApp *main_window,
387 ImgfilterVar *ivar
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),
403 "ivar",
404 ivar);
405 gtk_object_set_data (GTK_OBJECT (imf_inf->button_filter),
406 "imf_inf",
407 imf_inf);
408 gtk_widget_show(imf_inf->button_filter);
411 g_signal_connect(GTK_OBJECT(imf_inf->button_filter),
412 "enter",
413 G_CALLBACK (on_button_filter_enter),
414 (gchar *) ivar->appbar_msg);
415 g_signal_connect(GTK_OBJECT(imf_inf->button_filter),
416 "leave",
417 G_CALLBACK (on_widget_leave),
418 NULL);
419 g_signal_connect(GTK_OBJECT(imf_inf->button_filter),
420 "clicked",
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,
447 100,
448 10);
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),
461 TRUE);
462 gtk_object_set_data (GTK_OBJECT (imf_inf->spinbutton_filtervar),
463 "ivar",
464 ivar);
465 g_signal_connect (GTK_OBJECT (imf_inf->spinbutton_filtervar),
466 "changed",
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),
484 return imf_inf;
487 #endif /* ENABLE_IMGPROC */