bugrepair: drag and drop
[gpiv.git] / src / display_intregs.c
blobe958f7fb6bf193f30cc35fedb368055a4bb113bb
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 ----------------------------------------------------------------------*/
29 #include "gpiv_gui.h"
30 #include "display_intregs.h"
32 void
33 create_all_intregs (Display *disp
35 /*-----------------------------------------------------------------------------
36 * Creates all interrogation areas
39 char *err_msg = NULL;
40 GtkWidget *view_piv_display0 =
41 gtk_object_get_data(GTK_OBJECT(disp->mwin),
42 "view_piv_display0");
45 if (disp != NULL) {
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");
50 return;
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);
75 } else {
76 error_gpiv ("create_all_intregs: disp != NULL failed");
82 void
83 destroy_all_intregs (Display *disp
85 /*-----------------------------------------------------------------------------
86 * Destroys all interrogation areas
89 if (disp != NULL) {
90 destroy_all_intregs1 (disp);
91 destroy_all_intregs2 (disp);
92 destroy_intreg_data (disp);
93 disp->display_intregs = FALSE;
99 void
100 show_all_intregs(Display *disp
102 /*-----------------------------------------------------------------------------
103 * Shows all interrogation areas
106 if (disp != NULL
107 && !disp->intreg->exist_int) {
108 create_all_intregs(disp);
110 show_all_intregs1(disp);
111 show_all_intregs2(disp);
116 void
117 hide_all_intregs (Display *disp
119 /*-----------------------------------------------------------------------------
120 * Hides all interrogation areas
123 if (disp != NULL) {
124 hide_all_intregs1(disp);
125 hide_all_intregs2(disp);
131 GpivPivData *
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); */
146 if ((err_msg =
147 gpiv_piv_count_pivdata_fromimage (disp->img->image->header,
148 disp->intreg->par,
149 &nx,
150 &ny))
151 != NULL) {
152 g_warning ("create_intreg_data: %s", err_msg);
153 return NULL;
156 if ((data =
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;
161 return data;
166 void
167 destroy_intreg_data (Display *disp
169 /*-----------------------------------------------------------------------------
172 if (disp != NULL
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;
182 void
183 create_all_intregs1 (Display *disp
185 /* ----------------------------------------------------------------------------
186 * Displays all first interrogation areas
189 int i = 0, j;
190 gint nx = 0;
191 gint ny = 0;
193 if (disp != NULL
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);
209 void
210 create_intreg1 (Display *disp,
211 gint i,
212 gint j
214 /* ----------------------------------------------------------------------------
215 * Displays first interrogation area
218 int start_x = 0, start_y = 0, end_x = 0, end_y = 0;
219 float x, y;
221 if (disp != NULL
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,
249 NULL);
255 void
256 update_intreg1 (Display *disp,
257 gint i,
258 gint j
260 /* ----------------------------------------------------------------------------
261 * Updates first interrogation area
264 int start_x = 0, start_y = 0, end_x = 0, end_y = 0;
265 float x, y;
267 if (disp != NULL
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,
288 NULL);
294 void
295 destroy_intreg1 (Display *disp,
296 gint i,
297 gint j
299 /* ----------------------------------------------------------------------------
300 * Destroys 1st interrogation area at index i, j
303 if (disp != NULL
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;
313 void
314 show_all_intregs1 (Display *disp
316 /* ----------------------------------------------------------------------------
317 * Shows 1st interrogation areas
320 int i = 0, j = 0;
321 gint nx = 0, ny = 0;
323 if (disp != NULL
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]));
343 void
344 hide_all_intregs1 (Display *disp
346 /* ----------------------------------------------------------------------------
347 * Hides 1st interrogation areas
350 int i = 0, j = 0;
351 gint nx = 0, ny = 0;
353 if (disp != NULL
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]));
369 void
370 destroy_all_intregs1 (Display *disp
372 /* ----------------------------------------------------------------------------
373 * Destroys 1st interrogation areas
376 int i = 0, j = 0;
377 int nx = 0, ny = 0;
379 if (disp != NULL
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);
397 void
398 create_all_intregs2 (Display *disp
400 /* ----------------------------------------------------------------------------
401 * Displays all second interrogation areas
404 int i, j;
405 int nx, ny;
407 if (disp != NULL
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);
425 void
426 create_intreg2 (Display *disp,
427 gint i,
428 gint j
430 /* ----------------------------------------------------------------------------
431 - Displays second interrogation area
434 int start_x, start_y, end_x, end_y;
435 float x, y;
437 if (disp != NULL
438 && disp->intreg->exist_int) {
439 x = disp->intreg->data->point_x[i][j];
440 y = disp->intreg->data->point_y[i][j];
443 * with lines
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
460 (disp->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,
468 NULL);
474 void
475 update_intreg2 (Display *disp,
476 gint i,
477 gint j
479 /* ----------------------------------------------------------------------------
480 * Updates second interrogation area
483 int start_x, start_y, end_x, end_y;
484 float x, y;
486 if (disp != NULL
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,
509 NULL);
516 void
517 destroy_intreg2 (Display *disp,
518 gint i,
519 gint j
521 /* ----------------------------------------------------------------------------
522 * Destroys 2nd interrogation area at index i, j
525 if (disp != NULL
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;
535 void
536 show_all_intregs2 (Display *disp
538 /* ----------------------------------------------------------------------------
539 * Shows 2nd interrogation areas
542 int i, j;
543 int nx, ny;
545 if (disp != NULL
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]));
563 void
564 hide_all_intregs2 (Display *disp
566 /* ----------------------------------------------------------------------------
567 * Hides 2nd interrogation areas
570 int i, j;
571 int nx, ny;
573 if (disp != NULL
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]));
590 void
591 destroy_all_intregs2 (Display *disp
593 /* ----------------------------------------------------------------------------
594 * Destroys 2nd interrogation areas
597 int i, j;
598 int nx, ny;
600 if (disp != NULL
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);