1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 c-style: "K&R" -*- */
3 /*----------------------------------------------------------------------
5 gpiv - Graphic program for Particle Image Velocimetry, based on gtk/gnome
8 Copyright (C) 2006, 2007, 2008
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)
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 "display_intregs.h"
33 create_all_intregs (Display
*disp
35 /*-----------------------------------------------------------------------------
36 * Creates all interrogation areas
40 GtkWidget
*view_piv_display0
=
41 gtk_object_get_data(GTK_OBJECT(disp
->mwin
),
46 /* if (GTK_CHECK_MENU_ITEM(view_piv_display0)->disabled) { */
47 if (!disp
->intreg
->exist_int
) {
48 if ((disp
->intreg
->data
= create_intreg_data (disp
)) == NULL
) {
49 g_warning ("create_all_intregs: failing create_intreg_data");
54 /* disp->intreg->par->row_start_old = 0; */
55 /* disp->intreg->par->row_start = disp->pida->eval_par->row_start; */
56 /* disp->intreg->par->row_end = disp->pida->eval_par->row_end; */
57 /* disp->intreg->par->col_start_old = 0; */
58 /* disp->intreg->par->col_start = disp->pida->eval_par->col_start; */
59 /* disp->intreg->par->col_end = disp->pida->eval_par->col_end; */
60 /* disp->intreg->par->int_size_f = disp->pida->eval_par->int_size_f; */
61 /* disp->intreg->par->int_size_i = disp->pida->eval_par->int_size_i; */
62 /* disp->intreg->par->int_shift = disp->pida->eval_par->int_shift; */
63 /* disp->intreg->par->pre_shift_row = disp->pida->eval_par->pre_shift_row; */
64 /* disp->intreg->par->pre_shift_col = disp->pida->eval_par->pre_shift_col; */
66 /* g_message ("CREATE_ALL_INTREGS:: x_first = %d x_last = %d y_first = %d y_last = %d", */
67 /* disp->intreg->par->col_start, */
68 /* disp->intreg->par->col_end, */
69 /* disp->intreg->par->row_start, */
70 /* disp->intreg->par->row_end); */
72 create_all_intregs1 (disp
);
73 create_all_intregs2 (disp
);
76 error_gpiv ("create_all_intregs: disp != NULL failed");
83 destroy_all_intregs (Display
*disp
85 /*-----------------------------------------------------------------------------
86 * Destroys all interrogation areas
90 destroy_all_intregs1 (disp
);
91 destroy_all_intregs2 (disp
);
92 destroy_intreg_data (disp
);
93 disp
->display_intregs
= FALSE
;
100 show_all_intregs(Display
*disp
102 /*-----------------------------------------------------------------------------
103 * Shows all interrogation areas
107 && !disp
->intreg
->exist_int
) {
108 create_all_intregs(disp
);
110 show_all_intregs1(disp
);
111 show_all_intregs2(disp
);
117 hide_all_intregs (Display
*disp
119 /*-----------------------------------------------------------------------------
120 * Hides all interrogation areas
124 hide_all_intregs1(disp
);
125 hide_all_intregs2(disp
);
132 create_intreg_data (Display
*disp
134 /*-----------------------------------------------------------------------------
137 char *err_msg
= NULL
;
138 GpivPivData
*data
= NULL
;
139 guint nx
= 0, ny
= 0;
142 g_return_if_fail (!disp
->intreg
->exist_int
);
143 /* g_message ("CREATE_INTREG_DATA:: print_parameters"); */
144 /* gpiv_piv_fprint_parameters (NULL, disp->intreg->par); */
147 gpiv_piv_count_pivdata_fromimage (disp
->img
->image
->header
,
152 g_warning ("create_intreg_data: %s", err_msg
);
157 gpiv_piv_gridgen (nx
, ny
, disp
->img
->image
->header
, disp
->intreg
->par
))
158 == NULL
) error_gpiv ("%s: failing gpiv_piv_gridgen", RCSID
);
160 disp
->intreg
->exist_int
= TRUE
;
167 destroy_intreg_data (Display
*disp
169 /*-----------------------------------------------------------------------------
173 && disp
->intreg
->gci_intreg1
[0][0] == NULL
174 && disp
->intreg
->gci_intreg2
[0][0] == NULL
) {
175 gpiv_free_pivdata (disp
->intreg
->data
);
176 disp
->intreg
->exist_int
= FALSE
;
183 create_all_intregs1 (Display
*disp
185 /* ----------------------------------------------------------------------------
186 * Displays all first interrogation areas
194 && !disp
->intreg
->exist_int
)
195 disp
->intreg
->data
= create_intreg_data (disp
);
196 nx
= disp
->intreg
->data
->nx
;
197 ny
= disp
->intreg
->data
->ny
;
198 if (gpiv_par
->verbose
)
199 g_message ("create_all_intregs1: creating %d I.A.'s", nx
* ny
);
200 for (i
= 0; i
< ny
; i
++) {
201 for (j
= 0; j
< nx
; j
++) {
202 create_intreg1 (disp
, i
, j
);
210 create_intreg1 (Display
*disp
,
214 /* ----------------------------------------------------------------------------
215 * Displays first interrogation area
218 int start_x
= 0, start_y
= 0, end_x
= 0, end_y
= 0;
222 && disp
->intreg
->exist_int
) {
223 x
= disp
->intreg
->data
->point_x
[i
][j
];
224 y
= disp
->intreg
->data
->point_y
[i
][j
];
228 * Using centre points of interr regs
230 start_x
= (int) x
- disp
->intreg
->par
->int_size_f
/ 2;
231 start_y
= (int) y
- disp
->intreg
->par
->int_size_f
/ 2;
232 end_x
= (int) x
+ disp
->intreg
->par
->int_size_f
/ 2;
233 end_y
= (int) y
+ disp
->intreg
->par
->int_size_f
/ 2;
235 if (disp
->intreg
->gci_intreg1
[i
][j
] != NULL
) {
236 destroy_intreg1 (disp
, i
, j
);
239 disp
->intreg
->gci_intreg1
[i
][j
] =
240 gnome_canvas_item_new (gnome_canvas_root
241 (GNOME_CANVAS (disp
->canvas
)),
242 gnome_canvas_rect_get_type(),
243 "x1", (double) start_x
,
244 "y1", (double) start_y
,
245 "x2", (double) end_x
,
246 "y2", (double) end_y
,
247 "outline_color", "red",
248 "width_units", (double) THICKNESS
,
256 update_intreg1 (Display
*disp
,
260 /* ----------------------------------------------------------------------------
261 * Updates first interrogation area
264 int start_x
= 0, start_y
= 0, end_x
= 0, end_y
= 0;
268 && disp
->intreg
->gci_intreg1
[i
][j
] != NULL
) {
269 x
= disp
->intreg
->data
->point_x
[i
][j
];
270 y
= disp
->intreg
->data
->point_y
[i
][j
];
273 * Using centre points of interr regs
275 start_x
= (int) x
- disp
->intreg
->par
->int_size_f
/ 2;
276 start_y
= (int) y
- disp
->intreg
->par
->int_size_f
/ 2;
277 end_x
= (int) x
+ disp
->intreg
->par
->int_size_f
/ 2;
278 end_y
= (int) y
+ disp
->intreg
->par
->int_size_f
/ 2;
280 gnome_canvas_item_set (GNOME_CANVAS_ITEM
281 (disp
->intreg
->gci_intreg1
[i
][j
]),
282 "x1", (double) start_x
,
283 "y1", (double) start_y
,
284 "x2", (double) end_x
,
285 "y2", (double) end_y
,
286 "outline_color", "red",
287 "width_units", (double) THICKNESS
,
295 destroy_intreg1 (Display
*disp
,
299 /* ----------------------------------------------------------------------------
300 * Destroys 1st interrogation area at index i, j
304 && disp
->intreg
->gci_intreg1
[i
][j
] != NULL
) {
305 gtk_object_destroy (GTK_OBJECT
306 (disp
->intreg
->gci_intreg1
[i
][j
]));
307 disp
->intreg
->gci_intreg1
[i
][j
] = NULL
;
314 show_all_intregs1 (Display
*disp
316 /* ----------------------------------------------------------------------------
317 * Shows 1st interrogation areas
324 && disp
->intreg
->exist_int
) {
326 /* if (!disp->intreg->exist_int) */
327 /* disp->intreg->data = create_intreg_data (disp); */
328 nx
= disp
->intreg
->data
->nx
;
329 ny
= disp
->intreg
->data
->ny
;
331 for (i
= 0; i
< ny
; i
++) {
332 for (j
= 0; j
< nx
; j
++) {
333 assert (disp
->intreg
->gci_intreg1
[i
][j
] != NULL
);
334 gnome_canvas_item_show (GNOME_CANVAS_ITEM
335 (disp
->intreg
->gci_intreg1
[i
][j
]));
344 hide_all_intregs1 (Display
*disp
346 /* ----------------------------------------------------------------------------
347 * Hides 1st interrogation areas
354 && disp
->intreg
->exist_int
) {
355 nx
= disp
->intreg
->data
->nx
;
356 ny
= disp
->intreg
->data
->ny
;
357 for (i
= 0; i
< ny
; i
++) {
358 for (j
= 0; j
< nx
; j
++) {
359 if (disp
->intreg
->gci_intreg1
[i
][j
] != NULL
) {
360 gnome_canvas_item_hide (GNOME_CANVAS_ITEM
361 (disp
->intreg
->gci_intreg1
[i
][j
]));
370 destroy_all_intregs1 (Display
*disp
372 /* ----------------------------------------------------------------------------
373 * Destroys 1st interrogation areas
380 && disp
->intreg
->exist_int
) {
381 nx
= disp
->intreg
->data
->nx
;
382 ny
= disp
->intreg
->data
->ny
;
383 if (gpiv_par
->verbose
)
384 g_message("destroy_all_intregs1: destroying %d I.A.'s", nx
* ny
);
386 for (i
= 0; i
< ny
; i
++) {
387 for (j
= 0; j
< nx
; j
++) {
388 destroy_intreg1(disp
, i
, j
);
398 create_all_intregs2 (Display
*disp
400 /* ----------------------------------------------------------------------------
401 * Displays all second interrogation areas
408 && !disp
->intreg
->exist_int
)
409 disp
->intreg
->data
= create_intreg_data (disp
);
411 nx
= disp
->intreg
->data
->nx
;
412 ny
= disp
->intreg
->data
->ny
;
413 if (gpiv_par
->verbose
)
414 g_message("create_all_intregs2: creating %d I.A.'s", nx
* ny
);
416 for (i
= 0; i
< ny
; i
++) {
417 for (j
= 0; j
< nx
; j
++) {
418 create_intreg2 (disp
, i
, j
);
426 create_intreg2 (Display
*disp
,
430 /* ----------------------------------------------------------------------------
431 - Displays second interrogation area
434 int start_x
, start_y
, end_x
, end_y
;
438 && disp
->intreg
->exist_int
) {
439 x
= disp
->intreg
->data
->point_x
[i
][j
];
440 y
= disp
->intreg
->data
->point_y
[i
][j
];
445 start_x
= (int) x
- disp
->intreg
->par
->int_size_i
/ 2 +
446 disp
->intreg
->par
->pre_shift_col
;
447 start_y
= (int) y
- disp
->intreg
->par
->int_size_i
/ 2 +
448 disp
->intreg
->par
->pre_shift_row
;
449 end_x
= (int) x
+ disp
->intreg
->par
->int_size_i
/ 2 +
450 disp
->intreg
->par
->pre_shift_col
;
451 end_y
= (int) y
+ disp
->intreg
->par
->int_size_i
/ 2 +
452 disp
->intreg
->par
->pre_shift_row
;
454 if (disp
->intreg
->gci_intreg2
[i
][j
] != NULL
) {
455 destroy_intreg2(disp
, i
, j
);
458 disp
->intreg
->gci_intreg2
[i
][j
] =
459 gnome_canvas_item_new(gnome_canvas_root(GNOME_CANVAS
461 gnome_canvas_rect_get_type(),
462 "x1", (double) start_x
,
463 "y1", (double) start_y
,
464 "x2", (double) end_x
,
465 "y2", (double) end_y
,
466 "outline_color", "blue",
467 "width_units", (double) THICKNESS
,
475 update_intreg2 (Display
*disp
,
479 /* ----------------------------------------------------------------------------
480 * Updates second interrogation area
483 int start_x
, start_y
, end_x
, end_y
;
487 && disp
->intreg
->gci_intreg1
[i
][j
] != NULL
) {
489 x
= disp
->intreg
->data
->point_x
[i
][j
] + disp
->intreg
->par
->pre_shift_col
;
490 y
= disp
->intreg
->data
->point_y
[i
][j
] + disp
->intreg
->par
->pre_shift_row
;
493 * Using centre points of interr regs
495 start_x
= (int) x
- disp
->intreg
->par
->int_size_i
/ 2;
496 start_y
= (int) y
- disp
->intreg
->par
->int_size_i
/ 2;
497 end_x
= (int) x
+ disp
->intreg
->par
->int_size_i
/ 2;
498 end_y
= (int) y
+ disp
->intreg
->par
->int_size_i
/ 2;
500 if (disp
->intreg
->gci_intreg2
[i
][j
] != NULL
) {
501 gnome_canvas_item_set (GNOME_CANVAS_ITEM
502 (disp
->intreg
->gci_intreg2
[i
][j
]),
503 "x1", (double) start_x
,
504 "y1", (double) start_y
,
505 "x2", (double) end_x
,
506 "y2", (double) end_y
,
507 "outline_color", "blue",
508 "width_units", (double) THICKNESS
,
517 destroy_intreg2 (Display
*disp
,
521 /* ----------------------------------------------------------------------------
522 * Destroys 2nd interrogation area at index i, j
526 && disp
->intreg
->gci_intreg2
[i
][j
] != NULL
) {
527 gtk_object_destroy(GTK_OBJECT
528 (disp
->intreg
->gci_intreg2
[i
][j
]));
529 disp
->intreg
->gci_intreg2
[i
][j
] = NULL
;
536 show_all_intregs2 (Display
*disp
538 /* ----------------------------------------------------------------------------
539 * Shows 2nd interrogation areas
546 && disp
->intreg
->exist_int
) {
548 nx
= disp
->intreg
->data
->nx
;
549 ny
= disp
->intreg
->data
->ny
;
551 for (i
= 0; i
< ny
; i
++) {
552 for (j
= 0; j
< nx
; j
++) {
553 assert (disp
->intreg
->gci_intreg2
[i
][j
] != NULL
);
554 gnome_canvas_item_show (GNOME_CANVAS_ITEM
555 (disp
->intreg
->gci_intreg2
[i
][j
]));
564 hide_all_intregs2 (Display
*disp
566 /* ----------------------------------------------------------------------------
567 * Hides 2nd interrogation areas
574 && disp
->intreg
->exist_int
) {
575 nx
= disp
->intreg
->data
->nx
;
576 ny
= disp
->intreg
->data
->ny
;
578 for (i
= 0; i
< ny
; i
++) {
579 for (j
= 0; j
< nx
; j
++) {
580 assert (disp
->intreg
->gci_intreg2
[i
][j
] != NULL
);
581 gnome_canvas_item_hide (GNOME_CANVAS_ITEM
582 (disp
->intreg
->gci_intreg2
[i
][j
]));
591 destroy_all_intregs2 (Display
*disp
593 /* ----------------------------------------------------------------------------
594 * Destroys 2nd interrogation areas
601 && disp
->intreg
->exist_int
) {
602 nx
= disp
->intreg
->data
->nx
;
603 ny
= disp
->intreg
->data
->ny
;
604 if (gpiv_par
->verbose
)
605 g_message("destroy_all_intregs2: destroying %d I.A.'s", nx
* ny
);
607 for (i
= 0; i
< ny
; i
++) {
608 for (j
= 0; j
< nx
; j
++) {
609 destroy_intreg2(disp
, i
, j
);