Retreives images/data from URI using Gnome Virtual File System.
[gpiv.git] / src / display_piv.c
blob8488b7614f2f258aded4030c233adb4b7bd08fff
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_piv.h"
32 #ifdef CANVAS_AA
34 * BUGFIX repair color representation for canvas_aa
37 static guint32
38 create_vector_color (gint peak_no,
39 gfloat snr,
40 gfloat dl
43 #else /* CANVAS_AA */
44 static guint32
45 create_vector_color (gint peak_no,
46 gfloat snr,
47 gfloat dl
49 #endif /* CANVAS_AA */
51 gfloat
52 dxdy_min (GpivPivData piv_data
54 /*-----------------------------------------------------------------------------
55 * Calculates maximum particle displacement from dx and dy of a piv data-set
58 gint i, j;
59 gfloat dl_abs = 0.0, dl_min = 10.0e+9;
61 /* assert(piv_data.nx != 0); */
62 /* assert(piv_data.ny != 0); */
65 for (i = 0; i < piv_data.ny; i++) {
66 for (j = 0; j < piv_data.nx; j++) {
67 if (piv_data.peak_no[i][j] >= 1) {
68 dl_abs = sqrt(piv_data.dx[i][j] * piv_data.dx[i][j] +
69 piv_data.dy[i][j] * piv_data.dy[i][j]);
70 if (dl_abs < dl_min) {
71 dl_min = dl_abs;
77 return dl_min;
82 gfloat
83 dxdy_max(GpivPivData piv_data
85 /*-----------------------------------------------------------------------------
86 * Calculates maximum particle displacement from dx and dy of a piv data-set
89 gint i, j;
90 gfloat dl_abs = 0.0, dl_max = 0.0;
92 /* assert(piv_data.nx != 0); */
93 /* assert(piv_data.ny != 0); */
96 for (i = 0; i < piv_data.ny; i++) {
97 for (j = 0; j < piv_data.nx; j++) {
98 if (piv_data.peak_no[i][j] >= 1) {
99 dl_abs = sqrt(piv_data.dx[i][j] * piv_data.dx[i][j] +
100 piv_data.dy[i][j] * piv_data.dy[i][j]);
101 if (dl_abs > dl_max) {
102 dl_max = dl_abs;
108 return dl_max;
113 void
114 create_vector(GpivData * pida,
115 gint i,
116 gint j
118 /* ----------------------------------------------------------------------------
119 * Displays a single PIV vector on a Gnome canvas
122 GnomeCanvasPoints *points;
123 Display *disp = display_act;
125 float **point_x = pida->piv_data.point_x;
126 float **point_y = pida->piv_data.point_y;
127 float **dx = pida->piv_data.dx, **dy = pida->piv_data.dy;
128 int **peak_no = pida->piv_data.peak_no;
129 float **snr = pida->piv_data.snr;
130 float dl = sqrt(dx[i][j] * dx[i][j] + dy[i][j] * dy[i][j]);
131 guint32 color_val = 0;
132 points = gnome_canvas_points_new(2);
135 * Fill out the points
138 points->coords[0] = point_x[i][j];
139 points->coords[1] = point_y[i][j];
140 points->coords[2] = point_x[i][j] + dx[i][j] * gpiv_par.display__vector_scale;
141 points->coords[3] = point_y[i][j] + dy[i][j] * gpiv_par.display__vector_scale;
144 color_val = create_vector_color(peak_no[i][j], snr[i][j], dl);
146 if (pida->gci_vector[i][j] != NULL) {
147 /* g_warning("create_vector:: gci_vector[%d][%d] != NULL ==> destroying", */
148 /* i, j); */
149 destroy_vector(pida, i, j);
152 pida->gci_vector[i][j] =
153 gnome_canvas_item_new(gnome_canvas_root
154 (GNOME_CANVAS(disp->canvas)),
155 gnome_canvas_line_get_type(),
156 "points", points,
157 "fill_color_rgba", color_val,
158 "width_units", (double) THICKNESS,
159 "last_arrowhead", TRUE,
160 "arrow_shape_a", (double) ARROW_LENGTH *
161 ARROW_FACT * dl * gpiv_par.display__vector_scale +
162 ARROW_ADD,
163 "arrow_shape_b", (double) ARROW_EDGE *
164 ARROW_FACT * dl * gpiv_par.display__vector_scale +
165 ARROW_ADD,
166 "arrow_shape_c", (double) ARROW_WIDTH *
167 ARROW_FACT * dl * gpiv_par.display__vector_scale +
168 ARROW_ADD,
169 NULL);
171 gnome_canvas_points_free(points);
177 void
178 update_vector(GpivData * pida,
179 gint i,
180 gint j
182 /* ----------------------------------------------------------------------------
183 * Updates a single PIV vector on a Gnome canvas
186 GnomeCanvasPoints *points;
188 float **point_x = pida->piv_data.point_x, **point_y =
189 pida->piv_data.point_y;
190 float **dx = pida->piv_data.dx, **dy = pida->piv_data.dy;
191 float **snr = pida->piv_data.snr;
192 int **peak_no = pida->piv_data.peak_no;
193 float dl = sqrt(dx[i][j] * dx[i][j] + dy[i][j] * dy[i][j]);
194 guint32 color_val = 0;
195 points = gnome_canvas_points_new(2);
198 * Fill out the points
200 points->coords[0] = point_x[i][j];
201 points->coords[1] = point_y[i][j];
202 points->coords[2] = point_x[i][j] + dx[i][j] * gpiv_par.display__vector_scale;
203 points->coords[3] = point_y[i][j] + dy[i][j] * gpiv_par.display__vector_scale;
205 color_val = create_vector_color(peak_no[i][j], snr[i][j], dl);
207 if (pida->gci_vector[i][j] != NULL) {
208 gnome_canvas_item_set(GNOME_CANVAS_ITEM(pida->gci_vector[i][j]),
209 "points", points,
210 "fill_color_rgba", color_val,
211 "width_units", (double) THICKNESS,
212 "last_arrowhead", TRUE,
213 "arrow_shape_a", (double) ARROW_LENGTH *
214 ARROW_FACT * dl * gpiv_par.display__vector_scale
215 + ARROW_ADD,
216 "arrow_shape_b", (double) ARROW_EDGE *
217 ARROW_FACT * dl * gpiv_par.display__vector_scale
218 + ARROW_ADD,
219 "arrow_shape_c", (double) ARROW_WIDTH *
220 ARROW_FACT * dl * gpiv_par.display__vector_scale
221 + ARROW_ADD,
222 NULL);
225 gnome_canvas_points_free(points);
230 void
231 destroy_vector (GpivData * pida,
232 gint i,
233 gint j
235 /* ----------------------------------------------------------------------------
236 * Detroys a single PIV vector on a Gnome canvas
239 if (pida->gci_vector[i][j] != NULL) {
240 gtk_object_destroy(GTK_OBJECT (pida->gci_vector[i][j]));
241 pida->gci_vector[i][j] = NULL;
248 void
249 create_all_vectors (GpivData * pida
251 /* ---------------------------------------------------------------------------
252 * Displays all PIV vectors on a Gnome canvas
255 int i, j;
256 gint nx = pida->piv_data.nx, ny = pida->piv_data.ny;
258 if (pida->exist_vec) {
259 destroy_all_vectors(pida);
261 gpiv_var.dl_max = dxdy_max(pida->piv_data);
262 gpiv_var.dl_min = dxdy_min(pida->piv_data);
263 for (i = 0; i < ny; i++) {
264 for (j = 0; j < nx; j++) {
265 create_vector (pida, i, j);
269 pida->exist_vec = TRUE;
274 void
275 show_all_vectors(GpivData * pida
277 /* ----------------------------------------------------------------------------
278 * Shows all PIV vectors on a Gnome canvas
281 int i, j;
282 gint nx = pida->piv_data.nx, ny = pida->piv_data.ny;
284 for (i = 0; i < ny; i++) {
285 for (j = 0; j < nx; j++) {
286 if (pida->gci_vector[i][j] != NULL) {
287 gnome_canvas_item_show(GNOME_CANVAS_ITEM
288 (pida->gci_vector[i][j]));
296 void
297 hide_all_vectors(GpivData * pida
299 /* ----------------------------------------------------------------------------
300 * Hides all PIV vectors on a Gnome canvas
303 int i, j;
304 gint nx = pida->piv_data.nx, ny = pida->piv_data.ny;
306 for (i = 0; i < ny; i++) {
307 for (j = 0; j < nx; j++) {
308 if (pida->gci_vector[i][j] != NULL) {
309 gnome_canvas_item_hide(GNOME_CANVAS_ITEM
310 (pida->gci_vector[i][j]));
318 void
319 update_all_vectors(GpivData * pida
321 /* ----------------------------------------------------------------------------
322 * Scales PIV vectors for Gnome canvas
325 int i, j;
326 int nx = pida->piv_data.nx, ny = pida->piv_data.ny;
328 gpiv_var.dl_max = dxdy_max(pida->piv_data);
329 gpiv_var.dl_min = dxdy_min(pida->piv_data);
330 for (i = 0; i < ny; i++) {
331 for (j = 0; j < nx; j++) {
332 update_vector(pida, i, j);
340 void
341 destroy_all_vectors(GpivData * pida
343 /* ----------------------------------------------------------------------------
344 * Destroys all PIV vectors on a Gnome canvas
347 int i, j;
348 gint nx = pida->piv_data.nx, ny = pida->piv_data.ny;
350 if (pida->exist_vec) {
351 for (i = 0; i < ny; i++) {
352 for (j = 0; j < nx; j++) {
353 destroy_vector(pida, i, j);
356 /* } else { */
357 /* g_warning("destroy_all_vectors: exist_vec = FALSE"); */
359 pida->exist_vec = FALSE;
365 * Local functions
367 #ifdef CANVAS_AA
369 * BUGFIX repair color representation for canvas_aa
372 static guint32
373 create_vector_color (gint peak_no,
374 gfloat snr,
375 gfloat dl
377 /* ----------------------------------------------------------------------------
378 * Create vector color for in canvas
381 guint32 color = 0;
382 GdkColor *color_val = NULL;
383 gint shift_factor;
384 Display *disp = display_act;
386 color_val = (GdkColor *)g_malloc(sizeof(GdkColor));
388 if (gpiv_par.vector_color == SHOW_PEAKNR) {
389 if (peak_no == -1) {
390 color_val->red = BYTEVAL;
391 color_val->green = 0;
392 color_val->blue = 0;
394 } else if (peak_no == 0) {
395 color_val->red = 0;
396 color_val->green = 0;
397 color_val->blue = BYTEVAL;
399 } else if (peak_no == 1) {
400 color_val->red = 0;
401 color_val->green = BYTEVAL;
402 color_val->blue = 0;
404 } else if (peak_no == 2) {
405 color_val->red = 0;
406 color_val->green = BYTEVAL;
407 color_val->blue = BYTEVAL;
409 } else {
410 /* if (peak_no[i][j] == 3) */
411 color_val->red = BYTEVAL / 2;
412 color_val->green = BYTEVAL / 2;
413 color_val->blue = BYTEVAL / 2;
417 color = GNOME_CANVAS_COLOR(color_val->red,
418 color_val->green,
419 color_val->blue);
421 } else if (gpiv_par.display__vector_color == SHOW_SNR) {
422 if (snr >= disp->pida.valid_par.residu_max) {
423 /* color = "red"; */
424 color_val->red = BYTEVAL;
425 color_val->green = 0;
426 color_val->blue = 0;
427 } else {
428 /* color = "green"; */
429 color_val->red = 0;
430 color_val->green = BYTEVAL;
431 color_val->blue = 0;
434 color = GNOME_CANVAS_COLOR(color_val->red,
435 color_val->green,
436 color_val->blue);
438 } else if (gpiv_par.display__vector_color == SHOW_MAGNITUDE_GRAY) {
439 if (peak_no >= 1) {
440 color_val->red = (gint) (BYTEVAL * (dl - gpiv_var.dl_min) /
441 (gpiv_var.dl_max - gpiv_var.dl_min));
442 color_val->green = (gint) (BYTEVAL * (dl - gpiv_var.dl_min) /
443 (gpiv_var.dl_max - gpiv_var.dl_min));
444 color_val->blue = (gint) (BYTEVAL * (dl - gpiv_var.dl_min) /
445 (gpiv_var.dl_max - gpiv_var.dl_min));
446 } else {
447 color_val->red = 0;
448 color_val->green = 0;
449 color_val->blue = 0;
452 color = GNOME_CANVAS_COLOR(color_val->red,
453 color_val->green,
454 color_val->blue);
456 } else if (gpiv_par.display__vector_color == SHOW_MAGNITUDE) {
457 if (peak_no >= 1) {
458 shift_factor = (gint) (28.0 * (dl - gpiv_var.dl_min) /
459 (gpiv_var.dl_max - gpiv_var.dl_min));
460 color = (( 0xFFFF << shift_factor) | 0xFF);
463 } else {
464 color = GNOME_CANVAS_COLOR(0, 0, 0);
468 g_free(color_val);
469 return color;
473 #else /* CANVAS_AA */
474 static guint32
475 create_vector_color(gint peak_no,
476 gfloat snr,
477 gfloat dl
479 /* ----------------------------------------------------------------------------
480 * Create vector color for in canvas
483 guint32 color_val = 0;
484 gint shift_factor;
486 if (gpiv_par.display__vector_color == SHOW_PEAKNR) {
487 if (peak_no == -1) {
488 /* color = "red"; */
489 color_val = (gint) (BYTEVAL);
490 color_val = (color_val << BITSHIFT_RED);
491 } else if (peak_no == 0) {
492 /* color = "lightblue"; */
493 color_val = (gint) (BYTEVAL);
494 color_val = (color_val << BITSHIFT_BLUE);
495 } else if (peak_no == 1) {
496 /* color = "green"; */
497 color_val = (gint) (BYTEVAL);
498 color_val = (color_val << BITSHIFT_GREEN);
499 } else if (peak_no == 2) {
500 /* color = "yellow"; */
501 color_val = (gint) (BYTEVAL);
502 color_val = (color_val << BITSHIFT_GREEN)
503 + (color_val << BITSHIFT_BLUE);
504 } else {
505 /* if (peak_no == 3) */
506 /* color = "gray"; */
507 color_val = (gint) (127);
508 color_val = (color_val << BITSHIFT_RED)
509 + (color_val << BITSHIFT_GREEN)
510 + (color_val << BITSHIFT_BLUE);
514 } else if (gpiv_par.display__vector_color == SHOW_SNR) {
515 if (snr >= gl_valid_par.residu_max) {
516 /* color = "red"; */
517 color_val = (gint) (BYTEVAL);
518 color_val = (color_val << BITSHIFT_RED);
519 } else {
520 /* color = "green"; */
521 color_val = (gint) (BYTEVAL);
522 color_val = (color_val << BITSHIFT_GREEN);
526 } else if (gpiv_par.display__vector_color == SHOW_MAGNITUDE_GRAY) {
527 if (peak_no >= 1) {
528 color_val = (gint) (BYTEVAL * (dl - gpiv_var.dl_min) /
529 (gpiv_var.dl_max - gpiv_var.dl_min));
530 color_val = (color_val << BITSHIFT_RED) +
531 (color_val << BITSHIFT_GREEN) + (color_val << BITSHIFT_BLUE);
532 } else {
533 color_val = 0;
535 } else if (gpiv_par.display__vector_color == SHOW_MAGNITUDE) {
536 if (peak_no >= 1) {
537 shift_factor = (gint) (28.0 * (dl - gpiv_var.dl_min) /
538 (gpiv_var.dl_max - gpiv_var.dl_min));
539 color_val = ( 0xFFFF << shift_factor);
540 } else {
541 color_val = 0;
546 return color_val;
549 #endif /* CANVAS_AA */