Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYPolygon.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
16 /*
17  *
18  */
19 
20 #ifndef __TY_POLYGON__
21 #define __TY_POLYGON__
22 
24 #include "TYRepere.h"
25 #include "TYSurfaceInterface.h"
26 
30 class TYPolygon : public TYElement, public TYSurfaceInterface
31 {
35 
36  // Methodes
37 public:
41  TYPolygon();
45  TYPolygon(const TYPolygon& other);
49  TYPolygon(const TYTabPoint& pts);
50 
54  virtual ~TYPolygon();
55 
57  TYPolygon& operator=(const TYPolygon& other);
59  bool operator==(const TYPolygon& other) const;
61  bool operator!=(const TYPolygon& other) const;
62 
71  virtual bool deepCopy(const TYElement* pOther, bool copyId = true, bool pUseCopyTag = false);
72 
73  virtual std::string toString() const;
74 
75  virtual DOM_Element toXML(DOM_Element& domElement);
76  virtual int fromXML(DOM_Element domElement);
77 
78  virtual double surface() const;
79  virtual OVector3D normal() const;
80  virtual OPlan plan() const;
81  virtual TYTabPoint getContour(int n = -1) const;
82  virtual TYTabPoint3D getOContour(int n = -1) const;
83 
84  // TODO Check and tests those methods for numerical stability
85  virtual int intersects(const TYSurfaceInterface* pSurf, OSegment3D& seg) const;
86  virtual int intersects(const OSegment3D& seg, OPoint3D& pt) const;
87  virtual int intersects(const OSegment3D& seg, OPoint3D& pt, bool insideTest) const;
88 
89  // TODO This method is not numerically stable !
90  virtual int intersects(const OPoint3D& pt) const;
91 
95  void purge()
96  {
97  _pts.clear();
98  _bConvex = false;
99  updateNormal();
100  updateBox();
101  setIsGeometryModified(true);
102  }
103 
107  size_t getNbPts() const
108  {
109  return _pts.size();
110  }
111 
115  void setPoints(const TYTabPoint& pts);
119  bool checkCoplanar() const;
123  const TYTabPoint& getPoints() const
124  {
125  return _pts;
126  }
128  {
129  return _pts;
130  }
134  OPoint3D getPoint(size_t index) const
135  {
136  return _pts[index];
137  }
141  void transform(const OMatrix& matrix);
145  void setConvex(bool bConvex)
146  {
147  _bConvex = bConvex;
148  }
152  bool isConvex() const
153  {
154  return _bConvex;
155  }
159  bool isInBox(const OPoint3D& pt) const
160  {
161  return _box.isInside(pt);
162  }
163 
167  bool isInBox2D(const OPoint3D& pt) const
168  {
169  return _box.isInside2D(pt);
170  }
171 
173  {
174  OPoint3D p1;
175  p1._x = (_box._max._x + _box._min._x) / 2;
176  p1._y = (_box._max._y + _box._min._y) / 2;
177  p1._z = (_box._max._z + _box._min._z) / 2;
178  return p1;
179  }
180 
188  bool isValid() const;
189 
193  ORepere3D getORepere3D() const;
194 
201 
205  virtual const OPlan& getPlan() const
206  {
207  return _plan;
208  }
209  void updateNormal();
210  void updateBox();
211 
212  virtual void inverseNormale();
213 
214  virtual const OBox& getBox() const
215  {
216  return _box;
217  }
227  void exportMesh(std::deque<OPoint3D>& points, std::deque<OTriangle>& triangles,
228  const TYGeometryNode& geonode) const;
229 
230  // Membres
231 private:
233  TYTabPoint _pts; // TODO change this to TYTabPoint3D
234 
236 
238 
239  bool _bConvex;
240 
241  int isInpolyXY(const TYTabPoint& poly, int npoints, double xt, double yt) const;
242  int isInpolyXZ(const TYTabPoint& poly, int npoints, double xt, double yt) const;
243  int isInpolyYZ(const TYTabPoint& poly, int npoints, double xt, double yt) const;
244 };
245 
246 #endif // __TY_POLYGON__
QDomElement DOM_Element
Definition: QT2DOM.h:30
std::vector< TYPoint > TYTabPoint
Collection de TYPoint.
Definition: TYDefines.h:340
std::deque< OPoint3D > TYTabPoint3D
Collection de OPoint3D.
Definition: TYDefines.h:403
#define TY_EXT_GRAPHIC_DECL_ONLY(classname)
Definition: TYElement.h:432
#define OPROTODECL(classname)
Definition: TYElement.h:65
#define TY_EXTENSION_DECL_ONLY(classname)
Definition: TYElement.h:386
The box class.
Definition: 3d.h:1294
virtual bool isInside2D(const OPoint3D &pt) const
Test whether the point is inside the box or not (from upper point of view).
Definition: 3d.cpp:1564
virtual bool isInside(const OPoint3D &pt) const
Test whether the point is inside the box or not.
Definition: 3d.cpp:1535
OPoint3D _min
Minimal coordinates of the OBox.
Definition: 3d.h:1371
OPoint3D _max
Maximal coordinates of the OBox.
Definition: 3d.h:1372
double _y
y coordinate of OCoord3D
Definition: 3d.h:283
double _z
z coordinate of OCoord3D
Definition: 3d.h:284
double _x
x coordinate of OCoord3D
Definition: 3d.h:282
The 4x4 matrix class.
Definition: 3d.h:625
Plan defined by its equation : ax+by+cz+d=0.
Definition: plan.h:31
The 3D point class.
Definition: 3d.h:487
3D frame with a point and 3 vectors.
Definition: 3d.h:1211
Class to define a segment.
Definition: 3d.h:1089
The 3D vector class.
Definition: 3d.h:298
virtual void setIsGeometryModified(bool isModified)
Definition: TYElement.cpp:253
const TYTabPoint & getPoints() const
Definition: TYPolygon.h:123
void setConvex(bool bConvex)
Definition: TYPolygon.h:145
TYRectangle getBoundingRect() const
Definition: TYPolygon.cpp:457
void exportMesh(std::deque< OPoint3D > &points, std::deque< OTriangle > &triangles, const TYGeometryNode &geonode) const
Export the surface as a triangular mesh.
Definition: TYPolygon.cpp:741
size_t getNbPts() const
Definition: TYPolygon.h:107
bool isInBox(const OPoint3D &pt) const
Definition: TYPolygon.h:159
bool _bConvex
Definition: TYPolygon.h:239
virtual void inverseNormale()
Definition: TYPolygon.cpp:727
bool operator!=(const TYPolygon &other) const
Operateur !=.
Definition: TYPolygon.cpp:107
virtual OVector3D normal() const
Definition: TYPolygon.cpp:243
bool checkCoplanar() const
Definition: TYPolygon.cpp:399
ORepere3D getORepere3D() const
Definition: TYPolygon.cpp:433
OPoint3D getPoint(size_t index) const
Definition: TYPolygon.h:134
int isInpolyYZ(const TYTabPoint &poly, int npoints, double xt, double yt) const
Definition: TYPolygon.cpp:677
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
Definition: TYPolygon.cpp:112
void updateNormal()
Definition: TYPolygon.cpp:523
int isInpolyXY(const TYTabPoint &poly, int npoints, double xt, double yt) const
Definition: TYPolygon.cpp:577
virtual int intersects(const TYSurfaceInterface *pSurf, OSegment3D &seg) const
Definition: TYPolygon.cpp:271
void transform(const OMatrix &matrix)
Definition: TYPolygon.cpp:417
virtual TYTabPoint3D getOContour(int n=-1) const
Definition: TYPolygon.cpp:258
virtual const OBox & getBox() const
Definition: TYPolygon.h:214
void updateBox()
Definition: TYPolygon.cpp:550
virtual const OPlan & getPlan() const
Definition: TYPolygon.h:205
virtual ~TYPolygon()
Definition: TYPolygon.cpp:61
bool isConvex() const
Definition: TYPolygon.h:152
OPoint3D getCenter() const
Definition: TYPolygon.h:172
virtual TYTabPoint getContour(int n=-1) const
Definition: TYPolygon.cpp:253
OPlan _plan
Definition: TYPolygon.h:235
virtual std::string toString() const
Definition: TYPolygon.cpp:137
virtual int fromXML(DOM_Element domElement)
Definition: TYPolygon.cpp:159
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYPolygon.cpp:147
TYTabPoint _pts
Sommets.
Definition: TYPolygon.h:233
TYPolygon & operator=(const TYPolygon &other)
Operateur =.
Definition: TYPolygon.cpp:66
void purge()
Definition: TYPolygon.h:95
void setPoints(const TYTabPoint &pts)
Definition: TYPolygon.cpp:389
virtual OPlan plan() const
Definition: TYPolygon.cpp:248
int isInpolyXZ(const TYTabPoint &poly, int npoints, double xt, double yt) const
Definition: TYPolygon.cpp:627
virtual double surface() const
Definition: TYPolygon.cpp:186
bool operator==(const TYPolygon &other) const
Operateur ==.
Definition: TYPolygon.cpp:79
bool isValid() const
Definition: TYPolygon.cpp:427
TYTabPoint & getPoints()
Definition: TYPolygon.h:127
OBox _box
Definition: TYPolygon.h:237
bool isInBox2D(const OPoint3D &pt) const
Definition: TYPolygon.h:167