QWT API (English) 7.3.0
Qt Widget Library for Technical Applications - English API Documentation
Loading...
Searching...
No Matches
qwt3d_types.h
1#if defined(_MSC_VER) /* MSVC Compiler */
2#pragma warning(disable : 4786)
3#endif
4
5#ifndef QWT3D_TYPES_H
6#define QWT3D_TYPES_H
7
8#ifdef _DEBUG
9#include <fstream>
10#endif
11
12#include <string>
13
14#include "qwt3d_global.h"
15
16#ifndef WHEEL_DELTA
17#define WHEEL_DELTA 120
18#endif
19
20#include "qwt3d_portability.h"
21#include "qwt3d_helper.h"
22#include <QColor>
23
24
25
26const double Qwt3D_PI = 3.14159265358979323846264338328;
27
31enum PLOTSTYLE
32{
33 NOPLOT, // No visible data
34 WIREFRAME, // Wireframe style
35 HIDDENLINE, // Hidden Line style
36 FILLED, // Color filled polygons w/o edges
37 FILLEDMESH, // Color filled polygons w/ separately colored edges
38 QWT3D_POINTS, // User defined style (used by Enrichments)
39 USER // User defined style (used by Enrichments)
40};
41
45enum SHADINGSTYLE
46{
47 FLAT, // Flat shading (OpenGL)
48 GOURAUD // Gouraud Shading (OpenGL)
49};
50
54enum COORDSTYLE
55{
56 NOCOORD, // Coordinate system is not visible
57 BOX, // Boxed
58 FRAME // Frame - 3 visible axes
59};
60
64enum SCALETYPE
65{
66 LINEARSCALE, // Linear scaling
67 LOG10SCALE, // Logarithmic scaling (base 10)
68 USERSCALE // User-defined (for extensions)
69};
70
74enum FLOORSTYLE
75{
76 NOFLOOR, // Empty floor
77 FLOORISO, // Isoline projections visible
78 FLOORDATA // Projected polygons visible
79};
80
84enum DATATYPE
85{
86 GRID, // Rectangular grid
87 POLYGON // Convex polygon
88};
89
94enum AXIS
95{
96 X1 = 0, // 1st x-axis
97 X2 = 3, // 2nd x-axis
98 X3 = 4, // 3rd x-axis
99 X4 = 5, // 4th x-axis
100 Y1 = 1, // 1st y-axis
101 Y2 = 8, // 2nd y-axis
102 Y3 = 7, // 3rd y-axis
103 Y4 = 6, // 4th y-axis
104 Z1 = 2, // 1st z-axis
105 Z2 = 9, // 2nd z-axis
106 Z3 = 11, // 3rd z-axis
107 Z4 = 10 // 4th z-axis
108};
109
113enum SIDE
114{
115 NOSIDEGRID = 0,
116 LEFT = 1 << 0,
117 RIGHT = 1 << 1,
118 CEIL = 1 << 2,
119 FLOOR = 1 << 3,
120 FRONT = 1 << 4,
121 BACK = 1 << 5
122};
123
129enum INTERIOR_DIRECTION
130{
131 NO_INTERIOR = 0,
132 X_INNER = 1 << 0,
133 Y_INNER = 1 << 1,
134 Z_INNER = 1 << 2
135};
136
143enum TICKPOSITION
144{
145 TICK_BOTTOM, // Ticks on the visually lower axis (default)
146 TICK_TOP // Ticks on the visually upper axis
147};
148
155enum ASPECTRATIOMODE
156{
157 AUTOFILL, // Each axis independently scaled to fill the view (default)
158 DATARATIO // Preserve data proportions (equal aspect ratio)
159};
160
164enum ANCHOR
165{
166 BottomLeft,
167 BottomRight,
168 BottomCenter,
169 TopLeft,
170 TopRight,
171 TopCenter,
172 CenterLeft,
173 CenterRight,
174 Center
175};
176
181struct QWT3D_EXPORT Tuple
182{
183 // Calls Tuple(0,0)
184 Tuple() : x(0), y(0)
185 {
186 }
187 // Initialize Tuple with x and y
188 Tuple(double X, double Y) : x(X), y(Y)
189 {
190 }
191 // Tuple coordinates
192 double x, y;
193};
194
200struct QWT3D_EXPORT Triple
201{
202 // Initialize Triple with x,y and z
203 explicit Triple(double xv = 0, double yv = 0, double zv = 0) : x(xv), y(yv), z(zv)
204 {
205 }
206
207#ifndef QWT3D_NOT_FOR_DOXYGEN
208#ifdef Q_OS_IRIX
209 Triple(const Triple& val)
210 {
211 if (&val == this)
212 return;
213 x = val.x;
214 y = val.y;
215 z = val.z;
216 }
217 const Triple& operator=(const Triple& val)
218 {
219 if (&val == this)
220 return *this;
221 x = val.x;
222 y = val.y;
223 z = val.z;
224 return *this;
225 }
226#endif
227#endif // QWT3D_NOT_FOR_DOXYGEN
228
229 // Triple coordinates
230 double x, y, z;
231
232 Triple& operator+=(Triple t)
233 {
234 x += t.x;
235 y += t.y;
236 z += t.z;
237
238 return *this;
239 }
240
241 Triple& operator-=(Triple t)
242 {
243 x -= t.x;
244 y -= t.y;
245 z -= t.z;
246
247 return *this;
248 }
249 Triple& operator*=(double d)
250 {
251 x *= d;
252 y *= d;
253 z *= d;
254
255 return *this;
256 }
257 Triple& operator/=(double d)
258 {
259 x /= d;
260 y /= d;
261 z /= d;
262
263 return *this;
264 }
265 Triple& operator*=(Triple t) // scale
266 {
267 x *= t.x;
268 y *= t.y;
269 z *= t.z;
270
271 return *this;
272 }
273
274 bool operator!=(Triple t) const
275 {
276 return !isPracticallyZero(x, t.x) || !isPracticallyZero(y, t.y) || !isPracticallyZero(z, t.z);
277 }
278
279 bool operator==(Triple t) const
280 {
281 return !operator!=(t);
282 }
283
284 double length() const
285 {
286 double l2 = x * x + y * y + z * z;
287 return (isPracticallyZero(l2)) ? 0 : sqrt(l2);
288 }
289
290 void normalize()
291 {
292 double l = length();
293 if (l)
294 *this /= l;
295 }
296};
297
298inline const Triple operator+(const Triple& t, const Triple& t2)
299{
300 return Triple(t) += t2;
301}
302inline const Triple operator-(const Triple& t, const Triple& t2)
303{
304 return Triple(t) -= t2;
305}
306inline const Triple operator*(double d, const Triple& t)
307{
308 return Triple(t) *= d;
309}
310inline const Triple operator*(const Triple& t, double d)
311{
312 return Triple(t) *= d;
313}
314inline const Triple operator/(double d, const Triple& t)
315{
316 return Triple(t) /= d;
317}
318inline const Triple operator/(const Triple& t, double d)
319{
320 return Triple(t) /= d;
321}
322inline const Triple operator*(const Triple& t, const Triple& t2)
323{
324 return Triple(t) *= t2;
325}
326
333struct QWT3D_EXPORT ParallelEpiped
334{
335 // Construct non-initialized Parallelepiped
337 {
338 }
339
340 // Construct initialized Parallelepiped: minv -> minVertex, maxv -> maxVertex
341 ParallelEpiped(Triple minv, Triple maxv) : minVertex(minv), maxVertex(maxv)
342 {
343 }
344
345 Triple minVertex;
346 Triple maxVertex;
347};
348
353struct QWT3D_EXPORT FreeVector
354{
355 FreeVector()
356 {
357 }
358
359 // Construct initialized vector: b -> base, e -> top
360 FreeVector(Triple b, Triple t) : base(b), top(t)
361 {
362 }
363
364 Triple base;
365 Triple top;
366};
367
371using FreeVectorField = std::vector< FreeVector >;
372
376using TripleField = std::vector< Triple >;
377
381using Cell = std::vector< unsigned >;
382
386using CellField = std::vector< Cell >;
387
388// Returns the sum over the sizes of the single cells
389unsigned tesselationSize(CellField const& t);
390
394struct QWT3D_EXPORT RGBA
395{
396 RGBA() : r(0), g(0), b(0), a(1)
397 {
398 }
399 RGBA(double rr, double gg, double bb, double aa = 1) : r(rr), g(gg), b(bb), a(aa)
400 {
401 }
402 double r, g, b, a;
403};
404
408using ColorVector = std::vector< RGBA >;
409
410#ifndef QWT3D_NOT_FOR_DOXYGEN
411
412// RGB -> QColor
413QWT3D_EXPORT QColor GL2Qt(double r, double g, double b);
414// QColor -> RGBA
415QWT3D_EXPORT RGBA Qt2GL(QColor col);
416
417using Vertex = double*;
418using DataRow = std::vector< Vertex >;
419using DataMatrix = std::vector< DataRow >;
420
427{
428 QWT_DECLARE_PRIVATE(Qwt3DData)
429
430public:
431 DATATYPE datatype;
432 Qwt3DData();
433 virtual ~Qwt3DData();
434 // Destroy content
435 virtual void clear() = 0;
436 // No data
437 virtual bool empty() const = 0;
438 void setHull(ParallelEpiped const& h);
439 ParallelEpiped const& hull() const;
440};
441
448{
449 QWT_DECLARE_PRIVATE(Qwt3DGridData)
450
451public:
453 // See setSize()
454 Qwt3DGridData(unsigned int columns, unsigned int rows);
455 ~Qwt3DGridData() override;
456
457 int columns() const;
458 int rows() const;
459
460 // Destroy content
461 void clear();
462 bool empty() const;
463 // Destroys content and set new size, elements are uninitialized
464 void setSize(unsigned int columns, unsigned int rows);
465
466 // Mesh vertices
467 DataMatrix vertices;
468 // Mesh normals
469 DataMatrix normals;
470 void setPeriodic(bool u, bool v);
471 bool uperiodic() const;
472 bool vperiodic() const;
473};
474
481{
482public:
484 {
485 datatype = POLYGON;
486 }
488 {
489 clear();
490 }
491
492 // Destroy content
493 void clear();
494 bool empty() const
495 {
496 return cells.empty();
497 }
498
499 Triple const& operator()(unsigned cellnumber, unsigned vertexnumber);
500
501 // Polygon/cell mesh
502 CellField cells;
503 TripleField nodes;
504 // Mesh normals
505 TripleField normals;
506};
507
508inline Triple normalizedcross(Triple const& u, Triple const& v)
509{
510 Triple n;
511
512 /* compute the cross product (u x v for right-handed [ccw]) */
513 n.x = u.y * v.z - u.z * v.y;
514 n.y = u.z * v.x - u.x * v.z;
515 n.z = u.x * v.y - u.y * v.x;
516
517 /* normalize */
518 double l = n.length();
519 if (l) {
520 n /= l;
521 } else {
522 n = Triple(0, 0, 0);
523 }
524
525 return n;
526}
527
528inline double dotProduct(Triple const& u, Triple const& v)
529{
530 return u.x * v.x + u.y * v.y + u.z * v.z;
531}
532
533void convexhull2d(std::vector< unsigned >& idx, const std::vector< Tuple >& src);
534
535#endif // QWT3D_NOT_FOR_DOXYGEN
536
542struct QWT3D_EXPORT Qwt3DFunctionData
543{
545 std::vector<std::vector<double>> z;
546 unsigned int columns = 0;
547 unsigned int rows = 0;
548 double minx = 0.0;
549 double maxx = 0.0;
550 double miny = 0.0;
551 double maxy = 0.0;
552};
553
559struct QWT3D_EXPORT Qwt3DParametricData
560{
562 std::vector<std::vector<Triple>> vertices;
563 unsigned int columns = 0;
564 unsigned int rows = 0;
565 bool uperiodic = false;
566 bool vperiodic = false;
567};
568
580enum Rtti3DValues
581{
583 Rtti_Plot3DItem = 0,
584
586 Rtti_Plot3DSurface = 1001,
587
589 Rtti_Plot3DBar = 1002,
590
592 Rtti_Plot3DLine = 1003
593};
594
595
596#endif
Implements a graph-like cell structure with limit access functions.
Definition qwt3d_types.h:481
Abstract base class for plot data.
Definition qwt3d_types.h:427
Implements a matrix of z-Values with limit access functions.
Definition qwt3d_types.h:448
Free vector.
Definition qwt3d_types.h:354
Parallelepiped spanned by 2 Triples.
Definition qwt3d_types.h:334
Result of evaluating a Qwt3DFunction over its grid.
Definition qwt3d_types.h:543
std::vector< std::vector< double > > z
z[i][j] = z-value at column i, row j
Definition qwt3d_types.h:545
Result of evaluating a Qwt3DParametricSurface over its grid.
Definition qwt3d_types.h:560
std::vector< std::vector< Triple > > vertices
vertices[i][j] = xyz position at column i, row j
Definition qwt3d_types.h:562
Red-Green-Blue-Alpha value.
Definition qwt3d_types.h:395
Triple [x,y,z].
Definition qwt3d_types.h:201
Tuple [x,y].
Definition qwt3d_types.h:182