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, 2005, 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_scalars.h"
34 create_scalar_color (gint flag
,
44 create_scalar_color (gint flag
,
50 #endif /* CANVAS_AA */
54 destroy_filledrect (GnomeCanvasItem
*filled_rect
58 show_filledrect (GnomeCanvasItem
*filled_rect
62 hide_filledrect (GnomeCanvasItem
*filled_rect
66 create_vor (Display
*disp
,
73 create_sstrain (Display
*disp
,
80 create_nstrain (Display
*disp
,
90 create_all_scalars(Display
*disp
,
93 /* ----------------------------------------------------------------------------
94 * Displays all scalar gnome canvas items
98 int nx
= 0, ny
= 0, **flag
= NULL
;
101 float sc_min
= 10000.0, sc_max
= -10000.0;
103 GpivScalarData
*scalar_data
;
104 GtkWidget
*view_piv_display0
=
105 gtk_object_get_data(GTK_OBJECT(disp
->mwin
),
106 "view_piv_display0");
107 GtkWidget
* view_piv_display1
=
108 gtk_object_get_data(GTK_OBJECT(disp
->mwin
),
109 "view_piv_display1");
110 float scale_factor
= 0.0;
113 if (type
== GPIV_VORTICITY
) {
114 scalar_data
= disp
->pida
->vor_data
;
115 sc
= scalar_data
->scalar
;
116 nx
= disp
->pida
->vor_data
->nx
;
117 ny
= disp
->pida
->vor_data
->ny
;
118 flag
= disp
->pida
->vor_data
->flag
;
119 /* scalar_colval(disp); */
121 } else if (type
== GPIV_S_STRAIN
) {
122 scalar_data
= disp
->pida
->sstrain_data
;
123 sc
= scalar_data
->scalar
;
124 nx
= disp
->pida
->sstrain_data
->nx
;
125 ny
= disp
->pida
->sstrain_data
->ny
;
126 flag
= disp
->pida
->sstrain_data
->flag
;
128 } else if (type
== GPIV_N_STRAIN
) {
129 scalar_data
= disp
->pida
->nstrain_data
;
130 sc
= scalar_data
->scalar
;
131 nx
= disp
->pida
->nstrain_data
->nx
;
132 ny
= disp
->pida
->nstrain_data
->ny
;
133 flag
= disp
->pida
->nstrain_data
->flag
;
135 g_warning(_("create_all_scalars: unexisting type"));
139 * normalizing data between 0 and 1 to define color value col_val
141 /* scalar_colval(Display * disp) { */
142 for (i
= 0; i
< ny
; i
++) {
143 for (j
= 0; j
< nx
; j
++) {
144 if (flag
[i
][j
] != -1) {
145 if (sc
[i
][j
] < sc_min
) sc_min
= sc
[i
][j
];
146 if (sc
[i
][j
] > sc_max
) sc_max
= sc
[i
][j
];
152 if (-sc_min
>= sc_max
) {
153 scale_factor
= 1.0 / -sc_min
;
155 scale_factor
= 1.0 / sc_max
;
158 scale_factor
= 1.0 / sc_max
;
162 for (i
= 0; i
< ny
; i
++) {
163 for (j
= 0; j
< nx
; j
++) {
164 col_val
= create_scalar_color(flag
[i
][j
], sc_min
, sc_max
,
165 sc
[i
][j
], scale_factor
);
166 if (type
== GPIV_VORTICITY
) {
167 create_vor(disp
, i
, j
, col_val
);
168 } else if (type
== GPIV_S_STRAIN
) {
169 create_sstrain(disp
, i
, j
, col_val
);
170 } else if (type
== GPIV_N_STRAIN
) {
171 create_nstrain(disp
, i
, j
, col_val
);
173 g_warning(_("create_all_scalars: unexisting type"));
178 if (GTK_CHECK_MENU_ITEM(view_piv_display0
)->active
) {
179 for (i
= 0; i
< ny
; i
++) {
180 for (j
= 0; j
< nx
; j
++) {
181 gnome_canvas_item_raise_to_top
182 (disp
->intreg
->gci_intreg1
[i
][j
]);
183 gnome_canvas_item_raise_to_top
184 (display_act
->intreg
->gci_intreg2
[i
][j
]);
189 if (GTK_CHECK_MENU_ITEM(view_piv_display1
)->active
) {
190 if (disp
->pida
->exist_piv
&& disp
->display_piv
) {
191 for (i
= 0; i
< ny
; i
++) {
192 for (j
= 0; j
< nx
; j
++) {
193 gnome_canvas_item_raise_to_top
194 (disp
->pida
->gci_vector
[i
][j
]);
205 show_all_scalars(Display
*disp
,
208 /* ----------------------------------------------------------------------------
209 * Shows scalar gnome canvas items
213 guint nx
= 0, ny
= 0;
215 if (disp
->pida
->vor_data
== NULL
) return;
217 if (type
== GPIV_VORTICITY
218 && disp
->pida
->vor_data
!= NULL
) {
219 nx
= disp
->pida
->vor_data
->nx
;
220 ny
= disp
->pida
->vor_data
->ny
;
221 for (i
= 0; i
< ny
; i
++) {
222 for (j
= 0; j
< nx
; j
++) {
223 /* if (i ==0 && j==0) */
224 show_filledrect(display_act
->pida
->gci_scalar_vor
[i
][j
]);
227 display_act
->display_scalar
= SHOW_SC_VORTICITY
;
230 if (type
== GPIV_S_STRAIN
231 && disp
->pida
->sstrain_data
!= NULL
) {
232 nx
= disp
->pida
->sstrain_data
->nx
;
233 ny
= disp
->pida
->sstrain_data
->ny
;
234 for (i
= 0; i
< ny
; i
++) {
235 for (j
= 0; j
< nx
; j
++) {
236 show_filledrect(display_act
->pida
->gci_scalar_sstrain
[i
][j
]);
239 display_act
->display_scalar
= SHOW_SC_SSTRAIN
;
242 if (type
== GPIV_N_STRAIN
243 && disp
->pida
->nstrain_data
!= NULL
) {
244 nx
= disp
->pida
->nstrain_data
->nx
;
245 ny
= disp
->pida
->nstrain_data
->ny
;
246 for (i
= 0; i
< ny
; i
++) {
247 for (j
= 0; j
< nx
; j
++) {
248 show_filledrect(display_act
->pida
->gci_scalar_nstrain
[i
][j
]);
251 display_act
->display_scalar
= SHOW_SC_NSTRAIN
;
259 hide_all_scalars (Display
*disp
,
262 /* ----------------------------------------------------------------------------
263 * Hides all scalar gnome canvas items
267 /* int nx = disp->pida->scalar_data->nx, ny = disp->pida->scalar_data->ny; */
270 if (disp
->pida
->vor_data
== NULL
) return;
272 if (type
== GPIV_VORTICITY
273 && disp
->pida
->vor_data
!= NULL
) {
274 for (i
= 0; i
< disp
->pida
->vor_data
->ny
; i
++) {
275 for (j
= 0; j
< disp
->pida
->vor_data
->nx
; j
++) {
276 /* if (i ==0 && j==0) */
277 hide_filledrect(disp
->pida
->gci_scalar_vor
[i
][j
]);
280 disp
->display_scalar
= SHOW_SC_NONE
;
283 if (type
== GPIV_S_STRAIN
284 && disp
->pida
->sstrain_data
!= NULL
) {
285 for (i
= 0; i
< disp
->pida
->sstrain_data
->ny
; i
++) {
286 for (j
= 0; j
< disp
->pida
->sstrain_data
->nx
; j
++) {
287 hide_filledrect(disp
->pida
->gci_scalar_sstrain
[i
][j
]);
290 disp
->display_scalar
= SHOW_SC_NONE
;
293 if (type
== GPIV_N_STRAIN
294 && disp
->pida
->nstrain_data
!= NULL
) {
295 for (i
= 0; i
< disp
->pida
->nstrain_data
->ny
; i
++) {
296 for (j
= 0; j
< disp
->pida
->nstrain_data
->nx
; j
++) {
297 hide_filledrect(disp
->pida
->gci_scalar_nstrain
[i
][j
]);
300 disp
->display_scalar
= SHOW_SC_NONE
;
309 destroy_all_scalars(Display
*disp
,
312 /* ----------------------------------------------------------------------------
313 * Destroys scalar canvas items
319 if (disp
->pida
->vor_data
== NULL
) return;
321 if (type
== GPIV_VORTICITY
322 && disp
->pida
->vor_data
!= NULL
) {
323 for (i
= 0; i
< disp
->pida
->vor_data
->ny
; i
++) {
324 for (j
= 0; j
< disp
->pida
->vor_data
->nx
; j
++) {
325 /* if (i ==0 && j==0) */
326 destroy_filledrect(disp
->pida
->gci_scalar_vor
[i
][j
]);
330 } else if (type
== GPIV_S_STRAIN
331 && disp
->pida
->sstrain_data
!= NULL
) {
332 for (i
= 0; i
< disp
->pida
->sstrain_data
->ny
; i
++) {
333 for (j
= 0; j
< disp
->pida
->sstrain_data
->nx
; j
++) {
334 destroy_filledrect(disp
->pida
->gci_scalar_sstrain
[i
][j
]);
338 } else if (type
== GPIV_N_STRAIN
339 && disp
->pida
->nstrain_data
!= NULL
) {
340 for (i
= 0; i
< disp
->pida
->nstrain_data
->ny
; i
++) {
341 for (j
= 0; j
< disp
->pida
->nstrain_data
->nx
; j
++) {
342 destroy_filledrect(disp
->pida
->gci_scalar_nstrain
[i
][j
]);
346 g_warning(_("destroy_all_scalars: unexisting type"));
358 * BUGFIX repair color representation for canvas_aa
362 create_scalar_color (gint flag
,
368 /* ----------------------------------------------------------------------------
369 * Create scalar color for in canvas
373 GdkColor
*color_val
= NULL
;
375 color_val
= (GdkColor
*)g_malloc(sizeof(GdkColor
));
379 color_val
->red
= (gint
) (-sc
* BYTEVAL
* scale_factor
);
380 color_val
->green
= 0;
384 color_val
->green
= 0;
385 color_val
->blue
= (int) (sc
* BYTEVAL
* scale_factor
);
389 color_val
->green
= 0;
390 color_val
->blue
= (int) (sc
* BYTEVAL
* scale_factor
);
394 color_val
->green
= BYTEVAL
/ 2;
398 color
= GNOME_CANVAS_COLOR(color_val
->red
,
406 #else /* CANVAS_AA */
409 create_scalar_color (gint flag
,
415 /* ----------------------------------------------------------------------------
416 * Create scalar color for in canvas
424 color_val
= (int) (-sc
* BYTEVAL
* scale_factor
);
425 color_val
= (color_val
<< BITSHIFT_RED
);
427 color_val
= (int) (sc
* BYTEVAL
* scale_factor
);
428 color_val
= (color_val
<< BITSHIFT_BLUE
);
431 color_val
= (int) (sc
* BYTEVAL
* scale_factor
);
432 color_val
= (color_val
<< BITSHIFT_BLUE
);
435 color_val
= 128 << BITSHIFT_GREEN
;
443 #endif /* CANVAS_AA */
447 destroy_filledrect(GnomeCanvasItem
*filled_rect
449 /* ----------------------------------------------------------------------------
450 * Destroys a single filled rectangular canvas item
453 if (filled_rect
!= NULL
) {
454 gtk_object_destroy(GTK_OBJECT(filled_rect
));
462 show_filledrect(GnomeCanvasItem
*filled_rect
464 /* ----------------------------------------------------------------------------
465 * Shows a single filled rectangular canvas item
468 if (filled_rect
!= NULL
) {
469 gnome_canvas_item_show
470 (GNOME_CANVAS_ITEM(filled_rect
));
477 hide_filledrect(GnomeCanvasItem
*filled_rect
479 /* ----------------------------------------------------------------------------
480 * Hides a single filled rectangular canvas item
483 if (filled_rect
!= NULL
) {
484 gnome_canvas_item_hide
485 (GNOME_CANVAS_ITEM(filled_rect
));
492 create_vor (Display
*disp
,
497 /* ----------------------------------------------------------------------------
498 * Creates vorticity gnome canvas item by coloring the interrogation area
502 int start_x
, start_y
, end_x
, end_y
;
504 GnomeCanvasPoints
*points
;
505 points
= gnome_canvas_points_new(5);
509 * Using centre points of interr regs
511 x
= disp
->pida
->vor_data
->point_x
;
512 y
= disp
->pida
->vor_data
->point_y
;
513 start_x
= (int) x
[i
][j
] - disp
->pida
->piv_par
->int_size_f
/ 2;
514 start_y
= (int) y
[i
][j
] - disp
->pida
->piv_par
->int_size_f
/ 2;
515 end_x
= (int) x
[i
][j
] + disp
->pida
->piv_par
->int_size_f
/ 2;
516 end_y
= (int) y
[i
][j
] + disp
->pida
->piv_par
->int_size_f
/ 2;
518 disp
->pida
->gci_scalar_vor
[i
][j
] =
519 gnome_canvas_item_new(gnome_canvas_root
520 (GNOME_CANVAS(display_act
->canvas
)),
521 gnome_canvas_rect_get_type(),
522 "x1", (double) start_x
,
523 "y1", (double) start_y
,
524 "x2", (double) end_x
,
525 "y2", (double) end_y
,
526 "fill_color_rgba", col_val
,
529 gnome_canvas_points_free(points
);
535 create_sstrain (Display
*disp
,
540 /* ----------------------------------------------------------------------------
541 * Creates shear strain gnome canvas item by coloring the interrogation area
545 int start_x
, start_y
, end_x
, end_y
;
547 GnomeCanvasPoints
*points
;
548 points
= gnome_canvas_points_new(5);
552 * Using centre points of interr regs
554 x
= disp
->pida
->sstrain_data
->point_x
;
555 y
= disp
->pida
->sstrain_data
->point_y
;
556 start_x
= (int) x
[i
][j
] - disp
->pida
->piv_par
->int_size_f
/ 2;
557 start_y
= (int) y
[i
][j
] - disp
->pida
->piv_par
->int_size_f
/ 2;
558 end_x
= (int) x
[i
][j
] + disp
->pida
->piv_par
->int_size_f
/ 2;
559 end_y
= (int) y
[i
][j
] + disp
->pida
->piv_par
->int_size_f
/ 2;
561 disp
->pida
->gci_scalar_sstrain
[i
][j
] =
562 gnome_canvas_item_new(gnome_canvas_root
563 (GNOME_CANVAS(display_act
->canvas
)),
564 gnome_canvas_rect_get_type(),
565 "x1", (double) start_x
,
566 "y1", (double) start_y
,
567 "x2", (double) end_x
,
568 "y2", (double) end_y
,
569 "fill_color_rgba", col_val
,
572 gnome_canvas_points_free(points
);
578 create_nstrain (Display
*disp
,
583 /* ----------------------------------------------------------------------------
584 * Creates normal strain gnome canvas item by coloring the interrogation area
588 int start_x
, start_y
, end_x
, end_y
;
590 GnomeCanvasPoints
*points
;
591 points
= gnome_canvas_points_new(5);
595 * Using centre points of interr regs
598 x
= disp
->pida
->nstrain_data
->point_x
;
599 y
= disp
->pida
->nstrain_data
->point_y
;
600 start_x
= (int) x
[i
][j
] - disp
->pida
->piv_par
->int_size_f
/ 2;
601 start_y
= (int) y
[i
][j
] - disp
->pida
->piv_par
->int_size_f
/ 2;
602 end_x
= (int) x
[i
][j
] + disp
->pida
->piv_par
->int_size_f
/ 2;
603 end_y
= (int) y
[i
][j
] + disp
->pida
->piv_par
->int_size_f
/ 2;
605 disp
->pida
->gci_scalar_nstrain
[i
][j
] =
606 gnome_canvas_item_new(gnome_canvas_root
607 (GNOME_CANVAS(display_act
->canvas
)),
608 gnome_canvas_rect_get_type(),
609 "x1", (double) start_x
,
610 "y1", (double) start_y
,
611 "x2", (double) end_x
,
612 "y2", (double) end_y
,
613 "fill_color_rgba", col_val
,
616 gnome_canvas_points_free(points
);