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=0 , //!< 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=0, //!< 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=0, //!< Empty floor 73 FLOORISO, //!< Isoline projections visible 74 FLOORDATA //!< Projected polygons visible 75 }; 76 77 //! Data Projection modes 78 enum PROJECTMODE 79 { 80 FACE=0, //!< Projected front and back faces 81 SIDE, //!< Projected left and right side 82 BASE //!< Projected onto floor base 83 }; 84 85 //! Mesh type 86 enum DATATYPE 87 { 88 GRID, //!< Rectangular grid 89 POLYGON //!< Convex polygon 90 }; 91 92 //! The 12 axes 93 /** 94 \image html axes.png 95 */ 96 enum AXIS 97 { 98 X1 = 0, //!< 1st x-axis 99 X2 = 3, //!< 2nd x-axis 100 X3 = 4, //!< 3th x-axis 101 X4 = 5, //!< 4th x-axis 102 Y1 = 1, //!< 1st y-axis 103 Y2 = 8, //!< 2nd y-axis 104 Y3 = 7, //!< 3th y-axis 105 Y4 = 6, //!< 4th y-axis 106 Z1 = 2, //!< 1st z-axis 107 Z2 = 9, //!< 2nd z-axis 108 Z3 = 11, //!< 3th z-axis 109 Z4 = 10 //!< 4th z-axis 110 }; 111 112 //! The 6 sides 113 enum 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 124 //! Possible anchor points for drawing operations 125 enum ANCHOR 126 { 127 BottomLeft, 128 BottomRight, 129 BottomCenter, 130 TopLeft, 131 TopRight, 132 TopCenter, 133 CenterLeft, 134 CenterRight, 135 Center 136 }; 137 138 139 //! Tuple <tt>[x,y]</tt> 140 struct QWT3D_EXPORT Tuple 141 { 142 Tuple() : x(0), y(0) {} //!< Calls Tuple(0,0) 143 Tuple(double X, double Y) : x(X), y(Y) {} //!< Initialize Tuple with x and y 144 //! Tuple coordinates 145 double x,y; 146 }; 147 148 //! Triple <tt>[x,y,z]</tt> 149 /** 150 Consider Triples also as vectors in R^3 151 */ 152 struct QWT3D_EXPORT Triple 153 { 154 //! Initialize Triple with x,y and z 155 explicit Triple(double xv = 0,double yv = 0,double zv = 0) 156 : x(xv), y(yv), z(zv) 157 { 158 } 159 160 #ifndef QWT3D_NOT_FOR_DOXYGEN 161 #ifdef Q_OS_IRIX 162 Triple(const Triple& val) 163 { 164 if (&val == this) 165 return; 166 x = val.x; 167 y = val.y; 168 z = val.z; 169 } 170 const Triple& operator=(const Triple& val) 171 { 172 if (&val == this) 173 return *this; 174 x = val.x; 175 y = val.y; 176 z = val.z; 177 return *this; 178 } 179 #endif 180 #endif // QWT3D_NOT_FOR_DOXYGEN 181 182 //! Triple coordinates 183 double x,y,z; 184 185 Triple& operator+=(Triple t) 186 { 187 x += t.x; 188 y += t.y; 189 z += t.z; 190 191 return *this; 192 } 193 194 Triple& operator-=(Triple t) 195 { 196 x -= t.x; 197 y -= t.y; 198 z -= t.z; 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/=(double d) 211 { 212 x /= d; 213 y /= d; 214 z /= d; 215 216 return *this; 217 } 218 Triple& operator*=(Triple t) // scale 219 { 220 x *= t.x; 221 y *= t.y; 222 z *= t.z; 223 224 return *this; 225 } 226 227 bool operator!=(Triple t) const 228 { 229 return !isPracticallyZero(x,t.x) || !isPracticallyZero(y,t.y) || !isPracticallyZero(z,t.z); 230 } 231 232 bool operator==(Triple t) const 233 { 234 return !operator!=(t); 235 } 236 237 double length() const 238 { 239 double l2 = x*x + y*y + z*z; 240 return (isPracticallyZero(l2)) ? 0 :sqrt(l2); 241 } 242 243 void normalize() 244 { 245 double l = length(); 246 if (l) 247 *this /= l; 248 } 249 250 double operator()(unsigned int comp) 251 { 252 switch (comp) { 253 case 0: 254 return x; 255 case 1: 256 return y; 257 case 2: 258 return z; 259 default: 260 return 0; 261 } 262 } 263 }; 264 265 inline const Triple operator+(const Triple& t, const Triple& t2) 266 { 267 return Triple(t) += t2; 268 } 269 inline const Triple operator-(const Triple& t, const Triple& t2) 270 { 271 return Triple(t) -= t2; 272 } 273 inline const Triple operator*(double d, const Triple& t) 274 { 275 return Triple(t) *= d; 276 } 277 inline const Triple operator*(const Triple& t, double d) 278 { 279 return Triple(t) *= d; 280 } 281 inline const Triple operator/(double d, const Triple& t) 282 { 283 return Triple(t) /= d; 284 } 285 inline const Triple operator/(const Triple& t, double d) 286 { 287 return Triple(t) /= d; 288 } 289 inline const Triple operator*(const Triple& t, const Triple& t2) 290 { 291 return Triple(t) *= t2; 292 } 293 294 //! Parallelepiped spanned by 2 Triples 295 /** 296 Please use \em normalized Parallelepipeds:\n\n 297 minVertex.x <= maxVertex.x\n 298 minVertex.y <= maxVertex.y\n 299 minVertex.z <= maxVertex.z\n 300 */ 301 struct QWT3D_EXPORT ParallelEpiped 302 { 303 //! Construct non-initialized Parallelepiped 304 ParallelEpiped() 305 { 306 } 307 308 //! Construct initialized Parallelepiped 309 /** 310 minv -> minVertex\n 311 maxv -> maxVertex\n 312 */ 313 ParallelEpiped(Triple minv, Triple maxv) 314 : minVertex(minv), maxVertex(maxv) 315 { 316 } 317 318 Triple minVertex; 319 Triple maxVertex; 320 }; 321 322 //! Free vector 323 /** 324 FreeVectors represent objects like normal vectors and other vector fields inside R^3 325 */ 326 struct QWT3D_EXPORT FreeVector 327 { 328 FreeVector() 329 { 330 } 331 332 //! Construct initialized vector 333 /** 334 b -> base\n 335 e -> top\n 336 */ 337 FreeVector(Triple b, Triple t) 338 : base(b), top(t) 339 { 340 } 341 342 Triple base; 343 Triple top; 344 }; 345 346 //! A free vector field in R^3 347 typedef std::vector<FreeVector> FreeVectorField; 348 349 //! A point field in R^3 350 typedef std::vector<Triple> TripleField; 351 //! Holds indices in a TripleField interpreted as counterclockwise node numbering for a convex polygon 352 typedef std::vector<unsigned> Cell; 353 //! Vector of convex polygons. You need a TripleField as base for the node data 354 typedef std::vector<Cell> CellField; 355 //! Returns the sum over the sizes of the single cells 356 unsigned tesselationSize(Qwt3D::CellField const& t); 357 358 //! Red-Green-Blue-Alpha value 359 struct QWT3D_EXPORT RGBA 360 { 361 RGBA() 362 : r(0), g(0), b(0), a(1) 363 {} 364 RGBA(double rr, double gg, double bb, double aa = 1) 365 : r(rr), g(gg), b(bb), a(aa) 366 {} 367 double r,g,b,a; 368 }; 369 370 //! A Color field 371 typedef std::vector<RGBA> ColorVector; 372 373 #ifndef QWT3D_NOT_FOR_DOXYGEN 374 375 QWT3D_EXPORT QColor GL2Qt(GLdouble r, GLdouble g, GLdouble b); //!< RGB -> QColor 376 QWT3D_EXPORT Qwt3D::RGBA Qt2GL(QColor col); //!< QColor -> RGBA 377 378 typedef double *Vertex; 379 typedef std::vector<Vertex> DataRow; 380 typedef std::vector<DataRow> DataMatrix; 381 382 383 class Data 384 { 385 public: 386 Qwt3D::DATATYPE datatype; 387 Data() {datatype= Qwt3D::POLYGON;} 388 virtual ~Data() {} 389 virtual void clear() = 0; //!< destroy content 390 virtual bool empty() const = 0; //!< no data 391 void setHull(Qwt3D::ParallelEpiped const& h) {hull_p = h;} 392 Qwt3D::ParallelEpiped const& hull() const {return hull_p;} 393 394 protected: 395 Qwt3D::ParallelEpiped hull_p; 396 }; 397 398 399 //! Implements a matrix of z-Values with limit access functions 400 class GridData : public Data 401 { 402 public: 403 GridData(); 404 GridData(unsigned int columns, unsigned int rows); //!< see setSize() 405 ~GridData() { clear();} 406 407 int columns() const; 408 int rows() const; 409 410 void clear(); //!< destroy content 411 bool empty() const { return vertices.empty(); } 412 void setSize(unsigned int columns, unsigned int rows); //!< destroys content and set new size, elements are uninitialized 413 414 DataMatrix vertices; //!< mesh vertices 415 DataMatrix normals; //!< mesh normals 416 void setPeriodic(bool u, bool v) { uperiodic_ = u; vperiodic_ = v; } 417 bool uperiodic() const { return uperiodic_; } 418 bool vperiodic() const { return vperiodic_; } 419 420 private: 421 bool uperiodic_, vperiodic_; 422 }; 423 424 425 //! Implements a graph-like cell structure with limit access functions 426 class CellData : public Data 427 { 428 public: 429 CellData() { datatype=Qwt3D::POLYGON; } 430 ~CellData() { clear(); } 431 432 void clear(); //!< destroy content 433 bool empty() const { return cells.empty(); } 434 435 Triple const& operator()(unsigned cellnumber, unsigned vertexnumber); 436 437 CellField cells; //!< polygon/cell mesh 438 TripleField nodes; 439 TripleField normals; //!< mesh normals 440 }; 441 442 inline Triple normalizedcross(Triple const& u, Triple const& v) 443 { 444 Triple n; 445 446 /* compute the cross product (u x v for right-handed [ccw]) */ 447 n.x = u.y * v.z - u.z * v.y; 448 n.y = u.z * v.x - u.x * v.z; 449 n.z = u.x * v.y - u.y * v.x; 450 451 /* normalize */ 452 double l = n.length(); 453 if (l) 454 { 455 n /= l; 456 } 457 else 458 { 459 n = Triple(0,0,0); 460 } 461 462 return n; 463 } 464 465 inline double dotProduct(Triple const& u, Triple const& v) 466 { 467 return u.x*v.x + u.y*v.y + u.z*v.z; 468 } 469 470 void convexhull2d( std::vector<unsigned>& idx, const std::vector<Qwt3D::Tuple>& src ); 471 472 473 #endif // QWT3D_NOT_FOR_DOXYGEN 474 475 } // ns 476 477 #endif 478