Code_TYMPAN  4.2.0
Industrial site acoustic simulation
3d.h
Go to the documentation of this file.
1 /* WARNING: I am an auto-generated header file, don't modify me !! */
2 /* Modify Tympan/models/common/3d.h instead */
3 /*
4  * Copyright (C) <2012-2014> <EDF-R&D> <FRANCE>
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  * See the GNU General Public License for more details.
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17 
18 #ifndef TY_MC_3D
19 #define TY_MC_3D
20 
26 #include <cmath>
27 #include <math.h>
28 #include <vector>
29 #include <ostream>
30 
31 // Defines for intersection calculations.
33 #define INTERS_CONFONDU 2
34 #define INTERS_OUI 1
36 #define INTERS_NULLE 0
38 
39 #define EPSILON_3 0.001 // 10e-3
40 #define EPSILON_5 0.00001 // 10e-5
41 #define EPSILON_6 0.000001 // 10e-6
42 #define EPSILON_7 0.0000001 // 10e-7
43 #define EPSILON_13 0.0000000000001 // 10e-13
44 #define EPSILON_50 1.e-50
45 
46 /* From this threshold (in meters), two elements are considered as at the same
47  * position
48  * */
49 #define TYSEUILCONFONDUS EPSILON_3 // 1 mm
50 
51 #ifndef M_PI
52 #define M_PI 3.1415926535897932384626433832795
54 #endif
55 
57 #define M_2PI 6.283185307179586476925287766559
58 
59 
61 // Macros
63 
70 inline double ABS(double a)
71 {
72  return (a >= 0.0 ? a : -a);
73 }
74 
81 inline double SIGNE(double a)
82 {
83  return (a >= 0.0 ? 1 : -1);
84 }
85 
93 inline double MAX(double a, double b)
94 {
95  return (a > b ? a : b);
96 }
97 
106 inline double MAX3(double a, double b, double c)
107 {
108  return MAX(MAX(a, b), c);
109 }
110 
118 inline double MIN(double a, double b)
119 {
120  return (a < b ? a : b);
121 }
122 
129 inline double DEGTORAD(double a)
130 {
131  return (a / 180.0 * M_PI);
132 }
133 
140 inline double RADTODEG(double a)
141 {
142  return (a / M_PI * 180.0);
143 }
144 
151 inline double GRATORAD(double a)
152 {
153  return (a / 200.0 * M_PI);
154 }
155 
162 inline double RADTOGRA(double a)
163 {
164  return (a / M_PI * 200.0);
165 }
166 
173 inline double GRATODEG(double a)
174 {
175  return (a / 200.0 * 180.0);
176 }
177 
184 inline double DEGTOGRA(double a)
185 {
186  return (a / 180.0 * 200.0);
187 }
188 
195 inline int ROUND(double a)
196 {
197  return (a >= 0.0 ? (int)(a + 0.5) : (int)(a - 0.5));
198 }
199 
208 inline double BORNE(double a, double b, double c)
209 {
210  return (a < b ? b : (a > c ? c : a));
211 }
212 
219 inline int BORNE(int a)
220 {
221  return (int) BORNE((double) a, 0, 255);
222 }
223 
224 
229 class OCoord3D
230 {
231 public:
233  OCoord3D();
235  OCoord3D(const OCoord3D& coord);
237  OCoord3D(double x, double y, double z);
239  virtual ~OCoord3D();
240 
241  OCoord3D& operator=(const OCoord3D& coord);
242  bool operator==(const OCoord3D& coord) const;
243  bool operator!=(const OCoord3D& coord) const;
244 
249  void setCoords(double x, double y, double z);
254  void setCoords(double coords[3]);
259  void getCoords(double coords[3]);
264  double* getCoords();
265 
269  operator const double* () const { return &_value[0]; }
273  operator double* () { return &_value[0]; }
274 
275 public:
276  union
277  {
278  struct
279  {
280  double _x;
281  double _y;
282  double _z;
283  };
284  double _value[3];
285  };
286 };
287 
288 ::std::ostream& operator<<(::std::ostream& os, const OCoord3D& c);
289 
290 
296 class OVector3D: public OCoord3D
297 {
298 public:
300  OVector3D();
302  OVector3D(const OVector3D& vector);
308  OVector3D(const OCoord3D& coord);
316  OVector3D(const OCoord3D& coordFrom, const OCoord3D& coordTo);
325  OVector3D(double x, double y, double z);
327  virtual ~OVector3D();
328 
333  void reset();
335  OVector3D& operator=(const OVector3D& vector);
336  bool operator==(const OVector3D& vector) const;
337  bool operator!=(const OVector3D& vector) const;
338  OVector3D operator+(const OVector3D& vector) const;
339  OVector3D operator-(const OVector3D& vector) const;
340  // XXX meaningless component wise multiplication whereas a dot product would have been expected.
341  OVector3D operator*(const OVector3D& vector) const;
348  OVector3D operator*(const double a) const;
356  friend OVector3D operator*(const double a, const OVector3D& vector);
357 
361  double dot(const OVector3D& v)
362  { return _x * v._x + _y * v._y + _z * v._z; }
363 
372  OVector3D cross(const OVector3D& vector) const;
373 
382  void balance(double c1, const OVector3D& vector2, double c2);
383 
392  double scalar(const OVector3D& vector) const;
393 
400  double norme() const;
401 
408  OVector3D normal(const OVector3D& vector2, const OVector3D& vector3) const;
409 
414  void normalize();
415 
420  void invert();
421 
428  double angle(const OVector3D& vector) const;
429 
436  OVector3D getRotationOz(double alpha);
437 
444  OVector3D getRotationOzBase2(double alpha);
445 
450  OVector3D getRotationOy(double alpha);
451 
458  OVector3D getRotationOyBase2(double alpha);
459 
466  OVector3D getRotationOzOy(double alpha, double theta);
467 };
469 inline OCoord3D operator + (const OCoord3D& coord, const OVector3D& vect)
470 {
471  return OCoord3D(coord._x + vect._x, coord._y + vect._y, coord._z + vect._z);
472 }
473 
474 ::std::ostream& operator<<(::std::ostream& os, const OVector3D& v);
475 
476 
481 class OPoint3D;
482 typedef std::vector<OPoint3D> TabPoint3D;
483 
484 class OPoint3D: public OCoord3D
485 {
486  // Methods
487 public:
491  OPoint3D();
492 
498  OPoint3D(const OPoint3D& pt);
499 
505  OPoint3D(const OCoord3D& coord);
506 
515  OPoint3D(double x, double y, double z);
516 
523  OPoint3D(double v[]);
524 
528  virtual ~OPoint3D();
529 
537  virtual void set(double x, double y, double z);
538 
546  virtual void setFromOGL(double x, double y, double z);
547  virtual void setFromOGL(float x, float y, float z);
553  virtual void setFromOGL(float coords[3]);
559  virtual void setFromOGL(double coords[3])
560  {
561  setFromOGL(coords[0], coords[1], coords[2]);
562  }
570  virtual void getToOGL(double& x, double& y, double& z);
576  virtual void getToOGL(double coords[3]);
577 
584  double distFrom(const OPoint3D& pt) const;
585 
590  double dist2DFrom(const OPoint3D& pt) const;
591 
593  bool isEqual(const OPoint3D& oPoint) const
594  {
595  return *this == oPoint;
596  }
597 
607  static TabPoint3D checkPointsMaxDistance(const TabPoint3D& points,
608  const double& distanceMax);
609 
613  static TabPoint3D checkPointsMaxDistance(const OPoint3D& point1,
614  const OPoint3D& point2, const double& distanceMax);
615 
616 };
617 
618 ::std::ostream& operator<<(::std::ostream& os, const OPoint3D& v);
619 
620 
625 class OMatrix
626 {
627 public:
629  OMatrix();
631  OMatrix(const OMatrix& matrix);
632  OMatrix(double matrix[4][4]);
634  virtual ~OMatrix();
636  OMatrix& operator=(const OMatrix& matrix);
637  bool operator==(const OMatrix& matrix) const;
638  bool operator!=(const OMatrix& matrix) const;
639  OMatrix operator+(const OMatrix& matrix) const;
640  OMatrix operator-(const OMatrix& matrix) const;
641  OMatrix operator*(const OMatrix& matrix) const;
642 
649  OVector3D multNormal(const OVector3D& normal) const;
650 
655  void show();
656 
666  void reset();
667 
677  void unite();
678 
690  int setTranslation(double x, double y, double z);
691 
703  int setScale(double x, double y, double z);
704 
714  int setRotationOx(double a);
715 
725  int setRotationOy(double a);
726 
736  int setRotationOz(double a);
737 
779  int aligneVecteurSurOx(const OVector3D& vector);
780 
822  int aligneVecteurSurOy(const OVector3D& vector);
823 
840  int invert();
841 
850  OMatrix getInvert(int* ok = 0) const;
851 
876  void adjoint();
877 
884  OMatrix getAdjoint();
885 
893  double determinant();
894 
899  static double mat2x2Det(double a, double b, double c, double d);
900 
905  static double mat3x3Det(double a1, double a2, double a3, double b1, double b2, double b3, double c1, double c2, double c3);
906 
913  OCoord3D dot(const OCoord3D& coord) const;
914 
917  OCoord3D scale(const OCoord3D& coord) const;
918 
919 
920  // Members
921 public:
923  double _m[4][4];
924 };
925 
926 OVector3D operator*(const OMatrix& mat, const OVector3D& vec);
927 OPoint3D operator*(const OMatrix& mat, const OPoint3D& pt);
928 
929 
935 {
936 public:
948  static bool intersDemiSegmentAvecSegment(const OPoint3D& ptS, const OPoint3D& ptA, const OPoint3D& ptB);
949 
963  static int intersDroitesPoints(const OPoint3D& ptA, const OPoint3D& ptB, const OPoint3D& ptC, const OPoint3D& ptD, OPoint3D& ptI);
964 
978  static int intersDroitesPointVecteur(const OPoint3D& ptA, const OVector3D& vecA, const OPoint3D& ptB, const OVector3D& vecB, OPoint3D& ptI);
979 
992  static double symPointDroite(const OPoint3D& ptA, const OPoint3D& ptB, const OPoint3D& ptP, OPoint3D& ptI);
993 
1018  static bool pointInPolygonAngleSum(const OPoint3D& ptP, const OPoint3D* pts, int nbPts);
1019 
1031  static bool pointInPolygonRayCasting(const OPoint3D& ptP, const OPoint3D* pts, int nbPts);
1032 
1057  static bool shortestSegBetween2Lines(const OPoint3D& pt1, const OPoint3D& pt2, const OPoint3D& pt3, const OPoint3D& pt4,
1058  OPoint3D& ptA, OPoint3D& ptB, double* mua, double* mub);
1059 
1069  static void boundingBox(OPoint3D* pts, int nbPts, OPoint3D& ptMin, OPoint3D& ptMax);
1070 
1079  static void computeNormal(OPoint3D* pts, int nbPts, OVector3D& normal);
1080 };
1081 
1082 
1088 {
1089 public:
1091  OSegment3D();
1093  OSegment3D(const OSegment3D& other);
1094  OSegment3D(const OPoint3D& ptA, const OPoint3D& ptB);
1096  virtual ~OSegment3D();
1097 
1098  virtual OSegment3D& operator=(const OSegment3D& other);
1099  virtual bool operator==(const OSegment3D& other) const;
1100  virtual bool operator!=(const OSegment3D& other) const;
1101 
1110  virtual OSegment3D operator*(const OMatrix& matrix) const;
1111 
1116  virtual double longueur() const;
1117 
1127  virtual int symetrieOf(const OPoint3D& pt, OPoint3D& ptSym) const;
1128 
1140  virtual int projection(const OPoint3D& pt, OPoint3D& ptProj, double seuilConfondus) const;
1141 
1155  virtual int intersects(const OSegment3D& seg, OPoint3D& pt, double seuilConfondus) const;
1156 
1163  virtual OPoint3D centreOf() const;
1164 
1171  virtual OPoint3D centerOfCurvedPath(const double& R) const;
1172 
1179  virtual double lengthOfCurvedPath(const double& R);
1180 
1187  virtual OVector3D toVector3D() const { return OVector3D(_ptA, _ptB); }
1188 
1193  virtual OSegment3D swap() const;
1194 
1195 public:
1200 };
1201 
1202 
1208 {
1209 public:
1211  ORepere3D();
1213  ORepere3D(const ORepere3D& repere);
1222  ORepere3D(const OPoint3D& origin, const OVector3D& vecI, const OVector3D& vecJ, const OVector3D& vecK);
1227  ORepere3D(const OPoint3D& origin, const OVector3D& vec);
1233  ORepere3D(const OMatrix& matrix);
1235  virtual ~ORepere3D();
1236 
1237  ORepere3D& operator=(const ORepere3D& repere);
1238  bool operator==(const ORepere3D& repere) const;
1239  bool operator!=(const ORepere3D& repere) const;
1240 
1250  void set(const OPoint3D& origin, const OVector3D& vecI, const OVector3D& vecJ, const OVector3D& vecK);
1251 
1258  void set(const OMatrix& matrix);
1259 
1264  void normalize();
1265 
1272  OMatrix asMatrix() const;
1273 
1274 public:
1283 
1284 };
1285 
1286 
1292 class OBox
1293 {
1294 public:
1296  OBox();
1298  OBox(const OBox& box);
1299  OBox(const OCoord3D& min, const OCoord3D& max);
1300  OBox(double x1, double y1, double z1, double x2, double y2, double z2);
1302  virtual ~OBox() {}
1303 
1304  virtual OBox& operator=(const OBox& box);
1305  virtual bool operator==(const OBox& box) const;
1306  virtual bool operator!=(const OBox& box) const { return !operator==(box);}
1307 
1314  virtual bool isInside(const OPoint3D& pt) const;
1315 
1322  virtual bool isInside2D(const OPoint3D& pt) const;
1323 
1330  virtual bool isInContact(const OBox& box) const;
1331 
1338  virtual void Enlarge(const OPoint3D& pt);
1339 
1348  virtual void Enlarge(float x, float y, float z);
1349 
1356  virtual void Enlarge(const OBox& box);
1357 
1364  virtual void Translate(const OPoint3D& vectorTranslate);
1365 
1366 public:
1369 };
1370 
1371 
1376 class OBox2 : public OBox
1377 {
1378  // Methods
1379 public:
1381  OBox2();
1383  OBox2(const OBox2& box);
1389  OBox2(const OBox& box);
1394  OBox2(const double& length, const double& width, const double& height);
1395 
1396 private : // Set private for security seems to an "af hoc" adaptation and is used only by an internal member function
1404  OBox2(const OBox2& box, const ORepere3D& repere, const OPoint3D& centre);
1405 
1406 public :
1408  virtual ~OBox2() {}
1409 
1410  virtual OBox2& operator=(const OBox2& box);
1411  virtual bool operator==(const OBox2& box) const;
1412  virtual bool operator!=(const OBox2& box) const { return !operator==(box);}
1413 
1423  OPoint3D BoxCoord(int N) const;
1429  virtual bool isInside(const OPoint3D& pt) const;
1435  virtual bool isInside2D(const OPoint3D& pt) const;
1440  virtual void Translate(const OVector3D& vect);
1444  OBox2 boxRotation(const OPoint3D& O, const OPoint3D& P2);
1451  void BoxRotationOzOy(double alpha, double theta);
1456  void moveAndRotate(const OPoint3D& origin, const OVector3D& vec);
1457 
1458 private:
1463  OBox2 rotInXOYOnly(const OVector3D& v1, const OVector3D& v2, const OPoint3D& O, const OPoint3D& P2);
1468  OBox2 rotInXOZOnly(const OVector3D& v1, const OVector3D& v2, const OPoint3D& O, const OPoint3D& P2);
1473  OBox2 rot3D(const OVector3D& v1, const OVector3D& v2, const OPoint3D& O, const OPoint3D& P2);
1474 
1475 public:
1486  double _length;
1487  double _height;
1488  double _width;
1489 };
1490 
1491 
1508 {
1509 public:
1511  OHPlane3D();
1513  OHPlane3D(const OHPlane3D& Plane);
1520  OHPlane3D(const OVector3D& normal, const OPoint3D& origin);
1522  virtual ~OHPlane3D();
1523 
1530  void set(const OVector3D& normal, const OPoint3D& origin);
1531 
1532  OHPlane3D& operator=(const OHPlane3D& Plane);
1533  bool operator==(const OHPlane3D& Plane) const;
1534  bool operator!=(const OHPlane3D& Plane) const;
1535 
1554  int intersects(const OPoint3D& pt1, const OPoint3D& pt2, OPoint3D& ptIntersec, double& t) const;
1571  int intersects(const OSegment3D& seg, OPoint3D& ptIntersec) const;
1572 
1573 private:
1576  double _p;
1577 };
1578 
1579 
1580 #endif // TY_MC_3D
OPoint3D _B
Definition: 3d.h:1479
3D frame with a point and 3 vectors.
Definition: 3d.h:1207
The 3D vector class.
Definition: 3d.h:296
The 3D Plane class using Hessian normal form.
Definition: 3d.h:1507
double BORNE(double a, double b, double c)
Limit a number.
Definition: 3d.h:208
OVector3D _vecK
Vector K for the Z axis.
Definition: 3d.h:1282
OPoint3D _center
Definition: 3d.h:1477
OPoint3D _max
Maximal coordinates of the OBox.
Definition: 3d.h:1368
double ABS(double a)
Return the absolute value.
Definition: 3d.h:70
double MIN(double a, double b)
Return the smallest number of two ones.
Definition: 3d.h:118
Class to define a box (not necessary parallel to the axis as OBox)
Definition: 3d.h:1376
double _length
Definition: 3d.h:1486
virtual bool operator!=(const OBox2 &box) const
Definition: 3d.h:1412
OVector3D operator*(const OMatrix &mat, const OVector3D &vec)
Definition: 3d.cpp:604
OPoint3D _ptB
Point B of the segment.
Definition: 3d.h:1199
double RADTOGRA(double a)
Converts an angle from radians to gradians.
Definition: 3d.h:162
OPoint3D _ptA
Point A of the segment.
Definition: 3d.h:1197
double MAX3(double a, double b, double c)
Return the biggest number of three ones.
Definition: 3d.h:106
double MAX(double a, double b)
Return the biggest number of two ones.
Definition: 3d.h:93
#define M_PI
Pi.
Definition: 3d.h:53
bool operator==(const OCoord3D &coord) const
operator==
Definition: 3d.cpp:67
OCoord3D()
Default constructor.
Definition: 3d.cpp:33
std::vector< OPoint3D > TabPoint3D
Definition: 3d.h:481
ORepere3D _repere
Definition: 3d.h:1476
OCoord3D operator+(const OCoord3D &coord, const OVector3D &vect)
Return a OCoord3D from an operator+ between a OCoord3D and a OVector3D.
Definition: 3d.h:469
CGAL_Vector3 normalize(CGAL_Vector3 v)
normalize vector v
Definition: cgal_tools.cpp:26
double GRATORAD(double a)
Converts an angle from gradians to radians.
Definition: 3d.h:151
double * getCoords()
Gets the coordinates as an array of double.
Definition: 3d.cpp:104
bool operator!=(const OCoord3D &coord) const
operator!=
Definition: 3d.cpp:78
virtual ~OBox()
Destructor.
Definition: 3d.h:1302
virtual ~OCoord3D()
Destructor.
Definition: 3d.cpp:52
NxReal c
Definition: NxVec3.cpp:345
virtual void setFromOGL(double coords[3])
Definition: 3d.h:559
::std::ostream & operator<<(::std::ostream &os, const OCoord3D &c)
Definition: 3d.cpp:113
void setCoords(double x, double y, double z)
Sets the coordinates as an array of double.
Definition: 3d.cpp:83
double _height
Definition: 3d.h:1487
The box class.
Definition: 3d.h:1292
OPoint3D _E
Definition: 3d.h:1482
OVector3D _vecJ
Vector J for the Y axis.
Definition: 3d.h:1280
double _p
Definition: 3d.h:1576
double _y
y coordinate of OCoord3D
Definition: 3d.h:281
double _x
x coordinate of OCoord3D
Definition: 3d.h:280
double DEGTORAD(double a)
Converts an angle from degrees to radians.
Definition: 3d.h:129
OPoint3D _min
Minimal coordinates of the OBox.
Definition: 3d.h:1367
int ROUND(double a)
Compute the rounded value of a number.
Definition: 3d.h:195
OPoint3D _H
Definition: 3d.h:1485
OPoint3D _G
Definition: 3d.h:1484
virtual ~OBox2()
Destructor.
Definition: 3d.h:1408
Class to define a segment.
Definition: 3d.h:1087
The 4x4 matrix class.
Definition: 3d.h:625
OPoint3D _A
Definition: 3d.h:1478
double RADTODEG(double a)
Converts an angle from radians to degrees.
Definition: 3d.h:140
double _value[3]
Definition: 3d.h:284
OPoint3D _F
Definition: 3d.h:1483
OPoint3D _O
Definition: 3d.h:1575
double _width
Definition: 3d.h:1488
OPoint3D _C
Definition: 3d.h:1480
virtual OVector3D toVector3D() const
Build a OVector3D from a segment used for the direction of the sources.
Definition: 3d.h:1187
The 3D point class.
Definition: 3d.h:484
OPoint3D _D
Definition: 3d.h:1481
OCoord3D & operator=(const OCoord3D &coord)
operator=
Definition: 3d.cpp:56
double _z
z coordinate of OCoord3D
Definition: 3d.h:282
virtual bool operator!=(const OBox &box) const
Definition: 3d.h:1306
OPoint3D _origin
The origin point.
Definition: 3d.h:1276
double GRATODEG(double a)
Converts an angle from gradians to degrees.
Definition: 3d.h:173
OVector3D _vecI
Vector I for the X axis.
Definition: 3d.h:1278
The 3D coordinate class.
Definition: 3d.h:229
OVector3D _N
Definition: 3d.h:1574
Class Geometry utilities.
Definition: 3d.h:934
bool isEqual(const OPoint3D &oPoint) const
Compatibility alias for operator==.
Definition: 3d.h:593
double DEGTOGRA(double a)
Converts an angle from degrees to gradians.
Definition: 3d.h:184
double dot(const OVector3D &v)
dot product (assuming an orthonormal reference frame)
Definition: 3d.h:361
double SIGNE(double a)
Return the number sign.
Definition: 3d.h:81