1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
#include <math.h>
#include "qwt3d_color.h"
#include "qwt3d_plot.h"
#include "qwt3d_enrichment_std.h"
using namespace Qwt3D;
/////////////////////////////////////////////////////////////////
//
// CrossHair
//
/////////////////////////////////////////////////////////////////
CrossHair::CrossHair()
{
configure(0, 1, false, false);
}
CrossHair::CrossHair(double rad, double linewidth, bool smooth, bool boxed)
{
configure(rad, linewidth, smooth, boxed);
}
void CrossHair::configure(double rad, double linewidth, bool smooth, bool boxed)
{
plot = 0;
radius_ = rad;
linewidth_ = linewidth;
smooth_ = smooth;
boxed_ = boxed;
}
void CrossHair::drawBegin()
{
setDeviceLineWidth( linewidth_ );
oldstate_ = glIsEnabled(GL_LINE_SMOOTH);
if (smooth_)
glEnable(GL_LINE_SMOOTH);
else
glDisable(GL_LINE_SMOOTH);
glBegin( GL_LINES );
}
void CrossHair::drawEnd()
{
glEnd();
if (oldstate_)
glEnable(GL_LINE_SMOOTH);
else
glDisable(GL_LINE_SMOOTH);
}
void CrossHair::draw(Qwt3D::Triple const& pos)
{
RGBA rgba = (*plot->dataColor())(pos);
glColor4d(rgba.r,rgba.g,rgba.b,rgba.a);
double diag = (plot->hull().maxVertex-plot->hull().minVertex).length() * radius_;
glVertex3d( pos.x - diag, pos.y, pos.z);
glVertex3d( pos.x + diag, pos.y, pos.z);
glVertex3d( pos.x, pos.y - diag, pos.z);
glVertex3d( pos.x, pos.y + diag, pos.z);
glVertex3d( pos.x, pos.y, pos.z - diag);
glVertex3d( pos.x, pos.y, pos.z + diag);
// hull
if (!boxed_)
return;
glVertex3d( pos.x - diag, pos.y - diag, pos.z + diag);
glVertex3d( pos.x + diag, pos.y - diag, pos.z + diag);
glVertex3d( pos.x - diag, pos.y - diag, pos.z - diag);
glVertex3d( pos.x + diag, pos.y - diag, pos.z - diag);
glVertex3d( pos.x - diag, pos.y + diag, pos.z + diag);
glVertex3d( pos.x + diag, pos.y + diag, pos.z + diag);
glVertex3d( pos.x - diag, pos.y + diag, pos.z - diag);
glVertex3d( pos.x + diag, pos.y + diag, pos.z - diag);
glVertex3d( pos.x - diag, pos.y - diag, pos.z + diag);
glVertex3d( pos.x - diag, pos.y + diag, pos.z + diag);
glVertex3d( pos.x - diag, pos.y - diag, pos.z - diag);
glVertex3d( pos.x - diag, pos.y + diag, pos.z - diag);
glVertex3d( pos.x + diag, pos.y - diag, pos.z + diag);
glVertex3d( pos.x + diag, pos.y + diag, pos.z + diag);
glVertex3d( pos.x + diag, pos.y - diag, pos.z - diag);
glVertex3d( pos.x + diag, pos.y + diag, pos.z - diag);
glVertex3d( pos.x - diag, pos.y - diag, pos.z - diag);
glVertex3d( pos.x - diag, pos.y - diag, pos.z + diag);
glVertex3d( pos.x + diag, pos.y - diag, pos.z - diag);
glVertex3d( pos.x + diag, pos.y - diag, pos.z + diag);
glVertex3d( pos.x - diag, pos.y + diag, pos.z - diag);
glVertex3d( pos.x - diag, pos.y + diag, pos.z + diag);
glVertex3d( pos.x + diag, pos.y + diag, pos.z - diag);
glVertex3d( pos.x + diag, pos.y + diag, pos.z + diag);
}
/////////////////////////////////////////////////////////////////
//
// Dot
//
/////////////////////////////////////////////////////////////////
Dot::Dot()
{
configure(1, false);
}
Dot::Dot(double pointsize, bool smooth)
{
configure(pointsize, smooth);
}
void Dot::configure(double pointsize, bool smooth)
{
plot = 0;
pointsize_ = pointsize;
smooth_ = smooth;
}
void Dot::drawBegin()
{
setDevicePointSize( pointsize_ );
oldstate_ = glIsEnabled(GL_POINT_SMOOTH);
if (smooth_)
glEnable(GL_POINT_SMOOTH);
else
glDisable(GL_POINT_SMOOTH);
//glPointSize(10);
glBegin( GL_POINTS );
}
void Dot::drawEnd()
{
glEnd();
if (oldstate_)
glEnable(GL_POINT_SMOOTH);
else
glDisable(GL_POINT_SMOOTH);
}
void Dot::draw(Qwt3D::Triple const& pos)
{
RGBA rgba = (*plot->dataColor())(pos);
glColor4d(rgba.r,rgba.g,rgba.b,rgba.a);
glVertex3d( pos.x, pos.y, pos.z);
}
/////////////////////////////////////////////////////////////////
//
// Cone
//
/////////////////////////////////////////////////////////////////
Cone::Cone()
{
hat = gluNewQuadric();
disk = gluNewQuadric();
configure(0, 3);
}
Cone::Cone(double rad, unsigned quality)
{
hat = gluNewQuadric();
disk = gluNewQuadric();
configure(rad, quality);
}
Cone::~Cone()
{
gluDeleteQuadric(hat);
gluDeleteQuadric(disk);
}
void Cone::configure(double rad, unsigned quality)
{
plot = 0;
radius_ = rad;
quality_ = quality;
oldstate_ = GL_FALSE;
gluQuadricDrawStyle(hat,GLU_FILL);
gluQuadricNormals(hat,GLU_SMOOTH);
gluQuadricOrientation(hat,GLU_OUTSIDE);
gluQuadricDrawStyle(disk,GLU_FILL);
gluQuadricNormals(disk,GLU_SMOOTH);
gluQuadricOrientation(disk,GLU_OUTSIDE);
}
void Cone::draw(Qwt3D::Triple const& pos)
{
RGBA rgba = (*plot->dataColor())(pos);
glColor4d(rgba.r,rgba.g,rgba.b,rgba.a);
GLint mode;
glGetIntegerv(GL_MATRIX_MODE, &mode);
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glTranslatef(pos.x, pos.y, pos.z);
gluCylinder(hat, 0.0, radius_, radius_*2, quality_, 1);
glTranslatef(0, 0, radius_*2);
gluDisk(disk, 0.0, radius_, quality_, 1);
glPopMatrix();
glMatrixMode(mode);
}
/////////////////////////////////////////////////////////////////
//
// Arrow
//
/////////////////////////////////////////////////////////////////
Arrow::Arrow()
{
hat = gluNewQuadric();
disk = gluNewQuadric();
base = gluNewQuadric();
bottom = gluNewQuadric();
gluQuadricDrawStyle(hat,GLU_FILL);
gluQuadricNormals(hat,GLU_SMOOTH);
gluQuadricOrientation(hat,GLU_OUTSIDE);
gluQuadricDrawStyle(disk,GLU_FILL);
gluQuadricNormals(disk,GLU_SMOOTH);
gluQuadricOrientation(disk,GLU_OUTSIDE);
gluQuadricDrawStyle(base,GLU_FILL);
gluQuadricNormals(base,GLU_SMOOTH);
gluQuadricOrientation(base,GLU_OUTSIDE);
gluQuadricDrawStyle(bottom,GLU_FILL);
gluQuadricNormals(bottom,GLU_SMOOTH);
gluQuadricOrientation(bottom,GLU_OUTSIDE);
configure(3, 0.4, 0.06, 0.02);
}
Arrow::~Arrow()
{
gluDeleteQuadric(hat);
gluDeleteQuadric(disk);
gluDeleteQuadric(base);
gluDeleteQuadric(bottom);
}
/**
\param segs number of faces for the fields arrows (see the gallery for examples)
\param relconelength see picture
\param relconerad see picture
\param relstemrad see picture
\image html arrowanatomy.png
*/
void Arrow::configure(int segs, double relconelength, double relconerad, double relstemrad)
{
plot = 0;
segments_ = segs;
oldstate_ = GL_FALSE;
rel_cone_length = relconelength;
rel_cone_radius = relconerad;
rel_stem_radius = relstemrad;
}
void Arrow::draw(Qwt3D::Triple const& pos)
{
Triple end = top_;
Triple beg = pos;
Triple vdiff = end-beg;
double length = vdiff.length();
glColor4d(rgba_.r,rgba_.g,rgba_.b,rgba_.a);
double radius[2];
radius[0] = rel_cone_radius * length;
radius[1] = rel_stem_radius * length;
GLint mode;
glGetIntegerv(GL_MATRIX_MODE, &mode);
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
Triple axis;
double phi = calcRotation(axis, FreeVector(beg,end));
glTranslatef(beg.x, beg.y, beg.z);
glRotatef(phi, axis.x, axis.y, axis.z);
double baseheight = (1-rel_cone_length) * length;
glTranslatef(0, 0, baseheight);
gluCylinder(hat, radius[0], 0.0, rel_cone_length * length, segments_,1);
gluDisk(disk,radius[1],radius[0], segments_,1);
glTranslatef(0, 0, -baseheight);
gluCylinder(base, radius[1],radius[1], baseheight,segments_,1);
gluDisk(disk,0,radius[1],segments_,1);
glPopMatrix();
glMatrixMode(mode);
}
//! transform a vector on the z axis with length |beg-end|, to get them in coincidence with the vector(beg,end)
/**
\return Angle in degree to rotate
\param axis The axis to rotate around
\param beg result vector base point
\param end result vector top point
*/
double Arrow::calcRotation(Triple& axis, FreeVector const& vec)
{
Triple end = vec.top;
Triple beg = vec.base;
Triple firstbeg(0.0,0.0,0.0);
Triple firstend(0.0,0.0,(end-beg).length());
Triple first = firstend - firstbeg;
first.normalize();
Triple second = end-beg;
second.normalize();
axis = normalizedcross(first,second);
double cosphi = dotProduct(first,second);
return 180 * acos(cosphi) / Qwt3D::PI;
}
|