| [89] | 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_WS_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 |
|
|---|
| 28 | //! Common namespace for all QwtPlot3D classes
|
|---|
| 29 | namespace Qwt3D
|
|---|
| 30 | {
|
|---|
| 31 |
|
|---|
| 32 | const double PI = 3.14159265358979323846264338328;
|
|---|
| 33 |
|
|---|
| 34 | //! Plotting style
|
|---|
| 35 | enum PLOTSTYLE
|
|---|
| 36 | {
|
|---|
| 37 | NOPLOT , //!< No visible data
|
|---|
| 38 | WIREFRAME , //!< Wireframe style
|
|---|
| 39 | HIDDENLINE , //!< Hidden Line style
|
|---|
| 40 | FILLED , //!< Color filled polygons w/o edges
|
|---|
| 41 | FILLEDMESH , //!< Color filled polygons w/ separately colored edges
|
|---|
| 42 | POINTS , //!< User defined style (used by Enrichments)
|
|---|
| 43 | USER //!< User defined style (used by Enrichments)
|
|---|
| 44 | };
|
|---|
| 45 |
|
|---|
| 46 | //! Shading style
|
|---|
| 47 | enum SHADINGSTYLE
|
|---|
| 48 | {
|
|---|
| 49 | FLAT, //!< Flat shading (OpenGL)
|
|---|
| 50 | GOURAUD //!< Gouraud Shading (OpenGL)
|
|---|
| 51 | };
|
|---|
| 52 |
|
|---|
| 53 | //! Style of Coordinate system
|
|---|
| 54 | enum COORDSTYLE
|
|---|
| 55 | {
|
|---|
| 56 | NOCOORD, //!< Coordinate system is not visible
|
|---|
| 57 | BOX, //!< Boxed
|
|---|
| 58 | FRAME //!< Frame - 3 visible axes
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | //! Different types of axis scales
|
|---|
| 62 | enum SCALETYPE
|
|---|
| 63 | {
|
|---|
| 64 | LINEARSCALE,//!< Linear scaling
|
|---|
| 65 | LOG10SCALE, //!< Logarithmic scaling (base 10)
|
|---|
| 66 | USERSCALE //!< User-defined (for extensions)
|
|---|
| 67 | };
|
|---|
| 68 |
|
|---|
| 69 | //! Plotting style for floor data (projections)
|
|---|
| 70 | enum FLOORSTYLE
|
|---|
| 71 | {
|
|---|
| 72 | NOFLOOR, //!< Empty floor
|
|---|
| 73 | FLOORISO, //!< Isoline projections visible
|
|---|
| 74 | FLOORDATA //!< Projected polygons visible
|
|---|
| 75 | };
|
|---|
| 76 |
|
|---|
| 77 | //! Mesh type
|
|---|
| 78 | enum DATATYPE
|
|---|
| 79 | {
|
|---|
| 80 | GRID, //!< Rectangular grid
|
|---|
| 81 | POLYGON //!< Convex polygon
|
|---|
| 82 | };
|
|---|
| 83 |
|
|---|
| 84 | //! The 12 axes
|
|---|
| 85 | /**
|
|---|
| 86 | \image html axes.png
|
|---|
| 87 | */
|
|---|
| 88 | enum AXIS
|
|---|
| 89 | {
|
|---|
| 90 | X1 = 0, //!< 1st x-axis
|
|---|
| 91 | X2 = 3, //!< 2nd x-axis
|
|---|
| 92 | X3 = 4, //!< 3th x-axis
|
|---|
| 93 | X4 = 5, //!< 4th x-axis
|
|---|
| 94 | Y1 = 1, //!< 1st y-axis
|
|---|
| 95 | Y2 = 8, //!< 2nd y-axis
|
|---|
| 96 | Y3 = 7, //!< 3th y-axis
|
|---|
| 97 | Y4 = 6, //!< 4th y-axis
|
|---|
| 98 | Z1 = 2, //!< 1st z-axis
|
|---|
| 99 | Z2 = 9, //!< 2nd z-axis
|
|---|
| 100 | Z3 = 11, //!< 3th z-axis
|
|---|
| 101 | Z4 = 10 //!< 4th z-axis
|
|---|
| 102 | };
|
|---|
| 103 |
|
|---|
| 104 | //! The 6 sides
|
|---|
| 105 | enum SIDE
|
|---|
| 106 | {
|
|---|
| 107 | NOSIDEGRID = 0,
|
|---|
| 108 | LEFT = 1 << 0,
|
|---|
| 109 | RIGHT = 1 << 1,
|
|---|
| 110 | CEIL = 1 << 2,
|
|---|
| 111 | FLOOR = 1 << 3,
|
|---|
| 112 | FRONT = 1 << 4,
|
|---|
| 113 | BACK = 1 << 5
|
|---|
| 114 | };
|
|---|
| 115 |
|
|---|
| 116 | //! Possible anchor points for drawing operations
|
|---|
| 117 | enum ANCHOR
|
|---|
| 118 | {
|
|---|
| 119 | BottomLeft,
|
|---|
| 120 | BottomRight,
|
|---|
| 121 | BottomCenter,
|
|---|
| 122 | TopLeft,
|
|---|
| 123 | TopRight,
|
|---|
| 124 | TopCenter,
|
|---|
| 125 | CenterLeft,
|
|---|
| 126 | CenterRight,
|
|---|
| 127 | Center
|
|---|
| 128 | };
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 | //! Tuple <tt>[x,y]</tt>
|
|---|
| 132 | struct QWT3D_EXPORT Tuple
|
|---|
| 133 | {
|
|---|
| 134 | Tuple() : x(0), y(0) {} //!< Calls Tuple(0,0)
|
|---|
| 135 | Tuple(double X, double Y) : x(X), y(Y) {} //!< Initialize Tuple with x and y
|
|---|
| 136 | //! Tuple coordinates
|
|---|
| 137 | double x,y;
|
|---|
| 138 | };
|
|---|
| 139 |
|
|---|
| 140 | //! Triple <tt>[x,y,z]</tt>
|
|---|
| 141 | /**
|
|---|
| 142 | Consider Triples also as vectors in R^3
|
|---|
| 143 | */
|
|---|
| 144 | struct QWT3D_EXPORT Triple
|
|---|
| 145 | {
|
|---|
| 146 | //! Initialize Triple with x,y and z
|
|---|
| 147 | explicit Triple(double xv = 0,double yv = 0,double zv = 0)
|
|---|
| 148 | : x(xv), y(yv), z(zv)
|
|---|
| 149 | {
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | #ifndef QWT3D_NOT_FOR_DOXYGEN
|
|---|
| 153 | #ifdef Q_OS_IRIX
|
|---|
| 154 | Triple(const Triple& val)
|
|---|
| 155 | {
|
|---|
| 156 | if (&val == this)
|
|---|
| 157 | return;
|
|---|
| 158 | x = val.x;
|
|---|
| 159 | y = val.y;
|
|---|
| 160 | z = val.z;
|
|---|
| 161 | }
|
|---|
| 162 | const Triple& operator=(const Triple& val)
|
|---|
| 163 | {
|
|---|
| 164 | if (&val == this)
|
|---|
| 165 | return *this;
|
|---|
| 166 | x = val.x;
|
|---|
| 167 | y = val.y;
|
|---|
| 168 | z = val.z;
|
|---|
| 169 | return *this;
|
|---|
| 170 | }
|
|---|
| 171 | #endif
|
|---|
| 172 | #endif // QWT3D_NOT_FOR_DOXYGEN
|
|---|
| 173 |
|
|---|
| 174 | //! Triple coordinates
|
|---|
| 175 | double x,y,z;
|
|---|
| 176 |
|
|---|
| 177 | Triple& operator+=(Triple t)
|
|---|
| 178 | {
|
|---|
| 179 | x += t.x;
|
|---|
| 180 | y += t.y;
|
|---|
| 181 | z += t.z;
|
|---|
| 182 |
|
|---|
| 183 | return *this;
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | Triple& operator-=(Triple t)
|
|---|
| 187 | {
|
|---|
| 188 | x -= t.x;
|
|---|
| 189 | y -= t.y;
|
|---|
| 190 | z -= t.z;
|
|---|
| 191 |
|
|---|
| 192 | return *this;
|
|---|
| 193 | }
|
|---|
| 194 | Triple& operator*=(double d)
|
|---|
| 195 | {
|
|---|
| 196 | x *= d;
|
|---|
| 197 | y *= d;
|
|---|
| 198 | z *= d;
|
|---|
| 199 |
|
|---|
| 200 | return *this;
|
|---|
| 201 | }
|
|---|
| 202 | Triple& operator/=(double d)
|
|---|
| 203 | {
|
|---|
| 204 | x /= d;
|
|---|
| 205 | y /= d;
|
|---|
| 206 | z /= d;
|
|---|
| 207 |
|
|---|
| 208 | return *this;
|
|---|
| 209 | }
|
|---|
| 210 | Triple& operator*=(Triple t) // scale
|
|---|
| 211 | {
|
|---|
| 212 | x *= t.x;
|
|---|
| 213 | y *= t.y;
|
|---|
| 214 | z *= t.z;
|
|---|
| 215 |
|
|---|
| 216 | return *this;
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | bool operator!=(Triple t) const
|
|---|
| 220 | {
|
|---|
| 221 | return !isPracticallyZero(x,t.x) || !isPracticallyZero(y,t.y) || !isPracticallyZero(z,t.z);
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | bool operator==(Triple t) const
|
|---|
| 225 | {
|
|---|
| 226 | return !operator!=(t);
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | double length() const
|
|---|
| 230 | {
|
|---|
| 231 | double l2 = x*x + y*y + z*z;
|
|---|
| 232 | return (isPracticallyZero(l2)) ? 0 :sqrt(l2);
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | void normalize()
|
|---|
| 236 | {
|
|---|
| 237 | double l = length();
|
|---|
| 238 | if (l)
|
|---|
| 239 | *this /= l;
|
|---|
| 240 | }
|
|---|
| 241 | };
|
|---|
| 242 |
|
|---|
| 243 | inline const Triple operator+(const Triple& t, const Triple& t2)
|
|---|
| 244 | {
|
|---|
| 245 | return Triple(t) += t2;
|
|---|
| 246 | }
|
|---|
| 247 | inline const Triple operator-(const Triple& t, const Triple& t2)
|
|---|
| 248 | {
|
|---|
| 249 | return Triple(t) -= t2;
|
|---|
| 250 | }
|
|---|
| 251 | inline const Triple operator*(double d, const Triple& t)
|
|---|
| 252 | {
|
|---|
| 253 | return Triple(t) *= d;
|
|---|
| 254 | }
|
|---|
| 255 | inline const Triple operator*(const Triple& t, double d)
|
|---|
| 256 | {
|
|---|
| 257 | return Triple(t) *= d;
|
|---|
| 258 | }
|
|---|
| 259 | inline const Triple operator/(double d, const Triple& t)
|
|---|
| 260 | {
|
|---|
| 261 | return Triple(t) /= d;
|
|---|
| 262 | }
|
|---|
| 263 | inline const Triple operator/(const Triple& t, double d)
|
|---|
| 264 | {
|
|---|
| 265 | return Triple(t) /= d;
|
|---|
| 266 | }
|
|---|
| 267 | inline const Triple operator*(const Triple& t, const Triple& t2)
|
|---|
| 268 | {
|
|---|
| 269 | return Triple(t) *= t2;
|
|---|
| 270 | }
|
|---|
| 271 |
|
|---|
| 272 | //! Parallelepiped spanned by 2 Triples
|
|---|
| 273 | /**
|
|---|
| 274 | Please use \em normalized Parallelepipeds:\n\n
|
|---|
| 275 | minVertex.x <= maxVertex.x\n
|
|---|
| 276 | minVertex.y <= maxVertex.y\n
|
|---|
| 277 | minVertex.z <= maxVertex.z\n
|
|---|
| 278 | */
|
|---|
| 279 | struct QWT3D_EXPORT ParallelEpiped
|
|---|
| 280 | {
|
|---|
| 281 | //! Construct non-initialized Parallelepiped
|
|---|
| 282 | ParallelEpiped()
|
|---|
| 283 | {
|
|---|
| 284 | }
|
|---|
| 285 |
|
|---|
| 286 | //! Construct initialized Parallelepiped
|
|---|
| 287 | /**
|
|---|
| 288 | minv -> minVertex\n
|
|---|
| 289 | maxv -> maxVertex\n
|
|---|
| 290 | */
|
|---|
| 291 | ParallelEpiped(Triple minv, Triple maxv)
|
|---|
| 292 | : minVertex(minv), maxVertex(maxv)
|
|---|
| 293 | {
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | Triple minVertex;
|
|---|
| 297 | Triple maxVertex;
|
|---|
| 298 | };
|
|---|
| 299 |
|
|---|
| 300 | //! Free vector
|
|---|
| 301 | /**
|
|---|
| 302 | FreeVectors represent objects like normal vectors and other vector fields inside R^3
|
|---|
| 303 | */
|
|---|
| 304 | struct QWT3D_EXPORT FreeVector
|
|---|
| 305 | {
|
|---|
| 306 | FreeVector()
|
|---|
| 307 | {
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| 310 | //! Construct initialized vector
|
|---|
| 311 | /**
|
|---|
| 312 | b -> base\n
|
|---|
| 313 | e -> top\n
|
|---|
| 314 | */
|
|---|
| 315 | FreeVector(Triple b, Triple t)
|
|---|
| 316 | : base(b), top(t)
|
|---|
| 317 | {
|
|---|
| 318 | }
|
|---|
| 319 |
|
|---|
| 320 | Triple base;
|
|---|
| 321 | Triple top;
|
|---|
| 322 | };
|
|---|
| 323 |
|
|---|
| 324 | //! A free vector field in R^3
|
|---|
| 325 | typedef std::vector<FreeVector> FreeVectorField;
|
|---|
| 326 |
|
|---|
| 327 | //! A point field in R^3
|
|---|
| 328 | typedef std::vector<Triple> TripleField;
|
|---|
| 329 | //! Holds indices in a TripleField interpreted as counterclockwise node numbering for a convex polygon
|
|---|
| 330 | typedef std::vector<unsigned> Cell;
|
|---|
| 331 | //! Vector of convex polygons. You need a TripleField as base for the node data
|
|---|
| 332 | typedef std::vector<Cell> CellField;
|
|---|
| 333 | //! Returns the sum over the sizes of the single cells
|
|---|
| 334 | unsigned tesselationSize(Qwt3D::CellField const& t);
|
|---|
| 335 |
|
|---|
| 336 | //! Red-Green-Blue-Alpha value
|
|---|
| 337 | struct QWT3D_EXPORT RGBA
|
|---|
| 338 | {
|
|---|
| 339 | RGBA()
|
|---|
| 340 | : r(0), g(0), b(0), a(1)
|
|---|
| 341 | {}
|
|---|
| 342 | RGBA(double rr, double gg, double bb, double aa = 1)
|
|---|
| 343 | : r(rr), g(gg), b(bb), a(aa)
|
|---|
| 344 | {}
|
|---|
| 345 | double r,g,b,a;
|
|---|
| 346 | };
|
|---|
| 347 |
|
|---|
| 348 | //! A Color field
|
|---|
| 349 | typedef std::vector<RGBA> ColorVector;
|
|---|
| 350 |
|
|---|
| 351 | #ifndef QWT3D_NOT_FOR_DOXYGEN
|
|---|
| 352 |
|
|---|
| 353 | QWT3D_EXPORT QColor GL2Qt(GLdouble r, GLdouble g, GLdouble b); //!< RGB -> QColor
|
|---|
| 354 | QWT3D_EXPORT Qwt3D::RGBA Qt2GL(QColor col); //!< QColor -> RGBA
|
|---|
| 355 |
|
|---|
| 356 | typedef double *Vertex;
|
|---|
| 357 | typedef std::vector<Vertex> DataRow;
|
|---|
| 358 | typedef std::vector<DataRow> DataMatrix;
|
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 | class Data
|
|---|
| 362 | {
|
|---|
| 363 | public:
|
|---|
| 364 | Qwt3D::DATATYPE datatype;
|
|---|
| 365 | Data() {datatype= Qwt3D::POLYGON;}
|
|---|
| 366 | virtual ~Data() {}
|
|---|
| 367 | virtual void clear() = 0; //!< destroy content
|
|---|
| 368 | virtual bool empty() const = 0; //!< no data
|
|---|
| 369 | void setHull(Qwt3D::ParallelEpiped const& h) {hull_p = h;}
|
|---|
| 370 | Qwt3D::ParallelEpiped const& hull() const {return hull_p;}
|
|---|
| 371 |
|
|---|
| 372 | protected:
|
|---|
| 373 | Qwt3D::ParallelEpiped hull_p;
|
|---|
| 374 | };
|
|---|
| 375 |
|
|---|
| 376 |
|
|---|
| 377 | //! Implements a matrix of z-Values with limit access functions
|
|---|
| 378 | class GridData : public Data
|
|---|
| 379 | {
|
|---|
| 380 | public:
|
|---|
| 381 | GridData();
|
|---|
| 382 | GridData(unsigned int columns, unsigned int rows);//!< see setSize()
|
|---|
| 383 | ~GridData() { clear();}
|
|---|
| 384 |
|
|---|
| 385 | int columns() const;
|
|---|
| 386 | int rows() const;
|
|---|
| 387 |
|
|---|
| 388 | void clear(); //!< destroy content
|
|---|
| 389 | bool empty() const { return vertices.empty();}
|
|---|
| 390 | void setSize(unsigned int columns, unsigned int rows); //!< destroys content and set new size, elements are uninitialized
|
|---|
| 391 |
|
|---|
| 392 | DataMatrix vertices; //!< mesh vertices
|
|---|
| 393 | DataMatrix normals; //!< mesh normals
|
|---|
| 394 | void setPeriodic(bool u, bool v) {uperiodic_ = u; vperiodic_ = v;}
|
|---|
| 395 | bool uperiodic() const {return uperiodic_;}
|
|---|
| 396 | bool vperiodic() const {return vperiodic_;}
|
|---|
| 397 |
|
|---|
| 398 | private:
|
|---|
| 399 | bool uperiodic_, vperiodic_;
|
|---|
| 400 | };
|
|---|
| 401 |
|
|---|
| 402 |
|
|---|
| 403 | //! Implements a graph-like cell structure with limit access functions
|
|---|
| 404 | class CellData : public Data
|
|---|
| 405 | {
|
|---|
| 406 | public:
|
|---|
| 407 | CellData() {datatype=Qwt3D::POLYGON;}
|
|---|
| 408 | ~CellData() { clear();}
|
|---|
| 409 |
|
|---|
| 410 | void clear(); //!< destroy content
|
|---|
| 411 | bool empty() const { return cells.empty();}
|
|---|
| 412 |
|
|---|
| 413 | Triple const& operator()(unsigned cellnumber, unsigned vertexnumber);
|
|---|
| 414 |
|
|---|
| 415 | CellField cells; //!< polygon/cell mesh
|
|---|
| 416 | TripleField nodes;
|
|---|
| 417 | TripleField normals; //!< mesh normals
|
|---|
| 418 | };
|
|---|
| 419 |
|
|---|
| 420 | inline Triple normalizedcross(Triple const& u, Triple const& v)
|
|---|
| 421 | {
|
|---|
| 422 | Triple n;
|
|---|
| 423 |
|
|---|
| 424 | /* compute the cross product (u x v for right-handed [ccw]) */
|
|---|
| 425 | n.x = u.y * v.z - u.z * v.y;
|
|---|
| 426 | n.y = u.z * v.x - u.x * v.z;
|
|---|
| 427 | n.z = u.x * v.y - u.y * v.x;
|
|---|
| 428 |
|
|---|
| 429 | /* normalize */
|
|---|
| 430 | double l = n.length();
|
|---|
| 431 | if (l)
|
|---|
| 432 | {
|
|---|
| 433 | n /= l;
|
|---|
| 434 | }
|
|---|
| 435 | else
|
|---|
| 436 | {
|
|---|
| 437 | n = Triple(0,0,0);
|
|---|
| 438 | }
|
|---|
| 439 |
|
|---|
| 440 | return n;
|
|---|
| 441 | }
|
|---|
| 442 |
|
|---|
| 443 | inline double dotProduct(Triple const& u, Triple const& v)
|
|---|
| 444 | {
|
|---|
| 445 | return u.x*v.x + u.y*v.y + u.z*v.z;
|
|---|
| 446 | }
|
|---|
| 447 |
|
|---|
| 448 | void convexhull2d( std::vector<unsigned>& idx, const std::vector<Qwt3D::Tuple>& src );
|
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 | #endif // QWT3D_NOT_FOR_DOXYGEN
|
|---|
| 452 |
|
|---|
| 453 | } // ns
|
|---|
| 454 |
|
|---|
| 455 | #endif
|
|---|