Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/post/src/visuals/arrows.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 arrow 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: 26 Sep 1995
40
*
41
*
42
*
43
* Modification history:
44
*
45
* 28 Sep 1995, modified vis_initialize_arrow_visual to set the VisualName field
46
* of the visual_type structure
47
*
48
* Juha R.
49
*
50
******************************************************************************/
51
52
#include "../elmerpost.h"
53
54
55
/******************************************************************************
56
*
57
* Parameter structure definitions for arrow visual class
58
*
59
******************************************************************************/
60
typedef struct arrow_s
61
{
62
scalar_t *VectorData[4]; /* arrow direction quantity */
63
scalar_t *ColorData; /* arrow coloring quantity */
64
scalar_t *LengthData; /* arrow length quantity */
65
scalar_t *ThresholdData; /* arrow thresholding quantity */
66
67
arrow_style_t Style; /* arrow style, stick or arrow */
68
69
double Floor,Ceiling; /* threshold min & max */
70
71
double RadiusScale,LengthScale;
72
logical_t EqualLength,EqualRadius;
73
74
material_t *Material;
75
colormap_t *ColorMap;
76
77
int LineQuality;
78
line_style_t LineStyle;
79
} arrow_t;
80
81
82
/*******************************************************************************
83
*
84
* Name: vis_arrow
85
*
86
* Purpose: draw arrows given vector field
87
*
88
* Parameters:
89
*
90
* Input: (geometry_t *) geometry description
91
* (arrow_t *) arrow display parameters
92
* (double) real time for interaction
93
*
94
* Output: graphics
95
*
96
* Return value: if mouse interaction is going on, and time used exceeds
97
* given value (TooLong1,2) FALSE, otherwise TRUE
98
*
99
******************************************************************************/
100
static int vis_arrow( geometry_t *geometry, element_model_t *model, arrow_t *Arrows,double dt )
101
{
102
line_style_t line_style = Arrows->LineStyle;
103
arrow_style_t arrow_style = Arrows->Style;
104
105
vertex_t *v = geometry->Vertices;
106
107
int i,N=geometry->VertexCount,quick;
108
109
float x[3];
110
111
vertex_face_t *face;
112
113
element_t *elements = model->Elements;
114
115
double LScl,CScl,CAdd,vx,vy,vz,co;
116
double R,RadiusScale,L,LengthScale;
117
118
void gra_set_colormap(), gra_sphere_quality(), gra_set_material(), gra_arrow() ;
119
120
if ( !Arrows->VectorData ||
121
!Arrows->VectorData[1]->f || !Arrows->VectorData[2]->f || !Arrows->VectorData[3]->f
122
)
123
{
124
/*
125
fprintf( stderr, "vis_arrows: no arrow data\n" );
126
*/
127
return TRUE;
128
}
129
130
if ( !GlobalOptions.StereoMode )
131
if ( Arrows->Material->Diffuse[3] < 1.0 )
132
{
133
if ( GlobalPass != 0 ) return TRUE;
134
} else if ( GlobalPass == 0 )
135
{
136
return TRUE;
137
}
138
139
LengthScale = Arrows->LengthScale / 10.0;
140
RadiusScale = Arrows->RadiusScale / 10.0;
141
142
if ( Arrows->LengthData && Arrows->LengthData->f )
143
{
144
LScl = 0.05;
145
if ( ABS( Arrows->LengthData->max - Arrows->LengthData->min ) > 1.0E-10 )
146
LScl = 1.0 / (Arrows->LengthData->max - Arrows->LengthData->min);
147
}
148
149
if ( Arrows->ColorData && Arrows->ColorData->f )
150
{
151
CAdd = Arrows->ColorData->min;
152
CScl = 1.0 / ( Arrows->ColorData->max - Arrows->ColorData->min );
153
gra_set_colormap( Arrows->ColorMap );
154
} else gra_set_colormap( NULL );
155
156
quick = epMouseDown && epMouseDownTakesTooLong;
157
158
if ( quick )
159
{
160
line_style = line_style_line;
161
arrow_style = arrow_style_stick;
162
gra_line_width( 1.0 );
163
} else
164
{
165
if ( line_style == line_style_cylinder )
166
gra_sphere_quality( Arrows->LineQuality );
167
else
168
gra_line_width( Arrows->RadiusScale );
169
}
170
171
gra_set_material( Arrows->Material );
172
173
for( i=0; i<N; i++,v++ )
174
{
175
if ( !v->ElementModelNode ) continue;
176
177
for( face=v->Faces; face!=NULL; face=face->Next )
178
{
179
if ( geometry->Triangles[face->Face].Element->DisplayFlag ) break;
180
}
181
#if 1
182
if ( v->Faces && !face ) continue;
183
#else
184
if ( !face ) continue;
185
#endif
186
if ( Arrows->ThresholdData && Arrows->ThresholdData->f )
187
{
188
if ( Arrows->ThresholdData->f[i] < Arrows->Floor ||
189
Arrows->ThresholdData->f[i] > Arrows->Ceiling ) continue;
190
}
191
192
vx = Arrows->VectorData[1]->f[i];
193
vy = Arrows->VectorData[2]->f[i];
194
vz = Arrows->VectorData[3]->f[i];
195
196
L = sqrt( vx*vx + vy*vy + vz*vz );
197
if ( L < 1.0E-10 ) continue;
198
199
L = LengthScale / L;
200
R = LengthScale * RadiusScale;
201
202
if ( Arrows->ColorData && Arrows->ColorData->f )
203
{
204
co = CScl*(Arrows->ColorData->f[i]-CAdd);
205
}
206
207
x[0] = L*vx;
208
x[1] = L*vy;
209
x[2] = L*vz;
210
211
if ( !Arrows->EqualLength && Arrows->LengthData && Arrows->LengthData->f )
212
{
213
x[0] *= LScl*Arrows->LengthData->f[i];
214
x[1] *= LScl*Arrows->LengthData->f[i];
215
x[2] *= LScl*Arrows->LengthData->f[i];
216
217
if ( !Arrows->EqualRadius )
218
{
219
R *= LScl*Arrows->LengthData->f[i];
220
}
221
}
222
223
gra_arrow( v->x,x,co,line_style,arrow_style,R );
224
225
if ( epMouseDown && (i & 8) )
226
{
227
if ( !epMouseDownTakesTooLong )
228
{
229
if ( RealTime() - dt > TooLong1 )
230
{
231
++epMouseDownTakesTooLong;
232
return FALSE;
233
}
234
}
235
else if ( RealTime() - dt > TooLong2 )
236
if ( ++epMouseDownTakesTooLong > 3 )
237
{
238
return FALSE;
239
} else dt = RealTime();
240
}
241
242
if ( BreakLoop ) break;
243
}
244
245
return TRUE;
246
}
247
248
/*******************************************************************************
249
*
250
* Name: vis_arrow_alloc
251
*
252
* Purpose: allocate memory for arrow_t structure
253
*
254
* Parameters:
255
*
256
* Input: none
257
*
258
* Output: none
259
*
260
* Return value: pointer to allocated memory
261
*
262
******************************************************************************/
263
static arrow_t *vis_arrow_alloc()
264
{
265
arrow_t *arrow = (arrow_t *)calloc(sizeof(arrow_t),1);
266
267
if ( !arrow )
268
{
269
fprintf( stderr, "vis_arrow_alloc: FATAL: can't alloc a few bytes of memory\n" );
270
}
271
272
return arrow;
273
}
274
275
/*******************************************************************************
276
*
277
* Name: vis_arrow_delete
278
*
279
* Purpose: free memory associated with arrow_t structure
280
*
281
* Parameters:
282
*
283
* Input: (arrow_t *) pointer to structure
284
*
285
* Output: none
286
*
287
* Return value: void
288
*
289
******************************************************************************/
290
static void vis_arrow_delete(arrow_t *arrow)
291
{
292
if ( arrow ) free( arrow );
293
}
294
295
/*******************************************************************************
296
*
297
* Name: vis_initialize_arrow_visual
298
*
299
* Purpose: Register arrow visual type
300
*
301
* Parameters:
302
*
303
* Input: none
304
*
305
* Output: none
306
*
307
* Return value: vis_add_visual_type (malloc success probably)...
308
*
309
******************************************************************************/
310
int vis_initialize_arrow_visual()
311
{
312
static char *visual_name = "Arrows";
313
314
visual_type_t VisualDef;
315
316
static arrow_t arrow;
317
318
static visual_param_t ArrowParams[] =
319
{
320
{ "VectorData0", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, NULL },
321
{ "VectorData1", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, NULL },
322
{ "VectorData2", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, NULL },
323
{ "VectorData3", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, NULL },
324
{ "ColorData", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, NULL },
325
{ "LengthData", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, NULL },
326
{ "ThresholdData", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, NULL },
327
{ "Style", "%d", 0, VIS_VISUAL_PARAM_INT, arrow_style_arrow, 0.0, NULL },
328
{ "Floor", "%lf", 0, VIS_VISUAL_PARAM_FLOAT, 0, 0.0, NULL },
329
{ "Ceiling", "%lf", 0, VIS_VISUAL_PARAM_FLOAT, 0, 1.0, NULL },
330
{ "RadiusScale", "%lf", 0, VIS_VISUAL_PARAM_FLOAT, 0, 1.0, NULL },
331
{ "LengthScale", "%lf", 0, VIS_VISUAL_PARAM_FLOAT, 0, 1.0, NULL },
332
{ "EqualLength", "%c", 0, VIS_VISUAL_PARAM_LOGICAL, 1, 0.0, NULL },
333
{ "EqualRadius", "%c", 0, VIS_VISUAL_PARAM_LOGICAL, 0, 0.0, NULL },
334
{ "Material", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, &DefaultMaterial },
335
{ "ColorMap", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, &DefaultColorMap },
336
{ "LineQuality", "%d", 0, VIS_VISUAL_PARAM_INT, 1, 0.0, NULL },
337
{ "LineStyle", "%d", 0, VIS_VISUAL_PARAM_INT, line_style_line, 0.0, NULL },
338
{ NULL, NULL, 0, 0, 0,0.0, NULL }
339
};
340
341
int n = 0;
342
343
ArrowParams[n++].Offset = (char *)&arrow.VectorData[0] - (char *)&arrow;
344
ArrowParams[n++].Offset = (char *)&arrow.VectorData[1] - (char *)&arrow;
345
ArrowParams[n++].Offset = (char *)&arrow.VectorData[2] - (char *)&arrow;
346
ArrowParams[n++].Offset = (char *)&arrow.VectorData[3] - (char *)&arrow;
347
ArrowParams[n++].Offset = (char *)&arrow.ColorData - (char *)&arrow;
348
ArrowParams[n++].Offset = (char *)&arrow.LengthData - (char *)&arrow;
349
ArrowParams[n++].Offset = (char *)&arrow.ThresholdData - (char *)&arrow;
350
ArrowParams[n++].Offset = (char *)&arrow.Style - (char *)&arrow;
351
ArrowParams[n++].Offset = (char *)&arrow.Floor - (char *)&arrow;
352
ArrowParams[n++].Offset = (char *)&arrow.Ceiling - (char *)&arrow;
353
ArrowParams[n++].Offset = (char *)&arrow.RadiusScale - (char *)&arrow;
354
ArrowParams[n++].Offset = (char *)&arrow.LengthScale - (char *)&arrow;
355
ArrowParams[n++].Offset = (char *)&arrow.EqualLength - (char *)&arrow;
356
ArrowParams[n++].Offset = (char *)&arrow.EqualRadius - (char *)&arrow;
357
ArrowParams[n++].Offset = (char *)&arrow.Material - (char *)&arrow;
358
ArrowParams[n++].Offset = (char *)&arrow.ColorMap - (char *)&arrow;
359
ArrowParams[n++].Offset = (char *)&arrow.LineQuality - (char *)&arrow;
360
ArrowParams[n++].Offset = (char *)&arrow.LineStyle - (char *)&arrow;
361
362
VisualDef.VisualName = visual_name;
363
VisualDef.RealizeVisual = (int (*)()) vis_arrow;
364
VisualDef.AllocParams = (void *(*)()) vis_arrow_alloc;
365
VisualDef.DeleteParams = (void (*)()) vis_arrow_delete;
366
VisualDef.VisualParams = ArrowParams;
367
368
return vis_add_visual_type( &VisualDef );
369
}
370
371