Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/post/src/visuals/contour_lines.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 visual class ContourLines.
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: 26 Sep 1995
40
*
41
*
42
* Modification history:
43
*
44
* 28 Sep 1995, modified vis_initialize_contour_lines_visual to set the
45
* VisualName field of the visual_type structure
46
*
47
* Juha R.
48
*
49
******************************************************************************/
50
51
#include "../elmerpost.h"
52
53
/******************************************************************************
54
*
55
* Parameter structure definitions for Contour Lines visual class
56
*
57
******************************************************************************/
58
59
typedef struct contour_lines_s
60
{
61
scalar_t *ContourData;
62
scalar_t *ColorData;
63
64
int NofLevels;
65
double *Levels;
66
67
material_t *Material;
68
colormap_t *ColorMap;
69
70
int LineQuality;
71
double LineWidth;
72
73
line_style_t LineStyle;
74
} contour_lines_t;
75
76
/*******************************************************************************
77
*
78
* Name: vis_get_isolines
79
*
80
* Purpose: Extract isolines with given threshold
81
*
82
* Parameters:
83
*
84
* Input: (triangle_t *)
85
* (vertex_t *)
86
* (double *,double,double) color quantity, and scales => 0,1
87
* (double *) surface quantity
88
* (double) threshold value
89
*
90
* Output: (line_t *) place to store the line
91
*
92
* Return value: number of points generated, line exists if (n>=2)
93
*
94
******************************************************************************/
95
static int vis_get_isolines
96
(
97
element_model_t *model, element_t *element, vertex_t *vertices, line_t *Lines,
98
double *C, double *F, int nlevels, double *levels,double CScl,double CAdd
99
)
100
{
101
static double x[ELM_MAX_ELEMENT_NODES];
102
static double y[ELM_MAX_ELEMENT_NODES];
103
static double z[ELM_MAX_ELEMENT_NODES];
104
static double f[ELM_MAX_ELEMENT_NODES];
105
static double c[ELM_MAX_ELEMENT_NODES];
106
107
int i,j,n,*T=element->Topology;
108
element_type_t *elmt = element->ElementType;
109
110
if ( elmt->IsoLine )
111
{
112
for( i=0; i<elmt->NumberOfNodes; i++ )
113
{
114
x[i] = vertices[T[i]].x[0];
115
y[i] = vertices[T[i]].x[1];
116
z[i] = vertices[T[i]].x[2];
117
118
f[i] = F[T[i]];
119
120
if ( C )
121
c[i] = CScl*(C[T[i]]-CAdd);
122
else
123
c[i] = 0.0;
124
}
125
126
n = 0;
127
for( i=0; i<nlevels; i++ )
128
{
129
n += (*elmt->IsoLine)( levels[i],f,c,x,y,z,&Lines[n] );
130
}
131
132
return n;
133
}
134
135
return 0;
136
}
137
138
139
/*******************************************************************************
140
*
141
* Name: vis_draw_line
142
*
143
* Purpose: Draw a line
144
*
145
* Parameters:
146
*
147
* Input: (line_t *)
148
* (int ) line/solid
149
* (double) width of line
150
*
151
* Output: graphics
152
*
153
* Return value: void
154
*
155
******************************************************************************/
156
static void vis_draw_line( line_t *line, int quick, double width )
157
{
158
float x[2][3],c0,c1;
159
void gra_line(), gra_sphere();
160
161
x[0][0] = line->x[0];
162
x[0][1] = line->y[0];
163
x[0][2] = line->z[0];
164
165
x[1][0] = line->x[1];
166
x[1][1] = line->y[1];
167
x[1][2] = line->z[1];
168
169
c0 = line->c[0];
170
c1 = line->c[1];
171
172
if ( quick )
173
{
174
gra_line( x[0],c0,x[1],c1,line_style_line,width );
175
} else
176
{
177
gra_line( x[0],c0,x[1],c1,line_style_cylinder,width );
178
gra_sphere( x[0][0],x[0][1],x[0][2],c0, width );
179
gra_sphere( x[1][0],x[1][1],x[1][2],c1, width );
180
}
181
}
182
183
/*******************************************************************************
184
*
185
* Name: vis_contour_lines
186
*
187
* Purpose: Draw contour lines given data, and threshold values
188
*
189
* Parameters:
190
*
191
* Input: (geometry_t *)
192
* (contour_lines_t *) contour line display params
193
* (double) time used
194
*
195
* Output: graphics
196
*
197
* Return value: if mouse interaction is going on, and time used exceeds
198
* given value (TooLong1,2) FALSE, otherwise TRUE
199
*
200
******************************************************************************/
201
static int vis_contour_lines( geometry_t *geometry, element_model_t *model, contour_lines_t *ContourLines,double dt )
202
{
203
double CScl,CAdd,*Levels=ContourLines->Levels;
204
double *C=NULL, *F=NULL;
205
206
scalar_t *ColorData = ContourLines->ColorData;
207
scalar_t *ContourData = ContourLines->ContourData;
208
209
int i,j,n,quick;
210
211
double width = ContourLines->LineWidth*0.005;
212
213
static line_t Lines[1000];
214
215
element_t *elements = model->Elements;
216
217
void gra_set_colormap(), gra_sphere_quality(), gra_set_material();
218
219
if ( !ContourData || !ContourData->f ) return TRUE;
220
221
if ( !GlobalOptions.StereoMode )
222
if ( ContourLines->Material->Diffuse[3] < 1.0 )
223
{
224
if ( GlobalPass != 0 ) return TRUE;
225
} else if ( GlobalPass == 0 )
226
{
227
return TRUE;
228
}
229
230
F = ContourData->f;
231
232
if ( ColorData && ColorData->f )
233
{
234
CAdd = ColorData->min;
235
CScl = 1.0/(ColorData->max - ColorData->min);
236
237
C = ColorData->f;
238
239
gra_set_colormap( ContourLines->ColorMap );
240
} else gra_set_colormap( NULL );
241
242
quick = ContourLines->LineStyle == line_style_line;
243
quick |= epMouseDown && epMouseDownTakesTooLong;
244
245
if ( !quick && (ContourLines->LineStyle == line_style_cylinder) )
246
{
247
gra_sphere_quality( ContourLines->LineQuality );
248
}
249
250
if ( quick && !(epMouseDown && epMouseDownTakesTooLong) )
251
{
252
gra_line_width( ContourLines->LineWidth );
253
} else {
254
gra_line_width( 1.0 );
255
}
256
257
gra_set_material( ContourLines->Material );
258
259
if ( quick ) gra_beg_lines();
260
261
for( i=0; i<model->NofElements; i++ )
262
{
263
264
if ( !elements[i].DisplayFlag ) continue;
265
266
n = vis_get_isolines
267
(
268
model,&elements[i],geometry->Vertices,Lines,C,F,ContourLines->NofLevels,Levels,CScl,CAdd
269
);
270
for( j=0; j<n; j++ ) vis_draw_line( &Lines[j], quick, width );
271
272
if ( epMouseDown )
273
{
274
if ( quick )
275
{
276
if ( (i & 32) && (RealTime() - dt > TooLong2) )
277
if ( ++epMouseDownTakesTooLong > 3 )
278
{
279
gra_end_lines();
280
return FALSE;
281
} else dt = RealTime();
282
} else
283
{
284
if ( RealTime() - dt > TooLong1 )
285
{
286
epMouseDownTakesTooLong++;
287
return FALSE;
288
}
289
}
290
}
291
292
if ( BreakLoop ) break;
293
}
294
295
if ( quick ) gra_end_lines();
296
297
return TRUE;
298
}
299
300
301
/*******************************************************************************
302
*
303
* Name: vis_contour_lines_alloc
304
*
305
* Purpose: allocate memory for contour_lines_t structure
306
*
307
* Parameters:
308
*
309
* Input: none
310
*
311
* Output: none
312
*
313
* Return value: pointer to allocated memory
314
*
315
******************************************************************************/
316
static contour_lines_t *vis_contour_lines_alloc()
317
{
318
contour_lines_t *contour_line = (contour_lines_t *)calloc(sizeof(contour_lines_t),1);
319
320
if ( !contour_line )
321
{
322
fprintf( stderr, "vis_contour_lines_alloc: FATAL: can't alloc a few bytes of memory\n" );
323
}
324
325
return contour_line;
326
}
327
328
/*******************************************************************************
329
*
330
* Name: vis_contour_lines_delete
331
*
332
* Purpose: free memory associated with contour_lines_t structure
333
*
334
* Parameters:
335
*
336
* Input: (contour_lines_t *) pointer to structure
337
*
338
* Output: none
339
*
340
* Return value: void
341
*
342
******************************************************************************/
343
static void vis_contour_lines_delete(contour_lines_t *contour_line)
344
{
345
if ( contour_line ) free( contour_line );
346
}
347
348
/*******************************************************************************
349
*
350
* Name: vis_initialize_contour_lines_visual
351
*
352
* Purpose: Register "Contour Line" visual type
353
*
354
* Parameters:
355
*
356
* Input: none
357
*
358
* Output: none
359
*
360
* Return value: vis_add_visual_type (malloc success probably)...
361
*
362
******************************************************************************/
363
int vis_initialize_contour_line_visual()
364
{
365
static char *visual_name = "Contour Lines";
366
visual_type_t VisualDef;
367
368
static contour_lines_t contours;
369
370
static visual_param_t ContourLineParams[] =
371
{
372
{ "ContourData", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, NULL },
373
{ "ColorData", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, NULL },
374
{ "NofLevels","%d", 0, VIS_VISUAL_PARAM_INT, 0, 0.0, NULL },
375
{ "Levels", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, NULL },
376
{ "Material", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, &DefaultMaterial },
377
{ "ColorMap", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, &DefaultColorMap },
378
{ "LineWidth", "%lf", 0, VIS_VISUAL_PARAM_FLOAT, 0, 1.0, NULL },
379
{ "LineQuality", "%d", 0, VIS_VISUAL_PARAM_INT, 1, 0.0, NULL },
380
{ "LineStyle", "%d", 0, VIS_VISUAL_PARAM_INT,line_style_line, 0.0, NULL },
381
{ NULL, NULL, 0, 0, 0, 0.0, NULL }
382
};
383
384
int n = 0;
385
386
ContourLineParams[n++].Offset = (char *)&contours.ContourData - (char *)&contours;
387
ContourLineParams[n++].Offset = (char *)&contours.ColorData - (char *)&contours;
388
ContourLineParams[n++].Offset = (char *)&contours.NofLevels - (char *)&contours;
389
ContourLineParams[n++].Offset = (char *)&contours.Levels - (char *)&contours;
390
ContourLineParams[n++].Offset = (char *)&contours.Material - (char *)&contours;
391
ContourLineParams[n++].Offset = (char *)&contours.ColorMap - (char *)&contours;
392
ContourLineParams[n++].Offset = (char *)&contours.LineWidth - (char *)&contours;
393
ContourLineParams[n++].Offset = (char *)&contours.LineQuality - (char *)&contours;
394
ContourLineParams[n++].Offset = (char *)&contours.LineStyle - (char *)&contours;
395
396
VisualDef.VisualName = visual_name;
397
398
VisualDef.RealizeVisual = (int (*)()) vis_contour_lines;
399
VisualDef.AllocParams = (void *(*)()) vis_contour_lines_alloc;
400
VisualDef.DeleteParams = (void (*)()) vis_contour_lines_delete;
401
VisualDef.VisualParams = ContourLineParams;
402
403
return vis_add_visual_type( &VisualDef );
404
}
405
406