QWT API (中文) 7.0.1
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
qwt3d_types.h
1#if defined(_MSC_VER) /* MSVC Compiler */
2#pragma warning(disable : 4786)
3#endif
4
5#ifndef __DATATYPES_H__
6#define __DATATYPES_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
43enum PLOTSTYLE
44{
45 NOPLOT, // No visible data
46 WIREFRAME, // Wireframe style
47 HIDDENLINE, // Hidden Line style
48 FILLED, // Color filled polygons w/o edges
49 FILLEDMESH, // Color filled polygons w/ separately colored edges
50 POINTS, // User defined style (used by Enrichments)
51 USER // User defined style (used by Enrichments)
52};
53
63enum SHADINGSTYLE
64{
65 FLAT, // Flat shading (OpenGL)
66 GOURAUD // Gouraud Shading (OpenGL)
67};
68
78enum COORDSTYLE
79{
80 NOCOORD, // Coordinate system is not visible
81 BOX, // Boxed
82 FRAME // Frame - 3 visible axes
83};
84
94enum SCALETYPE
95{
96 LINEARSCALE, // Linear scaling
97 LOG10SCALE, // Logarithmic scaling (base 10)
98 USERSCALE // User-defined (for extensions)
99};
100
110enum FLOORSTYLE
111{
112 NOFLOOR, // Empty floor
113 FLOORISO, // Isoline projections visible
114 FLOORDATA // Projected polygons visible
115};
116
126enum DATATYPE
127{
128 GRID, // Rectangular grid
129 POLYGON // Convex polygon
130};
131
143enum AXIS
144{
145 X1 = 0, // 1st x-axis
146 X2 = 3, // 2nd x-axis
147 X3 = 4, // 3rd x-axis
148 X4 = 5, // 4th x-axis
149 Y1 = 1, // 1st y-axis
150 Y2 = 8, // 2nd y-axis
151 Y3 = 7, // 3rd y-axis
152 Y4 = 6, // 4th y-axis
153 Z1 = 2, // 1st z-axis
154 Z2 = 9, // 2nd z-axis
155 Z3 = 11, // 3rd z-axis
156 Z4 = 10 // 4th z-axis
157};
158
168enum SIDE
169{
170 NOSIDEGRID = 0,
171 LEFT = 1 << 0,
172 RIGHT = 1 << 1,
173 CEIL = 1 << 2,
174 FLOOR = 1 << 3,
175 FRONT = 1 << 4,
176 BACK = 1 << 5
177};
178
188enum ANCHOR
189{
190 BottomLeft,
191 BottomRight,
192 BottomCenter,
193 TopLeft,
194 TopRight,
195 TopCenter,
196 CenterLeft,
197 CenterRight,
198 Center
199};
200
212struct QWT3D_EXPORT Tuple
213{
214 // Calls Tuple(0,0)
215 Tuple() : x(0), y(0)
216 {
217 }
218 // Initialize Tuple with x and y
219 Tuple(double X, double Y) : x(X), y(Y)
220 {
221 }
222 // Tuple coordinates
223 double x, y;
224};
225
239struct QWT3D_EXPORT Triple
240{
241 // Initialize Triple with x,y and z
242 explicit Triple(double xv = 0, double yv = 0, double zv = 0) : x(xv), y(yv), z(zv)
243 {
244 }
245
246#ifndef QWT3D_NOT_FOR_DOXYGEN
247#ifdef Q_OS_IRIX
248 Triple(const Triple& val)
249 {
250 if (&val == this)
251 return;
252 x = val.x;
253 y = val.y;
254 z = val.z;
255 }
256 const Triple& operator=(const Triple& val)
257 {
258 if (&val == this)
259 return *this;
260 x = val.x;
261 y = val.y;
262 z = val.z;
263 return *this;
264 }
265#endif
266#endif // QWT3D_NOT_FOR_DOXYGEN
267
268 // Triple coordinates
269 double x, y, z;
270
271 Triple& operator+=(Triple t)
272 {
273 x += t.x;
274 y += t.y;
275 z += t.z;
276
277 return *this;
278 }
279
280 Triple& operator-=(Triple t)
281 {
282 x -= t.x;
283 y -= t.y;
284 z -= t.z;
285
286 return *this;
287 }
288 Triple& operator*=(double d)
289 {
290 x *= d;
291 y *= d;
292 z *= d;
293
294 return *this;
295 }
296 Triple& operator/=(double d)
297 {
298 x /= d;
299 y /= d;
300 z /= d;
301
302 return *this;
303 }
304 Triple& operator*=(Triple t) // scale
305 {
306 x *= t.x;
307 y *= t.y;
308 z *= t.z;
309
310 return *this;
311 }
312
313 bool operator!=(Triple t) const
314 {
315 return !isPracticallyZero(x, t.x) || !isPracticallyZero(y, t.y) || !isPracticallyZero(z, t.z);
316 }
317
318 bool operator==(Triple t) const
319 {
320 return !operator!=(t);
321 }
322
323 double length() const
324 {
325 double l2 = x * x + y * y + z * z;
326 return (isPracticallyZero(l2)) ? 0 : sqrt(l2);
327 }
328
329 void normalize()
330 {
331 double l = length();
332 if (l)
333 *this /= l;
334 }
335};
336
337inline const Triple operator+(const Triple& t, const Triple& t2)
338{
339 return Triple(t) += t2;
340}
341inline const Triple operator-(const Triple& t, const Triple& t2)
342{
343 return Triple(t) -= t2;
344}
345inline const Triple operator*(double d, const Triple& t)
346{
347 return Triple(t) *= d;
348}
349inline const Triple operator*(const Triple& t, double d)
350{
351 return Triple(t) *= d;
352}
353inline const Triple operator/(double d, const Triple& t)
354{
355 return Triple(t) /= d;
356}
357inline const Triple operator/(const Triple& t, double d)
358{
359 return Triple(t) /= d;
360}
361inline const Triple operator*(const Triple& t, const Triple& t2)
362{
363 return Triple(t) *= t2;
364}
365
381struct QWT3D_EXPORT ParallelEpiped
382{
383 // Construct non-initialized Parallelepiped
385 {
386 }
387
388 // Construct initialized Parallelepiped: minv -> minVertex, maxv -> maxVertex
389 ParallelEpiped(Triple minv, Triple maxv) : minVertex(minv), maxVertex(maxv)
390 {
391 }
392
393 Triple minVertex;
394 Triple maxVertex;
395};
396
408struct QWT3D_EXPORT FreeVector
409{
410 FreeVector()
411 {
412 }
413
414 // Construct initialized vector: b -> base, e -> top
415 FreeVector(Triple b, Triple t) : base(b), top(t)
416 {
417 }
418
419 Triple base;
420 Triple top;
421};
422
432using FreeVectorField = std::vector< FreeVector >;
433
443using TripleField = std::vector< Triple >;
444
454using Cell = std::vector< unsigned >;
455
465using CellField = std::vector< Cell >;
466
467// Returns the sum over the sizes of the single cells
468unsigned tesselationSize(Qwt3D::CellField const& t);
469
479struct QWT3D_EXPORT RGBA
480{
481 RGBA() : r(0), g(0), b(0), a(1)
482 {
483 }
484 RGBA(double rr, double gg, double bb, double aa = 1) : r(rr), g(gg), b(bb), a(aa)
485 {
486 }
487 double r, g, b, a;
488};
489
499using ColorVector = std::vector< RGBA >;
500
501#ifndef QWT3D_NOT_FOR_DOXYGEN
502
503// RGB -> QColor
504QWT3D_EXPORT QColor GL2Qt(GLdouble r, GLdouble g, GLdouble b);
505// QColor -> RGBA
506QWT3D_EXPORT Qwt3D::RGBA Qt2GL(QColor col);
507
508using Vertex = double*;
509using DataRow = std::vector< Vertex >;
510using DataMatrix = std::vector< DataRow >;
511
524class Data
525{
526public:
527 Qwt3D::DATATYPE datatype;
528 Data()
529 {
530 datatype = Qwt3D::POLYGON;
531 }
532 virtual ~Data()
533 {
534 }
535 // Destroy content
536 virtual void clear() = 0;
537 // No data
538 virtual bool empty() const = 0;
539 void setHull(Qwt3D::ParallelEpiped const& h)
540 {
541 hull_p = h;
542 }
543 Qwt3D::ParallelEpiped const& hull() const
544 {
545 return hull_p;
546 }
547
548protected:
550};
551
565class GridData : public Data
566{
567public:
568 GridData();
569 // See setSize()
570 GridData(unsigned int columns, unsigned int rows);
571 ~GridData()
572 {
573 clear();
574 }
575
576 int columns() const;
577 int rows() const;
578
579 // Destroy content
580 void clear();
581 bool empty() const
582 {
583 return vertices.empty();
584 }
585 // Destroys content and set new size, elements are uninitialized
586 void setSize(unsigned int columns,
587 unsigned int rows);
588
589 // Mesh vertices
590 DataMatrix vertices;
591 // Mesh normals
592 DataMatrix normals;
593 void setPeriodic(bool u, bool v)
594 {
595 uperiodic_ = u;
596 vperiodic_ = v;
597 }
598 bool uperiodic() const
599 {
600 return uperiodic_;
601 }
602 bool vperiodic() const
603 {
604 return vperiodic_;
605 }
606
607private:
608 bool uperiodic_, vperiodic_;
609};
610
624class CellData : public Data
625{
626public:
627 CellData()
628 {
629 datatype = Qwt3D::POLYGON;
630 }
631 ~CellData()
632 {
633 clear();
634 }
635
636 // Destroy content
637 void clear();
638 bool empty() const
639 {
640 return cells.empty();
641 }
642
643 Triple const& operator()(unsigned cellnumber, unsigned vertexnumber);
644
645 // Polygon/cell mesh
646 CellField cells;
647 TripleField nodes;
648 // Mesh normals
649 TripleField normals;
650};
651
652inline Triple normalizedcross(Triple const& u, Triple const& v)
653{
654 Triple n;
655
656 /* compute the cross product (u x v for right-handed [ccw]) */
657 n.x = u.y * v.z - u.z * v.y;
658 n.y = u.z * v.x - u.x * v.z;
659 n.z = u.x * v.y - u.y * v.x;
660
661 /* normalize */
662 double l = n.length();
663 if (l) {
664 n /= l;
665 } else {
666 n = Triple(0, 0, 0);
667 }
668
669 return n;
670}
671
672inline double dotProduct(Triple const& u, Triple const& v)
673{
674 return u.x * v.x + u.y * v.y + u.z * v.z;
675}
676
677void convexhull2d(std::vector< unsigned >& idx, const std::vector< Qwt3D::Tuple >& src);
678
679#endif // QWT3D_NOT_FOR_DOXYGEN
680
681} // ns
682
683#endif
实现带限制访问函数的图状单元格结构
Definition qwt3d_types.h:625
绘图数据的抽象基类
Definition qwt3d_types.h:525
实现带限制访问函数的 z 值矩阵
Definition qwt3d_types.h:566
自由向量
Definition qwt3d_types.h:409
由两个三元组张成的平行六面体
Definition qwt3d_types.h:382
红-绿-蓝-透明度值
Definition qwt3d_types.h:480
三元组 [x,y,z]
Definition qwt3d_types.h:240
二元组 [x,y]
Definition qwt3d_types.h:213