added gpiv_logo.xpm
[gpiv.git] / src / display_scalars.c
blobaf951f05a940fb45520e7043f0f8df85ee4418e7
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) 2002, 2003, 2004 Gerber van der Graaf
10 This file is part of gpiv.
12 Gpiv is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2, or (at your option)
15 any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 ----------------------------------------------------------------------*/
28 #include "gpiv_gui.h"
29 #include "display_scalars.h"
31 #ifdef CANVAS_AA
32 static guint
33 create_scalar_color (gint flag,
34 gfloat sc_min,
35 gfloat sc_max,
36 gfloat sc,
37 gfloat scale_factor
40 #else /* CANVAS_AA */
42 static guint
43 create_scalar_color (gint flag,
44 gfloat sc_min,
45 gfloat sc_max,
46 gfloat sc,
47 gfloat scale_factor
49 #endif /* CANVAS_AA */
52 static void
53 destroy_filledrect (GnomeCanvasItem *filled_rect
56 static void
57 show_filledrect (GnomeCanvasItem *filled_rect
60 static void
61 hide_filledrect (GnomeCanvasItem *filled_rect
64 static void
65 create_vor (Display *disp,
66 gint i,
67 gint j,
68 guint col_val
71 static void
72 create_sstrain (Display *disp,
73 gint i,
74 gint j,
75 guint col_val
78 static void
79 create_nstrain (Display *disp,
80 gint i,
81 gint j,
82 guint col_val
86 * Public functions
88 void
89 create_all_scalars(Display *disp,
90 gint type
92 /* ----------------------------------------------------------------------------
93 * Displays all scalar gnome canvas items
96 int i, j;
97 int nx = 0, ny = 0, **flag = NULL;
99 float **sc = NULL;
100 float sc_min = 10000.0, sc_max = -10000.0;
101 guint col_val = 0;
102 GpivScalarData *scalar_data;
103 GtkWidget *view_piv_display0 =
104 gtk_object_get_data(GTK_OBJECT(disp->mwin),
105 "view_piv_display0");
106 GtkWidget * view_piv_display1 =
107 gtk_object_get_data(GTK_OBJECT(disp->mwin),
108 "view_piv_display1");
109 float scale_factor = 0.0;
112 if (type == GPIV_VORTICITY) {
113 scalar_data = disp->pida->vor_data;
114 sc = scalar_data->scalar;
115 nx = disp->pida->vor_data->nx;
116 ny = disp->pida->vor_data->ny;
117 flag = disp->pida->vor_data->flag;
118 /* scalar_colval(disp); */
120 } else if (type == GPIV_S_STRAIN) {
121 scalar_data = disp->pida->sstrain_data;
122 sc = scalar_data->scalar;
123 nx = disp->pida->sstrain_data->nx;
124 ny = disp->pida->sstrain_data->ny;
125 flag = disp->pida->sstrain_data->flag;
127 } else if (type == GPIV_N_STRAIN) {
128 scalar_data = disp->pida->nstrain_data;
129 sc = scalar_data->scalar;
130 nx = disp->pida->nstrain_data->nx;
131 ny = disp->pida->nstrain_data->ny;
132 flag = disp->pida->nstrain_data->flag;
133 } else {
134 g_warning(_("create_all_scalars: unexisting type"));
138 * normalizing data between 0 and 1 to define color value col_val
140 /* scalar_colval(Display * disp) { */
141 for (i = 0; i < ny; i++) {
142 for (j = 0; j < nx; j++) {
143 if (flag[i][j] != -1) {
144 if (sc[i][j] < sc_min) sc_min = sc[i][j];
145 if (sc[i][j] > sc_max) sc_max = sc[i][j];
150 if (sc_min < 0) {
151 if (-sc_min >= sc_max) {
152 scale_factor = 1.0 / -sc_min;
153 } else {
154 scale_factor = 1.0 / sc_max;
156 } else {
157 scale_factor = 1.0 / sc_max;
161 for (i = 0; i < ny; i++) {
162 for (j = 0; j < nx; j++) {
163 col_val = create_scalar_color(flag[i][j], sc_min, sc_max,
164 sc[i][j], scale_factor);
165 if (type == GPIV_VORTICITY) {
166 create_vor(disp, i, j, col_val);
167 } else if (type == GPIV_S_STRAIN) {
168 create_sstrain(disp, i, j, col_val);
169 } else if (type == GPIV_N_STRAIN) {
170 create_nstrain(disp, i, j, col_val);
171 } else {
172 g_warning(_("create_all_scalars: unexisting type"));
177 if (GTK_CHECK_MENU_ITEM(view_piv_display0)->active) {
178 for (i = 0; i < ny; i++) {
179 for (j = 0; j < nx; j++) {
180 gnome_canvas_item_raise_to_top
181 (disp->intreg->gci_intreg1[i][j]);
182 gnome_canvas_item_raise_to_top
183 (display_act->intreg->gci_intreg2[i][j]);
188 if (GTK_CHECK_MENU_ITEM(view_piv_display1)->active) {
189 if (disp->pida->exist_piv && disp->display_piv) {
190 for (i = 0; i < ny; i++) {
191 for (j = 0; j < nx; j++) {
192 gnome_canvas_item_raise_to_top
193 (disp->pida->gci_vector[i][j]);
203 void
204 show_all_scalars(Display *disp,
205 gint type
207 /* ----------------------------------------------------------------------------
208 * Shows scalar gnome canvas items
211 guint i = 0, j = 0;
212 guint nx = 0, ny = 0;
214 if (disp->pida->vor_data == NULL) return;
216 if (type == GPIV_VORTICITY
217 && disp->pida->vor_data != NULL) {
218 nx = disp->pida->vor_data->nx;
219 ny = disp->pida->vor_data->ny;
220 for (i = 0; i < ny; i++) {
221 for (j = 0; j < nx; j++) {
222 /* if (i ==0 && j==0) */
223 show_filledrect(display_act->pida->gci_scalar_vor[i][j]);
226 display_act->display_scalar = SHOW_SC_VORTICITY;
229 if (type == GPIV_S_STRAIN
230 && disp->pida->sstrain_data != NULL) {
231 nx = disp->pida->sstrain_data->nx;
232 ny = disp->pida->sstrain_data->ny;
233 for (i = 0; i < ny; i++) {
234 for (j = 0; j < nx; j++) {
235 show_filledrect(display_act->pida->gci_scalar_sstrain[i][j]);
238 display_act->display_scalar = SHOW_SC_SSTRAIN;
241 if (type == GPIV_N_STRAIN
242 && disp->pida->nstrain_data != NULL) {
243 nx = disp->pida->nstrain_data->nx;
244 ny = disp->pida->nstrain_data->ny;
245 for (i = 0; i < ny; i++) {
246 for (j = 0; j < nx; j++) {
247 show_filledrect(display_act->pida->gci_scalar_nstrain[i][j]);
250 display_act->display_scalar = SHOW_SC_NSTRAIN;
257 void
258 hide_all_scalars (Display *disp,
259 gint type
261 /* ----------------------------------------------------------------------------
262 * Hides all scalar gnome canvas items
265 guint i, j;
266 /* int nx = disp->pida->scalar_data->nx, ny = disp->pida->scalar_data->ny; */
269 if (disp->pida->vor_data == NULL) return;
271 if (type == GPIV_VORTICITY
272 && disp->pida->vor_data != NULL) {
273 for (i = 0; i < disp->pida->vor_data->ny; i++) {
274 for (j = 0; j < disp->pida->vor_data->nx; j++) {
275 /* if (i ==0 && j==0) */
276 hide_filledrect(disp->pida->gci_scalar_vor[i][j]);
279 disp->display_scalar = SHOW_SC_NONE;
282 if (type == GPIV_S_STRAIN
283 && disp->pida->sstrain_data != NULL) {
284 for (i = 0; i < disp->pida->sstrain_data->ny; i++) {
285 for (j = 0; j < disp->pida->sstrain_data->nx; j++) {
286 hide_filledrect(disp->pida->gci_scalar_sstrain[i][j]);
289 disp->display_scalar = SHOW_SC_NONE;
292 if (type == GPIV_N_STRAIN
293 && disp->pida->nstrain_data != NULL) {
294 for (i = 0; i < disp->pida->nstrain_data->ny; i++) {
295 for (j = 0; j < disp->pida->nstrain_data->nx; j++) {
296 hide_filledrect(disp->pida->gci_scalar_nstrain[i][j]);
299 disp->display_scalar = SHOW_SC_NONE;
307 void
308 destroy_all_scalars(Display *disp,
309 gint type
311 /* ----------------------------------------------------------------------------
312 * Destroys scalar canvas items
315 guint i, j;
318 if (disp->pida->vor_data == NULL) return;
320 if (type == GPIV_VORTICITY
321 && disp->pida->vor_data != NULL) {
322 for (i = 0; i < disp->pida->vor_data->ny; i++) {
323 for (j = 0; j < disp->pida->vor_data->nx; j++) {
324 /* if (i ==0 && j==0) */
325 destroy_filledrect(disp->pida->gci_scalar_vor[i][j]);
329 } else if (type == GPIV_S_STRAIN
330 && disp->pida->sstrain_data != NULL) {
331 for (i = 0; i < disp->pida->sstrain_data->ny; i++) {
332 for (j = 0; j < disp->pida->sstrain_data->nx; j++) {
333 destroy_filledrect(disp->pida->gci_scalar_sstrain[i][j]);
337 } else if (type == GPIV_N_STRAIN
338 && disp->pida->nstrain_data != NULL) {
339 for (i = 0; i < disp->pida->nstrain_data->ny; i++) {
340 for (j = 0; j < disp->pida->nstrain_data->nx; j++) {
341 destroy_filledrect(disp->pida->gci_scalar_nstrain[i][j]);
344 } else {
345 g_warning(_("destroy_all_scalars: unexisting type"));
353 * Local functions
355 #ifdef CANVAS_AA
357 * BUGFIX repair color representation for canvas_aa
360 static guint
361 create_scalar_color (gint flag,
362 gfloat sc_min,
363 gfloat sc_max,
364 gfloat sc,
365 gfloat scale_factor
367 /* ----------------------------------------------------------------------------
368 * Create scalar color for in canvas
371 guint color = 0;
372 GdkColor *color_val = NULL;
374 color_val = (GdkColor *)g_malloc(sizeof(GdkColor));
375 if (flag != -1) {
376 if (sc_min < 0) {
377 if (sc <0) {
378 color_val->red = (gint) (-sc * BYTEVAL * scale_factor);
379 color_val->green = 0;
380 color_val->blue = 0;
381 } else {
382 color_val->red = 0;
383 color_val->green = 0;
384 color_val->blue = (int) (sc * BYTEVAL * scale_factor);
386 } else {
387 color_val->red = 0;
388 color_val->green = 0;
389 color_val->blue = (int) (sc * BYTEVAL * scale_factor);
391 } else {
392 color_val->red = 0;
393 color_val->green = BYTEVAL / 2;
394 color_val->blue = 0;
397 color = GNOME_CANVAS_COLOR(color_val->red,
398 color_val->green,
399 color_val->blue);
400 g_free(color_val);
401 return color;
405 #else /* CANVAS_AA */
407 static guint
408 create_scalar_color (gint flag,
409 gfloat sc_min,
410 gfloat sc_max,
411 gfloat sc,
412 gfloat scale_factor
414 /* ----------------------------------------------------------------------------
415 * Create scalar color for in canvas
418 guint color_val = 0;
420 if (flag != -1) {
421 if (sc_min < 0) {
422 if (sc <0) {
423 color_val = (int) (-sc * BYTEVAL * scale_factor);
424 color_val = (color_val << BITSHIFT_RED);
425 } else {
426 color_val = (int) (sc * BYTEVAL * scale_factor);
427 color_val = (color_val << BITSHIFT_BLUE);
429 } else {
430 color_val = (int) (sc * BYTEVAL * scale_factor);
431 color_val = (color_val << BITSHIFT_BLUE);
433 } else {
434 color_val = 128 << BITSHIFT_GREEN;
438 return color_val;
442 #endif /* CANVAS_AA */
445 static void
446 destroy_filledrect(GnomeCanvasItem *filled_rect
448 /* ----------------------------------------------------------------------------
449 * Destroys a single filled rectangular canvas item
452 if (filled_rect != NULL) {
453 gtk_object_destroy(GTK_OBJECT(filled_rect));
454 filled_rect = NULL;
460 static void
461 show_filledrect(GnomeCanvasItem *filled_rect
463 /* ----------------------------------------------------------------------------
464 * Shows a single filled rectangular canvas item
467 if (filled_rect != NULL) {
468 gnome_canvas_item_show
469 (GNOME_CANVAS_ITEM(filled_rect));
475 static void
476 hide_filledrect(GnomeCanvasItem *filled_rect
478 /* ----------------------------------------------------------------------------
479 * Hides a single filled rectangular canvas item
482 if (filled_rect != NULL) {
483 gnome_canvas_item_hide
484 (GNOME_CANVAS_ITEM(filled_rect));
490 static void
491 create_vor (Display *disp,
492 gint i,
493 gint j,
494 guint col_val
496 /* ----------------------------------------------------------------------------
497 * Creates vorticity gnome canvas item by coloring the interrogation area
500 float **x, **y;
501 int start_x, start_y, end_x, end_y;
503 GnomeCanvasPoints *points;
504 points = gnome_canvas_points_new(5);
508 * Using centre points of interr regs
510 x = disp->pida->vor_data->point_x;
511 y = disp->pida->vor_data->point_y;
512 start_x = (int) x[i][j] - disp->pida->piv_par->int_size_f / 2;
513 start_y = (int) y[i][j] - disp->pida->piv_par->int_size_f / 2;
514 end_x = (int) x[i][j] + disp->pida->piv_par->int_size_f / 2;
515 end_y = (int) y[i][j] + disp->pida->piv_par->int_size_f / 2;
517 disp->pida->gci_scalar_vor[i][j] =
518 gnome_canvas_item_new(gnome_canvas_root
519 (GNOME_CANVAS(display_act->canvas)),
520 gnome_canvas_rect_get_type(),
521 "x1", (double) start_x,
522 "y1", (double) start_y,
523 "x2", (double) end_x,
524 "y2", (double) end_y,
525 "fill_color_rgba", col_val,
526 NULL);
528 gnome_canvas_points_free(points);
533 static void
534 create_sstrain (Display *disp,
535 gint i,
536 gint j,
537 guint col_val
539 /* ----------------------------------------------------------------------------
540 * Creates shear strain gnome canvas item by coloring the interrogation area
543 float **x, **y;
544 int start_x, start_y, end_x, end_y;
546 GnomeCanvasPoints *points;
547 points = gnome_canvas_points_new(5);
551 * Using centre points of interr regs
553 x = disp->pida->sstrain_data->point_x;
554 y = disp->pida->sstrain_data->point_y;
555 start_x = (int) x[i][j] - disp->pida->piv_par->int_size_f / 2;
556 start_y = (int) y[i][j] - disp->pida->piv_par->int_size_f / 2;
557 end_x = (int) x[i][j] + disp->pida->piv_par->int_size_f / 2;
558 end_y = (int) y[i][j] + disp->pida->piv_par->int_size_f / 2;
560 disp->pida->gci_scalar_sstrain[i][j] =
561 gnome_canvas_item_new(gnome_canvas_root
562 (GNOME_CANVAS(display_act->canvas)),
563 gnome_canvas_rect_get_type(),
564 "x1", (double) start_x,
565 "y1", (double) start_y,
566 "x2", (double) end_x,
567 "y2", (double) end_y,
568 "fill_color_rgba", col_val,
569 NULL);
571 gnome_canvas_points_free(points);
576 static void
577 create_nstrain (Display *disp,
578 gint i,
579 gint j,
580 guint col_val
582 /* ----------------------------------------------------------------------------
583 * Creates normal strain gnome canvas item by coloring the interrogation area
586 float **x, **y;
587 int start_x, start_y, end_x, end_y;
589 GnomeCanvasPoints *points;
590 points = gnome_canvas_points_new(5);
594 * Using centre points of interr regs
597 x = disp->pida->nstrain_data->point_x;
598 y = disp->pida->nstrain_data->point_y;
599 start_x = (int) x[i][j] - disp->pida->piv_par->int_size_f / 2;
600 start_y = (int) y[i][j] - disp->pida->piv_par->int_size_f / 2;
601 end_x = (int) x[i][j] + disp->pida->piv_par->int_size_f / 2;
602 end_y = (int) y[i][j] + disp->pida->piv_par->int_size_f / 2;
604 disp->pida->gci_scalar_nstrain[i][j] =
605 gnome_canvas_item_new(gnome_canvas_root
606 (GNOME_CANVAS(display_act->canvas)),
607 gnome_canvas_rect_get_type(),
608 "x1", (double) start_x,
609 "y1", (double) start_y,
610 "x2", (double) end_x,
611 "y2", (double) end_y,
612 "fill_color_rgba", col_val,
613 NULL);
615 gnome_canvas_points_free(points);