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) 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)
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 ----------------------------------------------------------------------*/
29 #include "display_piv.h"
34 * BUGFIX repair color representation for canvas_aa
38 create_vector_color (gint peak_no
,
45 create_vector_color (gint peak_no
,
49 #endif /* CANVAS_AA */
52 dxdy_min (GpivPivData piv_data
54 /*-----------------------------------------------------------------------------
55 * Calculates maximum particle displacement from dx and dy of a piv data-set
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
) {
83 dxdy_max(GpivPivData piv_data
85 /*-----------------------------------------------------------------------------
86 * Calculates maximum particle displacement from dx and dy of a piv data-set
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
) {
114 create_vector(GpivData
* pida
,
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", */
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(),
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
+
163 "arrow_shape_b", (double) ARROW_EDGE
*
164 ARROW_FACT
* dl
* gpiv_par
.display__vector_scale
+
166 "arrow_shape_c", (double) ARROW_WIDTH
*
167 ARROW_FACT
* dl
* gpiv_par
.display__vector_scale
+
171 gnome_canvas_points_free(points
);
178 update_vector(GpivData
* pida
,
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
]),
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
216 "arrow_shape_b", (double) ARROW_EDGE
*
217 ARROW_FACT
* dl
* gpiv_par
.display__vector_scale
219 "arrow_shape_c", (double) ARROW_WIDTH
*
220 ARROW_FACT
* dl
* gpiv_par
.display__vector_scale
225 gnome_canvas_points_free(points
);
231 destroy_vector (GpivData
* pida
,
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
;
249 create_all_vectors (GpivData
* pida
251 /* ---------------------------------------------------------------------------
252 * Displays all PIV vectors on a Gnome canvas
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
;
275 show_all_vectors(GpivData
* pida
277 /* ----------------------------------------------------------------------------
278 * Shows all PIV vectors on a Gnome canvas
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
]));
297 hide_all_vectors(GpivData
* pida
299 /* ----------------------------------------------------------------------------
300 * Hides all PIV vectors on a Gnome canvas
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
]));
319 update_all_vectors(GpivData
* pida
321 /* ----------------------------------------------------------------------------
322 * Scales PIV vectors for Gnome canvas
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
);
341 destroy_all_vectors(GpivData
* pida
343 /* ----------------------------------------------------------------------------
344 * Destroys all PIV vectors on a Gnome canvas
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
);
357 /* g_warning("destroy_all_vectors: exist_vec = FALSE"); */
359 pida
->exist_vec
= FALSE
;
369 * BUGFIX repair color representation for canvas_aa
373 create_vector_color (gint peak_no
,
377 /* ----------------------------------------------------------------------------
378 * Create vector color for in canvas
382 GdkColor
*color_val
= NULL
;
384 Display
*disp
= display_act
;
386 color_val
= (GdkColor
*)g_malloc(sizeof(GdkColor
));
388 if (gpiv_par
.vector_color
== SHOW_PEAKNR
) {
390 color_val
->red
= BYTEVAL
;
391 color_val
->green
= 0;
394 } else if (peak_no
== 0) {
396 color_val
->green
= 0;
397 color_val
->blue
= BYTEVAL
;
399 } else if (peak_no
== 1) {
401 color_val
->green
= BYTEVAL
;
404 } else if (peak_no
== 2) {
406 color_val
->green
= BYTEVAL
;
407 color_val
->blue
= BYTEVAL
;
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
,
421 } else if (gpiv_par
.display__vector_color
== SHOW_SNR
) {
422 if (snr
>= disp
->pida
.valid_par
.residu_max
) {
424 color_val
->red
= BYTEVAL
;
425 color_val
->green
= 0;
428 /* color = "green"; */
430 color_val
->green
= BYTEVAL
;
434 color
= GNOME_CANVAS_COLOR(color_val
->red
,
438 } else if (gpiv_par
.display__vector_color
== SHOW_MAGNITUDE_GRAY
) {
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
));
448 color_val
->green
= 0;
452 color
= GNOME_CANVAS_COLOR(color_val
->red
,
456 } else if (gpiv_par
.display__vector_color
== SHOW_MAGNITUDE
) {
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);
464 color
= GNOME_CANVAS_COLOR(0, 0, 0);
473 #else /* CANVAS_AA */
475 create_vector_color(gint peak_no
,
479 /* ----------------------------------------------------------------------------
480 * Create vector color for in canvas
483 guint32 color_val
= 0;
486 if (gpiv_par
.display__vector_color
== SHOW_PEAKNR
) {
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
);
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
) {
517 color_val
= (gint
) (BYTEVAL
);
518 color_val
= (color_val
<< BITSHIFT_RED
);
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
) {
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
);
535 } else if (gpiv_par
.display__vector_color
== SHOW_MAGNITUDE
) {
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
);
549 #endif /* CANVAS_AA */