QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
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#if defined(Q_OS_WIN)
17#include <windows.h>
18#endif
19
20#ifndef WHEEL_DELTA
21#define WHEEL_DELTA 120
22#endif
23
24#include "qwt3d_portability.h"
25#include "qwt3d_helper.h"
26#include "qwt3d_openglhelper.h"
27#include <QColor>
28
29namespace Qwt3D
30{
31
32const double PI = 3.14159265358979323846264338328;
33
37enum PLOTSTYLE
38{
39 NOPLOT, // No visible data
40 WIREFRAME, // Wireframe style
41 HIDDENLINE, // Hidden Line style
42 FILLED, // Color filled polygons w/o edges
43 FILLEDMESH, // Color filled polygons w/ separately colored edges
44 POINTS, // User defined style (used by Enrichments)
45 USER // User defined style (used by Enrichments)
46};
47
51enum SHADINGSTYLE
52{
53 FLAT, // Flat shading (OpenGL)
54 GOURAUD // Gouraud Shading (OpenGL)
55};
56
60enum COORDSTYLE
61{
62 NOCOORD, // Coordinate system is not visible
63 BOX, // Boxed
64 FRAME // Frame - 3 visible axes
65};
66
70enum SCALETYPE
71{
72 LINEARSCALE, // Linear scaling
73 LOG10SCALE, // Logarithmic scaling (base 10)
74 USERSCALE // User-defined (for extensions)
75};
76
80enum FLOORSTYLE
81{
82 NOFLOOR, // Empty floor
83 FLOORISO, // Isoline projections visible
84 FLOORDATA // Projected polygons visible
85};
86
90enum DATATYPE
91{
92 GRID, // Rectangular grid
93 POLYGON // Convex polygon
94};
95
100enum AXIS
101{
102 X1 = 0, // 1st x-axis
103 X2 = 3, // 2nd x-axis
104 X3 = 4, // 3rd x-axis
105 X4 = 5, // 4th x-axis
106 Y1 = 1, // 1st y-axis
107 Y2 = 8, // 2nd y-axis
108 Y3 = 7, // 3rd y-axis
109 Y4 = 6, // 4th y-axis
110 Z1 = 2, // 1st z-axis
111 Z2 = 9, // 2nd z-axis
112 Z3 = 11, // 3rd z-axis
113 Z4 = 10 // 4th z-axis
114};
115
119enum SIDE
120{
121 NOSIDEGRID = 0,
122 LEFT = 1 << 0,
123 RIGHT = 1 << 1,
124 CEIL = 1 << 2,
125 FLOOR = 1 << 3,
126 FRONT = 1 << 4,
127 BACK = 1 << 5
128};
129
133enum ANCHOR
134{
135 BottomLeft,
136 BottomRight,
137 BottomCenter,
138 TopLeft,
139 TopRight,
140 TopCenter,
141 CenterLeft,
142 CenterRight,
143 Center
144};
145
150struct QWT3D_EXPORT Tuple
151{
152 // Calls Tuple(0,0)
153 Tuple() : x(0), y(0)
154 {
155 }
156 // Initialize Tuple with x and y
157 Tuple(double X, double Y) : x(X), y(Y)
158 {
159 }
160 // Tuple coordinates
161 double x, y;
162};
163
169struct QWT3D_EXPORT Triple
170{
171 // Initialize Triple with x,y and z
172 explicit Triple(double xv = 0, double yv = 0, double zv = 0) : x(xv), y(yv), z(zv)
173 {
174 }
175
176#ifndef QWT3D_NOT_FOR_DOXYGEN
177#ifdef Q_OS_IRIX
178 Triple(const Triple& val)
179 {
180 if (&val == this)
181 return;
182 x = val.x;
183 y = val.y;
184 z = val.z;
185 }
186 const Triple& operator=(const Triple& val)
187 {
188 if (&val == this)
189 return *this;
190 x = val.x;
191 y = val.y;
192 z = val.z;
193 return *this;
194 }
195#endif
196#endif // QWT3D_NOT_FOR_DOXYGEN
197
198 // Triple coordinates
199 double x, y, z;
200
201 Triple& operator+=(Triple t)
202 {
203 x += t.x;
204 y += t.y;
205 z += t.z;
206
207 return *this;
208 }
209
210 Triple& operator-=(Triple t)
211 {
212 x -= t.x;
213 y -= t.y;
214 z -= t.z;
215
216 return *this;
217 }
218 Triple& operator*=(double d)
219 {
220 x *= d;
221 y *= d;
222 z *= d;
223
224 return *this;
225 }
226 Triple& operator/=(double d)
227 {
228 x /= d;
229 y /= d;
230 z /= d;
231
232 return *this;
233 }
234 Triple& operator*=(Triple t) // scale
235 {
236 x *= t.x;
237 y *= t.y;
238 z *= t.z;
239
240 return *this;
241 }
242
243 bool operator!=(Triple t) const
244 {
245 return !isPracticallyZero(x, t.x) || !isPracticallyZero(y, t.y) || !isPracticallyZero(z, t.z);
246 }
247
248 bool operator==(Triple t) const
249 {
250 return !operator!=(t);
251 }
252
253 double length() const
254 {
255 double l2 = x * x + y * y + z * z;
256 return (isPracticallyZero(l2)) ? 0 : sqrt(l2);
257 }
258
259 void normalize()
260 {
261 double l = length();
262 if (l)
263 *this /= l;
264 }
265};
266
267inline const Triple operator+(const Triple& t, const Triple& t2)
268{
269 return Triple(t) += t2;
270}
271inline const Triple operator-(const Triple& t, const Triple& t2)
272{
273 return Triple(t) -= t2;
274}
275inline const Triple operator*(double d, const Triple& t)
276{
277 return Triple(t) *= d;
278}
279inline const Triple operator*(const Triple& t, double d)
280{
281 return Triple(t) *= d;
282}
283inline const Triple operator/(double d, const Triple& t)
284{
285 return Triple(t) /= d;
286}
287inline const Triple operator/(const Triple& t, double d)
288{
289 return Triple(t) /= d;
290}
291inline const Triple operator*(const Triple& t, const Triple& t2)
292{
293 return Triple(t) *= t2;
294}
295
302struct QWT3D_EXPORT ParallelEpiped
303{
304 // Construct non-initialized Parallelepiped
306 {
307 }
308
309 // Construct initialized Parallelepiped: minv -> minVertex, maxv -> maxVertex
310 ParallelEpiped(Triple minv, Triple maxv) : minVertex(minv), maxVertex(maxv)
311 {
312 }
313
314 Triple minVertex;
315 Triple maxVertex;
316};
317
322struct QWT3D_EXPORT FreeVector
323{
324 FreeVector()
325 {
326 }
327
328 // Construct initialized vector: b -> base, e -> top
329 FreeVector(Triple b, Triple t) : base(b), top(t)
330 {
331 }
332
333 Triple base;
334 Triple top;
335};
336
340using FreeVectorField = std::vector< FreeVector >;
341
345using TripleField = std::vector< Triple >;
346
350using Cell = std::vector< unsigned >;
351
355using CellField = std::vector< Cell >;
356
357// Returns the sum over the sizes of the single cells
358unsigned tesselationSize(Qwt3D::CellField const& t);
359
363struct QWT3D_EXPORT RGBA
364{
365 RGBA() : r(0), g(0), b(0), a(1)
366 {
367 }
368 RGBA(double rr, double gg, double bb, double aa = 1) : r(rr), g(gg), b(bb), a(aa)
369 {
370 }
371 double r, g, b, a;
372};
373
377using ColorVector = std::vector< RGBA >;
378
379#ifndef QWT3D_NOT_FOR_DOXYGEN
380
381// RGB -> QColor
382QWT3D_EXPORT QColor GL2Qt(GLdouble r, GLdouble g, GLdouble b);
383// QColor -> RGBA
384QWT3D_EXPORT Qwt3D::RGBA Qt2GL(QColor col);
385
386using Vertex = double*;
387using DataRow = std::vector< Vertex >;
388using DataMatrix = std::vector< DataRow >;
389
395class Data
396{
397 QWT_DECLARE_PRIVATE(Data)
398
399public:
400 Qwt3D::DATATYPE datatype;
401 Data();
402 virtual ~Data();
403 // Destroy content
404 virtual void clear() = 0;
405 // No data
406 virtual bool empty() const = 0;
407 void setHull(Qwt3D::ParallelEpiped const& h);
408 Qwt3D::ParallelEpiped const& hull() const;
409};
410
416class GridData : public Data
417{
418 QWT_DECLARE_PRIVATE(GridData)
419
420public:
421 GridData();
422 // See setSize()
423 GridData(unsigned int columns, unsigned int rows);
424 ~GridData() override;
425
426 int columns() const;
427 int rows() const;
428
429 // Destroy content
430 void clear();
431 bool empty() const;
432 // Destroys content and set new size, elements are uninitialized
433 void setSize(unsigned int columns, unsigned int rows);
434
435 // Mesh vertices
436 DataMatrix vertices;
437 // Mesh normals
438 DataMatrix normals;
439 void setPeriodic(bool u, bool v);
440 bool uperiodic() const;
441 bool vperiodic() const;
442};
443
449class CellData : public Data
450{
451public:
452 CellData()
453 {
454 datatype = Qwt3D::POLYGON;
455 }
456 ~CellData()
457 {
458 clear();
459 }
460
461 // Destroy content
462 void clear();
463 bool empty() const
464 {
465 return cells.empty();
466 }
467
468 Triple const& operator()(unsigned cellnumber, unsigned vertexnumber);
469
470 // Polygon/cell mesh
471 CellField cells;
472 TripleField nodes;
473 // Mesh normals
474 TripleField normals;
475};
476
477inline Triple normalizedcross(Triple const& u, Triple const& v)
478{
479 Triple n;
480
481 /* compute the cross product (u x v for right-handed [ccw]) */
482 n.x = u.y * v.z - u.z * v.y;
483 n.y = u.z * v.x - u.x * v.z;
484 n.z = u.x * v.y - u.y * v.x;
485
486 /* normalize */
487 double l = n.length();
488 if (l) {
489 n /= l;
490 } else {
491 n = Triple(0, 0, 0);
492 }
493
494 return n;
495}
496
497inline double dotProduct(Triple const& u, Triple const& v)
498{
499 return u.x * v.x + u.y * v.y + u.z * v.z;
500}
501
502void convexhull2d(std::vector< unsigned >& idx, const std::vector< Qwt3D::Tuple >& src);
503
504#endif // QWT3D_NOT_FOR_DOXYGEN
505
506} // ns
507
508#endif
Implements a graph-like cell structure with limit access functions
Definition qwt3d_types.h:450
Abstract base class for plot data
Definition qwt3d_types.h:396
Implements a matrix of z-Values with limit access functions
Definition qwt3d_types.h:417
Free vector
Definition qwt3d_types.h:323
Parallelepiped spanned by 2 Triples
Definition qwt3d_types.h:303
Red-Green-Blue-Alpha value
Definition qwt3d_types.h:364
Triple [x,y,z]
Definition qwt3d_types.h:170
Tuple [x,y]
Definition qwt3d_types.h:151