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) 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 * (callback) functions for Piv post processing window/tabulator
31 * Revision 1.1 2003-06-17 17:10:52 gerber
44 * Piv post-processing callbacks
47 on_spinbutton_post_scale(GtkSpinButton
* widget
, GtkWidget
* entry
)
48 /* (GtkWidget *widget, gpointer data) */
57 var_type
= atoi(gtk_object_get_data(GTK_OBJECT(widget
), "var_type"));
59 if (var_type
== COL_POS
) {
60 image_par
.z_off_x
= gtk_spin_button_get_value_as_float(widget
);
61 image_par
.z_off_logic
= 1;
62 if (display_act
!= NULL
) {
63 display_act
->img
.image_par
.z_off_x
= image_par
.z_off_x
;
64 display_act
->img
.image_par
.z_off_logic
= 1;
67 } else if (var_type
== ROW_POS
) {
68 image_par
.z_off_y
= gtk_spin_button_get_value_as_float(widget
);
69 image_par
.z_off_logic
= 1;
70 if (display_act
!= NULL
) {
71 display_act
->img
.image_par
.z_off_y
= image_par
.z_off_y
;
72 display_act
->img
.image_par
.z_off_logic
= 1;
75 } else if (var_type
== S_SCALE
) {
76 image_par
.s_scale
= gtk_spin_button_get_value_as_float(widget
) * 1e-3;
77 image_par
.s_scale_logic
= 1;
78 if (display_act
!= NULL
) {
79 display_act
->img
.image_par
.s_scale
= image_par
.s_scale
;
80 display_act
->img
.image_par
.s_scale_logic
= 1;
83 } else if (var_type
== T_SCALE
) {
84 image_par
.t_scale
= gtk_spin_button_get_value_as_float(widget
) * 1e-3;
85 image_par
.t_scale_logic
= 1;
86 if (display_act
!= NULL
) {
87 display_act
->img
.image_par
.t_scale
= image_par
.t_scale
;
88 display_act
->img
.image_par
.t_scale_logic
= 1;
92 g_warning("on_spinbutton_post_scale: should not arrive here");
99 on_button_post_scale_enter(GtkWidget
*widget
,
102 GpivConsole
*gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
103 gchar
*msg
= _("Calculates scaled locations and velocities");
104 gnome_appbar_set_status(GNOME_APPBAR(gpiv
->appbar
), msg
);
108 on_button_post_scale(GtkWidget
*widget
,
111 /* PivPost * post = gtk_object_get_data(GTK_OBJECT(widget), "post"); */
112 GpivConsole
*gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
116 for (row
= gpiv
->first_selected_row
; row
<= gpiv
->last_selected_row
;
118 display_act
= gtk_clist_get_row_data(GTK_CLIST(gpiv
->clist_buf
),
120 ibuf
= display_act
->count
;
121 if (display
[ibuf
] != NULL
122 && display_act
->mwin
!= NULL
123 && GTK_WIDGET_VISIBLE(GTK_WIDGET(display_act
->mwin
)) ) {
124 gdk_window_show(GTK_WIDGET(display_act
->mwin
)->window
);
125 gdk_window_raise(GTK_WIDGET(display_act
->mwin
)->window
);
127 g_warning("on_button_post_scale:: 1");
128 exec_scale(gpiv
->pivpost
);
129 g_warning("on_button_post_scale:: 2");
136 on_button_post_savg_enter(GtkWidget
*widget
,
139 GpivConsole
*gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
140 gchar
*msg
= _("Calculates spatial average displacements");
141 gnome_appbar_set_status(GNOME_APPBAR(gpiv
->appbar
), msg
);
146 on_button_post_savg(GtkWidget
*widget
,
149 PivPost
* post
= gtk_object_get_data(GTK_OBJECT(widget
), "post");
150 GpivConsole
*gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
154 for (row
= gpiv
->first_selected_row
; row
<= gpiv
->last_selected_row
;
156 display_act
= gtk_clist_get_row_data(GTK_CLIST(gpiv
->clist_buf
),
158 ibuf
= display_act
->count
;
159 if (display
[ibuf
] != NULL
160 && display_act
->mwin
!= NULL
161 && GTK_WIDGET_VISIBLE(GTK_WIDGET(display_act
->mwin
)) ) {
162 gdk_window_show(GTK_WIDGET(display_act
->mwin
)->window
);
163 gdk_window_raise(GTK_WIDGET(display_act
->mwin
)->window
);
172 on_button_post_subavg_enter(GtkWidget
*widget
,
175 GpivConsole
*gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
176 gchar
*msg
= _("Substracts mean displacements from PIV data");
177 gnome_appbar_set_status(GNOME_APPBAR(gpiv
->appbar
), msg
);
182 on_button_post_subavg(GtkWidget
*widget
,
185 PivPost
* post
= gtk_object_get_data(GTK_OBJECT(widget
), "post");
186 GpivConsole
*gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
190 for (row
= gpiv
->first_selected_row
; row
<= gpiv
->last_selected_row
;
192 display_act
= gtk_clist_get_row_data(GTK_CLIST(gpiv
->clist_buf
),
194 ibuf
= display_act
->count
;
195 if (display
[ibuf
] != NULL
196 && display_act
->mwin
!= NULL
197 && GTK_WIDGET_VISIBLE(GTK_WIDGET(display_act
->mwin
)) ) {
198 gdk_window_show(GTK_WIDGET(display_act
->mwin
)->window
);
199 gdk_window_raise(GTK_WIDGET(display_act
->mwin
)->window
);
208 on_radiobutton_post_vorstra_output_enter(GtkWidget
*widget
,
211 GpivConsole
*gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
212 gchar
*msg
= _("Selects the differential quantity");
213 gnome_appbar_set_status(GNOME_APPBAR(gpiv
->appbar
), msg
);
217 on_radiobutton_post_vorstra_output(GtkWidget
*widget
,
220 PivPost
* post
= gtk_object_get_data(GTK_OBJECT(widget
), "post");
221 piv_post_par
.operator_vorstra
= atoi(gtk_object_get_data
224 fprintf(stderr
, "operator_vorstra = %d\n", piv_post_par
.operator_vorstra
);
226 if (piv_post_par
.operator_vorstra
== VORTICITY
) {
227 gtk_widget_set_sensitive(post
->radiobutton_vorstra_diffscheme_4
,
230 if (piv_post_par
.diff_type
== CIRCULATION
) {
231 piv_post_par
.diff_type
= CENTRAL
;
232 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON
233 (post
->radiobutton_vorstra_diffscheme_1
),
236 gtk_widget_set_sensitive(post
->radiobutton_vorstra_diffscheme_4
,
243 on_radiobutton_post_vorstra_diffscheme_enter(GtkWidget
*widget
,
246 GpivConsole
*gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
247 gchar
*msg
= _("Selects the type of differential scheme");
248 gnome_appbar_set_status(GNOME_APPBAR(gpiv
->appbar
), msg
);
253 on_radiobutton_post_vorstra_diffscheme(GtkWidget
*widget
,
256 piv_post_par
.diff_type
= atoi(gtk_object_get_data(GTK_OBJECT(widget
),
258 /* fprintf(stderr, "diff_type = %d\n", piv_post_par.diff_type); */
264 on_button_post_vorstra_enter(GtkWidget
*widget
,
267 GpivConsole
*gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
268 gchar
*msg
= _("Calculates differential quantity");
269 gnome_appbar_set_status(GNOME_APPBAR(gpiv
->appbar
), msg
);
274 on_button_post_vorstra(GtkWidget
*widget
,
277 GpivConsole
*gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
281 for (row
= gpiv
->first_selected_row
; row
<= gpiv
->last_selected_row
;
283 display_act
= gtk_clist_get_row_data(GTK_CLIST(gpiv
->clist_buf
),
285 ibuf
= display_act
->count
;
286 if (display
[ibuf
] != NULL
287 && display_act
->mwin
!= NULL
288 && GTK_WIDGET_VISIBLE(GTK_WIDGET(display_act
->mwin
)) ) {
289 gdk_window_show(GTK_WIDGET(display_act
->mwin
)->window
);
290 gdk_window_raise(GTK_WIDGET(display_act
->mwin
)->window
);
299 * Other post-processing functions
303 exec_scale(PivPost
* pivpost
)
306 g_warning("exec_scale:: 1");
307 if (display_act
->gpd
.scaled_piv
)
308 gpiv_free_pivdata(&display_act
->gpd
.piv_data_scaled
);
310 display_act
->gpd
.piv_data_scaled
.nx
= display_act
->gpd
.piv_data
.nx
;
311 display_act
->gpd
.piv_data_scaled
.ny
= display_act
->gpd
.piv_data
.ny
;
312 gpiv_alloc_pivdata(&display_act
->gpd
.piv_data_scaled
);
313 g_warning("exec_scale:: 2");
315 if(display_act
->gpd
.exist_piv
&& !cancel_process
) {
316 if ((display_act
->gpd
.scaled_piv
=
317 gpiv_post_scale (display_act
->gpd
.piv_data
,
318 &display_act
->gpd
.piv_data_scaled
,
319 display_act
->img
.image_par
)) != 1) {
320 gtk_error("exec_scale:: Failure calling gpiv_post_scale");
323 free_post_bufmems(display_act
);
325 gtk_warning(_("no PIV data"));
332 void exec_savg(PivPost
* pivpost
)
335 gfloat mean_dx
= 0.0, sdev_dx
= 0.0, min_dx
= 0.0, max_dx
= 0.0;
336 gfloat mean_dy
= 0.0, sdev_dy
= 0.0, min_dy
= 0.0, max_dy
= 0.0;
338 gfloat mean_dx_scaled
= 0.0, sdev_dx_scaled
= 0.0, min_dx_scaled
= 0.0,
340 gfloat mean_dy_scaled
= 0.0, sdev_dy_scaled
= 0.0, min_dy_scaled
= 0.0,
344 if (display_act
->gpd
.exist_piv
&& !cancel_process
) {
346 piv_post_par
.substract
= 0;
347 gpiv_post_savg(display_act
->gpd
.piv_data
,
361 /* display_act->gpd. */
362 g_warning("::mean_dx = %f sdev_dx = %f min_dx = %f max_dx = %f",
363 mean_dx
, sdev_dx
, min_dx
, max_dx
);
364 g_warning("::mean_dy = %f sdev_dy = %f min_dy = %f max_dy = %f\n",
365 mean_dy
, sdev_dy
, min_dy
, max_dy
);
368 gtk_spin_button_set_value (GTK_SPIN_BUTTON
369 (pivpost
->spinbutton_suavg
),
371 gtk_spin_button_set_value (GTK_SPIN_BUTTON
372 (pivpost
->spinbutton_svavg
),
376 * Repete same process for scaled piv_data
378 if (display_act
->gpd
.scaled_piv
) {
379 gpiv_post_savg(display_act
->gpd
.piv_data_scaled
,
392 g_warning(":: mean_dx = %f sdev_dx = %f min_dx = %f max_dx = %f",
393 mean_dx_scaled
, sdev_dx_scaled
, min_dx_scaled
, max_dx_scaled
);
394 g_warning("::mean_dy = %f sdev_dy = %f min_dy = %f max_dy = %f\n",
395 mean_dy_scaled
, sdev_dy_scaled
, min_dy_scaled
, max_dy_scaled
);
398 gtk_spin_button_set_value (GTK_SPIN_BUTTON
399 (pivpost
->spinbutton_suavg
),
400 (gfloat
) mean_dx_scaled
);
401 gtk_spin_button_set_value (GTK_SPIN_BUTTON
402 (pivpost
->spinbutton_svavg
),
403 (gfloat
) mean_dy_scaled
);
406 * Copy parameters in Buffer structure for saving and, eventual,
410 display_act
->gpd
.piv_post_par
.z_off_dx
= piv_post_par
.z_off_dx
;
411 display_act
->gpd
.piv_post_par
.z_off_dy
= piv_post_par
.z_off_dy
;
413 display_act
->gpd
.piv_post_par
.z_off_d_logic
= 1;
414 exec_process
= FALSE
;
417 gtk_warning(_("no PIV data"));
420 /* g_warning("exec_savg:: entering"); */
421 /* gtk_warning(_("not connected, yet")); */
427 void exec_subavg(PivPost
* pivpost
)
429 gint ndata
= 0, i
, j
;
430 gfloat mean_dx
= 0.0, sdev_dx
= 0.0, min_dx
= 0.0, max_dx
= 0.0;
431 gfloat mean_dy
= 0.0, sdev_dy
= 0.0, min_dy
= 0.0, max_dy
= 0.0;
432 gfloat mean_dx_scaled
= 0.0, sdev_dx_scaled
= 0.0, min_dx_scaled
= 0.0,
434 gfloat mean_dy_scaled
= 0.0, sdev_dy_scaled
= 0.0, min_dy_scaled
= 0.0,
436 PivData out_data
, out_data_scaled
;
438 out_data
.point_x
= NULL
;
439 out_data
.point_y
= NULL
;
443 out_data
.peak_no
= NULL
;
445 out_data_scaled
.point_x
= NULL
;
446 out_data_scaled
.point_y
= NULL
;
447 out_data_scaled
.dx
= NULL
;
448 out_data_scaled
.dy
= NULL
;
449 out_data_scaled
.snr
= NULL
;
450 out_data_scaled
.peak_no
= NULL
;
452 if (display_act
->gpd
.exist_piv
&& !cancel_process
) {
454 piv_post_par
.substract
= 1;
455 out_data
.nx
= display_act
->gpd
.piv_data
.nx
;
456 out_data
.ny
= display_act
->gpd
.piv_data
.ny
;
457 gpiv_alloc_pivdata(&out_data
);
458 gpiv_post_savg(display_act
->gpd
.piv_data
,
471 gtk_spin_button_set_value (GTK_SPIN_BUTTON(pivpost
->spinbutton_suavg
),
473 gtk_spin_button_set_value (GTK_SPIN_BUTTON(pivpost
->spinbutton_svavg
),
476 for (i
= 0; i
< display_act
->gpd
.piv_data
.ny
; i
++) {
477 for (j
= 0; j
< display_act
->gpd
.piv_data
.nx
; j
++) {
478 display_act
->gpd
.piv_data
.dx
[i
][j
] = out_data
.dx
[i
][j
];
479 display_act
->gpd
.piv_data
.dy
[i
][j
] = out_data
.dy
[i
][j
];
483 gpiv_free_pivdata(&out_data
);
484 update_all_vectors(&display_act
->gpd
);
487 * Repete same process for scaled piv_data
489 if (display_act
->gpd
.scaled_piv
) {
490 out_data
.nx
= display_act
->gpd
.piv_data_scaled
.nx
;
491 out_data
.ny
= display_act
->gpd
.piv_data_scaled
.ny
;
492 gpiv_alloc_pivdata(&out_data
);
493 gpiv_post_savg(display_act
->gpd
.piv_data_scaled
,
506 gtk_spin_button_set_value (GTK_SPIN_BUTTON(pivpost
->spinbutton_suavg
),
507 (gfloat
) mean_dx_scaled
);
508 gtk_spin_button_set_value (GTK_SPIN_BUTTON(pivpost
->spinbutton_svavg
),
509 (gfloat
) mean_dy_scaled
);
511 for (i
= 0; i
< display_act
->gpd
.piv_data
.ny
; i
++) {
512 for (j
= 0; j
< display_act
->gpd
.piv_data
.nx
; j
++) {
513 display_act
->gpd
.piv_data_scaled
.dx
[i
][j
] = out_data
.dx
[i
][j
];
514 display_act
->gpd
.piv_data_scaled
.dy
[i
][j
] = out_data
.dy
[i
][j
];
518 gpiv_free_pivdata(&out_data
);
523 * Copy parameters in Buffer structure for saving and, eventual,
527 display_act
->gpd
.piv_post_par
.z_off_dx
= piv_post_par
.z_off_dx
;
528 display_act
->gpd
.piv_post_par
.z_off_dy
= piv_post_par
.z_off_dy
;
530 display_act
->gpd
.piv_post_par
.z_off_d_logic
= 1;
531 exec_process
= FALSE
;
534 gtk_warning(_("no PIV data"));
537 /* g_warning("exec_savg:: entering"); */
538 /* gtk_warning(_("not connected, yet")); */
543 void exec_vorstra(void)
545 /* ScalarData out_data; */
547 if (display_act
->gpd
.exist_piv
&& !cancel_process
) {
552 * Vorticity calculation
554 if (piv_post_par
.operator_vorstra
== VORTICITY
) {
555 if (display_act
->gpd
.exist_vor
) {
556 destroy_all_scalars(&display_act
->gpd
.vor_data
,
558 /* display_act->gpd.gci_scalar_vor */
560 gpiv_free_scdata(&display_act
->gpd
.vor_data
);
561 display_act
->gpd
.exist_vor
= FALSE
;
562 /* display_act->gpd.d_vor = FALSE; */
565 display_act
->gpd
.vor_data
.nx
= display_act
->gpd
.piv_data
.nx
;
566 display_act
->gpd
.vor_data
.ny
= display_act
->gpd
.piv_data
.ny
;
567 gpiv_alloc_scdata(&display_act
->gpd
.vor_data
);
568 gpiv_post_vorstra(display_act
->gpd
.piv_data
, &display_act
->gpd
.vor_data
,
570 display_all_scalars(&display_act
->gpd
.vor_data
,
572 /* display_act->gpd.gci_scalar_vor */
574 display_act
->gpd
.exist_vor
= TRUE
;
575 display_act
->gpd
.saved_vor
= FALSE
;
576 /* display_act->gpd.d_vor = TRUE; */
579 * Repete vorticity calculation process for scaled piv_data
581 if (display_act
->gpd
.scaled_piv
) {
582 display_act
->gpd
.vor_data_scaled
.nx
=
583 display_act
->gpd
.piv_data
.nx
;
584 display_act
->gpd
.vor_data_scaled
.ny
=
585 display_act
->gpd
.piv_data
.ny
;
586 gpiv_alloc_scdata(&display_act
->gpd
.vor_data_scaled
);
587 gpiv_post_vorstra(display_act
->gpd
.piv_data
,
588 &display_act
->gpd
.vor_data_scaled
,
590 display_act
->gpd
.exist_vor_scaled
= TRUE
;
595 * Shear strain calculation
597 } else if (piv_post_par
.operator_vorstra
== S_STRAIN
) {
598 if (display_act
->gpd
.exist_sstrain
) {
599 destroy_all_scalars(&display_act
->gpd
.sstrain_data
, S_STRAIN
);
600 gpiv_free_scdata(&display_act
->gpd
.sstrain_data
);
601 display_act
->gpd
.exist_sstrain
= FALSE
;
602 /* display_act->gpd.d_sstrain = FALSE; */
605 display_act
->gpd
.sstrain_data
.nx
= display_act
->gpd
.piv_data
.nx
;
606 display_act
->gpd
.sstrain_data
.ny
= display_act
->gpd
.piv_data
.ny
;
607 gpiv_alloc_scdata(&display_act
->gpd
.sstrain_data
);
608 gpiv_post_vorstra(display_act
->gpd
.piv_data
, &display_act
->gpd
.sstrain_data
,
610 display_all_scalars(&display_act
->gpd
.sstrain_data
, S_STRAIN
);
611 display_act
->gpd
.exist_sstrain
= TRUE
;
612 display_act
->gpd
.saved_sstrain
= FALSE
;
613 /* display_act->gpd.d_sstrain = TRUE; */
616 * Repete shear strain calculation process for scaled piv_data
618 if (display_act
->gpd
.scaled_piv
) {
619 display_act
->gpd
.sstrain_data_scaled
.nx
=
620 display_act
->gpd
.piv_data
.nx
;
621 display_act
->gpd
.sstrain_data_scaled
.ny
=
622 display_act
->gpd
.piv_data
.ny
;
623 gpiv_alloc_scdata(&display_act
->gpd
.sstrain_data_scaled
);
624 gpiv_post_vorstra(display_act
->gpd
.piv_data
,
625 &display_act
->gpd
.sstrain_data_scaled
,
627 display_act
->gpd
.exist_sstrain_scaled
= TRUE
;
631 * Normal strain calculation
633 } else if (piv_post_par
.operator_vorstra
== N_STRAIN
) {
634 if (display_act
->gpd
.exist_nstrain
) {
635 destroy_all_scalars(&display_act
->gpd
.nstrain_data
, N_STRAIN
);
636 gpiv_free_scdata(&display_act
->gpd
.nstrain_data
);
637 display_act
->gpd
.exist_nstrain
= FALSE
;
638 /* display_act->gpd.d_nstrain = FALSE; */
641 display_act
->gpd
.nstrain_data
.nx
= display_act
->gpd
.piv_data
.nx
;
642 display_act
->gpd
.nstrain_data
.ny
= display_act
->gpd
.piv_data
.ny
;
643 gpiv_alloc_scdata(&display_act
->gpd
.nstrain_data
);
644 gpiv_post_vorstra(display_act
->gpd
.piv_data
, &display_act
->gpd
.nstrain_data
,
646 display_all_scalars(&display_act
->gpd
.nstrain_data
, N_STRAIN
);
647 display_act
->gpd
.exist_nstrain
= TRUE
;
648 display_act
->gpd
.saved_nstrain
= FALSE
;
649 /* display_act->gpd.d_nstrain = TRUE; */
652 * Repete normal strain calculation process for scaled piv_data
654 if (display_act
->gpd
.scaled_piv
) {
655 display_act
->gpd
.nstrain_data_scaled
.nx
=
656 display_act
->gpd
.piv_data
.nx
;
657 display_act
->gpd
.nstrain_data_scaled
.ny
=
658 display_act
->gpd
.piv_data
.ny
;
659 gpiv_alloc_scdata(&display_act
->gpd
.nstrain_data_scaled
);
660 gpiv_post_vorstra(display_act
->gpd
.piv_data
,
661 &display_act
->gpd
.nstrain_data_scaled
,
663 display_act
->gpd
.exist_nstrain_scaled
= TRUE
;
669 gtk_warning(_("non valid vorstra operation"));
671 exec_process
= FALSE
;
674 gtk_warning(_("no PIV data"));
677 /* --------------------------------------------------------------------
678 Copy parameters in Buffer structure for saving and, eventual,
681 if (display_act
->gpd
.exist_vor
|| display_act
->gpd
.exist_sstrain
||
682 display_act
->gpd
.exist_nstrain
) {
684 display_act
->gpd
.piv_post_par
.diff_type
= piv_post_par
.diff_type
;
685 display_act
->gpd
.piv_post_par
.operator_vorstra
=
686 piv_post_par
.operator_vorstra
;
688 display_act
->gpd
.piv_post_par
.diff_type_logic
= 1;
689 display_act
->gpd
.piv_post_par
.operator_vorstra_logic
= 1;
691 gpiv_post_print_parameters(display_act
->gpd
.piv_post_par
);
695 /* gpiv_write_scdata( &display_act->gpd.vor_data, c_line, nc_lines, */