Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/post/src/visuals/sphere.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 sphere 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: 28 Sep 1995
40
*
41
* Modification history:
42
*
43
* 28 Sep 1995, modified vis_initialize_sphere_visual to set the VisualName
44
* field of the visual_type structure
45
*
46
* 29 Sep 1995, modified vis_initialize_sphere_visual to set new field
47
* VisualParams of the visual_type structure, and removed
48
* vis_spehre_set_param routine, the program now uses the
49
* visual_params_t structure and the routine vis_set_param
50
* in file visual.c
51
*
52
* Juha R.
53
*
54
******************************************************************************/
55
56
#include "../elmerpost.h"
57
/******************************************************************************
58
*
59
* Parameter structure definitions for sphere visual class
60
*
61
******************************************************************************/
62
typedef struct shpere_s
63
{
64
scalar_t *ColorData;
65
scalar_t *RadiusData;
66
67
double RadiusScale;
68
69
scalar_t *ThresholdData;
70
double Floor,Ceiling;
71
72
material_t *Material;
73
colormap_t *ColorMap;
74
75
int Quality;
76
} sphere_t;
77
78
/*******************************************************************************
79
*
80
* Name: vis_sphere
81
*
82
* Purpose: draw sphere as lines or surface, with color coded or not
83
*
84
* Parameters:
85
*
86
* Input: (geometry_t *) geometry description
87
* (sphere_t *) sphere display parameters
88
* (double)
89
*
90
* Output: graphics
91
*
92
* Return value: if mouse interaction is going on, and time used exceeds
93
* given value (TooLong1,2) FALSE, otherwise TRUE
94
*
95
******************************************************************************/
96
static int vis_sphere( geometry_t *geometry, element_model_t *model, sphere_t *Sphere,double dt )
97
{
98
scalar_t *RadiusData = Sphere->RadiusData;
99
scalar_t *ColorData = Sphere->ColorData;
100
scalar_t *ThresholdData = Sphere->ThresholdData;
101
102
vertex_t *v = geometry->Vertices;
103
104
vertex_face_t *face;
105
106
int i,j,quick,N=geometry->VertexCount;
107
108
double *C=NULL, *R=NULL, *T=NULL;
109
double CScl=1.0,CAdd=0.0,RScl=1.0,RAdd=0.0,Rad=1.0,Col=1.0;
110
111
void gra_set_colormap(), gra_sphere_quality(), gra_set_material(), gra_point(), gra_sphere();
112
113
if ( !GlobalOptions.StereoMode )
114
if ( Sphere->Material->Diffuse[3] < 1.0 )
115
{
116
if ( GlobalPass != 0 ) return TRUE;
117
} else if ( GlobalPass == 0 )
118
{
119
return TRUE;
120
}
121
122
if ( ColorData && ColorData->f )
123
{
124
C = ColorData->f;
125
CAdd = ColorData->min;
126
CScl = 1.0/(ColorData->max - ColorData->min);
127
128
gra_set_colormap( Sphere->ColorMap );
129
} else gra_set_colormap( NULL );
130
131
if ( RadiusData && RadiusData->f )
132
{
133
R = RadiusData->f;
134
RAdd = RadiusData->min;
135
RScl = 1.0/(RadiusData->max - RadiusData->min);
136
}
137
else { RAdd = 0.0; RScl = 0.05*Sphere->RadiusScale; }
138
139
if ( ThresholdData && ThresholdData->f ) T = ThresholdData->f;
140
141
quick = (epMouseDown && epMouseDownTakesTooLong) || (Sphere->Quality < 0);
142
143
if ( quick )
144
{
145
gra_begin( GRA_POINTS );
146
#if 0
147
gra_polygon_mode( GRA_LINE );
148
gra_sphere_quality( 1 );
149
#endif
150
} else {
151
gra_sphere_quality( Sphere->Quality );
152
if ( Sphere->Quality == 0 ) gra_polygon_mode( GRA_LINE );
153
}
154
155
gra_set_material( Sphere->Material );
156
157
for( i=0; i<N; i++ )
158
{
159
if ( v[i].ElementModelNode )
160
{
161
for( face=v[i].Faces; face!=NULL; face=face->Next )
162
{
163
if ( geometry->Triangles[face->Face].Element->DisplayFlag ) break;
164
}
165
#if 1
166
if ( v[i].Faces && !face ) continue;
167
#else
168
if ( !face ) continue;
169
#endif
170
171
if ( T && (T[i]<Sphere->Floor || T[i]>Sphere->Ceiling) ) continue;
172
173
if ( R )
174
Rad = RScl*(R[i]-RAdd)+0.05;
175
else Rad = 1.0;
176
177
Rad *= 0.05*Sphere->RadiusScale;
178
179
if ( C ) Col = CScl*(C[i] - CAdd); else Col = CScl;
180
181
if ( quick ) {
182
gra_point( v[i].x[0],v[i].x[1],v[i].x[2],Col,Rad );
183
} else {
184
gra_sphere( v[i].x[0],v[i].x[1],v[i].x[2],Col,Rad );
185
}
186
187
} else break;
188
189
if ( epMouseDown && (i & 8) )
190
{
191
if ( !epMouseDownTakesTooLong )
192
{
193
if ( RealTime() - dt > TooLong1 )
194
{
195
if ( quick ) gra_end();
196
gra_polygon_mode( GRA_FILL );
197
++epMouseDownTakesTooLong;
198
return FALSE;
199
}
200
}
201
else if ( RealTime() - dt > TooLong2 )
202
if ( ++epMouseDownTakesTooLong > 3 )
203
{
204
gra_end();
205
gra_polygon_mode( GRA_FILL );
206
return FALSE;
207
} else dt = RealTime();
208
}
209
210
if ( BreakLoop ) break;
211
}
212
213
if ( quick ) gra_end();
214
gra_polygon_mode( GRA_FILL );
215
216
return TRUE;
217
}
218
219
220
/*******************************************************************************
221
*
222
* Name: vis_sphere_alloc
223
*
224
* Purpose: allocate memory for sphere_t structure
225
*
226
* Parameters:
227
*
228
* Input: none
229
*
230
* Output: none
231
*
232
* Return value: pointer to allocated memory
233
*
234
******************************************************************************/
235
static sphere_t *vis_sphere_alloc()
236
{
237
sphere_t *sphere = (sphere_t *)calloc(sizeof(sphere_t),1);
238
239
if ( !sphere )
240
{
241
fprintf( stderr, "vis_sphere_alloc: FATAL: can't alloc a few bytes of memory\n" );
242
}
243
244
return sphere;
245
}
246
247
/*******************************************************************************
248
*
249
* Name: vis_sphere_delete
250
*
251
* Purpose: free memory associated with sphere_t structure
252
*
253
* Parameters:
254
*
255
* Input: (sphere_t *) pointer to structure
256
*
257
* Output: none
258
*
259
* Return value: void
260
*
261
******************************************************************************/
262
static void vis_sphere_delete(sphere_t *sphere)
263
{
264
if ( sphere ) free( sphere );
265
}
266
267
/*******************************************************************************
268
*
269
* Name: vis_initialize_sphere_visual
270
*
271
* Purpose: Register "Spheres" visual type
272
*
273
* Parameters:
274
*
275
* Input: none
276
*
277
* Output: none
278
*
279
* Return value: vis_add_visual_type (malloc success probably)...
280
*
281
******************************************************************************/
282
int vis_initialize_sphere_visual()
283
{
284
static char *visual_name = "Spheres";
285
visual_type_t VisualDef;
286
287
static sphere_t sphere;
288
289
int n = 0;
290
291
static visual_param_t SphereParams[] =
292
{
293
{ "ColorData", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, NULL },
294
{ "RadiusData", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, NULL },
295
{ "RadiusScale", "%lf", 0, VIS_VISUAL_PARAM_FLOAT, 0, 1.0, NULL },
296
{ "ThresholdData", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 1.0, NULL },
297
{ "Floor", "%lf", 0, VIS_VISUAL_PARAM_FLOAT, 0, 0.0, NULL },
298
{ "Ceiling", "%lf", 0, VIS_VISUAL_PARAM_FLOAT, 0, 1.0, NULL },
299
{ "Material", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, &DefaultMaterial },
300
{ "ColorMap", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, &DefaultColorMap },
301
{ "Quality", "%d", 0, VIS_VISUAL_PARAM_INT, 1, 0.0, NULL },
302
{ NULL, NULL, 0, 0, 0, 0.0, NULL }
303
};
304
305
SphereParams[n++].Offset = (char *)&sphere.ColorData - (char *)&sphere;
306
SphereParams[n++].Offset = (char *)&sphere.RadiusData - (char *)&sphere;
307
SphereParams[n++].Offset = (char *)&sphere.RadiusScale - (char *)&sphere;
308
SphereParams[n++].Offset = (char *)&sphere.ThresholdData - (char *)&sphere;
309
SphereParams[n++].Offset = (char *)&sphere.Floor - (char *)&sphere;
310
SphereParams[n++].Offset = (char *)&sphere.Ceiling - (char *)&sphere;
311
SphereParams[n++].Offset = (char *)&sphere.Material - (char *)&sphere;
312
SphereParams[n++].Offset = (char *)&sphere.ColorMap - (char *)&sphere;
313
SphereParams[n++].Offset = (char *)&sphere.Quality - (char *)&sphere;
314
315
VisualDef.VisualName = visual_name;
316
VisualDef.RealizeVisual = (int (*)()) vis_sphere;
317
VisualDef.AllocParams = (void *(*)()) vis_sphere_alloc;
318
VisualDef.DeleteParams = (void (*)()) vis_sphere_delete;
319
VisualDef.VisualParams = SphereParams;
320
321
return vis_add_visual_type( &VisualDef );
322
}
323
324