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_scalars.h"
33 create_scalar_color (gint flag
,
43 create_scalar_color (gint flag
,
49 #endif /* CANVAS_AA */
53 destroy_filledrect (GnomeCanvasItem
*filled_rect
57 show_filledrect (GnomeCanvasItem
*filled_rect
61 hide_filledrect (GnomeCanvasItem
*filled_rect
65 create_vor (Display
*disp
,
72 create_sstrain (Display
*disp
,
79 create_nstrain (Display
*disp
,
89 create_all_scalars(Display
*disp
,
92 /* ----------------------------------------------------------------------------
93 * Displays all scalar gnome canvas items
97 int nx
= 0, ny
= 0, **flag
= NULL
;
100 float sc_min
= 10000.0, sc_max
= -10000.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
;
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
];
151 if (-sc_min
>= sc_max
) {
152 scale_factor
= 1.0 / -sc_min
;
154 scale_factor
= 1.0 / sc_max
;
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
);
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
]);
204 show_all_scalars(Display
*disp
,
207 /* ----------------------------------------------------------------------------
208 * Shows scalar gnome canvas items
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
;
258 hide_all_scalars (Display
*disp
,
261 /* ----------------------------------------------------------------------------
262 * Hides all scalar gnome canvas items
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
;
308 destroy_all_scalars(Display
*disp
,
311 /* ----------------------------------------------------------------------------
312 * Destroys scalar canvas items
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
]);
345 g_warning(_("destroy_all_scalars: unexisting type"));
357 * BUGFIX repair color representation for canvas_aa
361 create_scalar_color (gint flag
,
367 /* ----------------------------------------------------------------------------
368 * Create scalar color for in canvas
372 GdkColor
*color_val
= NULL
;
374 color_val
= (GdkColor
*)g_malloc(sizeof(GdkColor
));
378 color_val
->red
= (gint
) (-sc
* BYTEVAL
* scale_factor
);
379 color_val
->green
= 0;
383 color_val
->green
= 0;
384 color_val
->blue
= (int) (sc
* BYTEVAL
* scale_factor
);
388 color_val
->green
= 0;
389 color_val
->blue
= (int) (sc
* BYTEVAL
* scale_factor
);
393 color_val
->green
= BYTEVAL
/ 2;
397 color
= GNOME_CANVAS_COLOR(color_val
->red
,
405 #else /* CANVAS_AA */
408 create_scalar_color (gint flag
,
414 /* ----------------------------------------------------------------------------
415 * Create scalar color for in canvas
423 color_val
= (int) (-sc
* BYTEVAL
* scale_factor
);
424 color_val
= (color_val
<< BITSHIFT_RED
);
426 color_val
= (int) (sc
* BYTEVAL
* scale_factor
);
427 color_val
= (color_val
<< BITSHIFT_BLUE
);
430 color_val
= (int) (sc
* BYTEVAL
* scale_factor
);
431 color_val
= (color_val
<< BITSHIFT_BLUE
);
434 color_val
= 128 << BITSHIFT_GREEN
;
442 #endif /* CANVAS_AA */
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
));
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
));
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
));
491 create_vor (Display
*disp
,
496 /* ----------------------------------------------------------------------------
497 * Creates vorticity gnome canvas item by coloring the interrogation area
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
,
528 gnome_canvas_points_free(points
);
534 create_sstrain (Display
*disp
,
539 /* ----------------------------------------------------------------------------
540 * Creates shear strain gnome canvas item by coloring the interrogation area
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
,
571 gnome_canvas_points_free(points
);
577 create_nstrain (Display
*disp
,
582 /* ----------------------------------------------------------------------------
583 * Creates normal strain gnome canvas item by coloring the interrogation area
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
,
615 gnome_canvas_points_free(points
);