Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/post/src/visuals/colscale.c
3203 views
1
/*****************************************************************************
2
*
3
* Elmer, A Finite Element Software for Multiphysical Problems
4
*
5
* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland
6
*
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 2
10
* of the License, or (at your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program (in file fem/GPL-2); if not, write to the
19
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20
* Boston, MA 02110-1301, USA.
21
*
22
*****************************************************************************/
23
24
/*******************************************************************************
25
*
26
* Action routines for the colscale visual class.
27
*
28
*******************************************************************************
29
*
30
* Author: Juha Ruokolainen
31
*
32
* Address: CSC - IT Center for Science Ltd.
33
* Keilaranta 14, P.O. BOX 405
34
* 02101 Espoo, Finland
35
* Tel. +358 0 457 2723
36
* Telefax: +358 0 457 2302
37
* EMail: [email protected]
38
*
39
* Date: 15 Jan 1996
40
*
41
*
42
* Modification history:
43
*
44
*
45
******************************************************************************/
46
47
#include "../elmerpost.h"
48
49
50
/******************************************************************************
51
*
52
* Parameter structure definitions for colscale visual class
53
*
54
******************************************************************************/
55
56
typedef struct colscale_s
57
{
58
double Length,Thickness,XPosition,YPosition,FontSize;
59
int Entries,Decimals,Style,FontColor;
60
61
scalar_t *ColorData;
62
colormap_t *ColorMap;
63
material_t *Material;
64
} colscale_t;
65
66
67
/*******************************************************************************
68
*
69
* Name: vis_colscale
70
*
71
* Purpose: draw colscale as lines or surface, with color codes or not
72
*
73
* Parameters:
74
*
75
* Input: (geometry_t *) triangles to draw
76
* (colscale_t *) colscale display parameters
77
* (double)
78
*
79
* Output: graphics
80
*
81
* Return value: if mouse interaction is going on, and time used exceeds
82
* given value (TooLong1,2) FALSE, otherwise TRUE
83
*
84
******************************************************************************/
85
static int vis_colscale( geometry_t *geometry, element_model_t *model,
86
colscale_t *ColorScale,double dt )
87
{
88
scalar_t *ColorData = ColorScale->ColorData;
89
90
static char str[120],fmt[120];
91
int i,j,n;
92
93
double CScl,CAdd,*C,y,xl;
94
95
GLboolean clip[6], lights_on;
96
97
float coords[4][3];
98
99
void gra_set_colormap(), gra_set_material(), gra_flat_quad(), PrintString();
100
101
if ( epMouseDown && epMouseDownTakesTooLong ) return TRUE;
102
103
#if 0
104
if ( !(ColorData && ColorData->f) ) return TRUE;
105
#endif
106
107
for( i=0; i<6; i++ )
108
{
109
glGetBooleanv( GL_CLIP_PLANE0+i, &clip[i] );
110
if ( clip[i] ) glDisable( GL_CLIP_PLANE0+i );
111
}
112
113
glMatrixMode( GL_MODELVIEW );
114
gra_push_matrix();
115
gra_load_identity();
116
117
glMatrixMode(GL_PROJECTION);
118
gra_push_matrix();
119
gra_load_identity();
120
121
glGetBooleanv( GL_LIGHTING, &lights_on );
122
glDisable( GL_LIGHTING );
123
124
gra_polygon_mode( GRA_FILL );
125
126
if ( !ColorData || !ColorData->f )
127
{
128
C = ColorData->f;
129
130
CAdd = ColorData->min;
131
if ( ABS(ColorData->max - ColorData->min)>0.0 )
132
CScl = 1.0 / (ColorData->max - ColorData->min);
133
else
134
CScl = 1.0;
135
} else {
136
CAdd = 0.0;
137
CScl = 1.0;
138
}
139
140
gra_set_colormap( ColorScale->ColorMap );
141
gra_set_material( ColorScale->Material );
142
143
n = ColorScale->Entries;
144
gra_begin( GRA_QUADS );
145
146
if ( ColorScale->Style == 0 )
147
{
148
for( i=0; i<ColorScale->ColorMap->NumberOfEntries-1; i++ )
149
{
150
y = ColorScale->Length * i / (ColorScale->ColorMap->NumberOfEntries-1.0) + ColorScale->YPosition;
151
coords[0][0] = ColorScale->XPosition;
152
coords[1][0] = ColorScale->XPosition + ColorScale->Thickness;
153
coords[2][0] = ColorScale->XPosition + ColorScale->Thickness;
154
coords[3][0] = ColorScale->XPosition;
155
156
coords[0][1] = y;
157
coords[1][1] = y;
158
coords[2][1] = y + ColorScale->Length/(ColorScale->ColorMap->NumberOfEntries-1.0);
159
coords[3][1] = y + ColorScale->Length/(ColorScale->ColorMap->NumberOfEntries-1.0);
160
161
coords[0][2] = 0.0;
162
coords[1][2] = 0.0;
163
coords[2][2] = 0.0;
164
coords[3][2] = 0.0;
165
166
gra_flat_quad( coords, i / (ColorScale->ColorMap->NumberOfEntries-1.0) );
167
}
168
169
gra_end();
170
171
glColor3f( ((ColorScale->FontColor & 0xff0000)>>16)/255.0,
172
((ColorScale->FontColor & 0xff00)>>8)/255.0,
173
(ColorScale->FontColor & 0xff)/255.0 );
174
175
sprintf( fmt, "%%.%de", ColorScale->Decimals );
176
177
for( i=0; i<n; i++ )
178
{
179
sprintf( str, fmt, (ColorData->max - ColorData->min)*i/(n-1.0) + ColorData->min );
180
y = ColorScale->Length * i / (n-1.0) + ColorScale->YPosition;
181
182
xl = (ColorScale->Decimals + 9) * ColorScale->FontSize / (double)GraphicsXSize;
183
#ifndef WIN32
184
if ( CurrentXFont ) {
185
xl = (XTextWidth( CurrentXFont, str, strlen(str) ) + 125.0 ) / (double)GraphicsXSize;
186
}
187
#endif
188
glRasterPos3f( ColorScale->XPosition - xl,y,0.0 );
189
PrintString( str );
190
191
xl = ColorScale->FontSize / GraphicsXSize;
192
gra_beg_lines();
193
glVertex3f( ColorScale->XPosition-xl,y,0.01 );
194
glVertex3f( ColorScale->XPosition,y,0.01 );
195
gra_end_lines();
196
}
197
198
if ( ColorScale->ColorData->name ) {
199
xl = strlen((char *)ColorScale->ColorData-name) * ColorScale->FontSize / (double)GraphicsXSize;
200
#ifndef WIN32
201
if ( CurrentXFont ) {
202
xl = (XTextWidth( CurrentXFont, str, strlen(ColorScale->ColorData->name)))/(double)GraphicsXSize;
203
}
204
#endif
205
glRasterPos3f( ColorScale->XPosition - xl,
206
ColorScale->YPosition-ColorScale->Thickness,0.0 );
207
208
PrintString( ColorScale->ColorData->name );
209
}
210
211
} else {
212
213
for( i=0; i<ColorScale->ColorMap->NumberOfEntries; i++ )
214
{
215
y = ColorScale->Length * i / (ColorScale->ColorMap->NumberOfEntries-1.0) + ColorScale->XPosition;
216
217
coords[0][0] = y;
218
coords[1][0] = y + ColorScale->Length/(ColorScale->ColorMap->NumberOfEntries-1.0);
219
coords[2][0] = y + ColorScale->Length/(ColorScale->ColorMap->NumberOfEntries-1.0);
220
coords[3][0] = y;
221
222
coords[0][1] = ColorScale->YPosition;
223
coords[1][1] = ColorScale->YPosition;
224
coords[2][1] = ColorScale->YPosition + ColorScale->Thickness;
225
coords[3][1] = ColorScale->YPosition + ColorScale->Thickness;
226
227
coords[0][2] = 0.0;
228
coords[1][2] = 0.0;
229
coords[2][2] = 0.0;
230
coords[3][2] = 0.0;
231
232
gra_flat_quad( coords, i / (ColorScale->ColorMap->NumberOfEntries-1.0) );
233
}
234
235
gra_end();
236
237
glColor3f( ((ColorScale->FontColor & 0xff0000)>>16)/255.0,
238
((ColorScale->FontColor & 0xff00)>>8)/255.0,
239
(ColorScale->FontColor & 0xff)/255.0 );
240
241
sprintf( fmt, "%%-8.%dg",ColorScale->Decimals );
242
243
for( i=0; i<n; i++ )
244
{
245
sprintf( str, fmt, (ColorData->max - ColorData->min)*i/(n-1.0) + ColorData->min );
246
247
y = ColorScale->Length * i / (n-1.0) + ColorScale->XPosition;
248
glRasterPos3f( y,ColorScale->YPosition+ColorScale->Thickness+0.05,0.0 );
249
PrintString( str );
250
251
gra_beg_lines();
252
glVertex3f( y,ColorScale->YPosition+ColorScale->Thickness,0.01 );
253
glVertex3f( y,ColorScale->YPosition+ColorScale->Thickness+0.025,0.01 );
254
gra_end_lines();
255
}
256
257
if ( ColorScale->ColorData->name ) {
258
glRasterPos3f( ColorScale->XPosition,
259
ColorScale->YPosition-ColorScale->Thickness,0.0 );
260
261
PrintString( ColorScale->ColorData->name );
262
}
263
}
264
265
if ( lights_on ) glEnable( GL_LIGHTING );
266
gra_pop_matrix();
267
268
glMatrixMode( GL_MODELVIEW );
269
gra_pop_matrix();
270
271
for( i=0; i<6; i++ )
272
if ( clip[i] ) glEnable( GL_CLIP_PLANE0+i );
273
274
return TRUE;
275
}
276
277
278
279
/*******************************************************************************
280
*
281
* Name: vis_colscale_alloc
282
*
283
* Purpose: allocate memory for colscale_t structure
284
*
285
* Parameters:
286
*
287
* Input: none
288
*
289
* Output: none
290
*
291
* Return value: pointer to allocated memory
292
*
293
******************************************************************************/
294
static colscale_t *vis_colscale_alloc()
295
{
296
colscale_t *colscale = (colscale_t *)calloc(sizeof(colscale_t),1);
297
298
if ( !colscale )
299
{
300
fprintf( stderr, "vis_colscale_alloc: FATAL: can't alloc a few bytes of memory\n" );
301
}
302
303
return colscale;
304
}
305
306
/*******************************************************************************
307
*
308
* Name: vis_colscale_delete
309
*
310
* Purpose: free memory associated with colscale_t structure
311
*
312
* Parameters:
313
*
314
* Input: (colscale_t *) pointer to structure
315
*
316
* Output: none
317
*
318
* Return value: void
319
*
320
******************************************************************************/
321
static void vis_colscale_delete(colscale_t *colscale)
322
{
323
if ( colscale ) free( colscale );
324
}
325
326
/*******************************************************************************
327
*
328
* Name: vis_initialize_colscale_visual
329
*
330
* Purpose: Register "ColorScale" visual type
331
*
332
* Parameters:
333
*
334
* Input: none
335
*
336
* Output: none
337
*
338
* Return value: vis_add_visual_type (malloc success probably)...
339
*
340
******************************************************************************/
341
int vis_initialize_colscale_visual()
342
{
343
static char *visual_name = "ColorScale";
344
visual_type_t VisualDef;
345
346
static colscale_t colscale;
347
348
349
static visual_param_t ColorScaleParams[] =
350
{
351
{ "Entries", "%d", 0, VIS_VISUAL_PARAM_INT, 6, 0.0, NULL },
352
{ "Decimals", "%d", 0, VIS_VISUAL_PARAM_INT, 2, 0.0, NULL },
353
{ "Style", "%d", 0, VIS_VISUAL_PARAM_INT, 0, 0.0, NULL },
354
{ "XPosition", "%d", 0, VIS_VISUAL_PARAM_FLOAT, 0, 0.8, NULL },
355
{ "YPosition", "%d", 0, VIS_VISUAL_PARAM_FLOAT, 0, -0.8, NULL },
356
{ "Length", "%d", 0, VIS_VISUAL_PARAM_FLOAT, 0, 1.5, NULL },
357
{ "Thickness", "%d", 0, VIS_VISUAL_PARAM_FLOAT, 0, 0.1, NULL },
358
{ "Font Color", "%d", 0, VIS_VISUAL_PARAM_INT, 0xffffff, 0.0, NULL },
359
{ "Font Size", "%d", 0, VIS_VISUAL_PARAM_FLOAT, 0, 17.0, NULL },
360
{ "ColorData", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, NULL },
361
{ "ColorMap", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, &DefaultColorMap },
362
{ "Material", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, &DefaultMaterial },
363
{ NULL, NULL, 0, 0, 0, 0.0, NULL }
364
};
365
366
int n = 0;
367
368
ColorScaleParams[n++].Offset = (char *)&colscale.Entries - (char *)&colscale;
369
ColorScaleParams[n++].Offset = (char *)&colscale.Decimals - (char *)&colscale;
370
ColorScaleParams[n++].Offset = (char *)&colscale.Style - (char *)&colscale;
371
ColorScaleParams[n++].Offset = (char *)&colscale.XPosition - (char *)&colscale;
372
ColorScaleParams[n++].Offset = (char *)&colscale.YPosition - (char *)&colscale;
373
ColorScaleParams[n++].Offset = (char *)&colscale.Length - (char *)&colscale;
374
ColorScaleParams[n++].Offset = (char *)&colscale.Thickness - (char *)&colscale;
375
ColorScaleParams[n++].Offset = (char *)&colscale.FontColor - (char *)&colscale;
376
ColorScaleParams[n++].Offset = (char *)&colscale.FontSize - (char *)&colscale;
377
ColorScaleParams[n++].Offset = (char *)&colscale.ColorData - (char *)&colscale;
378
ColorScaleParams[n++].Offset = (char *)&colscale.ColorMap - (char *)&colscale;
379
ColorScaleParams[n++].Offset = (char *)&colscale.Material - (char *)&colscale;
380
381
VisualDef.VisualName = visual_name;
382
383
VisualDef.RealizeVisual = (int (*)()) vis_colscale;
384
VisualDef.AllocParams = (void *(*)()) vis_colscale_alloc;
385
VisualDef.DeleteParams = (void (*)()) vis_colscale_delete;
386
VisualDef.VisualParams = ColorScaleParams;
387
388
return vis_add_visual_type( &VisualDef );
389
}
390
391