updated copyright statement
[gpiv.git] / src / display_event.c
blob31db452f53fee82cfb2dd9df57c0dcf4b16c4b36
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, 2007, 2008
9 Gerber van der Graaf
11 This file is part of gpiv.
13 Gpiv is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2, or (at your option)
16 any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 ----------------------------------------------------------------------*/
30 #include "gpiv_gui.h"
31 #include "display.h"
32 #include "display_zoom.h"
33 #include "piveval_interrogate.h"
35 GdkCursor *cursor;
37 static void
38 canvas_display_motion_notify__NO_MS (Display *disp,
39 gint x,
40 gint y,
41 gint *index_x,
42 gint *index_y
45 static void
46 canvas_display_button_release__AOI_MS (Display *disp,
47 GpivConsole *gpiv,
48 GtkWidget *view_piv_display0,
49 gdouble x,
50 gdouble y
53 static void
54 canvas_display_motion_notify__DRAGINT_MS (Display *disp,
55 gint x,
56 gint y,
57 gint *index_x,
58 gint *index_y
61 static void
62 canvas_display_motion_notify__SINGLE_POINT_MS (Display *disp,
63 gint x,
64 gint y
68 static char *
69 canvas_display_button_press__SINGLE_AREA_MS (GpivConsole *gpiv,
70 Display *disp,
71 gint x,
72 gint y
75 static char *
76 canvas_display_button_release__SINGLE_AREA_MS (GpivConsole *gpiv,
77 Display *disp,
78 gdouble x,
79 gdouble y
82 static void
83 canvas_display_button_press__SINGLE_POINT_MS (GpivConsole *gpiv,
84 Display *disp,
85 gint x,
86 gint y
89 static void
90 canvas_display_button_release__HVLINE_MS (Display *disp,
91 GpivConsole *gpiv,
92 GtkWidget *view_piv_display0,
93 gdouble x,
94 gdouble y
96 static void
97 canvas_display_button_press__DISABLE_POINT_MS (Display *disp,
98 gint x,
99 gint y
101 static void
102 set__NO_MS (GpivConsole *gpiv,
103 Display *disp
106 static void
107 search_nearest_index (Display *disp,
108 gint x,
109 gint y,
110 gint *index_x,
111 gint *index_y,
112 gint data_type
115 static void
116 highlight_intreg (gint index_y,
117 gint index_x,
118 Display *disp
121 static void
122 create_msg_display_with_pivdata (GpivPivData *piv_data,
123 gint index_y,
124 gint index_x,
125 gint scale
128 static void
129 create_msg_display_with_scdata (GpivScalarData *sc_data,
130 gchar *sc_type,
131 gint index_y,
132 gint index_x,
133 gint scale
135 static void
136 create_msg_display_with_pivscdata (GpivPivData *piv_data,
137 GpivScalarData *sc_data,
138 gchar *sc_type,
139 gint index_y,
140 gint index_x,
141 gint scale
144 static void
145 create_line (Display *disp,
146 gint x1,
147 gint y1,
148 gint x2,
149 gint y2
152 static void
153 update_line (gint x1,
154 gint y1,
155 gint x2,
156 gint y2
159 static void
160 destroy_line ();
162 static void
163 update_rect (gint x,
164 gint y
167 static void
168 create_rect (Display *disp,
169 gint x,
170 gint y
173 static void
174 destroy_rect ();
176 static void
177 pane_canvas (Display *disp,
178 gfloat x,
179 gfloat y
182 static void
183 pane_canvas_x (Display *disp,
184 gfloat x
187 static void
188 pane_canvas_y (Display *disp,
189 gfloat y
193 * Public display functions
195 gboolean
196 canvas_display_enter_notify (GtkWidget *widget,
197 GdkEventMotion *event,
198 gpointer data
200 /*-----------------------------------------------------------------------------
203 Display *disp = gtk_object_get_data(GTK_OBJECT(widget), "disp");
204 GtkWidget *view_piv_display0 =
205 gtk_object_get_data(GTK_OBJECT(disp->mwin),
206 "view_piv_display0");
209 disp->index_x_old = 0;
210 disp->index_y_old = 0;
211 disp->index_old = FALSE;
214 if (m_select == NO_MS) {
215 cursor = gdk_cursor_new(GDK_DOTBOX);
217 } else if (m_select == SINGLE_AREA_MS
218 || m_select == ENABLE_POINT_MS
219 || m_select == DISABLE_POINT_MS) {
220 cursor = gdk_cursor_new(GDK_CROSSHAIR);
224 } else if ( m_select == DRAG_MS ) {
225 cursor = gdk_cursor_new(GDK_CROSS);
229 } else if (m_select == SINGLE_POINT_MS
230 || m_select == V_LINE_MS
231 || m_select == H_LINE_MS
233 if (m_select == V_LINE_MS) {
234 cursor = gdk_cursor_new (GDK_SB_V_DOUBLE_ARROW);
236 if (m_select == H_LINE_MS) {
237 cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW);
240 if (m_select == SINGLE_POINT_MS) {
241 cursor = gdk_cursor_new(GDK_CROSS);
245 if (display_act->pida->exist_piv && disp->display_piv) {
246 hide_all_vectors(display_act->pida);
249 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
250 hide_all_intregs(disp);
255 } else if (m_select == AOI_MS
256 || m_select == ENABLE_AREA_MS
257 || m_select == DISABLE_AREA_MS) {
258 cursor = gdk_cursor_new(GDK_CROSSHAIR);
260 if (m_select == AOI_MS) {
261 if (display_act->pida->exist_piv && disp->display_piv) {
262 hide_all_vectors(display_act->pida);
265 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
266 hide_all_intregs(disp);
272 } else if (m_select == SPANLENGTH_MS
273 || m_select == V_SPANLENGTH_MS
274 || m_select == H_SPANLENGTH_MS
276 cursor = gdk_cursor_new(GDK_CROSS);
279 gdk_window_set_cursor(disp->mwin->window, cursor);
282 return TRUE;
287 gboolean
288 canvas_display_motion_notify (GtkWidget *widget,
289 GdkEventMotion *event,
290 gpointer data
292 /*-----------------------------------------------------------------------------
295 Display *disp = gtk_object_get_data(GTK_OBJECT(widget), "disp");
296 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(widget), "gpiv");
297 GtkAdjustment *hadj = GTK_ADJUSTMENT (disp->hadj);
298 GtkAdjustment *vadj = GTK_ADJUSTMENT (disp->hadj);
300 gdouble x, y;
301 gint x_grab, y_grab;
302 gint index_y = 0, index_x = 0;
304 GdkModifierType state;
305 GnomeCanvasPoints *points;
308 points = gnome_canvas_points_new(2);
310 if (event->is_hint) {
311 gdk_window_get_pointer (event->window, &x_grab, &y_grab, &state);
313 x = x_grab;
314 y = y_grab;
316 } else {
317 x = event->x;
318 y = event->y;
320 state = event->state;
324 /* g_message ("canvas_display_motion_notify:: x = %f y = %f x/zoom = %f y/zoom = %f", */
325 /* x, y, x / disp->zoom_factor, y / disp->zoom_factor); */
327 /* if (x >= hadj->value && x < hadj->value + hadj->page_size */
328 /* && y >= vadj->value && y < vadj->value + vadj->page_size) { */
331 if (x >= 0 && x < disp->img->image->header->ncolumns * disp->zoom_factor
332 && y >= 0 && y < disp->img->image->header->nrows * disp->zoom_factor) {
335 * display particle displacements / velocities and its attributes,
337 if (m_select == NO_MS
338 || m_select == SINGLE_AREA_MS
339 || m_select == DRAG_MS
340 || m_select == ENABLE_POINT_MS
341 || m_select == DISABLE_POINT_MS) {
345 * display locations of interrogation area's and estimators,
346 * only display locations of interrogation area's,
347 * or nothing
350 canvas_display_motion_notify__NO_MS (disp,
351 (gint) (x / disp->zoom_factor),
352 (gint) (y / disp->zoom_factor),
353 &index_x,
354 &index_y);
357 * Pane (moving) the canvas. Identic effect as moving the scroll bars.
359 if (m_select == NO_MS) {
360 if (state & GDK_BUTTON1_MASK) {
361 pane_canvas (disp, x, y);
366 if ( m_select == DRAG_MS ) {
367 canvas_display_motion_notify__DRAGINT_MS (disp,
368 (gint) (x / disp->zoom_factor),
369 (gint) (y / disp->zoom_factor),
370 &index_x,
371 &index_y);
374 disp->index_x_old = index_x;
375 disp->index_y_old = index_y;
379 * Only displays pointer position
381 } else if (m_select == AOI_MS
382 || m_select == ENABLE_AREA_MS
383 || m_select == DISABLE_AREA_MS ) {
384 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d px y=%d px",
385 (gint) (x / disp->zoom_factor),
386 (gint) (y / disp->zoom_factor));
389 * Update the drawing of the rectangle
391 if (state & GDK_BUTTON1_MASK) {
392 if (gci_aoi != NULL) {
393 update_rect((gint) (x / disp->zoom_factor),
394 (gint) (y / disp->zoom_factor));
400 } else if ( m_select == SINGLE_POINT_MS) {
401 canvas_display_motion_notify__SINGLE_POINT_MS (disp,
402 (gint) x / disp->zoom_factor,
403 (gint) y / disp->zoom_factor);
408 * Update a vertical line
410 } else if (m_select == V_LINE_MS) {
411 if (state & GDK_BUTTON1_MASK) {
412 g_snprintf (msg_display, GPIV_MAX_CHARS, "x=%d px y=%d px",
413 (gint) (disp->xgrab_first / disp->zoom_factor),
414 (gint) (y / disp->zoom_factor));
415 if ( gci_line != NULL ) {
416 update_line ((gint) (disp->xgrab_first / disp->zoom_factor) ,
417 (gint) (disp->ygrab_first / disp->zoom_factor),
418 (gint) (disp->xgrab_first / disp->zoom_factor),
419 (gint) (y / disp->zoom_factor));
421 } else {
422 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d px y=%d px",
423 (gint) (x / disp->zoom_factor),
424 (gint) (y / disp->zoom_factor));
430 * Update a horizontal line
432 } else if (m_select == H_LINE_MS) {
433 if (state & GDK_BUTTON1_MASK) {
434 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d y=%d",
435 (gint) (x / disp->zoom_factor),
436 (gint) (disp->ygrab_first / disp->zoom_factor));
437 if (gci_line != NULL ) {
438 update_line ((gint) (disp->xgrab_first / disp->zoom_factor),
439 (gint) (disp->ygrab_first / disp->zoom_factor),
440 (gint) (x / disp->zoom_factor),
441 (gint) (disp->ygrab_first / disp->zoom_factor));
443 } else {
444 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d px y=%d px",
445 (gint) (x / disp->zoom_factor),
446 (gint) (y / disp->zoom_factor));
451 } else if (m_select == SPANLENGTH_MS) {
452 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d px y=%d px",
453 (gint) (x / disp->zoom_factor),
454 (gint) (y / disp->zoom_factor));
456 if (state & GDK_BUTTON1_MASK && gci_line != NULL ) {
457 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d y=%d",
458 (gint) (x / disp->zoom_factor),
459 (gint) (y / disp->zoom_factor));
460 update_line ((gint) (disp->xgrab_first / disp->zoom_factor),
461 (gint) (disp->ygrab_first / disp->zoom_factor),
462 (gint) (x / disp->zoom_factor),
463 (gint) (y / disp->zoom_factor));
466 } else if (m_select == V_SPANLENGTH_MS) {
467 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d px y=%d px",
468 (gint) (x / disp->zoom_factor),
469 (gint) (y / disp->zoom_factor));
471 if (state & GDK_BUTTON1_MASK && gci_line != NULL ) {
472 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d y=%d",
473 (gint) (disp->xgrab_first / disp->zoom_factor),
474 (gint) (y / disp->zoom_factor));
475 update_line ((gint) (disp->xgrab_first / disp->zoom_factor),
476 (gint) (disp->ygrab_first / disp->zoom_factor),
477 (gint) (disp->xgrab_first / disp->zoom_factor),
478 (gint) (y / disp->zoom_factor));
481 } else if (m_select == H_SPANLENGTH_MS) {
482 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d px y=%d px",
483 (gint) (x / disp->zoom_factor),
484 (gint) (y / disp->zoom_factor));
486 if (state & GDK_BUTTON1_MASK && gci_line != NULL ) {
487 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d y=%d",
488 (gint) (x / disp->zoom_factor),
489 (gint) (disp->ygrab_first / disp->zoom_factor));
490 update_line ((gint) (disp->xgrab_first / disp->zoom_factor),
491 (gint) (disp->ygrab_first / disp->zoom_factor),
492 (gint) (x / disp->zoom_factor),
493 (gint) (disp->ygrab_first / disp->zoom_factor));
500 gnome_appbar_push(GNOME_APPBAR(disp->appbar), msg_display);
501 gnome_appbar_push(GNOME_APPBAR(gpiv->appbar), msg_display);
506 /* } else { */
507 /* g_message("canvas_display_motion_notify: out of image borders"); */
510 gnome_canvas_points_free(points);
511 return TRUE;
516 gboolean
517 canvas_display_button_press (GtkWidget *widget,
518 GdkEventButton *event,
519 gpointer data
521 /*-----------------------------------------------------------------------------
524 Display *disp = gtk_object_get_data(GTK_OBJECT(widget), "disp");
525 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(widget), "gpiv");
526 gdouble x, y;
527 gint x_grab, y_grab;
528 gint index_x = 0, index_y = 0;
529 GdkModifierType state;
530 GnomeCanvasPoints *points;
531 GtkWidget *view_piv_display0 =
532 gtk_object_get_data(GTK_OBJECT(disp->mwin),
533 "view_piv_display0");
536 points = gnome_canvas_points_new(2);
537 GtkMenu *menu = GTK_MENU (disp->display_popupmenu);
539 gdk_window_get_pointer(event->window, &x_grab, &y_grab, &state);
540 x = x_grab ;
541 y = y_grab ;
545 if (event->button == 1) {
546 disp->xgrab_first = x;
547 disp->ygrab_first = y;
548 /* g_message ("canvas_display_button_press:: xgrab_first = %f ygrab_first = %f", */
549 /* disp->xgrab_first, disp->ygrab_first); */
551 * No mouse select
553 if (m_select == NO_MS) {
554 cursor = gdk_cursor_new (GDK_FLEUR );
555 gdk_window_set_cursor (disp->mwin->window, cursor);
556 /* g_message ("canvas_display_button_press:: x_grab = %d y_grab = %d", */
557 /* x_grab, y_grab); */
558 /* g_message ("CANVAS_DISPLAY_BUTTON_PRESS:: x = %f y = %f", x, y); */
562 * select Area Of Interest
564 } else if (m_select == AOI_MS) {
566 * storige of original AOI
568 disp->intreg->col_start_old = disp->pida->piv_par->col_start;
569 disp->intreg->row_start_old = disp->pida->piv_par->row_start;
571 /* g_message ("CANVAS_DISPLAY_BUTTON_PRESS (AOI):: x_grab = %d y_grab = %d", */
572 /* x_grab, y_grab); */
573 create_rect (disp,
574 disp->xgrab_first / disp->zoom_factor,
575 disp->ygrab_first / disp->zoom_factor);
578 * select at single interrogation area
580 } else if ((m_select == SINGLE_AREA_MS || m_select == DRAG_MS) &&
581 disp->img->exist_img) {
582 canvas_display_button_press__SINGLE_AREA_MS (gpiv, disp,
583 x / disp->zoom_factor,
584 y / disp->zoom_factor);
587 * select a single point
589 } else if (m_select == SINGLE_POINT_MS && disp->img->exist_img) {
590 canvas_display_button_press__SINGLE_POINT_MS (gpiv, disp,
591 x / disp->zoom_factor,
592 y / disp->zoom_factor);
596 * select a vertical line
598 } else if (m_select == V_LINE_MS && display_act->img->exist_img) {
599 /* g_message ("CANVAS_DISPLAY_BUTTON_PRESS (V_LINE_MS) 11:: x_grab = %d y_grab = %d", */
600 /* x_grab, y_grab); */
601 if (gci_line != NULL) destroy_line();
602 create_line (disp,
603 disp->xgrab_first / disp->zoom_factor,
604 disp->ygrab_first / disp->zoom_factor,
605 disp->xgrab_first / disp->zoom_factor,
606 disp->ygrab_first / disp->zoom_factor);
610 * select a horizontal line
612 } else if (m_select == H_LINE_MS && disp->img->exist_img) {
613 /* g_message ("CANVAS_DISPLAY_BUTTON_PRESS (H_LINE_MS) 1:: x_grab = %d y_grab = %d", */
614 /* x_grab, y_grab); */
615 if (gci_line != NULL) destroy_line();
616 create_line (disp,
617 disp->xgrab_first / disp->zoom_factor,
618 disp->ygrab_first / disp->zoom_factor,
619 disp->xgrab_first / disp->zoom_factor,
620 disp->ygrab_first / disp->zoom_factor);
622 } else if ( m_select == ENABLE_POINT_MS ) {
624 * Only active with piv data
626 if (disp->pida->exist_piv && disp->display_piv
627 /* && GTK_CHECK_MENU_ITEM(view_piv_display0)->active */
629 search_nearest_index (disp, x, y, &index_x, &index_y,
630 /* DATA_TYPE__INTREG); */
631 DATA_TYPE__PIV);
632 disp->pida->piv_data->peak_no[index_y][index_x] = 1;
633 update_vector (disp->pida, index_y, index_x);
638 * Enabling and disabling only active with piv data
640 } else if ((m_select == DISABLE_POINT_MS
641 || m_select == ENABLE_AREA_MS
642 || m_select == DISABLE_AREA_MS)
643 && disp->pida->exist_piv && disp->display_piv) {
644 canvas_display_button_press__DISABLE_POINT_MS (disp, x, y);
647 } else if (m_select == SPANLENGTH_MS
648 && disp->img->exist_img) {
649 if (gci_line != NULL) destroy_line();
650 create_line (disp,
651 disp->xgrab_first / disp->zoom_factor,
652 disp->ygrab_first / disp->zoom_factor,
653 disp->xgrab_first / disp->zoom_factor,
654 disp->ygrab_first / disp->zoom_factor);
658 } else if (m_select == V_SPANLENGTH_MS
659 && disp->img->exist_img) {
660 if (gci_line != NULL) destroy_line();
661 create_line (disp,
662 disp->xgrab_first / disp->zoom_factor,
663 disp->ygrab_first / disp->zoom_factor,
664 disp->xgrab_first / disp->zoom_factor,
665 disp->ygrab_first / disp->zoom_factor);
669 } else if (m_select == H_SPANLENGTH_MS
670 && disp->img->exist_img) {
671 if (gci_line != NULL) destroy_line();
672 create_line (disp,
673 disp->xgrab_first / disp->zoom_factor,
674 disp->ygrab_first / disp->zoom_factor,
675 disp->xgrab_first / disp->zoom_factor,
676 disp->ygrab_first / disp->zoom_factor);
679 } else {
680 g_warning(_("canvas_display_button_press: should not arrive here; m_select=%d"),
681 m_select);
685 } else if (event->button == 3) {
686 gtk_menu_popup (menu, NULL, NULL, NULL, NULL,
687 event->button, event->time);
691 gnome_canvas_points_free(points);
692 return TRUE;
696 gboolean
697 canvas_display_button_release (GtkWidget *widget,
698 GdkEventButton *event,
699 gpointer data
701 /*-----------------------------------------------------------------------------
704 Display *disp = gtk_object_get_data(GTK_OBJECT(widget), "disp");
705 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(widget), "gpiv");
706 GtkWidget *view_piv_display0 =
707 gtk_object_get_data(GTK_OBJECT(disp->mwin),
708 "view_piv_display0");
709 gdouble x, y;
710 gint x_grab, y_grab;
711 gint i, j;
712 GdkModifierType state;
715 shift_pressed = event->state & GDK_SHIFT_MASK;
716 gdk_window_get_pointer (event->window, &x_grab, &y_grab, &state);
718 /* BUGFIX: repair for different mouse selections */
719 x = x_grab;
720 y = y_grab;
723 /* g_message ("canvas_display_button_release:: x = %f y = %f", x, y); */
724 if (event->button == 1) {
726 if (m_select == AOI_MS && gci_aoi != NULL) {
727 canvas_display_button_release__AOI_MS (disp, gpiv,
728 view_piv_display0,
729 (gdouble) (x),
730 (gdouble) (y));
734 } else if ((m_select == V_LINE_MS || m_select == H_LINE_MS)
735 && disp->img->exist_img) {
736 /* g_message ("CANVAS_DISPLAY_BUTTON_RELEASE (HV_LINE):: x_grab = %d y_grab = %d", */
737 /* x_grab, y_grab); */
738 canvas_display_button_release__HVLINE_MS (disp, gpiv,
739 view_piv_display0,
740 (gdouble) (x),
741 (gdouble) (y));
746 * analyse at single interrogation area
748 } else if ((m_select == SINGLE_AREA_MS || m_select == DRAG_MS) &&
749 disp->img->exist_img) {
750 canvas_display_button_release__SINGLE_AREA_MS(gpiv, disp,
751 (gdouble) (x),
752 (gdouble) (y));
756 } else if (m_select == ENABLE_AREA_MS && gci_aoi != NULL) {
757 enable_col_end = x;
758 enable_row_end = y;
759 if (disp->pida->exist_piv) {
760 for (i = 0; i < disp->pida->piv_data->ny; i++) {
761 for (j = 0; j < disp->pida->piv_data->nx; j++) {
762 if (disp->pida->piv_data->point_x[i][j] >=
763 enable_col_start
764 && disp->pida->piv_data->point_x[i][j] <
765 enable_col_end
766 && disp->pida->piv_data->point_y[i][j] >=
767 enable_row_start
768 && disp->pida->piv_data->point_y[i][j] <
769 enable_row_end) {
770 disp->pida->piv_data->peak_no[i][j] = 1;
771 if (disp->display_piv)
772 update_vector(disp->pida, i, j);
778 if (gci_aoi != NULL) destroy_rect();
782 } else if (m_select == DISABLE_AREA_MS && gci_aoi != NULL) {
783 enable_col_end = x;
784 enable_row_end = y;
785 if (disp->pida->exist_piv) {
786 for (i = 0; i < disp->pida->piv_data->ny; i++) {
787 for (j = 0; j < disp->pida->piv_data->nx; j++) {
788 if (disp->pida->piv_data->point_x[i][j] >=
789 enable_col_start
790 && disp->pida->piv_data->point_x[i][j] <
791 enable_col_end
792 && disp->pida->piv_data->point_y[i][j] >=
793 enable_row_start
794 && disp->pida->piv_data->point_y[i][j] <
795 enable_row_end) {
796 disp->pida->piv_data->peak_no[i][j] = -1;
797 disp->pida->piv_data->snr[i][j] = GPIV_SNR_DISABLE;
799 if (disp->pida->post_par->set == TRUE) {
800 disp->pida->piv_data->dx[i][j] =
801 disp->pida->post_par->set_dx;
802 disp->pida->piv_data->dy[i][j] =
803 disp->pida->post_par->set_dx;
806 if (disp->display_piv)
807 update_vector(disp->pida, i, j);
813 if (gci_aoi != NULL) destroy_rect();
817 } else if (m_select == SPANLENGTH_MS
818 && disp->img->exist_img
819 && gci_line != NULL
821 gfloat hdist = abs ((x - disp->xgrab_first) / disp->zoom_factor);
822 gfloat vdist = abs ((y - disp->ygrab_first) / disp->zoom_factor);
824 gpiv_var->img_span_px = sqrt (hdist * hdist + vdist * vdist);
825 if (gci_line != NULL) destroy_line ();
826 gtk_spin_button_set_value (GTK_SPIN_BUTTON
827 (gpiv->imgh->spinbutton_sscale_px),
828 gpiv_var->img_span_px
833 } else if (m_select == V_SPANLENGTH_MS
834 && disp->img->exist_img
835 && gci_line != NULL
837 gpiv_var->img_span_px = abs ((y - disp->ygrab_first) / disp->zoom_factor);
838 if (gci_line != NULL) destroy_line ();
839 gtk_spin_button_set_value (GTK_SPIN_BUTTON
840 (gpiv->imgh->spinbutton_sscale_px),
841 gpiv_var->img_span_px);
845 } else if (m_select == H_SPANLENGTH_MS
846 && disp->img->exist_img
847 && gci_line != NULL
849 gpiv_var->img_span_px = abs ((x - disp->xgrab_first) / disp->zoom_factor);
850 if (gci_line != NULL) destroy_line ();
851 gtk_spin_button_set_value (GTK_SPIN_BUTTON
852 (gpiv->imgh->spinbutton_sscale_px),
853 gpiv_var->img_span_px);
858 * No action
860 } else if (m_select == GPIV_NONE
861 || m_select == SINGLE_POINT_MS
862 || m_select == ENABLE_POINT_MS
863 || m_select == DISABLE_POINT_MS
865 cursor = gdk_cursor_new (GDK_DOTBOX);
866 gdk_window_set_cursor (disp->mwin->window, cursor);
868 } else {
869 g_warning(_("canvas_display_button_release: should not arrive here; m_select=%d"),
870 m_select);
874 return TRUE;
879 gboolean
880 canvas_display_leave_notify (GtkWidget *widget,
881 GdkEventMotion *event,
882 gpointer data
884 /*-----------------------------------------------------------------------------
887 Display *disp = gtk_object_get_data(GTK_OBJECT(widget), "disp");
888 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(widget), "gpiv");
889 GtkWidget *view_piv_display0 =
890 gtk_object_get_data(GTK_OBJECT(disp->mwin),
891 "view_piv_display0");
894 gnome_appbar_push(GNOME_APPBAR(disp->appbar),
895 disp->msg_display_default);
896 gnome_appbar_push(GNOME_APPBAR(gpiv->appbar), msg_default);
899 if (m_select == SINGLE_POINT_MS
900 && GTK_CHECK_MENU_ITEM(view_piv_display0)->active
902 if (!disp->intreg->exist_int) {
903 update_intreg1(disp, m_select_index_y, m_select_index_x);
904 update_intreg2(disp, m_select_index_y, m_select_index_x);
907 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
908 show_all_intregs(disp);
912 if (disp->pida->exist_piv && disp->display_piv) {
913 show_all_vectors(disp->pida);
917 } else if (m_select == DRAG_MS) {
918 if (!disp->intreg->exist_int) {
919 update_intreg1(disp, disp->index_y_old, disp->index_x_old);
920 update_intreg2(disp, disp->index_y_old, disp->index_x_old);
923 } else if (m_select == SINGLE_AREA_MS && disp->intreg->exist_int) {
924 if (!disp->intreg->exist_int) {
925 update_intreg1(disp, 0, 0);
926 update_intreg2(disp, 0, 0);
930 } else if (m_select == AOI_MS
931 || m_select == V_LINE_MS
932 || m_select == H_LINE_MS) {
933 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
934 show_all_intregs(disp);
937 if (disp->pida->exist_piv && disp->display_piv) {
938 show_all_vectors(disp->pida);
941 if (gci_line != NULL) {
942 gtk_object_destroy(GTK_OBJECT(gci_line));
943 gci_line = NULL;
950 if (GDK_BUTTON1_MASK) {
952 * Cancel AOI_MS selection
954 if (m_select == AOI_MS) {
955 if (gci_aoi != NULL) {
956 disp->pida->piv_par->col_start = disp->intreg->col_start_old;
957 disp->pida->piv_par->row_start = disp->intreg->row_start_old;
958 gtk_spin_button_set_value(GTK_SPIN_BUTTON
959 (gpiv->piveval->spinbutton_colstart),
960 disp->pida->piv_par->col_start);
961 gtk_spin_button_set_value(GTK_SPIN_BUTTON
962 (gpiv->piveval->spinbutton_rowstart),
963 disp->pida->piv_par->row_start);
964 if (gci_aoi != NULL) destroy_rect();
967 /* show_all_intregs(disp); */
969 } else if ( m_select == ENABLE_AREA_MS
970 || m_select == DISABLE_AREA_MS) {
971 enable_col_start = 0;
972 enable_row_start = 0;
973 enable_col_end = 0;
974 enable_row_end = 0;
975 if (gci_aoi != NULL) destroy_rect();
978 * Cancel V_LINE_MS, LINE_MS selection
979 * (V_, H_) SPANLENGTH_MS
981 } else if (m_select == V_LINE_MS
982 || m_select == H_LINE_MS
983 || m_select == SPANLENGTH_MS
984 || m_select == V_SPANLENGTH_MS
985 || m_select == H_SPANLENGTH_MS
987 if (gci_line != NULL) destroy_line();
995 * General
997 if (cursor != NULL) {
998 gdk_cursor_destroy(cursor);
999 cursor = NULL;
1002 if (disp->intreg->gci_intreg2[disp->index_y_old][disp->index_x_old]
1003 != NULL) {
1004 update_intreg2(disp, disp->index_y_old, disp->index_x_old);
1007 if (disp->intreg->gci_intreg1[disp->index_y_old][disp->index_x_old]
1008 != NULL) {
1009 update_intreg1(disp, disp->index_y_old, disp->index_x_old);
1012 disp->index_x_old = 0;
1013 disp->index_y_old = 0;
1016 return TRUE;
1020 * Private display functions
1024 static void
1025 canvas_display_motion_notify__NO_MS (Display *disp,
1026 gint x,
1027 gint y,
1028 gint *index_x,
1029 gint *index_y
1031 /*-----------------------------------------------------------------------------
1032 * Moves pointer over the display canvas if no mouse selection (NO_MS) is set
1035 GpivPivData *piv_data = disp->pida->piv_data;
1036 GpivPivData *piv_data_scaled = disp->pida->piv_data_scaled;
1037 GpivScalarData *vor_data = disp->pida->vor_data;
1038 GpivScalarData *vor_data_scaled = disp->pida->vor_data_scaled;
1039 GpivScalarData *sstrain_data = disp->pida->sstrain_data;
1040 GpivScalarData *sstrain_data_scaled = disp->pida->sstrain_data_scaled;
1041 GpivScalarData *nstrain_data = disp->pida->nstrain_data;
1042 GpivScalarData *nstrain_data_scaled = disp->pida->nstrain_data_scaled;
1043 GtkWidget *view_piv_display0 =
1044 gtk_object_get_data(GTK_OBJECT(disp->mwin),
1045 "view_piv_display0");
1048 *index_y = 0;
1049 *index_x = 0;
1051 if ((disp->pida->exist_piv && disp->display_piv
1052 && GTK_CHECK_MENU_ITEM(view_piv_display0)->active
1053 && piv_data->ny == disp->intreg->data->ny
1054 && piv_data->nx == disp->intreg->data->nx
1055 && piv_data->point_y[0][0] == disp->intreg->data->point_y[0][0]
1056 && piv_data->point_x[0][0] == disp->intreg->data->point_x[0][0]
1057 && piv_data->point_y[piv_data->ny - 1][piv_data->nx - 1] ==
1058 disp->intreg->data->point_y[disp->intreg->data->ny - 1]
1059 [disp->intreg->data->nx - 1]
1060 && piv_data->point_x[piv_data->ny - 1][piv_data->nx - 1] ==
1061 disp->intreg->data->point_x[disp->intreg->data->ny - 1]
1062 [disp->intreg->data->nx - 1] )
1063 || (disp->pida->exist_piv && disp->display_piv
1064 && !GTK_CHECK_MENU_ITEM(view_piv_display0)->active)
1067 search_nearest_index(disp, x, y, index_x, index_y, DATA_TYPE__PIV);
1068 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1069 highlight_intreg(*index_y, *index_x, disp);
1073 if (disp->pida->exist_vor
1074 && disp->display_scalar == SHOW_SC_VORTICITY) {
1075 if (disp->pida->scaled_piv) {
1076 create_msg_display_with_pivscdata (piv_data_scaled,
1077 vor_data_scaled,
1078 "vor",
1079 *index_y,
1080 *index_x,
1081 disp->pida->scaled_piv);
1082 } else {
1083 create_msg_display_with_pivscdata (piv_data,
1084 vor_data,
1085 "vor",
1086 *index_y,
1087 *index_x,
1088 disp->pida->scaled_piv);
1091 } else if (disp->pida->exist_sstrain
1092 && disp->display_scalar == SHOW_SC_SSTRAIN) {
1093 if (disp->pida->scaled_piv) {
1094 create_msg_display_with_pivscdata (piv_data_scaled,
1095 sstrain_data_scaled,
1096 "sstrain",
1097 *index_y,
1098 *index_x,
1099 disp->pida->scaled_piv);
1100 } else {
1101 create_msg_display_with_pivscdata (piv_data,
1102 sstrain_data,
1103 "sstrain",
1104 *index_y,
1105 *index_x,
1106 disp->pida->scaled_piv);
1109 } else if (disp->pida->exist_nstrain
1110 && disp->display_scalar == SHOW_SC_NSTRAIN) {
1112 if (disp->pida->scaled_piv) {
1113 create_msg_display_with_pivscdata (piv_data_scaled,
1114 nstrain_data_scaled,
1115 "nstrain",
1116 *index_y,
1117 *index_x,
1118 disp->pida->scaled_piv);
1119 } else {
1120 create_msg_display_with_pivscdata (piv_data,
1121 nstrain_data,
1122 "nstrain",
1123 *index_y,
1124 *index_x,
1125 disp->pida->scaled_piv);
1128 } else {
1129 if (disp->pida->scaled_piv) {
1130 create_msg_display_with_pivdata (piv_data_scaled,
1131 *index_y,
1132 *index_x,
1133 disp->pida->scaled_piv);
1135 } else {
1136 create_msg_display_with_pivdata (piv_data,
1137 *index_y,
1138 *index_x,
1139 disp->pida->scaled_piv);
1145 * piv data exist, but are not displayed
1146 * displays eventually piv-derived scalar data
1148 } else if ((disp->pida->exist_piv
1149 && !disp->display_piv
1150 && GTK_CHECK_MENU_ITEM(view_piv_display0)->active
1151 && piv_data->ny == disp->intreg->data->ny
1152 && piv_data->nx == disp->intreg->data->nx
1153 && piv_data->point_y[0][0] == disp->intreg->data->point_y[0][0]
1154 && piv_data->point_x[0][0] == disp->intreg->data->point_x[0][0]
1155 && piv_data->point_y[piv_data->ny - 1][piv_data->nx - 1] ==
1156 disp->intreg->data->point_y[disp->intreg->data->ny - 1]
1157 [disp->intreg->data->nx - 1]
1158 && piv_data->point_x[piv_data->ny - 1][piv_data->nx - 1] ==
1159 disp->intreg->data->point_x[disp->intreg->data->ny - 1]
1160 [disp->intreg->data->nx - 1]
1161 && ((disp->pida->exist_vor
1162 && disp->display_scalar == SHOW_SC_VORTICITY)
1163 || (disp->pida->exist_sstrain
1164 && disp->display_scalar == SHOW_SC_SSTRAIN)
1165 || (disp->pida->exist_nstrain &&
1166 disp->display_scalar == SHOW_SC_NSTRAIN))
1168 || (disp->pida->exist_piv
1169 && !disp->display_piv
1170 && !GTK_CHECK_MENU_ITEM(view_piv_display0)->active
1171 && ((disp->pida->exist_vor
1172 && disp->display_scalar == SHOW_SC_VORTICITY)
1173 || (disp->pida->exist_sstrain
1174 && disp->display_scalar == SHOW_SC_SSTRAIN)
1175 || (disp->pida->exist_nstrain
1176 && disp->display_scalar == SHOW_SC_NSTRAIN))
1180 search_nearest_index(disp, x, y, index_x, index_y,
1181 DATA_TYPE__PIV);
1182 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1183 highlight_intreg(*index_y, *index_x, disp);
1186 if (disp->pida->exist_vor &&
1187 disp->display_scalar == SHOW_SC_VORTICITY) {
1188 if (disp->pida->scaled_piv) {
1189 create_msg_display_with_scdata(vor_data_scaled,
1190 "vor",
1191 *index_y,
1192 *index_x,
1193 disp->pida->scaled_piv);
1194 } else {
1195 create_msg_display_with_scdata(vor_data,
1196 "vor",
1197 *index_y,
1198 *index_x,
1199 disp->pida->scaled_piv);
1202 } else if (disp->pida->exist_sstrain &&
1203 disp->display_scalar == SHOW_SC_SSTRAIN) {
1204 if (disp->pida->scaled_piv) {
1205 create_msg_display_with_scdata(sstrain_data_scaled,
1206 "sstrain",
1207 *index_y,
1208 *index_x,
1209 disp->pida->scaled_piv);
1210 } else {
1211 create_msg_display_with_scdata(sstrain_data,
1212 "sstrain",
1213 *index_y,
1214 *index_x,
1215 disp->pida->scaled_piv);
1218 } else if (disp->pida->exist_nstrain
1219 && disp->display_scalar == SHOW_SC_NSTRAIN) {
1220 if (disp->pida->scaled_piv) {
1221 create_msg_display_with_scdata(nstrain_data_scaled,
1222 "nstrain",
1223 *index_y,
1224 *index_x,
1225 disp->pida->scaled_piv);
1226 } else {
1227 create_msg_display_with_scdata(nstrain_data,
1228 "nstrain",
1229 *index_y,
1230 *index_x,
1231 disp->pida->scaled_piv);
1236 * PIV data (and resulting derivatives) do not exist are and not displayed
1237 * Interrogation area's are displayed
1239 } else if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1240 search_nearest_index(disp, x, y, index_x, index_y, DATA_TYPE__INTREG);
1241 highlight_intreg(*index_y, *index_x, disp);
1243 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%3.2f y=%3.2f i=%d j=%d ",
1244 disp->intreg->data->point_x[*index_y][*index_x],
1245 disp->intreg->data->point_y[*index_y][*index_x],
1246 *index_y, *index_x);
1250 * Only image is displayed
1252 } else if (disp->display_backgrnd == SHOW_BG_IMG1) {
1253 if (disp->pida->scaled_piv) {
1254 g_snprintf(msg_display, GPIV_MAX_CHARS,
1255 "xp=%d px ==> %5.4f m yp=%d px ==> %5.4f m img #1: pixval=%d",
1257 disp->img->image->header->s_scale * x * 1e-3
1258 + disp->img->image->header->z_off_x,
1260 disp->img->image->header->s_scale * y * 1e-3
1261 + disp->img->image->header->z_off_y,
1262 disp->img->image->frame1[y][x]
1264 } else {
1265 g_snprintf(msg_display, GPIV_MAX_CHARS,
1266 "xp=%d px yp=%d px img #1: pixval=%d",
1267 x, y,
1268 disp->img->image->frame1[y][x]
1272 } else if (disp->display_backgrnd == SHOW_BG_IMG2) {
1273 if (disp->pida->scaled_piv) {
1274 g_snprintf(msg_display, GPIV_MAX_CHARS,
1275 "xp=%d px ==> %5.4f m yp=%d px ==> %5.4f m img #1: pixval=%d",
1277 disp->img->image->header->s_scale * x * 1e-3
1278 + disp->img->image->header->z_off_x,
1280 disp->img->image->header->s_scale * y * 1e-3
1281 + disp->img->image->header->z_off_y,
1282 disp->img->image->frame2[y][x]
1284 } else {
1285 g_snprintf(msg_display, GPIV_MAX_CHARS,
1286 "xp=%d px yp=%d px img #2: pixval=%d",
1287 x, y,
1288 disp->img->image->frame2[y][x]
1292 } else {
1293 g_snprintf(msg_display, GPIV_MAX_CHARS, "No data are displayed");
1300 static void
1301 canvas_display_button_release__AOI_MS (Display *disp,
1302 GpivConsole *gpiv,
1303 GtkWidget *view_piv_display0,
1304 gdouble x,
1305 gdouble y
1307 /*-----------------------------------------------------------------------------
1308 * Performs action on mouse button release when AOI_MS has been enabled
1311 PivEval *eval = gpiv->piveval;
1312 gdouble l_col_start, l_col_end, l_row_start, l_row_end;
1315 if (gci_aoi != NULL) destroy_rect();
1317 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1318 destroy_all_intregs(disp);
1322 /* g_message ("canvas_display_button_release__AOI_MS:: x = %f y = %f" */
1323 /* " xgrab_first = %f ygrab_first = %f", */
1324 /* x, y, disp->xgrab_first, disp->ygrab_first); */
1326 if (x >= disp->xgrab_first) {
1327 l_col_start = disp->xgrab_first / disp->zoom_factor;
1328 l_col_end = x / disp->zoom_factor;
1329 disp->pida->piv_par->col_start = (gint) l_col_start;
1330 disp->pida->piv_par->col_end = (gint) l_col_end;
1331 } else {
1332 l_col_end = disp->xgrab_first / disp->zoom_factor;
1333 l_col_start = x / disp->zoom_factor;
1334 disp->pida->piv_par->col_end = (gint) l_col_end;
1335 disp->pida->piv_par->col_start = (gint) l_col_start;
1338 if (y >= disp->ygrab_first) {
1339 l_row_start = disp->ygrab_first / disp->zoom_factor;
1340 l_row_end = y / disp->zoom_factor;
1341 disp->pida->piv_par->row_start = (gint) l_row_start;
1342 disp->pida->piv_par->row_end = (gint) l_row_end;
1343 } else {
1344 l_row_end = disp->ygrab_first / disp->zoom_factor;
1345 l_row_start = y / disp->zoom_factor;
1346 disp->pida->piv_par->row_end = (gint) l_row_end;
1347 disp->pida->piv_par->row_start = (gint) l_row_start;
1352 gtk_spin_button_set_value (GTK_SPIN_BUTTON
1353 (eval->spinbutton_colstart),
1354 (gdouble)l_col_start);
1356 gtk_spin_button_set_value (GTK_SPIN_BUTTON
1357 (eval->spinbutton_colend),
1358 (gdouble) l_col_end);
1360 gtk_spin_button_set_value (GTK_SPIN_BUTTON
1361 (eval->spinbutton_rowstart),
1362 (gdouble) l_row_start);
1364 gtk_spin_button_set_value (GTK_SPIN_BUTTON
1365 (eval->spinbutton_rowend),
1366 (gdouble) l_row_end);
1368 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1369 create_all_intregs (disp);
1376 static void
1377 canvas_display_motion_notify__DRAGINT_MS (Display *disp,
1378 gint x,
1379 gint y,
1380 gint *index_x,
1381 gint *index_y
1383 /*-----------------------------------------------------------------------------
1384 * displaces interrogation area nearest to pointer
1387 if (disp->intreg->exist_int) {
1388 if (!disp->index_old) {
1389 disp->index_x_old = *index_x;
1390 disp->index_y_old = *index_y;
1391 disp->index_old = TRUE;
1394 if (*index_x == disp->index_x_old
1395 && *index_y == disp->index_y_old) {
1397 gnome_canvas_item_set
1398 (GNOME_CANVAS_ITEM(disp->intreg->
1399 gci_intreg1[*index_y][*index_x]),
1400 "x1", (double) x - disp->pida->piv_par->int_size_f / 2,
1401 "y1", (double) y - disp->pida->piv_par->int_size_f / 2,
1402 "x2", (double) x + disp->pida->piv_par->int_size_f / 2,
1403 "y2", (double) y + disp->pida->piv_par->int_size_f / 2,
1404 NULL);
1406 gnome_canvas_item_set
1407 (GNOME_CANVAS_ITEM(disp->intreg->
1408 gci_intreg2[*index_y][*index_x]),
1409 "x1", (double) x - disp->pida->piv_par->int_size_i /
1410 2 + disp->pida->piv_par->pre_shift_col,
1411 "y1", (double) y - disp->pida->piv_par->int_size_i /
1412 2 + disp->pida->piv_par->pre_shift_row,
1413 "x2", (double) x + disp->pida->piv_par->int_size_i /
1414 2 + disp->pida->piv_par->pre_shift_col,
1415 "y2", (double) y + disp->pida->piv_par->int_size_i /
1416 2 + disp->pida->piv_par->pre_shift_row,
1417 NULL);
1419 * put the interrogation area back to its original location
1421 } else {
1422 update_intreg1(disp, disp->index_y_old, disp->index_x_old);
1423 update_intreg2(disp, disp->index_y_old, disp->index_x_old);
1430 static void
1431 canvas_display_motion_notify__SINGLE_POINT_MS (Display *disp,
1432 gint x,
1433 gint y
1435 /*-----------------------------------------------------------------------------
1436 * Interrogates at a single arbitrary point in the image.
1437 * I am using the first interrogation area ([0][0]) temporarly for
1438 * displaying
1441 GtkWidget *view_piv_display0 =
1442 gtk_object_get_data(GTK_OBJECT(disp->mwin),
1443 "view_piv_display0");
1446 if (disp->intreg->gci_intreg1[0][0] != NULL &&
1447 disp->intreg->gci_intreg2[0][0] != NULL
1449 if (!GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1451 if (disp->intreg->gci_intreg1[0][0] != NULL) {
1452 gnome_canvas_item_show
1453 (GNOME_CANVAS_ITEM(disp->intreg->gci_intreg1[0][0]));
1455 if (disp->intreg->gci_intreg2[0][0] != NULL) {
1456 gnome_canvas_item_show
1457 (GNOME_CANVAS_ITEM(disp->intreg->gci_intreg2[0][0]));
1459 disp->display_intregs = TRUE;
1462 if (disp->pida->exist_piv && disp->pida->scaled_piv) {
1463 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%3.2f mm y=%3.2f mm",
1464 (gfloat) x * disp->img->image->header->s_scale *10e2
1465 + (gfloat) disp->img->image->header->z_off_x *10e2,
1466 (gfloat) y * disp->img->image->header->s_scale *10e2
1467 + (gfloat) disp->img->image->header->z_off_y *10e2);
1468 } else {
1469 g_snprintf(msg_display, GPIV_MAX_CHARS, "x=%d px y=%d px", x, y);
1472 gnome_canvas_item_set
1473 (GNOME_CANVAS_ITEM(disp->intreg->gci_intreg1[0][0]),
1474 "x1", (double) x - disp->pida->piv_par->int_size_f / 2,
1475 "y1", (double) y - disp->pida->piv_par->int_size_f / 2,
1476 "x2", (double) x + disp->pida->piv_par->int_size_f / 2,
1477 "y2", (double) y + disp->pida->piv_par->int_size_f / 2,
1478 NULL);
1480 gnome_canvas_item_set
1481 (GNOME_CANVAS_ITEM(disp->intreg->gci_intreg2[0][0]),
1482 "x1", (double) x - disp->pida->piv_par->int_size_f / 2
1483 + disp->pida->piv_par->pre_shift_col,
1484 "y1", (double) y - disp->pida->piv_par->int_size_f / 2
1485 + disp->pida->piv_par->pre_shift_row,
1486 "x2", (double) x + disp->pida->piv_par->int_size_f / 2
1487 + disp->pida->piv_par->pre_shift_col,
1488 "y2", (double) y + disp->pida->piv_par->int_size_f / 2
1489 + disp->pida->piv_par->pre_shift_row,
1490 NULL);
1492 } else {
1493 create_intreg1 (disp, 0, 0);
1494 create_intreg2 (disp, 0, 0);
1501 static char *
1502 canvas_display_button_press__SINGLE_AREA_MS (GpivConsole *gpiv,
1503 Display *disp,
1504 gint x,
1505 gint y
1507 /*-----------------------------------------------------------------------------
1508 * Performs action on mouse button press when SINGLE_AREA_MS has been enabled
1511 char *err_msg = NULL;
1512 gint index_x = 0, index_y = 0;
1513 GtkWidget *view_piv_display0 =
1514 gtk_object_get_data(GTK_OBJECT(disp->mwin),
1515 "view_piv_display0");
1518 if (disp->pida->exist_piv
1519 /* && GTK_CHECK_MENU_ITEM(view_piv_display0)->active */
1520 /* && disp->intreg->data->nx == disp->pida->piv_data->nx */
1521 /* && disp->intreg->data->ny == disp->pida->piv_data->ny */
1525 /* search_nearest_index(disp, x, y, &index_x, &index_y, */
1526 /* DATA_TYPE__INTREG); */
1527 search_nearest_index (disp, x, y, &index_x, &index_y,
1528 DATA_TYPE__PIV);
1531 if (m_select == SINGLE_AREA_MS) {
1532 /* if (disp->intreg->data->point_x[index_y][index_x] == */
1533 /* disp->pida->piv_data->point_x[index_y][index_x] */
1534 /* && disp->intreg->data->point_y[index_y][index_x] == */
1535 /* disp->pida->piv_data->point_y[index_y][index_x] */
1536 /* ) { */
1537 m_select_index_x = index_x;
1538 m_select_index_y = index_y;
1539 /* gpiv_warning("canvas_display_button_press__SINGLE_AREA_MS:: index_x=%d index_y = %d", index_x, index_y); */
1540 /* } else { */
1541 /* set__NO_MS(gpiv, disp); */
1542 /* err_msg = "Interrogation area's have to be at the same positions \nas the already existing piv data"; */
1543 /* warning_gpiv(err_msg); */
1544 /* return err_msg; */
1545 /* } */
1546 /* g_message("x=%d point_x=%d y=%d point_x=%d */
1548 } else if (m_select == DRAG_MS) {
1549 m_select_index_x = index_x;
1550 m_select_index_y = index_y;
1551 disp->pida->piv_data->point_x[m_select_index_y]
1552 [m_select_index_x] = (float) x;
1553 disp->pida->piv_data->point_y[m_select_index_y]
1554 [m_select_index_x] = (float) y;
1555 /* BUGFIXED ? */
1556 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1557 disp->intreg->data->point_x[m_select_index_y]
1558 [m_select_index_x] = (float) x;
1559 disp->intreg->data->point_y[m_select_index_y]
1560 [m_select_index_x] = (float) y;
1562 } else {
1563 err_msg = "canvas_display_button_press__SINGLE_AREA_MS: should not arrive here";
1564 error_gpiv(err_msg);
1570 return err_msg;
1575 static char *
1576 canvas_display_button_release__SINGLE_AREA_MS (GpivConsole *gpiv,
1577 Display *disp,
1578 gdouble x,
1579 gdouble y
1581 /*-----------------------------------------------------------------------------
1582 * Performs action on mouse button release when SINGLE_AREA_MS has been enabled
1585 char *err_msg = NULL;
1586 gint index_x = 0, index_y = 0;
1587 GtkWidget *view_piv_display0 =
1588 gtk_object_get_data(GTK_OBJECT(disp->mwin),
1589 "view_piv_display0");
1592 /* g_message ("canvas_display_button_release__SINGLE_AREA_MS:: x = %f y = %f" */
1593 /* " xgrab_first = %f ygrab_first = %f " */
1594 /* "m_select_index_x = %d m_select_index_y = %d", */
1595 /* x, y, disp->xgrab_first, disp->ygrab_first, */
1596 /* m_select_index_x, m_select_index_y */
1597 /* ); */
1599 if (disp->pida->exist_piv
1600 /* && GTK_CHECK_MENU_ITEM(view_piv_display0)->active */
1601 /* && disp->intreg->data->nx == disp->pida->piv_data->nx */
1602 /* && disp->intreg->data->ny == disp->pida->piv_data->ny */
1606 * There will only be action if the pointer, during pressing the button (as
1607 * defined in canvas_display_button_press__SINGLE_AREA_MS), is at identical
1608 * position as during releasing the button->
1610 search_nearest_index(disp, (gint) x, (gint) y, &index_x, &index_y,
1611 DATA_TYPE__PIV);
1612 /* gpiv_warning("canvas_display_button_release__SINGLE_AREA_MS:: index_x=%d index_y = %d", index_x, index_y); */
1616 if (m_select_index_x == index_x
1617 && m_select_index_y == index_y
1619 gl_piv_par->int_point_col = m_select_index_x;
1620 gl_piv_par->int_point_row = m_select_index_y;
1621 disp->pida->piv_par = gpiv_piv_cp_parameters (gl_piv_par);
1623 /* g_message ("canvas_display_button_release__SINGLE_AREA_MS:: calling interrogate"); */
1625 disp->pida->piv_data = interrogate_img (disp->img->image,
1626 disp->pida->piv_par,
1627 disp->pida->valid_par,
1628 gpiv);
1630 /* exec_piv (gpiv); */
1631 /* g_message ("canvas_display_button_release__SINGLE_AREA_MS:: back from interrogate"); */
1632 if (disp->pida->gci_vector[m_select_index_y][m_select_index_x]
1633 != NULL) {
1634 update_vector (disp->pida, m_select_index_y, m_select_index_x);
1635 } else {
1636 create_vector (disp->pida, m_select_index_y, m_select_index_x);
1639 /* g_message ("canvas_display_button_release__SINGLE_AREA_MS:: display vector"); */
1640 /* disp->pida->exist_piv = TRUE; */
1641 disp->display_piv = TRUE;
1642 if (m_select == DRAG_MS) {
1643 if (disp->intreg->
1644 gci_intreg1[m_select_index_y][m_select_index_x]
1645 != NULL)
1646 update_intreg1 (disp, m_select_index_y, m_select_index_x);
1647 if (disp->intreg->
1648 gci_intreg2[m_select_index_y][m_select_index_x]
1649 != NULL)
1650 update_intreg2 (disp, m_select_index_y, m_select_index_x);
1653 } else {
1654 err_msg = "moved pointer too far away from \nintar to be interrogated";
1655 return err_msg;
1658 } else {
1659 /* err_msg = "Interrogation area's and piv data must already exist \n and must be of identic quantity!"; */
1660 err_msg = "Piv data must exist!";
1661 warning_gpiv (err_msg);
1662 return err_msg;
1666 if (!shift_pressed) set__NO_MS(gpiv, disp);
1669 return err_msg;
1674 static void
1675 canvas_display_button_press__SINGLE_POINT_MS (GpivConsole *gpiv,
1676 Display *disp,
1677 gint x,
1678 gint y
1680 /*-----------------------------------------------------------------------------
1681 * Performs action on mouse button release when SINGLE_POINT_MS has
1682 * been enabled
1685 GtkWidget *view_piv_display0 =
1686 gtk_object_get_data(GTK_OBJECT(disp->mwin),
1687 "view_piv_display0");
1690 if (disp->pida->exist_piv) {
1691 destroy_all_vectors(disp->pida);
1692 gpiv_free_pivdata (disp->pida->piv_data);
1693 disp->pida->exist_piv = FALSE;
1694 if (disp->pida->scaled_piv) {
1695 gpiv_free_pivdata (disp->pida->piv_data_scaled);
1696 disp->pida->scaled_piv = FALSE;
1700 free_post_bufmems(disp);
1701 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1702 destroy_all_intregs(disp);
1704 m_select_index_x = 0;
1705 m_select_index_y = 0;
1706 disp->pida->piv_par->int_point_col = (float) x;
1707 disp->pida->piv_par->int_point_row = (float) y;
1708 disp->pida->piv_data = gpiv_alloc_pivdata (1, 1);
1709 disp->pida->exist_piv = TRUE;
1711 disp->pida->piv_data->point_x[0][0] = (float) x;
1712 disp->pida->piv_data->point_y[0][0] = (float) y;
1714 disp->intreg->data->nx = 1;
1715 disp->intreg->data->ny = 1;
1716 create_all_intregs(disp);
1717 disp->intreg->exist_int = TRUE;
1719 disp->intreg->data->point_x[0][0] = (float) x;
1720 disp->intreg->data->point_y[0][0] = (float) y;
1721 show_all_intregs(disp);
1722 disp->display_intregs = TRUE;
1724 disp->pida->piv_data = interrogate_img (disp->img->image,
1725 disp->pida->piv_par,
1726 disp->pida->valid_par,
1727 gpiv);
1729 disp->display_piv = TRUE;
1731 create_all_vectors(disp->pida);
1732 gnome_canvas_update_now(GNOME_CANVAS(disp->canvas));
1734 if (!shift_pressed) set__NO_MS(gpiv, disp);
1739 static void
1740 canvas_display_button_release__HVLINE_MS (Display *disp,
1741 GpivConsole *gpiv,
1742 GtkWidget *view_piv_display0,
1743 gdouble x,
1744 gdouble y
1746 /*-----------------------------------------------------------------------------
1747 * Performs action on mouse button release when H_LINE_MS or V_LINE_MS has
1748 * been enabled
1751 gdouble l_col_start,l_col_end, l_row_start, l_row_end;
1752 gboolean reset_display_intregs;
1755 /* g_message ("canvas_display_button_release__HVLINE_MS:: x = %f y = %f" */
1756 /* " xgrab_first = %f ygrab_first = %f", */
1757 /* x, y, disp->xgrab_first, disp->ygrab_first); */
1759 if (GTK_CHECK_MENU_ITEM (view_piv_display0)->active) {
1761 * Remove exixting intreg contours
1762 * Disable displaying temporarly to avoid several calls to
1763 * the 'on_spinbutton_piv_int' function
1765 destroy_all_intregs (disp);
1766 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM
1767 (view_piv_display0),
1768 FALSE);
1769 reset_display_intregs = TRUE;
1772 /* if (disp->pida->exist_piv) { */
1773 /* destroy_all_vectors(disp->pida); */
1774 /* disp->display_piv = FALSE; */
1775 /* } */
1778 m_select_index_x = 0;
1779 m_select_index_y = 0;
1782 * Vertical line selected
1784 if (m_select == V_LINE_MS) {
1785 if (y >= disp->ygrab_first) {
1786 l_row_start = (gdouble) (disp->ygrab_first / disp->zoom_factor);
1787 l_row_end = (gdouble) (y / disp->zoom_factor);
1788 disp->pida->piv_par->row_start = (gint) l_row_start;
1789 disp->pida->piv_par->row_end = (gint) l_row_end;
1790 disp->pida->piv_par->int_line_row_end = (gint) l_row_end;
1791 } else {
1792 l_row_start = (gdouble) (y / disp->zoom_factor);
1793 l_row_end = (gdouble) (disp->ygrab_first / disp->zoom_factor);
1794 disp->pida->piv_par->row_start = (gint) l_row_start;
1795 disp->pida->piv_par->row_end = (gint) l_row_end;
1796 disp->pida->piv_par->int_line_row_end = (gint) l_row_end;
1799 l_col_start = (gdouble) (disp->xgrab_first / disp->zoom_factor -
1800 disp->pida->piv_par->int_size_i / 2 + 1);
1801 disp->pida->piv_par->col_start = (gint) l_col_start;
1803 l_col_end = (gdouble) (disp->xgrab_first / disp->zoom_factor +
1804 disp->pida->piv_par->int_size_i / 2 +
1805 disp->pida->piv_par->pre_shift_col);
1806 disp->pida->piv_par->col_end = (gint) l_col_end;
1810 * Horizontal line selected
1812 } else if (m_select == H_LINE_MS) {
1813 if (x >= disp->xgrab_first) {
1814 l_col_start = (gdouble) (disp->xgrab_first / disp->zoom_factor);
1815 l_col_end = (gdouble) (x / disp->zoom_factor);
1816 disp->pida->piv_par->col_start = (gint) l_col_start;
1817 disp->pida->piv_par->col_end = (gint) l_col_end;
1818 disp->pida->piv_par->int_line_col_end = (gint) l_col_end;
1819 } else {
1820 l_col_start = (gdouble) (x / disp->zoom_factor);
1821 l_col_end = (gdouble) (disp->xgrab_first / disp->zoom_factor);
1822 disp->pida->piv_par->col_start = (gint) l_col_start;
1823 disp->pida->piv_par->col_end = (gint) l_col_end;
1824 disp->pida->piv_par->int_line_col_end = (gint) l_col_end;
1827 l_row_start = (gdouble) (disp->ygrab_first / disp->zoom_factor -
1828 disp->pida->piv_par->int_size_i / 2 + 1);
1829 disp->pida->piv_par->row_start = (gint) l_row_start;
1831 l_row_end = (gdouble) (disp->ygrab_first / disp->zoom_factor +
1832 disp->pida->piv_par->int_size_i / 2 +
1833 disp->pida->piv_par->pre_shift_col);
1834 disp->pida->piv_par->row_end = (gint) l_row_end;
1837 } else {
1838 g_warning("canvas_display_button_release__HVLINE_MS: H_LINE_MS or V_LINE_MS inactive");
1841 if (gci_line != NULL) destroy_line();
1842 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1843 create_all_intregs(disp);
1847 * updating entry's for col/row_start_end
1849 /* g_message ("canvas_display_button_release__HVLINE_MS:: zoom_factor = %f col_start = %f col_end = %f" */
1850 /* " row_start = %f row_end = %f", */
1851 /* disp->zoom_factor, l_col_start, l_col_end, l_row_start, l_row_end); */
1853 gtk_spin_button_set_value (GTK_SPIN_BUTTON
1854 (gpiv->piveval->spinbutton_colstart),
1855 (gdouble) l_col_start);
1857 gtk_spin_button_set_value (GTK_SPIN_BUTTON
1858 (gpiv->piveval->spinbutton_rowstart),
1859 (gdouble) l_row_start);
1861 gtk_spin_button_set_value (GTK_SPIN_BUTTON
1862 (gpiv->piveval->spinbutton_colend),
1863 (gdouble) l_col_end);
1866 * The last call to on_spinbutton_piv_int will update the contours of the intregs
1868 if (reset_display_intregs) {
1869 /* g_message ("release__HV:: resetting"); */
1870 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM
1871 (view_piv_display0),
1872 TRUE);
1875 gtk_spin_button_set_value (GTK_SPIN_BUTTON
1876 (gpiv->piveval->spinbutton_rowend),
1877 (gdouble) l_row_end);
1879 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1880 /* create_all_intregs (disp); */
1887 static void
1888 canvas_display_button_press__DISABLE_POINT_MS (Display *disp,
1889 gint x,
1890 gint y
1892 /*-----------------------------------------------------------------------------
1893 * Performs action on mouse button press when DISABLE_POINT_MS has
1894 * been enabled
1897 gchar *err_msg;
1898 gint index_x = 0, index_y = 0;
1899 GtkWidget *view_piv_display0 =
1900 gtk_object_get_data(GTK_OBJECT(disp->mwin),
1901 "view_piv_display0");
1904 if ( m_select == DISABLE_POINT_MS ) {
1905 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
1906 search_nearest_index(disp, x, y, &index_x, &index_y,
1907 DATA_TYPE__INTREG);
1908 } else {
1909 search_nearest_index(disp, x, y, &index_x, &index_y,
1910 DATA_TYPE__PIV);
1913 disp->pida->piv_data->peak_no[index_y][index_x] = -1;
1914 disp->pida->piv_data->snr[index_y][index_x] = GPIV_SNR_DISABLE;
1916 if (disp->pida->post_par->set == TRUE) {
1917 disp->pida->piv_data->dx[index_y][index_x] =
1918 disp->pida->post_par->set_dx;
1919 disp->pida->piv_data->dy[index_y][index_x] =
1920 disp->pida->post_par->set_dx;
1922 update_vector(disp->pida, index_y, index_x);
1924 } else if ( m_select == ENABLE_AREA_MS ) {
1925 enable_col_start = x;
1926 enable_row_start = y;
1927 assert( gci_aoi == NULL);
1928 gci_aoi =
1929 gnome_canvas_item_new (gnome_canvas_root
1930 (GNOME_CANVAS(disp->canvas)),
1931 gnome_canvas_rect_get_type(),
1932 "x1", (double) x,
1933 "y1", (double) y,
1934 "x2", (double) x,
1935 "y2", (double) y,
1936 "outline_color", "yellow",
1937 "width_units", (double) THICKNESS,
1938 NULL);
1941 } else if ( m_select == DISABLE_AREA_MS) {
1942 enable_col_start = x;
1943 enable_row_start = y;
1944 assert( gci_aoi == NULL);
1945 gci_aoi =
1946 gnome_canvas_item_new (gnome_canvas_root
1947 (GNOME_CANVAS(disp->canvas)),
1948 gnome_canvas_rect_get_type(),
1949 "x1", (double) x,
1950 "y1", (double) y,
1951 "x2", (double) x,
1952 "y2", (double) y,
1953 "outline_color", "yellow",
1954 "width_units", (double) THICKNESS,
1955 NULL);
1956 } else {
1957 err_msg = _("no image or piv data");
1958 warning_gpiv(err_msg);
1965 static void
1966 set__NO_MS (GpivConsole *gpiv,
1967 Display *disp
1969 /*-----------------------------------------------------------------------------
1970 * Reset mouse selection to inactive
1973 gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON
1974 (gpiv->piveval->radiobutton_mouse_1),
1975 TRUE);
1976 cursor = gdk_cursor_new (GDK_DOTBOX);
1977 gdk_window_set_cursor (disp->mwin->window, cursor);
1982 static void
1983 search_nearest_index (Display *disp,
1984 gint x,
1985 gint y,
1986 gint *index_x,
1987 gint *index_y,
1988 gint data_type
1990 /*-----------------------------------------------------------------------------
1991 * Search nearest index belongin to x an y points
1994 gint i, j, x_min = 10e4, y_min = 10e4, dif;
1997 if (data_type == DATA_TYPE__INTREG) {
1998 for (i = 0, j = 0; i < disp->intreg->data->ny; i++) {
1999 dif = abs(y - (int) disp->intreg->data->point_y[i][j]);
2000 if (dif < y_min) {
2001 y_min = dif;
2002 *index_y = i;
2006 for (i = 0, j = 0; j < disp->intreg->data->nx; j++) {
2007 dif = abs(x - (int) disp->intreg->data->point_x[i][j]);
2008 if (dif < x_min) {
2009 x_min = dif;
2010 *index_x = j;
2015 } else if (data_type == DATA_TYPE__PIV) {
2016 for (i = 0, j = 0; i < disp->pida->piv_data->ny; i++) {
2017 dif = abs(y - (int) disp->pida->piv_data->point_y[i][j]);
2018 if (dif < y_min) {
2019 y_min = dif;
2020 *index_y = i;
2024 for (i = 0, j = 0; j < disp->pida->piv_data->nx; j++) {
2025 dif = abs(x - (int) disp->pida->piv_data->point_x[i][j]);
2026 if (dif < x_min) {
2027 x_min = dif;
2028 *index_x = j;
2032 } else {
2033 g_warning("search_nearest_index: Inavalid Data Type");
2040 static void
2041 highlight_intreg (gint index_y,
2042 gint index_x,
2043 Display *disp
2045 /*-----------------------------------------------------------------------------
2046 * Highlights first and second interrogation area's
2049 GtkWidget *view_piv_display0 =
2050 gtk_object_get_data(GTK_OBJECT(disp->mwin),
2051 "view_piv_display0");
2054 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active
2055 && index_y <= disp->intreg->data->ny
2056 && index_x <= disp->intreg->data->nx) {
2058 if (disp->intreg->gci_intreg1[disp->index_y_old][disp->index_x_old]
2059 != NULL) {
2060 gnome_canvas_item_set(disp->intreg->gci_intreg1
2061 [disp->index_y_old][disp->index_x_old],
2062 "outline_color", "red",
2063 NULL);
2066 if (disp->intreg->gci_intreg2[disp->index_y_old][disp->index_x_old]
2067 != NULL) {
2068 gnome_canvas_item_set(disp->intreg->gci_intreg2
2069 [disp->index_y_old][disp->index_x_old],
2070 "outline_color", "blue",
2071 NULL);
2074 if (disp->intreg->gci_intreg1[index_y][index_x] != NULL) {
2075 gnome_canvas_item_set(disp->intreg->gci_intreg1[index_y][index_x],
2076 "outline_color", "yellow",
2077 NULL);
2078 gnome_canvas_item_raise_to_top(disp->intreg->
2079 gci_intreg1[index_y][index_x]);
2082 if (disp->intreg->gci_intreg2[index_y][index_x] != NULL) {
2083 gnome_canvas_item_set(disp->intreg->gci_intreg2[index_y][index_x],
2084 "outline_color", "green",
2085 NULL);
2086 gnome_canvas_item_raise_to_top(disp->intreg->
2087 gci_intreg2[index_y][index_x]);
2095 static void
2096 create_msg_display_with_pivdata (GpivPivData *piv_data,
2097 gint index_y,
2098 gint index_x,
2099 gint scale
2101 /*-----------------------------------------------------------------------------
2102 * Displays message with piv data values
2106 if (scale) {
2107 if (piv_data->snr[index_y][index_x] == GPIV_SNR_NAN) {
2108 g_snprintf (msg_display, GPIV_MAX_CHARS,
2109 "xp=%3.2fmm yp=%3.2fmm %s",
2110 piv_data->point_x[index_y][index_x] * 1e3,
2111 piv_data->point_y[index_y][index_x] * 1e3,
2112 _("Disabled: not a number"));
2113 } else if (piv_data->snr[index_y][index_x] == GPIV_SNR_DISABLE) {
2114 g_snprintf (msg_display, GPIV_MAX_CHARS,
2115 "xp=%3.2fmm yp=%3.2fmm %s",
2116 piv_data->point_x[index_y][index_x] * 1e3,
2117 piv_data->point_y[index_y][index_x] * 1e3,
2118 _("Disabled manually"));
2119 } else {
2120 g_snprintf (msg_display, GPIV_MAX_CHARS,
2121 "xp=%3.2fmm yp=%3.2fmm U=%3.2fm/s V=%3.2fm/s"
2122 " snr=%3.2f peak #%d",
2123 piv_data->point_x[index_y][index_x] * 1e3,
2124 piv_data->point_y[index_y][index_x] * 1e3,
2125 piv_data->dx[index_y][index_x],
2126 piv_data->dy[index_y][index_x],
2127 piv_data->snr[index_y][index_x],
2128 piv_data->peak_no[index_y][index_x]);
2131 } else {
2132 if (piv_data->snr[index_y][index_x] == GPIV_SNR_NAN) {
2133 g_snprintf (msg_display, GPIV_MAX_CHARS,
2134 "xp=%3.0fpx yp=%3.0fpx %s",
2135 piv_data->point_x[index_y][index_x],
2136 piv_data->point_y[index_y][index_x],
2137 _("Disabled: not a number"));
2138 } else if (piv_data->snr[index_y][index_x] == GPIV_SNR_DISABLE) {
2139 g_snprintf (msg_display, GPIV_MAX_CHARS,
2140 "xp=%3.0fpx yp=%3.0fpx %s",
2141 piv_data->point_x[index_y][index_x],
2142 piv_data->point_y[index_y][index_x],
2143 _("Disabled manually"));
2144 } else {
2145 g_snprintf (msg_display, GPIV_MAX_CHARS,
2146 "xp=%3.0fpx yp=%3.0fpx dx=%3.2fpx dy=%3.2fpx"
2147 " snr=%3.2f peak #%d",
2148 piv_data->point_x[index_y][index_x],
2149 piv_data->point_y[index_y][index_x],
2150 piv_data->dx[index_y][index_x],
2151 piv_data->dy[index_y][index_x],
2152 piv_data->snr[index_y][index_x],
2153 piv_data->peak_no[index_y][index_x]);
2161 static void
2162 create_msg_display_with_scdata (GpivScalarData *sc_data,
2163 gchar *sc_type,
2164 gint index_y,
2165 gint index_x,
2166 gint scale
2168 /*-----------------------------------------------------------------------------
2169 * Displays message with scalar data values
2172 if (scale) {
2173 g_snprintf (msg_display, GPIV_MAX_CHARS,
2174 "xp=%3.2fmm yp=%3.2fmm %s=%3.2f1/s",
2175 sc_data->point_x[index_y][index_x] * 1e3,
2176 sc_data->point_y[index_y][index_x] * 1e3,
2177 sc_type,
2178 sc_data->scalar[index_y][index_x]);
2179 } else {
2180 g_snprintf (msg_display, GPIV_MAX_CHARS,
2181 "xp=%3.0fpx yp=%3.0fpx %s=%3.2f",
2182 sc_data->point_x[index_y][index_x],
2183 sc_data->point_y[index_y][index_x],
2184 sc_type,
2185 sc_data->scalar[index_y][index_x]);
2191 static void
2192 create_msg_display_with_pivscdata (GpivPivData *piv_data,
2193 GpivScalarData *sc_data,
2194 gchar *sc_type,
2195 gint index_y,
2196 gint index_x,
2197 gint scale
2199 /*-----------------------------------------------------------------------------
2200 * Displays message with piv and scalar data values
2203 if (scale) {
2204 g_snprintf (msg_display, GPIV_MAX_CHARS,
2205 "xp=%3.2fmm yp=%3.2fmm U=%3.2fm/s V=%3.2fm/s "
2206 "snr=%3.2f peak #%d %s=%3.2f1/s",
2207 piv_data->point_x[index_y][index_x] * 1e3,
2208 piv_data->point_y[index_y][index_x] * 1e3,
2209 piv_data->dx[index_y][index_x],
2210 piv_data->dy[index_y][index_x],
2211 piv_data->snr[index_y][index_x],
2212 piv_data->peak_no[index_y][index_x],
2213 sc_type,
2214 sc_data->scalar[index_y][index_x]);
2215 } else {
2216 g_snprintf (msg_display, GPIV_MAX_CHARS,
2217 "xp=%3.0fpx yp=%3.0fpx dx=%3.2fpx dy=%3.2fpx "
2218 "snr=%3.2f peak #%d %s=%3.2f",
2219 piv_data->point_x[index_y][index_x],
2220 piv_data->point_y[index_y][index_x],
2221 piv_data->dx[index_y][index_x],
2222 piv_data->dy[index_y][index_x],
2223 piv_data->snr[index_y][index_x],
2224 piv_data->peak_no[index_y][index_x],
2225 sc_type,
2226 sc_data->scalar[index_y][index_x]);
2232 static void
2233 create_line (Display *disp,
2234 gint x1,
2235 gint y1,
2236 gint x2,
2237 gint y2
2239 /*-----------------------------------------------------------------------------
2242 GnomeCanvasPoints *points;
2243 points = gnome_canvas_points_new (2);
2245 /* g_message("CREATE_LINE:: x1 = %d y1 = %d x2 = %d y2 = %d", x1, y1, x2, y2); */
2247 if (disp != NULL
2248 && gci_line == NULL) {
2250 points->coords[0] = x1;
2251 points->coords[1] = y1;
2252 points->coords[2] = x2;
2253 points->coords[3] = y2;
2254 gci_line =
2255 gnome_canvas_item_new (gnome_canvas_root(GNOME_CANVAS(disp->canvas)),
2256 gnome_canvas_line_get_type(),
2257 "points", points,
2258 "fill_color", "yellow",
2259 "width_units", (double) THICKNESS,
2260 NULL);
2262 gnome_canvas_points_free (points);
2267 static void
2268 update_line (gint x1,
2269 gint y1,
2270 gint x2,
2271 gint y2
2273 /*-----------------------------------------------------------------------------
2276 GnomeCanvasPoints *points;
2277 points = gnome_canvas_points_new (2);
2279 /* g_message("UPDATE_LINE:: x1 = %d y1 = %d x2 = %d y2 = %d", x1, y1, x2, y2); */
2281 if (gci_line != NULL) {
2283 points->coords[0] = x1;
2284 points->coords[1] = y1;
2285 points->coords[2] = x2;
2286 points->coords[3] = y2;
2288 gnome_canvas_item_set (GNOME_CANVAS_ITEM(/* disp-> */gci_line),
2289 "points", points,
2290 "fill_color", "yellow",
2291 "width_units", (double) THICKNESS,
2292 NULL);
2294 gnome_canvas_points_free (points);
2299 static void
2300 destroy_line ()
2301 /*-----------------------------------------------------------------------------
2304 if (gci_line != NULL) {
2306 gtk_object_destroy(GTK_OBJECT (gci_line));
2307 gci_line = NULL;
2313 static void
2314 create_rect (Display *disp,
2315 gint x,
2316 gint y
2318 /*-----------------------------------------------------------------------------
2321 if (disp != NULL
2322 && gci_aoi == NULL) {
2324 /* g_message("CREATE_RECT:: x = %d y = %d", x, y); */
2326 gci_aoi =
2327 gnome_canvas_item_new (gnome_canvas_root
2328 (GNOME_CANVAS(disp->canvas)),
2329 gnome_canvas_rect_get_type(),
2330 "x1", (double) x,
2331 "y1", (double) y,
2332 "x2", (double) x,
2333 "y2", (double) y,
2334 "outline_color", "yellow",
2335 "width_units", (double) THICKNESS,
2336 NULL);
2342 static void
2343 update_rect (gint x,
2344 gint y
2346 /*-----------------------------------------------------------------------------
2349 if (gci_aoi != NULL) {
2351 gnome_canvas_item_set (GNOME_CANVAS_ITEM(gci_aoi),
2352 "x2", (double) x,
2353 "y2", (double) y,
2354 NULL);
2359 static void
2360 destroy_rect ()
2361 /*-----------------------------------------------------------------------------
2364 if (gci_aoi != NULL) {
2366 gtk_object_destroy (GTK_OBJECT (gci_aoi));
2367 gci_aoi = NULL;
2372 gdouble
2373 gtk_adjustment_get_lower (GtkAdjustment *adjustment)
2375 /* g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), 0.); */
2377 return adjustment->lower;
2382 static void
2383 pane_canvas (Display *disp,
2384 gfloat x,
2385 gfloat y
2387 /*-----------------------------------------------------------------------------
2390 pane_canvas_x (disp, x);
2391 pane_canvas_y (disp, y);
2396 static void
2397 pane_canvas_x (Display *disp,
2398 gfloat x
2400 /*-----------------------------------------------------------------------------
2403 GtkAdjustment *adj = GTK_ADJUSTMENT (disp->hadj);
2404 /* gdouble adj_value = gtk_adjustment_get_value */
2405 (GTK_ADJUSTMENT (disp->hadj));
2406 gdouble diff;
2407 gdouble adj_new;
2409 diff = x - disp->xgrab_first;
2410 /* g_message ("PANE_CANVAS_X:: x = %f x_first = %f => diff = %f", */
2411 /* x, disp->xgrab_first, diff); */
2413 adj_new = (adj->value - diff);
2414 /* g_message ("PANE_CANVAS_X:: value = %f lower = %f upper = %f page_s = %f => adj_new = %f", */
2415 /* adj->value, adj->lower, adj->upper, adj->page_size, adj_new); */
2417 if (adj_new >= adj->lower
2418 && adj_new < adj->upper - adj->page_size) {
2419 /* g_message ("PANE_CANVAS_X:: passed if ()"); */
2421 gtk_adjustment_set_value (GTK_ADJUSTMENT (disp->hadj),
2422 adj_new
2430 static void
2431 pane_canvas_y (Display *disp,
2432 gfloat y
2434 /*-----------------------------------------------------------------------------
2437 GtkAdjustment *adj = GTK_ADJUSTMENT (disp->vadj);
2438 /* gdouble adj_value = gtk_adjustment_get_value */
2439 /* (GTK_ADJUSTMENT (disp->vadj)); */
2440 gdouble diff;
2441 gdouble adj_new;
2443 diff = y - disp->ygrab_first;
2444 adj_new = (adj->value - diff);
2445 if (adj_new >= 0
2446 && adj_new < adj->upper - adj->page_size) {
2447 gtk_adjustment_set_value (GTK_ADJUSTMENT (disp->vadj),
2448 adj_new