Adapted for use on cluster (using MPI/OMP) parallelised gpiv_rr from gpivtools)
[gpiv.git] / src / display_event.c
blob0b471dec7cd7bc0b7a2520128996c3d1d7541b52
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) 2006 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 #include "gpiv_gui.h"
30 #include "display.h"
31 #include "display_zoom.h"
32 #include "piveval_interrogate.h"
34 GdkCursor *cursor;
36 static void
37 canvas_display_motion_notify__NO_MS (Display *disp,
38 gint x,
39 gint y,
40 gint *index_x,
41 gint *index_y
44 static void
45 canvas_display_button_release__AOI_MS (Display *disp,
46 GpivConsole *gpiv,
47 GtkWidget *view_piv_display0,
48 gdouble x,
49 gdouble y
52 static void
53 canvas_display_motion_notify__DRAGINT_MS (Display *disp,
54 gint x,
55 gint y,
56 gint *index_x,
57 gint *index_y
60 static void
61 canvas_display_motion_notify__SINGLE_POINT_MS (Display *disp,
62 gint x,
63 gint y
67 static char *
68 canvas_display_button_press__SINGLE_AREA_MS (GpivConsole *gpiv,
69 Display *disp,
70 gint x,
71 gint y
74 static char *
75 canvas_display_button_release__SINGLE_AREA_MS (GpivConsole *gpiv,
76 Display *disp,
77 gdouble x,
78 gdouble y
81 static void
82 canvas_display_button_press__SINGLE_POINT_MS (GpivConsole *gpiv,
83 Display *disp,
84 gint x,
85 gint y
88 static void
89 canvas_display_button_release__HVLINE_MS (Display *disp,
90 GpivConsole *gpiv,
91 GtkWidget *view_piv_display0,
92 gdouble x,
93 gdouble y
95 static void
96 canvas_display_button_press__DISABLE_POINT_MS (Display *disp,
97 gint x,
98 gint y
100 static void
101 set__NO_MS (GpivConsole *gpiv,
102 Display *disp
105 static void
106 search_nearest_index (Display *disp,
107 gint x,
108 gint y,
109 gint *index_x,
110 gint *index_y,
111 gint data_type
114 static void
115 highlight_intreg (gint index_y,
116 gint index_x,
117 Display *disp
120 static void
121 create_msg_display_with_pivdata (GpivPivData *piv_data,
122 gint index_y,
123 gint index_x,
124 gint scale
127 static void
128 create_msg_display_with_scdata (GpivScalarData *sc_data,
129 gchar *sc_type,
130 gint index_y,
131 gint index_x,
132 gint scale
134 static void
135 create_msg_display_with_pivscdata (GpivPivData *piv_data,
136 GpivScalarData *sc_data,
137 gchar *sc_type,
138 gint index_y,
139 gint index_x,
140 gint scale
143 static void
144 create_line (Display *disp,
145 gint x1,
146 gint y1,
147 gint x2,
148 gint y2
151 static void
152 update_line (gint x1,
153 gint y1,
154 gint x2,
155 gint y2
158 static void
159 destroy_line ();
161 static void
162 update_rect (gint x,
163 gint y
166 static void
167 create_rect (Display *disp,
168 gint x,
169 gint y
172 static void
173 destroy_rect ();
175 static void
176 pane_canvas (Display *disp,
177 gfloat x,
178 gfloat y
181 static void
182 pane_canvas_x (Display *disp,
183 gfloat x
186 static void
187 pane_canvas_y (Display *disp,
188 gfloat y
192 * Public display functions
194 gboolean
195 canvas_display_enter_notify (GtkWidget *widget,
196 GdkEventMotion *event,
197 gpointer data
199 /*-----------------------------------------------------------------------------
202 Display *disp = gtk_object_get_data(GTK_OBJECT(widget), "disp");
203 GtkWidget *view_piv_display0 =
204 gtk_object_get_data(GTK_OBJECT(disp->mwin),
205 "view_piv_display0");
208 disp->index_x_old = 0;
209 disp->index_y_old = 0;
210 disp->index_old = FALSE;
213 if (m_select == NO_MS) {
214 cursor = gdk_cursor_new(GDK_DOTBOX);
216 } else if (m_select == SINGLE_AREA_MS
217 || m_select == ENABLE_POINT_MS
218 || m_select == DISABLE_POINT_MS) {
219 cursor = gdk_cursor_new(GDK_CROSSHAIR);
223 } else if ( m_select == DRAG_MS ) {
224 cursor = gdk_cursor_new(GDK_CROSS);
228 } else if (m_select == SINGLE_POINT_MS
229 || m_select == V_LINE_MS
230 || m_select == H_LINE_MS
232 if (m_select == V_LINE_MS) {
233 cursor = gdk_cursor_new (GDK_SB_V_DOUBLE_ARROW);
235 if (m_select == H_LINE_MS) {
236 cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW);
239 if (m_select == SINGLE_POINT_MS) {
240 cursor = gdk_cursor_new(GDK_CROSS);
244 if (display_act->pida->exist_piv && disp->display_piv) {
245 hide_all_vectors(display_act->pida);
248 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
249 hide_all_intregs(disp);
254 } else if (m_select == AOI_MS
255 || m_select == ENABLE_AREA_MS
256 || m_select == DISABLE_AREA_MS) {
257 cursor = gdk_cursor_new(GDK_CROSSHAIR);
259 if (m_select == AOI_MS) {
260 if (display_act->pida->exist_piv && disp->display_piv) {
261 hide_all_vectors(display_act->pida);
264 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
265 hide_all_intregs(disp);
271 } else if (m_select == SPANLENGTH_MS
272 || m_select == V_SPANLENGTH_MS
273 || m_select == H_SPANLENGTH_MS
275 cursor = gdk_cursor_new(GDK_CROSS);
278 gdk_window_set_cursor(disp->mwin->window, cursor);
281 return TRUE;
286 gboolean
287 canvas_display_motion_notify (GtkWidget *widget,
288 GdkEventMotion *event,
289 gpointer data
291 /*-----------------------------------------------------------------------------
294 Display *disp = gtk_object_get_data(GTK_OBJECT(widget), "disp");
295 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(widget), "gpiv");
296 GtkAdjustment *hadj = GTK_ADJUSTMENT (disp->hadj);
297 GtkAdjustment *vadj = GTK_ADJUSTMENT (disp->hadj);
299 gdouble x, y;
300 gint x_grab, y_grab;
301 gint index_y = 0, index_x = 0;
303 GdkModifierType state;
304 GnomeCanvasPoints *points;
307 points = gnome_canvas_points_new(2);
309 if (event->is_hint) {
310 gdk_window_get_pointer (event->window, &x_grab, &y_grab, &state);
312 x = x_grab;
313 y = y_grab;
315 } else {
316 x = event->x;
317 y = event->y;
319 state = event->state;
323 /* g_message ("canvas_display_motion_notify:: x = %f y = %f x/zoom = %f y/zoom = %f", */
324 /* x, y, x / disp->zoom_factor, y / disp->zoom_factor); */
326 /* if (x >= hadj->value && x < hadj->value + hadj->page_size */
327 /* && y >= vadj->value && y < vadj->value + vadj->page_size) { */
330 if (x >= 0 && x < disp->img->image->header->ncolumns * disp->zoom_factor
331 && y >= 0 && y < disp->img->image->header->nrows * disp->zoom_factor) {
334 * display particle displacements / velocities and its attributes,
336 if (m_select == NO_MS
337 || m_select == SINGLE_AREA_MS
338 || m_select == DRAG_MS
339 || m_select == ENABLE_POINT_MS
340 || m_select == DISABLE_POINT_MS) {
344 * display locations of interrogation area's and estimators,
345 * only display locations of interrogation area's,
346 * or nothing
349 canvas_display_motion_notify__NO_MS (disp,
350 (gint) (x / disp->zoom_factor),
351 (gint) (y / disp->zoom_factor),
352 &index_x,
353 &index_y);
356 * Pane (moving) the canvas. Identic effect as moving the scroll bars.
358 if (m_select == NO_MS) {
359 if (state & GDK_BUTTON1_MASK) {
360 pane_canvas (disp, x, y);
365 if ( m_select == DRAG_MS ) {
366 canvas_display_motion_notify__DRAGINT_MS (disp,
367 (gint) (x / disp->zoom_factor),
368 (gint) (y / disp->zoom_factor),
369 &index_x,
370 &index_y);
373 disp->index_x_old = index_x;
374 disp->index_y_old = index_y;
378 * Only displays pointer position
380 } else if (m_select == AOI_MS
381 || m_select == ENABLE_AREA_MS
382 || m_select == DISABLE_AREA_MS ) {
383 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d px y=%d px",
384 (gint) (x / disp->zoom_factor),
385 (gint) (y / disp->zoom_factor));
388 * Update the drawing of the rectangle
390 if (state & GDK_BUTTON1_MASK) {
391 if (gci_aoi != NULL) {
392 update_rect((gint) (x / disp->zoom_factor),
393 (gint) (y / disp->zoom_factor));
399 } else if ( m_select == SINGLE_POINT_MS) {
400 canvas_display_motion_notify__SINGLE_POINT_MS (disp,
401 (gint) x / disp->zoom_factor,
402 (gint) y / disp->zoom_factor);
407 * Update a vertical line
409 } else if (m_select == V_LINE_MS) {
410 if (state & GDK_BUTTON1_MASK) {
411 g_snprintf (msg_display, GPIV_MAX_CHARS, "x=%d px y=%d px",
412 (gint) (disp->xgrab_first / disp->zoom_factor),
413 (gint) (y / disp->zoom_factor));
414 if ( gci_line != NULL ) {
415 update_line ((gint) (disp->xgrab_first / disp->zoom_factor) ,
416 (gint) (disp->ygrab_first / disp->zoom_factor),
417 (gint) (disp->xgrab_first / disp->zoom_factor),
418 (gint) (y / disp->zoom_factor));
420 } else {
421 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d px y=%d px",
422 (gint) (x / disp->zoom_factor),
423 (gint) (y / disp->zoom_factor));
429 * Update a horizontal line
431 } else if (m_select == H_LINE_MS) {
432 if (state & GDK_BUTTON1_MASK) {
433 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d y=%d",
434 (gint) (x / disp->zoom_factor),
435 (gint) (disp->ygrab_first / disp->zoom_factor));
436 if (gci_line != NULL ) {
437 update_line ((gint) (disp->xgrab_first / disp->zoom_factor),
438 (gint) (disp->ygrab_first / disp->zoom_factor),
439 (gint) (x / disp->zoom_factor),
440 (gint) (disp->ygrab_first / disp->zoom_factor));
442 } else {
443 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d px y=%d px",
444 (gint) (x / disp->zoom_factor),
445 (gint) (y / disp->zoom_factor));
450 } else if (m_select == SPANLENGTH_MS) {
451 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d px y=%d px",
452 (gint) (x / disp->zoom_factor),
453 (gint) (y / disp->zoom_factor));
455 if (state & GDK_BUTTON1_MASK && gci_line != NULL ) {
456 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d y=%d",
457 (gint) (x / disp->zoom_factor),
458 (gint) (y / disp->zoom_factor));
459 update_line ((gint) (disp->xgrab_first / disp->zoom_factor),
460 (gint) (disp->ygrab_first / disp->zoom_factor),
461 (gint) (x / disp->zoom_factor),
462 (gint) (y / disp->zoom_factor));
465 } else if (m_select == V_SPANLENGTH_MS) {
466 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d px y=%d px",
467 (gint) (x / disp->zoom_factor),
468 (gint) (y / disp->zoom_factor));
470 if (state & GDK_BUTTON1_MASK && gci_line != NULL ) {
471 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d y=%d",
472 (gint) (disp->xgrab_first / disp->zoom_factor),
473 (gint) (y / disp->zoom_factor));
474 update_line ((gint) (disp->xgrab_first / disp->zoom_factor),
475 (gint) (disp->ygrab_first / disp->zoom_factor),
476 (gint) (disp->xgrab_first / disp->zoom_factor),
477 (gint) (y / disp->zoom_factor));
480 } else if (m_select == H_SPANLENGTH_MS) {
481 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d px y=%d px",
482 (gint) (x / disp->zoom_factor),
483 (gint) (y / disp->zoom_factor));
485 if (state & GDK_BUTTON1_MASK && gci_line != NULL ) {
486 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d y=%d",
487 (gint) (x / disp->zoom_factor),
488 (gint) (disp->ygrab_first / disp->zoom_factor));
489 update_line ((gint) (disp->xgrab_first / disp->zoom_factor),
490 (gint) (disp->ygrab_first / disp->zoom_factor),
491 (gint) (x / disp->zoom_factor),
492 (gint) (disp->ygrab_first / disp->zoom_factor));
499 gnome_appbar_push(GNOME_APPBAR(disp->appbar), msg_display);
500 gnome_appbar_push(GNOME_APPBAR(gpiv->appbar), msg_display);
505 /* } else { */
506 /* g_message("canvas_display_motion_notify: out of image borders"); */
509 gnome_canvas_points_free(points);
510 return TRUE;
515 gboolean
516 canvas_display_button_press (GtkWidget *widget,
517 GdkEventButton *event,
518 gpointer data
520 /*-----------------------------------------------------------------------------
523 Display *disp = gtk_object_get_data(GTK_OBJECT(widget), "disp");
524 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(widget), "gpiv");
525 gdouble x, y;
526 gint x_grab, y_grab;
527 gint index_x = 0, index_y = 0;
528 GdkModifierType state;
529 GnomeCanvasPoints *points;
530 GtkWidget *view_piv_display0 =
531 gtk_object_get_data(GTK_OBJECT(disp->mwin),
532 "view_piv_display0");
535 points = gnome_canvas_points_new(2);
536 GtkMenu *menu = GTK_MENU (disp->display_popupmenu);
538 gdk_window_get_pointer(event->window, &x_grab, &y_grab, &state);
539 x = x_grab ;
540 y = y_grab ;
544 if (event->button == 1) {
545 disp->xgrab_first = x;
546 disp->ygrab_first = y;
547 /* g_message ("canvas_display_button_press:: xgrab_first = %f ygrab_first = %f", */
548 /* disp->xgrab_first, disp->ygrab_first); */
550 * No mouse select
552 if (m_select == NO_MS) {
553 cursor = gdk_cursor_new (GDK_FLEUR );
554 gdk_window_set_cursor (disp->mwin->window, cursor);
555 /* g_message ("canvas_display_button_press:: x_grab = %d y_grab = %d", */
556 /* x_grab, y_grab); */
557 /* g_message ("CANVAS_DISPLAY_BUTTON_PRESS:: x = %f y = %f", x, y); */
561 * select Area Of Interest
563 } else if (m_select == AOI_MS) {
565 * storige of original AOI
567 disp->intreg->col_start_old = disp->pida->piv_par->col_start;
568 disp->intreg->row_start_old = disp->pida->piv_par->row_start;
570 /* g_message ("CANVAS_DISPLAY_BUTTON_PRESS (AOI):: x_grab = %d y_grab = %d", */
571 /* x_grab, y_grab); */
572 create_rect (disp,
573 disp->xgrab_first / disp->zoom_factor,
574 disp->ygrab_first / disp->zoom_factor);
577 * select at single interrogation area
579 } else if ((m_select == SINGLE_AREA_MS || m_select == DRAG_MS) &&
580 disp->img->exist_img) {
581 canvas_display_button_press__SINGLE_AREA_MS (gpiv, disp,
582 x / disp->zoom_factor,
583 y / disp->zoom_factor);
586 * select a single point
588 } else if (m_select == SINGLE_POINT_MS && disp->img->exist_img) {
589 canvas_display_button_press__SINGLE_POINT_MS (gpiv, disp,
590 x / disp->zoom_factor,
591 y / disp->zoom_factor);
595 * select a vertical line
597 } else if (m_select == V_LINE_MS && display_act->img->exist_img) {
598 /* g_message ("CANVAS_DISPLAY_BUTTON_PRESS (V_LINE_MS) 11:: x_grab = %d y_grab = %d", */
599 /* x_grab, y_grab); */
600 if (gci_line != NULL) destroy_line();
601 create_line (disp,
602 disp->xgrab_first / disp->zoom_factor,
603 disp->ygrab_first / disp->zoom_factor,
604 disp->xgrab_first / disp->zoom_factor,
605 disp->ygrab_first / disp->zoom_factor);
609 * select a horizontal line
611 } else if (m_select == H_LINE_MS && disp->img->exist_img) {
612 /* g_message ("CANVAS_DISPLAY_BUTTON_PRESS (H_LINE_MS) 1:: x_grab = %d y_grab = %d", */
613 /* x_grab, y_grab); */
614 if (gci_line != NULL) destroy_line();
615 create_line (disp,
616 disp->xgrab_first / disp->zoom_factor,
617 disp->ygrab_first / disp->zoom_factor,
618 disp->xgrab_first / disp->zoom_factor,
619 disp->ygrab_first / disp->zoom_factor);
621 } else if ( m_select == ENABLE_POINT_MS ) {
623 * Only active with piv data
625 if (disp->pida->exist_piv && disp->display_piv
626 /* && GTK_CHECK_MENU_ITEM(view_piv_display0)->active */
628 search_nearest_index (disp, x, y, &index_x, &index_y,
629 /* DATA_TYPE__INTREG); */
630 DATA_TYPE__PIV);
631 disp->pida->piv_data->peak_no[index_y][index_x] = 1;
632 update_vector (disp->pida, index_y, index_x);
637 * Enabling and disabling only active with piv data
639 } else if ((m_select == DISABLE_POINT_MS
640 || m_select == ENABLE_AREA_MS
641 || m_select == DISABLE_AREA_MS)
642 && disp->pida->exist_piv && disp->display_piv) {
643 canvas_display_button_press__DISABLE_POINT_MS (disp, x, y);
646 } else if (m_select == SPANLENGTH_MS
647 && disp->img->exist_img) {
648 if (gci_line != NULL) destroy_line();
649 create_line (disp,
650 disp->xgrab_first / disp->zoom_factor,
651 disp->ygrab_first / disp->zoom_factor,
652 disp->xgrab_first / disp->zoom_factor,
653 disp->ygrab_first / disp->zoom_factor);
657 } else if (m_select == V_SPANLENGTH_MS
658 && disp->img->exist_img) {
659 if (gci_line != NULL) destroy_line();
660 create_line (disp,
661 disp->xgrab_first / disp->zoom_factor,
662 disp->ygrab_first / disp->zoom_factor,
663 disp->xgrab_first / disp->zoom_factor,
664 disp->ygrab_first / disp->zoom_factor);
668 } else if (m_select == H_SPANLENGTH_MS
669 && disp->img->exist_img) {
670 if (gci_line != NULL) destroy_line();
671 create_line (disp,
672 disp->xgrab_first / disp->zoom_factor,
673 disp->ygrab_first / disp->zoom_factor,
674 disp->xgrab_first / disp->zoom_factor,
675 disp->ygrab_first / disp->zoom_factor);
678 } else {
679 g_warning(_("canvas_display_button_press: should not arrive here; m_select=%d"),
680 m_select);
684 } else if (event->button == 3) {
685 gtk_menu_popup (menu, NULL, NULL, NULL, NULL,
686 event->button, event->time);
690 gnome_canvas_points_free(points);
691 return TRUE;
695 gboolean
696 canvas_display_button_release (GtkWidget *widget,
697 GdkEventButton *event,
698 gpointer data
700 /*-----------------------------------------------------------------------------
703 Display *disp = gtk_object_get_data(GTK_OBJECT(widget), "disp");
704 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(widget), "gpiv");
705 GtkWidget *view_piv_display0 =
706 gtk_object_get_data(GTK_OBJECT(disp->mwin),
707 "view_piv_display0");
708 gdouble x, y;
709 gint x_grab, y_grab;
710 gint i, j;
711 GdkModifierType state;
714 shift_pressed = event->state & GDK_SHIFT_MASK;
715 gdk_window_get_pointer (event->window, &x_grab, &y_grab, &state);
717 /* BUGFIX: repair for different mouse selections */
718 x = x_grab;
719 y = y_grab;
722 /* g_message ("canvas_display_button_release:: x = %f y = %f", x, y); */
723 if (event->button == 1) {
725 if (m_select == AOI_MS && gci_aoi != NULL) {
726 canvas_display_button_release__AOI_MS (disp, gpiv,
727 view_piv_display0,
728 (gdouble) (x),
729 (gdouble) (y));
733 } else if ((m_select == V_LINE_MS || m_select == H_LINE_MS)
734 && disp->img->exist_img) {
735 /* g_message ("CANVAS_DISPLAY_BUTTON_RELEASE (HV_LINE):: x_grab = %d y_grab = %d", */
736 /* x_grab, y_grab); */
737 canvas_display_button_release__HVLINE_MS (disp, gpiv,
738 view_piv_display0,
739 (gdouble) (x),
740 (gdouble) (y));
745 * analyse at single interrogation area
747 } else if ((m_select == SINGLE_AREA_MS || m_select == DRAG_MS) &&
748 disp->img->exist_img) {
749 canvas_display_button_release__SINGLE_AREA_MS(gpiv, disp,
750 (gdouble) (x),
751 (gdouble) (y));
755 } else if (m_select == ENABLE_AREA_MS && gci_aoi != NULL) {
756 enable_col_end = x;
757 enable_row_end = y;
758 if (disp->pida->exist_piv) {
759 for (i = 0; i < disp->pida->piv_data->ny; i++) {
760 for (j = 0; j < disp->pida->piv_data->nx; j++) {
761 if (disp->pida->piv_data->point_x[i][j] >=
762 enable_col_start
763 && disp->pida->piv_data->point_x[i][j] <
764 enable_col_end
765 && disp->pida->piv_data->point_y[i][j] >=
766 enable_row_start
767 && disp->pida->piv_data->point_y[i][j] <
768 enable_row_end) {
769 disp->pida->piv_data->peak_no[i][j] = 1;
770 if (disp->display_piv)
771 update_vector(disp->pida, i, j);
777 if (gci_aoi != NULL) destroy_rect();
781 } else if (m_select == DISABLE_AREA_MS && gci_aoi != NULL) {
782 enable_col_end = x;
783 enable_row_end = y;
784 if (disp->pida->exist_piv) {
785 for (i = 0; i < disp->pida->piv_data->ny; i++) {
786 for (j = 0; j < disp->pida->piv_data->nx; j++) {
787 if (disp->pida->piv_data->point_x[i][j] >=
788 enable_col_start
789 && disp->pida->piv_data->point_x[i][j] <
790 enable_col_end
791 && disp->pida->piv_data->point_y[i][j] >=
792 enable_row_start
793 && disp->pida->piv_data->point_y[i][j] <
794 enable_row_end) {
795 disp->pida->piv_data->peak_no[i][j] = -1;
796 disp->pida->piv_data->snr[i][j] = GPIV_SNR_DISABLE;
798 if (disp->pida->post_par->set == TRUE) {
799 disp->pida->piv_data->dx[i][j] =
800 disp->pida->post_par->set_dx;
801 disp->pida->piv_data->dy[i][j] =
802 disp->pida->post_par->set_dx;
805 if (disp->display_piv)
806 update_vector(disp->pida, i, j);
812 if (gci_aoi != NULL) destroy_rect();
816 } else if (m_select == SPANLENGTH_MS
817 && disp->img->exist_img
818 && gci_line != NULL
820 gfloat hdist = abs ((x - disp->xgrab_first) / disp->zoom_factor);
821 gfloat vdist = abs ((y - disp->ygrab_first) / disp->zoom_factor);
823 gpiv_var->img_span_px = sqrt (hdist * hdist + vdist * vdist);
824 if (gci_line != NULL) destroy_line ();
825 gtk_spin_button_set_value (GTK_SPIN_BUTTON
826 (gpiv->imgh->spinbutton_sscale_px),
827 gpiv_var->img_span_px
832 } else if (m_select == V_SPANLENGTH_MS
833 && disp->img->exist_img
834 && gci_line != NULL
836 gpiv_var->img_span_px = abs ((y - disp->ygrab_first) / disp->zoom_factor);
837 if (gci_line != NULL) destroy_line ();
838 gtk_spin_button_set_value (GTK_SPIN_BUTTON
839 (gpiv->imgh->spinbutton_sscale_px),
840 gpiv_var->img_span_px);
844 } else if (m_select == H_SPANLENGTH_MS
845 && disp->img->exist_img
846 && gci_line != NULL
848 gpiv_var->img_span_px = abs ((x - disp->xgrab_first) / disp->zoom_factor);
849 if (gci_line != NULL) destroy_line ();
850 gtk_spin_button_set_value (GTK_SPIN_BUTTON
851 (gpiv->imgh->spinbutton_sscale_px),
852 gpiv_var->img_span_px);
857 * No action
859 } else if (m_select == GPIV_NONE
860 || m_select == SINGLE_POINT_MS
861 || m_select == ENABLE_POINT_MS
862 || m_select == DISABLE_POINT_MS
864 cursor = gdk_cursor_new (GDK_DOTBOX);
865 gdk_window_set_cursor (disp->mwin->window, cursor);
867 } else {
868 g_warning(_("canvas_display_button_release: should not arrive here; m_select=%d"),
869 m_select);
873 return TRUE;
878 gboolean
879 canvas_display_leave_notify (GtkWidget *widget,
880 GdkEventMotion *event,
881 gpointer data
883 /*-----------------------------------------------------------------------------
886 Display *disp = gtk_object_get_data(GTK_OBJECT(widget), "disp");
887 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(widget), "gpiv");
888 GtkWidget *view_piv_display0 =
889 gtk_object_get_data(GTK_OBJECT(disp->mwin),
890 "view_piv_display0");
893 gnome_appbar_push(GNOME_APPBAR(disp->appbar),
894 disp->msg_display_default);
895 gnome_appbar_push(GNOME_APPBAR(gpiv->appbar), msg_default);
898 if (m_select == SINGLE_POINT_MS
899 && GTK_CHECK_MENU_ITEM(view_piv_display0)->active
901 if (!disp->intreg->exist_int) {
902 update_intreg1(disp, m_select_index_y, m_select_index_x);
903 update_intreg2(disp, m_select_index_y, m_select_index_x);
906 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
907 show_all_intregs(disp);
911 if (disp->pida->exist_piv && disp->display_piv) {
912 show_all_vectors(disp->pida);
916 } else if (m_select == DRAG_MS) {
917 if (!disp->intreg->exist_int) {
918 update_intreg1(disp, disp->index_y_old, disp->index_x_old);
919 update_intreg2(disp, disp->index_y_old, disp->index_x_old);
922 } else if (m_select == SINGLE_AREA_MS && disp->intreg->exist_int) {
923 if (!disp->intreg->exist_int) {
924 update_intreg1(disp, 0, 0);
925 update_intreg2(disp, 0, 0);
929 } else if (m_select == AOI_MS
930 || m_select == V_LINE_MS
931 || m_select == H_LINE_MS) {
932 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
933 show_all_intregs(disp);
936 if (disp->pida->exist_piv && disp->display_piv) {
937 show_all_vectors(disp->pida);
940 if (gci_line != NULL) {
941 gtk_object_destroy(GTK_OBJECT(gci_line));
942 gci_line = NULL;
949 if (GDK_BUTTON1_MASK) {
951 * Cancel AOI_MS selection
953 if (m_select == AOI_MS) {
954 if (gci_aoi != NULL) {
955 disp->pida->piv_par->col_start = disp->intreg->col_start_old;
956 disp->pida->piv_par->row_start = disp->intreg->row_start_old;
957 gtk_spin_button_set_value(GTK_SPIN_BUTTON
958 (gpiv->piveval->spinbutton_colstart),
959 disp->pida->piv_par->col_start);
960 gtk_spin_button_set_value(GTK_SPIN_BUTTON
961 (gpiv->piveval->spinbutton_rowstart),
962 disp->pida->piv_par->row_start);
963 if (gci_aoi != NULL) destroy_rect();
966 /* show_all_intregs(disp); */
968 } else if ( m_select == ENABLE_AREA_MS
969 || m_select == DISABLE_AREA_MS) {
970 enable_col_start = 0;
971 enable_row_start = 0;
972 enable_col_end = 0;
973 enable_row_end = 0;
974 if (gci_aoi != NULL) destroy_rect();
977 * Cancel V_LINE_MS, LINE_MS selection
978 * (V_, H_) SPANLENGTH_MS
980 } else if (m_select == V_LINE_MS
981 || m_select == H_LINE_MS
982 || m_select == SPANLENGTH_MS
983 || m_select == V_SPANLENGTH_MS
984 || m_select == H_SPANLENGTH_MS
986 if (gci_line != NULL) destroy_line();
994 * General
996 if (cursor != NULL) {
997 gdk_cursor_destroy(cursor);
998 cursor = NULL;
1001 if (disp->intreg->gci_intreg2[disp->index_y_old][disp->index_x_old]
1002 != NULL) {
1003 update_intreg2(disp, disp->index_y_old, disp->index_x_old);
1006 if (disp->intreg->gci_intreg1[disp->index_y_old][disp->index_x_old]
1007 != NULL) {
1008 update_intreg1(disp, disp->index_y_old, disp->index_x_old);
1011 disp->index_x_old = 0;
1012 disp->index_y_old = 0;
1015 return TRUE;
1019 * Private display functions
1023 static void
1024 canvas_display_motion_notify__NO_MS (Display *disp,
1025 gint x,
1026 gint y,
1027 gint *index_x,
1028 gint *index_y
1030 /*-----------------------------------------------------------------------------
1031 * Moves pointer over the display canvas if no mouse selection (NO_MS) is set
1034 GpivPivData *piv_data = disp->pida->piv_data;
1035 GpivPivData *piv_data_scaled = disp->pida->piv_data_scaled;
1036 GpivScalarData *vor_data = disp->pida->vor_data;
1037 GpivScalarData *vor_data_scaled = disp->pida->vor_data_scaled;
1038 GpivScalarData *sstrain_data = disp->pida->sstrain_data;
1039 GpivScalarData *sstrain_data_scaled = disp->pida->sstrain_data_scaled;
1040 GpivScalarData *nstrain_data = disp->pida->nstrain_data;
1041 GpivScalarData *nstrain_data_scaled = disp->pida->nstrain_data_scaled;
1042 GtkWidget *view_piv_display0 =
1043 gtk_object_get_data(GTK_OBJECT(disp->mwin),
1044 "view_piv_display0");
1047 *index_y = 0;
1048 *index_x = 0;
1050 if ((disp->pida->exist_piv && disp->display_piv
1051 && GTK_CHECK_MENU_ITEM(view_piv_display0)->active
1052 && piv_data->ny == disp->intreg->data->ny
1053 && piv_data->nx == disp->intreg->data->nx
1054 && piv_data->point_y[0][0] == disp->intreg->data->point_y[0][0]
1055 && piv_data->point_x[0][0] == disp->intreg->data->point_x[0][0]
1056 && piv_data->point_y[piv_data->ny - 1][piv_data->nx - 1] ==
1057 disp->intreg->data->point_y[disp->intreg->data->ny - 1]
1058 [disp->intreg->data->nx - 1]
1059 && piv_data->point_x[piv_data->ny - 1][piv_data->nx - 1] ==
1060 disp->intreg->data->point_x[disp->intreg->data->ny - 1]
1061 [disp->intreg->data->nx - 1] )
1062 || (disp->pida->exist_piv && disp->display_piv
1063 && !GTK_CHECK_MENU_ITEM(view_piv_display0)->active)
1066 search_nearest_index(disp, x, y, index_x, index_y, DATA_TYPE__PIV);
1067 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1068 highlight_intreg(*index_y, *index_x, disp);
1072 if (disp->pida->exist_vor
1073 && disp->display_scalar == SHOW_SC_VORTICITY) {
1074 if (disp->pida->scaled_piv) {
1075 create_msg_display_with_pivscdata (piv_data_scaled,
1076 vor_data_scaled,
1077 "vor",
1078 *index_y,
1079 *index_x,
1080 disp->pida->scaled_piv);
1081 } else {
1082 create_msg_display_with_pivscdata (piv_data,
1083 vor_data,
1084 "vor",
1085 *index_y,
1086 *index_x,
1087 disp->pida->scaled_piv);
1090 } else if (disp->pida->exist_sstrain
1091 && disp->display_scalar == SHOW_SC_SSTRAIN) {
1092 if (disp->pida->scaled_piv) {
1093 create_msg_display_with_pivscdata (piv_data_scaled,
1094 sstrain_data_scaled,
1095 "sstrain",
1096 *index_y,
1097 *index_x,
1098 disp->pida->scaled_piv);
1099 } else {
1100 create_msg_display_with_pivscdata (piv_data,
1101 sstrain_data,
1102 "sstrain",
1103 *index_y,
1104 *index_x,
1105 disp->pida->scaled_piv);
1108 } else if (disp->pida->exist_nstrain
1109 && disp->display_scalar == SHOW_SC_NSTRAIN) {
1111 if (disp->pida->scaled_piv) {
1112 create_msg_display_with_pivscdata (piv_data_scaled,
1113 nstrain_data_scaled,
1114 "nstrain",
1115 *index_y,
1116 *index_x,
1117 disp->pida->scaled_piv);
1118 } else {
1119 create_msg_display_with_pivscdata (piv_data,
1120 nstrain_data,
1121 "nstrain",
1122 *index_y,
1123 *index_x,
1124 disp->pida->scaled_piv);
1127 } else {
1128 if (disp->pida->scaled_piv) {
1129 create_msg_display_with_pivdata (piv_data_scaled,
1130 *index_y,
1131 *index_x,
1132 disp->pida->scaled_piv);
1134 } else {
1135 create_msg_display_with_pivdata (piv_data,
1136 *index_y,
1137 *index_x,
1138 disp->pida->scaled_piv);
1144 * piv data exist, but are not displayed
1145 * displays eventually piv-derived scalar data
1147 } else if ((disp->pida->exist_piv
1148 && !disp->display_piv
1149 && GTK_CHECK_MENU_ITEM(view_piv_display0)->active
1150 && piv_data->ny == disp->intreg->data->ny
1151 && piv_data->nx == disp->intreg->data->nx
1152 && piv_data->point_y[0][0] == disp->intreg->data->point_y[0][0]
1153 && piv_data->point_x[0][0] == disp->intreg->data->point_x[0][0]
1154 && piv_data->point_y[piv_data->ny - 1][piv_data->nx - 1] ==
1155 disp->intreg->data->point_y[disp->intreg->data->ny - 1]
1156 [disp->intreg->data->nx - 1]
1157 && piv_data->point_x[piv_data->ny - 1][piv_data->nx - 1] ==
1158 disp->intreg->data->point_x[disp->intreg->data->ny - 1]
1159 [disp->intreg->data->nx - 1]
1160 && ((disp->pida->exist_vor
1161 && disp->display_scalar == SHOW_SC_VORTICITY)
1162 || (disp->pida->exist_sstrain
1163 && disp->display_scalar == SHOW_SC_SSTRAIN)
1164 || (disp->pida->exist_nstrain &&
1165 disp->display_scalar == SHOW_SC_NSTRAIN))
1167 || (disp->pida->exist_piv
1168 && !disp->display_piv
1169 && !GTK_CHECK_MENU_ITEM(view_piv_display0)->active
1170 && ((disp->pida->exist_vor
1171 && disp->display_scalar == SHOW_SC_VORTICITY)
1172 || (disp->pida->exist_sstrain
1173 && disp->display_scalar == SHOW_SC_SSTRAIN)
1174 || (disp->pida->exist_nstrain
1175 && disp->display_scalar == SHOW_SC_NSTRAIN))
1179 search_nearest_index(disp, x, y, index_x, index_y,
1180 DATA_TYPE__PIV);
1181 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1182 highlight_intreg(*index_y, *index_x, disp);
1185 if (disp->pida->exist_vor &&
1186 disp->display_scalar == SHOW_SC_VORTICITY) {
1187 if (disp->pida->scaled_piv) {
1188 create_msg_display_with_scdata(vor_data_scaled,
1189 "vor",
1190 *index_y,
1191 *index_x,
1192 disp->pida->scaled_piv);
1193 } else {
1194 create_msg_display_with_scdata(vor_data,
1195 "vor",
1196 *index_y,
1197 *index_x,
1198 disp->pida->scaled_piv);
1201 } else if (disp->pida->exist_sstrain &&
1202 disp->display_scalar == SHOW_SC_SSTRAIN) {
1203 if (disp->pida->scaled_piv) {
1204 create_msg_display_with_scdata(sstrain_data_scaled,
1205 "sstrain",
1206 *index_y,
1207 *index_x,
1208 disp->pida->scaled_piv);
1209 } else {
1210 create_msg_display_with_scdata(sstrain_data,
1211 "sstrain",
1212 *index_y,
1213 *index_x,
1214 disp->pida->scaled_piv);
1217 } else if (disp->pida->exist_nstrain
1218 && disp->display_scalar == SHOW_SC_NSTRAIN) {
1219 if (disp->pida->scaled_piv) {
1220 create_msg_display_with_scdata(nstrain_data_scaled,
1221 "nstrain",
1222 *index_y,
1223 *index_x,
1224 disp->pida->scaled_piv);
1225 } else {
1226 create_msg_display_with_scdata(nstrain_data,
1227 "nstrain",
1228 *index_y,
1229 *index_x,
1230 disp->pida->scaled_piv);
1235 * PIV data (and resulting derivatives) do not exist are and not displayed
1236 * Interrogation area's are displayed
1238 } else if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1239 search_nearest_index(disp, x, y, index_x, index_y, DATA_TYPE__INTREG);
1240 highlight_intreg(*index_y, *index_x, disp);
1242 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%3.2f y=%3.2f i=%d j=%d ",
1243 disp->intreg->data->point_x[*index_y][*index_x],
1244 disp->intreg->data->point_y[*index_y][*index_x],
1245 *index_y, *index_x);
1249 * Only image is displayed
1251 } else if (disp->display_backgrnd == SHOW_BG_IMG1) {
1252 if (disp->pida->scaled_piv) {
1253 g_snprintf(msg_display, GPIV_MAX_CHARS,
1254 "xp=%d px ==> %5.4f m yp=%d px ==> %5.4f m img #1: pixval=%d",
1256 disp->img->image->header->s_scale * x * 1e-3
1257 + disp->img->image->header->z_off_x,
1259 disp->img->image->header->s_scale * y * 1e-3
1260 + disp->img->image->header->z_off_y,
1261 disp->img->image->frame1[y][x]
1263 } else {
1264 g_snprintf(msg_display, GPIV_MAX_CHARS,
1265 "xp=%d px yp=%d px img #1: pixval=%d",
1266 x, y,
1267 disp->img->image->frame1[y][x]
1271 } else if (disp->display_backgrnd == SHOW_BG_IMG2) {
1272 if (disp->pida->scaled_piv) {
1273 g_snprintf(msg_display, GPIV_MAX_CHARS,
1274 "xp=%d px ==> %5.4f m yp=%d px ==> %5.4f m img #1: pixval=%d",
1276 disp->img->image->header->s_scale * x * 1e-3
1277 + disp->img->image->header->z_off_x,
1279 disp->img->image->header->s_scale * y * 1e-3
1280 + disp->img->image->header->z_off_y,
1281 disp->img->image->frame2[y][x]
1283 } else {
1284 g_snprintf(msg_display, GPIV_MAX_CHARS,
1285 "xp=%d px yp=%d px img #2: pixval=%d",
1286 x, y,
1287 disp->img->image->frame2[y][x]
1291 } else {
1292 g_snprintf(msg_display, GPIV_MAX_CHARS, "No data are displayed");
1299 static void
1300 canvas_display_button_release__AOI_MS (Display *disp,
1301 GpivConsole *gpiv,
1302 GtkWidget *view_piv_display0,
1303 gdouble x,
1304 gdouble y
1306 /*-----------------------------------------------------------------------------
1307 * Performs action on mouse button release when AOI_MS has been enabled
1310 PivEval *eval = gpiv->piveval;
1311 gdouble l_col_start, l_col_end, l_row_start, l_row_end;
1314 if (gci_aoi != NULL) destroy_rect();
1316 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1317 destroy_all_intregs(disp);
1321 /* g_message ("canvas_display_button_release__AOI_MS:: x = %f y = %f" */
1322 /* " xgrab_first = %f ygrab_first = %f", */
1323 /* x, y, disp->xgrab_first, disp->ygrab_first); */
1325 if (x >= disp->xgrab_first) {
1326 l_col_start = disp->xgrab_first / disp->zoom_factor;
1327 l_col_end = x / disp->zoom_factor;
1328 disp->pida->piv_par->col_start = (gint) l_col_start;
1329 disp->pida->piv_par->col_end = (gint) l_col_end;
1330 } else {
1331 l_col_end = disp->xgrab_first / disp->zoom_factor;
1332 l_col_start = x / disp->zoom_factor;
1333 disp->pida->piv_par->col_end = (gint) l_col_end;
1334 disp->pida->piv_par->col_start = (gint) l_col_start;
1337 if (y >= disp->ygrab_first) {
1338 l_row_start = disp->ygrab_first / disp->zoom_factor;
1339 l_row_end = y / disp->zoom_factor;
1340 disp->pida->piv_par->row_start = (gint) l_row_start;
1341 disp->pida->piv_par->row_end = (gint) l_row_end;
1342 } else {
1343 l_row_end = disp->ygrab_first / disp->zoom_factor;
1344 l_row_start = y / disp->zoom_factor;
1345 disp->pida->piv_par->row_end = (gint) l_row_end;
1346 disp->pida->piv_par->row_start = (gint) l_row_start;
1351 gtk_spin_button_set_value (GTK_SPIN_BUTTON
1352 (eval->spinbutton_colstart),
1353 (gdouble)l_col_start);
1355 gtk_spin_button_set_value (GTK_SPIN_BUTTON
1356 (eval->spinbutton_colend),
1357 (gdouble) l_col_end);
1359 gtk_spin_button_set_value (GTK_SPIN_BUTTON
1360 (eval->spinbutton_rowstart),
1361 (gdouble) l_row_start);
1363 gtk_spin_button_set_value (GTK_SPIN_BUTTON
1364 (eval->spinbutton_rowend),
1365 (gdouble) l_row_end);
1367 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1368 create_all_intregs (disp);
1375 static void
1376 canvas_display_motion_notify__DRAGINT_MS (Display *disp,
1377 gint x,
1378 gint y,
1379 gint *index_x,
1380 gint *index_y
1382 /*-----------------------------------------------------------------------------
1383 * displaces interrogation area nearest to pointer
1386 if (disp->intreg->exist_int) {
1387 if (!disp->index_old) {
1388 disp->index_x_old = *index_x;
1389 disp->index_y_old = *index_y;
1390 disp->index_old = TRUE;
1393 if (*index_x == disp->index_x_old
1394 && *index_y == disp->index_y_old) {
1396 gnome_canvas_item_set
1397 (GNOME_CANVAS_ITEM(disp->intreg->
1398 gci_intreg1[*index_y][*index_x]),
1399 "x1", (double) x - disp->pida->piv_par->int_size_f / 2,
1400 "y1", (double) y - disp->pida->piv_par->int_size_f / 2,
1401 "x2", (double) x + disp->pida->piv_par->int_size_f / 2,
1402 "y2", (double) y + disp->pida->piv_par->int_size_f / 2,
1403 NULL);
1405 gnome_canvas_item_set
1406 (GNOME_CANVAS_ITEM(disp->intreg->
1407 gci_intreg2[*index_y][*index_x]),
1408 "x1", (double) x - disp->pida->piv_par->int_size_i /
1409 2 + disp->pida->piv_par->pre_shift_col,
1410 "y1", (double) y - disp->pida->piv_par->int_size_i /
1411 2 + disp->pida->piv_par->pre_shift_row,
1412 "x2", (double) x + disp->pida->piv_par->int_size_i /
1413 2 + disp->pida->piv_par->pre_shift_col,
1414 "y2", (double) y + disp->pida->piv_par->int_size_i /
1415 2 + disp->pida->piv_par->pre_shift_row,
1416 NULL);
1418 * put the interrogation area back to its original location
1420 } else {
1421 update_intreg1(disp, disp->index_y_old, disp->index_x_old);
1422 update_intreg2(disp, disp->index_y_old, disp->index_x_old);
1429 static void
1430 canvas_display_motion_notify__SINGLE_POINT_MS (Display *disp,
1431 gint x,
1432 gint y
1434 /*-----------------------------------------------------------------------------
1435 * Interrogates at a single arbitrary point in the image.
1436 * I am using the first interrogation area ([0][0]) temporarly for
1437 * displaying
1440 GtkWidget *view_piv_display0 =
1441 gtk_object_get_data(GTK_OBJECT(disp->mwin),
1442 "view_piv_display0");
1445 if (disp->intreg->gci_intreg1[0][0] != NULL &&
1446 disp->intreg->gci_intreg2[0][0] != NULL
1448 if (!GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1450 if (disp->intreg->gci_intreg1[0][0] != NULL) {
1451 gnome_canvas_item_show
1452 (GNOME_CANVAS_ITEM(disp->intreg->gci_intreg1[0][0]));
1454 if (disp->intreg->gci_intreg2[0][0] != NULL) {
1455 gnome_canvas_item_show
1456 (GNOME_CANVAS_ITEM(disp->intreg->gci_intreg2[0][0]));
1458 disp->display_intregs = TRUE;
1461 if (disp->pida->exist_piv && disp->pida->scaled_piv) {
1462 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%3.2f mm y=%3.2f mm",
1463 (gfloat) x * disp->img->image->header->s_scale *10e2
1464 + (gfloat) disp->img->image->header->z_off_x *10e2,
1465 (gfloat) y * disp->img->image->header->s_scale *10e2
1466 + (gfloat) disp->img->image->header->z_off_y *10e2);
1467 } else {
1468 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d px y=%d px", x, y);
1471 gnome_canvas_item_set
1472 (GNOME_CANVAS_ITEM(disp->intreg->gci_intreg1[0][0]),
1473 "x1", (double) x - disp->pida->piv_par->int_size_f / 2,
1474 "y1", (double) y - disp->pida->piv_par->int_size_f / 2,
1475 "x2", (double) x + disp->pida->piv_par->int_size_f / 2,
1476 "y2", (double) y + disp->pida->piv_par->int_size_f / 2,
1477 NULL);
1479 gnome_canvas_item_set
1480 (GNOME_CANVAS_ITEM(disp->intreg->gci_intreg2[0][0]),
1481 "x1", (double) x - disp->pida->piv_par->int_size_f / 2
1482 + disp->pida->piv_par->pre_shift_col,
1483 "y1", (double) y - disp->pida->piv_par->int_size_f / 2
1484 + disp->pida->piv_par->pre_shift_row,
1485 "x2", (double) x + disp->pida->piv_par->int_size_f / 2
1486 + disp->pida->piv_par->pre_shift_col,
1487 "y2", (double) y + disp->pida->piv_par->int_size_f / 2
1488 + disp->pida->piv_par->pre_shift_row,
1489 NULL);
1491 } else {
1492 create_intreg1 (disp, 0, 0);
1493 create_intreg2 (disp, 0, 0);
1500 static char *
1501 canvas_display_button_press__SINGLE_AREA_MS (GpivConsole *gpiv,
1502 Display *disp,
1503 gint x,
1504 gint y
1506 /*-----------------------------------------------------------------------------
1507 * Performs action on mouse button press when SINGLE_AREA_MS has been enabled
1510 char *err_msg = NULL;
1511 gint index_x = 0, index_y = 0;
1512 GtkWidget *view_piv_display0 =
1513 gtk_object_get_data(GTK_OBJECT(disp->mwin),
1514 "view_piv_display0");
1517 if (disp->pida->exist_piv
1518 /* && GTK_CHECK_MENU_ITEM(view_piv_display0)->active */
1519 /* && disp->intreg->data->nx == disp->pida->piv_data->nx */
1520 /* && disp->intreg->data->ny == disp->pida->piv_data->ny */
1524 /* search_nearest_index(disp, x, y, &index_x, &index_y, */
1525 /* DATA_TYPE__INTREG); */
1526 search_nearest_index (disp, x, y, &index_x, &index_y,
1527 DATA_TYPE__PIV);
1530 if (m_select == SINGLE_AREA_MS) {
1531 /* if (disp->intreg->data->point_x[index_y][index_x] == */
1532 /* disp->pida->piv_data->point_x[index_y][index_x] */
1533 /* && disp->intreg->data->point_y[index_y][index_x] == */
1534 /* disp->pida->piv_data->point_y[index_y][index_x] */
1535 /* ) { */
1536 m_select_index_x = index_x;
1537 m_select_index_y = index_y;
1538 /* gpiv_warning("canvas_display_button_press__SINGLE_AREA_MS:: index_x=%d index_y = %d", index_x, index_y); */
1539 /* } else { */
1540 /* set__NO_MS(gpiv, disp); */
1541 /* err_msg = "Interrogation area's have to be at the same positions \nas the already existing piv data"; */
1542 /* warning_gpiv(err_msg); */
1543 /* return err_msg; */
1544 /* } */
1545 /* g_message("x=%d point_x=%d y=%d point_x=%d */
1547 } else if (m_select == DRAG_MS) {
1548 m_select_index_x = index_x;
1549 m_select_index_y = index_y;
1550 disp->pida->piv_data->point_x[m_select_index_y]
1551 [m_select_index_x] = (float) x;
1552 disp->pida->piv_data->point_y[m_select_index_y]
1553 [m_select_index_x] = (float) y;
1554 /* BUGFIXED ? */
1555 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1556 disp->intreg->data->point_x[m_select_index_y]
1557 [m_select_index_x] = (float) x;
1558 disp->intreg->data->point_y[m_select_index_y]
1559 [m_select_index_x] = (float) y;
1561 } else {
1562 err_msg = "canvas_display_button_press__SINGLE_AREA_MS: should not arrive here";
1563 error_gpiv(err_msg);
1569 return err_msg;
1574 static char *
1575 canvas_display_button_release__SINGLE_AREA_MS (GpivConsole *gpiv,
1576 Display *disp,
1577 gdouble x,
1578 gdouble y
1580 /*-----------------------------------------------------------------------------
1581 * Performs action on mouse button release when SINGLE_AREA_MS has been enabled
1584 char *err_msg = NULL;
1585 gint index_x = 0, index_y = 0;
1586 GtkWidget *view_piv_display0 =
1587 gtk_object_get_data(GTK_OBJECT(disp->mwin),
1588 "view_piv_display0");
1591 /* g_message ("canvas_display_button_release__SINGLE_AREA_MS:: x = %f y = %f" */
1592 /* " xgrab_first = %f ygrab_first = %f " */
1593 /* "m_select_index_x = %d m_select_index_y = %d", */
1594 /* x, y, disp->xgrab_first, disp->ygrab_first, */
1595 /* m_select_index_x, m_select_index_y */
1596 /* ); */
1598 if (disp->pida->exist_piv
1599 /* && GTK_CHECK_MENU_ITEM(view_piv_display0)->active */
1600 /* && disp->intreg->data->nx == disp->pida->piv_data->nx */
1601 /* && disp->intreg->data->ny == disp->pida->piv_data->ny */
1605 * There will only be action if the pointer, during pressing the button (as
1606 * defined in canvas_display_button_press__SINGLE_AREA_MS), is at identical
1607 * position as during releasing the button->
1609 search_nearest_index(disp, (gint) x, (gint) y, &index_x, &index_y,
1610 DATA_TYPE__PIV);
1611 /* gpiv_warning("canvas_display_button_release__SINGLE_AREA_MS:: index_x=%d index_y = %d", index_x, index_y); */
1615 if (m_select_index_x == index_x
1616 && m_select_index_y == index_y
1618 gl_piv_par->int_point_col = m_select_index_x;
1619 gl_piv_par->int_point_row = m_select_index_y;
1620 disp->pida->piv_par = gpiv_piv_cp_parameters (gl_piv_par);
1622 /* g_message ("canvas_display_button_release__SINGLE_AREA_MS:: calling interrogate"); */
1624 disp->pida->piv_data = interrogate_img (disp->img->image,
1625 disp->pida->piv_par,
1626 disp->pida->valid_par,
1627 gpiv);
1629 /* exec_piv (gpiv); */
1630 /* g_message ("canvas_display_button_release__SINGLE_AREA_MS:: back from interrogate"); */
1631 if (disp->pida->gci_vector[m_select_index_y][m_select_index_x]
1632 != NULL) {
1633 update_vector (disp->pida, m_select_index_y, m_select_index_x);
1634 } else {
1635 create_vector (disp->pida, m_select_index_y, m_select_index_x);
1638 /* g_message ("canvas_display_button_release__SINGLE_AREA_MS:: display vector"); */
1639 /* disp->pida->exist_piv = TRUE; */
1640 disp->display_piv = TRUE;
1641 if (m_select == DRAG_MS) {
1642 if (disp->intreg->
1643 gci_intreg1[m_select_index_y][m_select_index_x]
1644 != NULL)
1645 update_intreg1 (disp, m_select_index_y, m_select_index_x);
1646 if (disp->intreg->
1647 gci_intreg2[m_select_index_y][m_select_index_x]
1648 != NULL)
1649 update_intreg2 (disp, m_select_index_y, m_select_index_x);
1652 } else {
1653 err_msg = "moved pointer too far away from \nintar to be interrogated";
1654 return err_msg;
1657 } else {
1658 /* err_msg = "Interrogation area's and piv data must already exist \n and must be of identic quantity!"; */
1659 err_msg = "Piv data must exist!";
1660 warning_gpiv (err_msg);
1661 return err_msg;
1665 if (!shift_pressed) set__NO_MS(gpiv, disp);
1668 return err_msg;
1673 static void
1674 canvas_display_button_press__SINGLE_POINT_MS (GpivConsole *gpiv,
1675 Display *disp,
1676 gint x,
1677 gint y
1679 /*-----------------------------------------------------------------------------
1680 * Performs action on mouse button release when SINGLE_POINT_MS has
1681 * been enabled
1684 GtkWidget *view_piv_display0 =
1685 gtk_object_get_data(GTK_OBJECT(disp->mwin),
1686 "view_piv_display0");
1689 if (disp->pida->exist_piv) {
1690 destroy_all_vectors(disp->pida);
1691 gpiv_free_pivdata (disp->pida->piv_data);
1692 disp->pida->exist_piv = FALSE;
1693 if (disp->pida->scaled_piv) {
1694 gpiv_free_pivdata (disp->pida->piv_data_scaled);
1695 disp->pida->scaled_piv = FALSE;
1699 free_post_bufmems(disp);
1700 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1701 destroy_all_intregs(disp);
1703 m_select_index_x = 0;
1704 m_select_index_y = 0;
1705 disp->pida->piv_par->int_point_col = (float) x;
1706 disp->pida->piv_par->int_point_row = (float) y;
1707 disp->pida->piv_data = gpiv_alloc_pivdata (1, 1);
1708 disp->pida->exist_piv = TRUE;
1710 disp->pida->piv_data->point_x[0][0] = (float) x;
1711 disp->pida->piv_data->point_y[0][0] = (float) y;
1713 disp->intreg->data->nx = 1;
1714 disp->intreg->data->ny = 1;
1715 create_all_intregs(disp);
1716 disp->intreg->exist_int = TRUE;
1718 disp->intreg->data->point_x[0][0] = (float) x;
1719 disp->intreg->data->point_y[0][0] = (float) y;
1720 show_all_intregs(disp);
1721 disp->display_intregs = TRUE;
1723 disp->pida->piv_data = interrogate_img (disp->img->image,
1724 disp->pida->piv_par,
1725 disp->pida->valid_par,
1726 gpiv);
1728 disp->display_piv = TRUE;
1730 create_all_vectors(disp->pida);
1731 gnome_canvas_update_now(GNOME_CANVAS(disp->canvas));
1733 if (!shift_pressed) set__NO_MS(gpiv, disp);
1738 static void
1739 canvas_display_button_release__HVLINE_MS (Display *disp,
1740 GpivConsole *gpiv,
1741 GtkWidget *view_piv_display0,
1742 gdouble x,
1743 gdouble y
1745 /*-----------------------------------------------------------------------------
1746 * Performs action on mouse button release when H_LINE_MS or V_LINE_MS has
1747 * been enabled
1750 gdouble l_col_start,l_col_end, l_row_start, l_row_end;
1751 gboolean reset_display_intregs;
1754 /* g_message ("canvas_display_button_release__HVLINE_MS:: x = %f y = %f" */
1755 /* " xgrab_first = %f ygrab_first = %f", */
1756 /* x, y, disp->xgrab_first, disp->ygrab_first); */
1758 if (GTK_CHECK_MENU_ITEM (view_piv_display0)->active) {
1760 * Remove exixting intreg contours
1761 * Disable displaying temporarly to avoid several calls to
1762 * the 'on_spinbutton_piv_int' function
1764 destroy_all_intregs (disp);
1765 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM
1766 (view_piv_display0),
1767 FALSE);
1768 reset_display_intregs = TRUE;
1771 /* if (disp->pida->exist_piv) { */
1772 /* destroy_all_vectors(disp->pida); */
1773 /* disp->display_piv = FALSE; */
1774 /* } */
1777 m_select_index_x = 0;
1778 m_select_index_y = 0;
1781 * Vertical line selected
1783 if (m_select == V_LINE_MS) {
1784 if (y >= disp->ygrab_first) {
1785 l_row_start = (gdouble) (disp->ygrab_first / disp->zoom_factor);
1786 l_row_end = (gdouble) (y / disp->zoom_factor);
1787 disp->pida->piv_par->row_start = (gint) l_row_start;
1788 disp->pida->piv_par->row_end = (gint) l_row_end;
1789 disp->pida->piv_par->int_line_row_end = (gint) l_row_end;
1790 } else {
1791 l_row_start = (gdouble) (y / disp->zoom_factor);
1792 l_row_end = (gdouble) (disp->ygrab_first / disp->zoom_factor);
1793 disp->pida->piv_par->row_start = (gint) l_row_start;
1794 disp->pida->piv_par->row_end = (gint) l_row_end;
1795 disp->pida->piv_par->int_line_row_end = (gint) l_row_end;
1798 l_col_start = (gdouble) (disp->xgrab_first / disp->zoom_factor -
1799 disp->pida->piv_par->int_size_i / 2 + 1);
1800 disp->pida->piv_par->col_start = (gint) l_col_start;
1802 l_col_end = (gdouble) (disp->xgrab_first / disp->zoom_factor +
1803 disp->pida->piv_par->int_size_i / 2 +
1804 disp->pida->piv_par->pre_shift_col);
1805 disp->pida->piv_par->col_end = (gint) l_col_end;
1809 * Horizontal line selected
1811 } else if (m_select == H_LINE_MS) {
1812 if (x >= disp->xgrab_first) {
1813 l_col_start = (gdouble) (disp->xgrab_first / disp->zoom_factor);
1814 l_col_end = (gdouble) (x / disp->zoom_factor);
1815 disp->pida->piv_par->col_start = (gint) l_col_start;
1816 disp->pida->piv_par->col_end = (gint) l_col_end;
1817 disp->pida->piv_par->int_line_col_end = (gint) l_col_end;
1818 } else {
1819 l_col_start = (gdouble) (x / disp->zoom_factor);
1820 l_col_end = (gdouble) (disp->xgrab_first / disp->zoom_factor);
1821 disp->pida->piv_par->col_start = (gint) l_col_start;
1822 disp->pida->piv_par->col_end = (gint) l_col_end;
1823 disp->pida->piv_par->int_line_col_end = (gint) l_col_end;
1826 l_row_start = (gdouble) (disp->ygrab_first / disp->zoom_factor -
1827 disp->pida->piv_par->int_size_i / 2 + 1);
1828 disp->pida->piv_par->row_start = (gint) l_row_start;
1830 l_row_end = (gdouble) (disp->ygrab_first / disp->zoom_factor +
1831 disp->pida->piv_par->int_size_i / 2 +
1832 disp->pida->piv_par->pre_shift_col);
1833 disp->pida->piv_par->row_end = (gint) l_row_end;
1836 } else {
1837 g_warning("canvas_display_button_release__HVLINE_MS: H_LINE_MS or V_LINE_MS inactive");
1840 if (gci_line != NULL) destroy_line();
1841 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1842 create_all_intregs(disp);
1846 * updating entry's for col/row_start_end
1848 /* g_message ("canvas_display_button_release__HVLINE_MS:: zoom_factor = %f col_start = %f col_end = %f" */
1849 /* " row_start = %f row_end = %f", */
1850 /* disp->zoom_factor, l_col_start, l_col_end, l_row_start, l_row_end); */
1852 gtk_spin_button_set_value (GTK_SPIN_BUTTON
1853 (gpiv->piveval->spinbutton_colstart),
1854 (gdouble) l_col_start);
1856 gtk_spin_button_set_value (GTK_SPIN_BUTTON
1857 (gpiv->piveval->spinbutton_rowstart),
1858 (gdouble) l_row_start);
1860 gtk_spin_button_set_value (GTK_SPIN_BUTTON
1861 (gpiv->piveval->spinbutton_colend),
1862 (gdouble) l_col_end);
1865 * The last call to on_spinbutton_piv_int will update the contours of the intregs
1867 if (reset_display_intregs) {
1868 /* g_message ("release__HV:: resetting"); */
1869 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM
1870 (view_piv_display0),
1871 TRUE);
1874 gtk_spin_button_set_value (GTK_SPIN_BUTTON
1875 (gpiv->piveval->spinbutton_rowend),
1876 (gdouble) l_row_end);
1878 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1879 /* create_all_intregs (disp); */
1886 static void
1887 canvas_display_button_press__DISABLE_POINT_MS (Display *disp,
1888 gint x,
1889 gint y
1891 /*-----------------------------------------------------------------------------
1892 * Performs action on mouse button press when DISABLE_POINT_MS has
1893 * been enabled
1896 gchar *err_msg;
1897 gint index_x = 0, index_y = 0;
1898 GtkWidget *view_piv_display0 =
1899 gtk_object_get_data(GTK_OBJECT(disp->mwin),
1900 "view_piv_display0");
1903 if ( m_select == DISABLE_POINT_MS ) {
1904 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1905 search_nearest_index(disp, x, y, &index_x, &index_y,
1906 DATA_TYPE__INTREG);
1907 } else {
1908 search_nearest_index(disp, x, y, &index_x, &index_y,
1909 DATA_TYPE__PIV);
1912 disp->pida->piv_data->peak_no[index_y][index_x] = -1;
1913 disp->pida->piv_data->snr[index_y][index_x] = GPIV_SNR_DISABLE;
1915 if (disp->pida->post_par->set == TRUE) {
1916 disp->pida->piv_data->dx[index_y][index_x] =
1917 disp->pida->post_par->set_dx;
1918 disp->pida->piv_data->dy[index_y][index_x] =
1919 disp->pida->post_par->set_dx;
1921 update_vector(disp->pida, index_y, index_x);
1923 } else if ( m_select == ENABLE_AREA_MS ) {
1924 enable_col_start = x;
1925 enable_row_start = y;
1926 assert( gci_aoi == NULL);
1927 gci_aoi =
1928 gnome_canvas_item_new (gnome_canvas_root
1929 (GNOME_CANVAS(disp->canvas)),
1930 gnome_canvas_rect_get_type(),
1931 "x1", (double) x,
1932 "y1", (double) y,
1933 "x2", (double) x,
1934 "y2", (double) y,
1935 "outline_color", "yellow",
1936 "width_units", (double) THICKNESS,
1937 NULL);
1940 } else if ( m_select == DISABLE_AREA_MS) {
1941 enable_col_start = x;
1942 enable_row_start = y;
1943 assert( gci_aoi == NULL);
1944 gci_aoi =
1945 gnome_canvas_item_new (gnome_canvas_root
1946 (GNOME_CANVAS(disp->canvas)),
1947 gnome_canvas_rect_get_type(),
1948 "x1", (double) x,
1949 "y1", (double) y,
1950 "x2", (double) x,
1951 "y2", (double) y,
1952 "outline_color", "yellow",
1953 "width_units", (double) THICKNESS,
1954 NULL);
1955 } else {
1956 err_msg = _("no image or piv data");
1957 warning_gpiv(err_msg);
1964 static void
1965 set__NO_MS (GpivConsole *gpiv,
1966 Display *disp
1968 /*-----------------------------------------------------------------------------
1969 * Reset mouse selection to inactive
1972 gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON
1973 (gpiv->piveval->radiobutton_mouse_1),
1974 TRUE);
1975 cursor = gdk_cursor_new (GDK_DOTBOX);
1976 gdk_window_set_cursor (disp->mwin->window, cursor);
1981 static void
1982 search_nearest_index (Display *disp,
1983 gint x,
1984 gint y,
1985 gint *index_x,
1986 gint *index_y,
1987 gint data_type
1989 /*-----------------------------------------------------------------------------
1990 * Search nearest index belongin to x an y points
1993 gint i, j, x_min = 10e4, y_min = 10e4, dif;
1996 if (data_type == DATA_TYPE__INTREG) {
1997 for (i = 0, j = 0; i < disp->intreg->data->ny; i++) {
1998 dif = abs(y - (int) disp->intreg->data->point_y[i][j]);
1999 if (dif < y_min) {
2000 y_min = dif;
2001 *index_y = i;
2005 for (i = 0, j = 0; j < disp->intreg->data->nx; j++) {
2006 dif = abs(x - (int) disp->intreg->data->point_x[i][j]);
2007 if (dif < x_min) {
2008 x_min = dif;
2009 *index_x = j;
2014 } else if (data_type == DATA_TYPE__PIV) {
2015 for (i = 0, j = 0; i < disp->pida->piv_data->ny; i++) {
2016 dif = abs(y - (int) disp->pida->piv_data->point_y[i][j]);
2017 if (dif < y_min) {
2018 y_min = dif;
2019 *index_y = i;
2023 for (i = 0, j = 0; j < disp->pida->piv_data->nx; j++) {
2024 dif = abs(x - (int) disp->pida->piv_data->point_x[i][j]);
2025 if (dif < x_min) {
2026 x_min = dif;
2027 *index_x = j;
2031 } else {
2032 g_warning("search_nearest_index: Inavalid Data Type");
2039 static void
2040 highlight_intreg (gint index_y,
2041 gint index_x,
2042 Display *disp
2044 /*-----------------------------------------------------------------------------
2045 * Highlights first and second interrogation area's
2048 GtkWidget *view_piv_display0 =
2049 gtk_object_get_data(GTK_OBJECT(disp->mwin),
2050 "view_piv_display0");
2053 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active
2054 && index_y <= disp->intreg->data->ny
2055 && index_x <= disp->intreg->data->nx) {
2057 if (disp->intreg->gci_intreg1[disp->index_y_old][disp->index_x_old]
2058 != NULL) {
2059 gnome_canvas_item_set(disp->intreg->gci_intreg1
2060 [disp->index_y_old][disp->index_x_old],
2061 "outline_color", "red",
2062 NULL);
2065 if (disp->intreg->gci_intreg2[disp->index_y_old][disp->index_x_old]
2066 != NULL) {
2067 gnome_canvas_item_set(disp->intreg->gci_intreg2
2068 [disp->index_y_old][disp->index_x_old],
2069 "outline_color", "blue",
2070 NULL);
2073 if (disp->intreg->gci_intreg1[index_y][index_x] != NULL) {
2074 gnome_canvas_item_set(disp->intreg->gci_intreg1[index_y][index_x],
2075 "outline_color", "yellow",
2076 NULL);
2077 gnome_canvas_item_raise_to_top(disp->intreg->
2078 gci_intreg1[index_y][index_x]);
2081 if (disp->intreg->gci_intreg2[index_y][index_x] != NULL) {
2082 gnome_canvas_item_set(disp->intreg->gci_intreg2[index_y][index_x],
2083 "outline_color", "green",
2084 NULL);
2085 gnome_canvas_item_raise_to_top(disp->intreg->
2086 gci_intreg2[index_y][index_x]);
2094 static void
2095 create_msg_display_with_pivdata (GpivPivData *piv_data,
2096 gint index_y,
2097 gint index_x,
2098 gint scale
2100 /*-----------------------------------------------------------------------------
2101 * Displays message with piv data values
2105 if (scale) {
2106 if (piv_data->snr[index_y][index_x] == GPIV_SNR_NAN) {
2107 g_snprintf (msg_display, GPIV_MAX_CHARS,
2108 "xp=%3.2fmm yp=%3.2fmm %s",
2109 piv_data->point_x[index_y][index_x] * 1e3,
2110 piv_data->point_y[index_y][index_x] * 1e3,
2111 _("Disabled: not a number"));
2112 } else if (piv_data->snr[index_y][index_x] == GPIV_SNR_DISABLE) {
2113 g_snprintf (msg_display, GPIV_MAX_CHARS,
2114 "xp=%3.2fmm yp=%3.2fmm %s",
2115 piv_data->point_x[index_y][index_x] * 1e3,
2116 piv_data->point_y[index_y][index_x] * 1e3,
2117 _("Disabled manually"));
2118 } else {
2119 g_snprintf (msg_display, GPIV_MAX_CHARS,
2120 "xp=%3.2fmm yp=%3.2fmm U=%3.2fm/s V=%3.2fm/s"
2121 " snr=%3.2f peak #%d",
2122 piv_data->point_x[index_y][index_x] * 1e3,
2123 piv_data->point_y[index_y][index_x] * 1e3,
2124 piv_data->dx[index_y][index_x],
2125 piv_data->dy[index_y][index_x],
2126 piv_data->snr[index_y][index_x],
2127 piv_data->peak_no[index_y][index_x]);
2130 } else {
2131 if (piv_data->snr[index_y][index_x] == GPIV_SNR_NAN) {
2132 g_snprintf (msg_display, GPIV_MAX_CHARS,
2133 "xp=%3.0fpx yp=%3.0fpx %s",
2134 piv_data->point_x[index_y][index_x],
2135 piv_data->point_y[index_y][index_x],
2136 _("Disabled: not a number"));
2137 } else if (piv_data->snr[index_y][index_x] == GPIV_SNR_DISABLE) {
2138 g_snprintf (msg_display, GPIV_MAX_CHARS,
2139 "xp=%3.0fpx yp=%3.0fpx %s",
2140 piv_data->point_x[index_y][index_x],
2141 piv_data->point_y[index_y][index_x],
2142 _("Disabled manually"));
2143 } else {
2144 g_snprintf (msg_display, GPIV_MAX_CHARS,
2145 "xp=%3.0fpx yp=%3.0fpx dx=%3.2fpx dy=%3.2fpx"
2146 " snr=%3.2f peak #%d",
2147 piv_data->point_x[index_y][index_x],
2148 piv_data->point_y[index_y][index_x],
2149 piv_data->dx[index_y][index_x],
2150 piv_data->dy[index_y][index_x],
2151 piv_data->snr[index_y][index_x],
2152 piv_data->peak_no[index_y][index_x]);
2160 static void
2161 create_msg_display_with_scdata (GpivScalarData *sc_data,
2162 gchar *sc_type,
2163 gint index_y,
2164 gint index_x,
2165 gint scale
2167 /*-----------------------------------------------------------------------------
2168 * Displays message with scalar data values
2171 if (scale) {
2172 g_snprintf (msg_display, GPIV_MAX_CHARS,
2173 "xp=%3.2fmm yp=%3.2fmm %s=%3.2f1/s",
2174 sc_data->point_x[index_y][index_x] * 1e3,
2175 sc_data->point_y[index_y][index_x] * 1e3,
2176 sc_type,
2177 sc_data->scalar[index_y][index_x]);
2178 } else {
2179 g_snprintf (msg_display, GPIV_MAX_CHARS,
2180 "xp=%3.0fpx yp=%3.0fpx %s=%3.2f",
2181 sc_data->point_x[index_y][index_x],
2182 sc_data->point_y[index_y][index_x],
2183 sc_type,
2184 sc_data->scalar[index_y][index_x]);
2190 static void
2191 create_msg_display_with_pivscdata (GpivPivData *piv_data,
2192 GpivScalarData *sc_data,
2193 gchar *sc_type,
2194 gint index_y,
2195 gint index_x,
2196 gint scale
2198 /*-----------------------------------------------------------------------------
2199 * Displays message with piv and scalar data values
2202 if (scale) {
2203 g_snprintf (msg_display, GPIV_MAX_CHARS,
2204 "xp=%3.2fmm yp=%3.2fmm U=%3.2fm/s V=%3.2fm/s "
2205 "snr=%3.2f peak #%d %s=%3.2f1/s",
2206 piv_data->point_x[index_y][index_x] * 1e3,
2207 piv_data->point_y[index_y][index_x] * 1e3,
2208 piv_data->dx[index_y][index_x],
2209 piv_data->dy[index_y][index_x],
2210 piv_data->snr[index_y][index_x],
2211 piv_data->peak_no[index_y][index_x],
2212 sc_type,
2213 sc_data->scalar[index_y][index_x]);
2214 } else {
2215 g_snprintf (msg_display, GPIV_MAX_CHARS,
2216 "xp=%3.0fpx yp=%3.0fpx dx=%3.2fpx dy=%3.2fpx "
2217 "snr=%3.2f peak #%d %s=%3.2f",
2218 piv_data->point_x[index_y][index_x],
2219 piv_data->point_y[index_y][index_x],
2220 piv_data->dx[index_y][index_x],
2221 piv_data->dy[index_y][index_x],
2222 piv_data->snr[index_y][index_x],
2223 piv_data->peak_no[index_y][index_x],
2224 sc_type,
2225 sc_data->scalar[index_y][index_x]);
2231 static void
2232 create_line (Display *disp,
2233 gint x1,
2234 gint y1,
2235 gint x2,
2236 gint y2
2238 /*-----------------------------------------------------------------------------
2241 GnomeCanvasPoints *points;
2242 points = gnome_canvas_points_new (2);
2244 /* g_message("CREATE_LINE:: x1 = %d y1 = %d x2 = %d y2 = %d", x1, y1, x2, y2); */
2246 if (disp != NULL
2247 && gci_line == NULL) {
2249 points->coords[0] = x1;
2250 points->coords[1] = y1;
2251 points->coords[2] = x2;
2252 points->coords[3] = y2;
2253 gci_line =
2254 gnome_canvas_item_new (gnome_canvas_root(GNOME_CANVAS(disp->canvas)),
2255 gnome_canvas_line_get_type(),
2256 "points", points,
2257 "fill_color", "yellow",
2258 "width_units", (double) THICKNESS,
2259 NULL);
2261 gnome_canvas_points_free (points);
2266 static void
2267 update_line (gint x1,
2268 gint y1,
2269 gint x2,
2270 gint y2
2272 /*-----------------------------------------------------------------------------
2275 GnomeCanvasPoints *points;
2276 points = gnome_canvas_points_new (2);
2278 /* g_message("UPDATE_LINE:: x1 = %d y1 = %d x2 = %d y2 = %d", x1, y1, x2, y2); */
2280 if (gci_line != NULL) {
2282 points->coords[0] = x1;
2283 points->coords[1] = y1;
2284 points->coords[2] = x2;
2285 points->coords[3] = y2;
2287 gnome_canvas_item_set (GNOME_CANVAS_ITEM(/* disp-> */gci_line),
2288 "points", points,
2289 "fill_color", "yellow",
2290 "width_units", (double) THICKNESS,
2291 NULL);
2293 gnome_canvas_points_free (points);
2298 static void
2299 destroy_line ()
2300 /*-----------------------------------------------------------------------------
2303 if (gci_line != NULL) {
2305 gtk_object_destroy(GTK_OBJECT (gci_line));
2306 gci_line = NULL;
2312 static void
2313 create_rect (Display *disp,
2314 gint x,
2315 gint y
2317 /*-----------------------------------------------------------------------------
2320 if (disp != NULL
2321 && gci_aoi == NULL) {
2323 /* g_message("CREATE_RECT:: x = %d y = %d", x, y); */
2325 gci_aoi =
2326 gnome_canvas_item_new (gnome_canvas_root
2327 (GNOME_CANVAS(disp->canvas)),
2328 gnome_canvas_rect_get_type(),
2329 "x1", (double) x,
2330 "y1", (double) y,
2331 "x2", (double) x,
2332 "y2", (double) y,
2333 "outline_color", "yellow",
2334 "width_units", (double) THICKNESS,
2335 NULL);
2341 static void
2342 update_rect (gint x,
2343 gint y
2345 /*-----------------------------------------------------------------------------
2348 if (gci_aoi != NULL) {
2350 gnome_canvas_item_set (GNOME_CANVAS_ITEM(gci_aoi),
2351 "x2", (double) x,
2352 "y2", (double) y,
2353 NULL);
2358 static void
2359 destroy_rect ()
2360 /*-----------------------------------------------------------------------------
2363 if (gci_aoi != NULL) {
2365 gtk_object_destroy (GTK_OBJECT (gci_aoi));
2366 gci_aoi = NULL;
2371 gdouble
2372 gtk_adjustment_get_lower (GtkAdjustment *adjustment)
2374 /* g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), 0.); */
2376 return adjustment->lower;
2381 static void
2382 pane_canvas (Display *disp,
2383 gfloat x,
2384 gfloat y
2386 /*-----------------------------------------------------------------------------
2389 pane_canvas_x (disp, x);
2390 pane_canvas_y (disp, y);
2395 static void
2396 pane_canvas_x (Display *disp,
2397 gfloat x
2399 /*-----------------------------------------------------------------------------
2402 GtkAdjustment *adj = GTK_ADJUSTMENT (disp->hadj);
2403 /* gdouble adj_value = gtk_adjustment_get_value */
2404 (GTK_ADJUSTMENT (disp->hadj));
2405 gdouble diff;
2406 gdouble adj_new;
2408 diff = x - disp->xgrab_first;
2409 /* g_message ("PANE_CANVAS_X:: x = %f x_first = %f => diff = %f", */
2410 /* x, disp->xgrab_first, diff); */
2412 adj_new = (adj->value - diff);
2413 /* g_message ("PANE_CANVAS_X:: value = %f lower = %f upper = %f page_s = %f => adj_new = %f", */
2414 /* adj->value, adj->lower, adj->upper, adj->page_size, adj_new); */
2416 if (adj_new >= adj->lower
2417 && adj_new < adj->upper - adj->page_size) {
2418 /* g_message ("PANE_CANVAS_X:: passed if ()"); */
2420 gtk_adjustment_set_value (GTK_ADJUSTMENT (disp->hadj),
2421 adj_new
2429 static void
2430 pane_canvas_y (Display *disp,
2431 gfloat y
2433 /*-----------------------------------------------------------------------------
2436 GtkAdjustment *adj = GTK_ADJUSTMENT (disp->vadj);
2437 /* gdouble adj_value = gtk_adjustment_get_value */
2438 /* (GTK_ADJUSTMENT (disp->vadj)); */
2439 gdouble diff;
2440 gdouble adj_new;
2442 diff = y - disp->ygrab_first;
2443 adj_new = (adj->value - diff);
2444 if (adj_new >= 0
2445 && adj_new < adj->upper - adj->page_size) {
2446 gtk_adjustment_set_value (GTK_ADJUSTMENT (disp->vadj),
2447 adj_new