Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYAcousticPolygon.cpp
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 
17 #if TY_USE_IHM
20 #endif
21 #include "TYAcousticPolygon.h"
22 
25 
27 {
29 
30  _pPolygon = new TYPolygon();
31  _pPolygon->setParent(this);
32 }
33 
35 {
36  *this = other;
37 }
38 
40 
42 {
43  if (this != &other)
44  {
46  _pPolygon = other._pPolygon;
47  }
48  return *this;
49 }
50 
52 {
53  if (this != &other)
54  {
55  if (TYAcousticSurface::operator!=(other))
56  {
57  return false;
58  }
59  if (_pPolygon != other._pPolygon)
60  {
61  return false;
62  }
63  }
64  return true;
65 }
66 
68 {
69  return !operator==(other);
70 }
71 
72 bool TYAcousticPolygon::deepCopy(const TYElement* pOther, bool copyId /*=true*/, bool pUseCopyTag /*=false*/)
73 {
74  if (!TYAcousticSurface::deepCopy(pOther, copyId))
75  {
76  return false;
77  }
78 
79  TYAcousticPolygon* pOtherPoly = (TYAcousticPolygon*)pOther;
80 
81  _pPolygon->deepCopy(pOtherPoly->_pPolygon, copyId);
82 
83  return true;
84 }
85 
86 std::string TYAcousticPolygon::toString() const
87 {
88  return "TYAcousticPolygon";
89 }
90 
92 {
93  DOM_Element domNewElem = TYAcousticSurface::toXML(domElement);
94 
95  _pPolygon->toXML(domNewElem);
96 
97  return domNewElem;
98 }
99 
101 {
102  TYAcousticSurface::fromXML(domElement);
103 
104  DOM_Element elemCur;
105 
106  QDomNodeList childs = domElement.childNodes();
107  for (unsigned int i = 0; i < childs.length(); i++)
108  {
109  elemCur = childs.item(i).toElement();
110 
111  _pPolygon->callFromXMLIfEqual(elemCur);
112  }
113 
114  return 1;
115 }
116 
118 {
120 }
121 
123 {
124  return TYSourcePonctuelle();
125 }
126 
128 {
129  // Suppression des sources existantes
130  _pSrcSurf->purge();
131 
132  if ((_isRayonnant == false) || (_pSrcSurf->getDensiteSrcsH() == 0) || (_pSrcSurf->getDensiteSrcsV() == 0))
133  {
134  // Pas de calcul
135  return;
136  }
137 
138  // Tableau de points
139  size_t nbPts = _pPolygon->getNbPts();
140 
141  if (nbPts <= 0)
142  {
143  return;
144  }
145 
146  OPoint3D* pts = new OPoint3D[nbPts];
147  for (size_t i = 0; i < nbPts; i++)
148  {
149  pts[i] = _pPolygon->getPoint(i);
150  }
151 
152  // Calcul de l'offset pour la position des sources (utilisation du lancer de rayon)
153  OVector3D normale = _pPolygon->normal();
154  double offsetZ = _offsetSources * normale._z;
155 
156  // Rectangle de travail pour la distribution des sources
157  TYRectangle BoundingRect = _pPolygon->getBoundingRect();
158 
159  // On cherche les vecteurs des cotes H et V du rectangle
160  OVector3D vecH(BoundingRect._pts[0], BoundingRect._pts[1]);
161  OVector3D vecV(BoundingRect._pts[0], BoundingRect._pts[3]);
162 
163  // On calcul le nb de source en H et V
164  int nbSrcsH = (int)(vecH.norme() / _pSrcSurf->getDensiteSrcsH());
165  int nbSrcsV = (int)(vecV.norme() / _pSrcSurf->getDensiteSrcsV());
166 
167  // On essaye de se rapprocher au mieux de la densite totale (H*V)
168  // (On veut au moins 1 source)
169  if ((nbSrcsH * nbSrcsV) != (surface() * _pSrcSurf->getDensiteSrcs()))
170  {
171  nbSrcsV ? nbSrcsV : nbSrcsV++;
172  nbSrcsH ? nbSrcsH : nbSrcsH++;
173  }
174 
175  // nombre d'iterations (nbSrcsH * nbSrcsV);
176 
177  // Calcul des vecteurs pas en H et V (ecart entre chaque src)
178  vecH = vecH * (1.0 / (double)nbSrcsH);
179  vecV = vecV * (1.0 / (double)nbSrcsV);
180 
181  // Calcul du pt de depart pour le placement des srcs
182  OVector3D startPt = OVector3D(BoundingRect._pts[0]) + (vecH * 0.5) + (vecV * 0.5);
183 
184  OPoint3D ptMin, ptMax;
185 
186  OGeometrie::boundingBox(pts, static_cast<int>(nbPts), ptMin, ptMax);
187 
188  OBox box(ptMin, ptMax);
189 
190  // To define directivity
191  // As the bounding rectangle is not calculated correctly (but bounding box is), we need to do it
192  const OBox box2 = _pPolygon->getBox();
193  OPoint3D pt0(box._min._x, box._max._y, box._max._z);
194  OPoint3D pt1(box._max._x, box._max._y, box._max._z);
195  OPoint3D pt2(box._max._x, box._min._y, box._max._z);
196  OPoint3D pt3(box._min._x, box._min._y, box._max._z);
197  TYRectangle rect(pt0, pt1, pt2, pt3);
198  double specificSize = rect.getDiagSize();
199  OVector3D faceNormal = normal();
200  faceNormal.normalize();
202 
203  // Scan V
204  for (int iV = 0; (iV < nbSrcsV); iV++)
205  {
206  // Scan H
207  for (int iH = 0; (iH < nbSrcsH); iH++)
208  {
209 
210  // Positionnement, on "parcours" la surface par des multiples
211  // des vecteurs pas
212  OPoint3D pos(startPt + (vecH * iH) + (vecV * iV));
213 
214  // Il faut ensuite tester si le point trouve
215  // est inclu dans le polygone
216  if (OGeometrie::pointInPolygonAngleSum(pos, pts, static_cast<int>(nbPts)))
217  {
218  // Creation d'une source ponctuelle
220  pSrc->setDirectivity(new TYComputedDirectivity(faceNormal, type, specificSize));
221 
222  // Definition de sa position
223  pos._z += offsetZ; // on decale les sources pour le lancer de rayon selon l'orientation de la
224  // normale
225  pSrc->setPos(new TYPoint(pos));
226 
227  // Attribution du parent
228  pSrc->setParent(this);
229 
230  // Definition des sources comme sources a directivite calculee
231  pSrc->setTypeRaynt(CALCULATED);
232 
233  // Ajout de la src ponct a la src surf
234  _pSrcSurf->addSrc(pSrc);
235  }
236  }
237  }
238 
239  delete[] pts;
240 }
241 
243 {
244  return TYAcousticSurface::setSrcsLw(); // Appel de la methode generale
245 }
246 
248 {
249  return _pPolygon->surface();
250 }
251 
253 {
254  return _pPolygon->normal();
255 }
256 
258 {
259  return _pPolygon->plan();
260 }
261 
263 {
264  return _pPolygon->getContour(n);
265 }
266 
268 {
269  return _pPolygon->getOContour(n);
270 }
271 
273 {
274  return _pPolygon->intersects(pSurf, seg);
275 }
276 
278 {
279  return _pPolygon->intersects(seg, pt);
280 }
281 
283 {
284  return _pPolygon->intersects(pt);
285 }
All base classes related to 3D manipulation.
QDomElement DOM_Element
Definition: QT2DOM.h:30
Representation graphique d'un polygone accoustique (fichier header)
objet IHM pour un polygone acoustique (fichier header)
TY_EXTENSION_INST(TYAcousticPolygon)
TY_EXT_GRAPHIC_INST(TYAcousticPolygon)
std::vector< TYPoint > TYTabPoint
Collection de TYPoint.
Definition: TYDefines.h:340
std::deque< OPoint3D > TYTabPoint3D
Collection de OPoint3D.
Definition: TYDefines.h:403
std::vector< LPTYSourcePonctuelleGeoNode > TYTabSourcePonctuelleGeoNode
Collection de noeuds geometriques de type TYSourcePonctuelle.
@ CALCULATED
The box class.
Definition: 3d.h:1294
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
static void boundingBox(OPoint3D *pts, int nbPts, OPoint3D &ptMin, OPoint3D &ptMax)
Computes the simple bounding box for a volume using min-max method.
Definition: 3d.cpp:1109
static bool pointInPolygonAngleSum(const OPoint3D &ptP, const OPoint3D *pts, int nbPts)
Tests if a point is inside a polygon using angle sum algorithm.
Definition: 3d.cpp:1016
Plan defined by its equation : ax+by+cz+d=0.
Definition: plan.h:31
The 3D point class.
Definition: 3d.h:487
virtual const char * getClassName() const
Definition: TYElement.h:249
Class to define a segment.
Definition: 3d.h:1089
The 3D vector class.
Definition: 3d.h:298
double norme() const
Computes the length of this vector.
Definition: 3d.cpp:215
void normalize()
Normalizes this vector.
Definition: 3d.cpp:225
double _offsetSources
Offset de decalage des sources ponctuelles sur les surfaces.
bool _isRayonnant
Etat courant de l'element (rayonnant ou non rayonnant)
bool operator!=(const TYAcousticPolygon &other) const
Operateur !=.
virtual TYTabSourcePonctuelleGeoNode getSrcs() const
virtual bool setSrcsLw()
TYAcousticPolygon & operator=(const TYAcousticPolygon &other)
Operateur =.
virtual int intersects(const TYSurfaceInterface *pSurf, OSegment3D &seg) const
LPTYPolygon _pPolygon
Le polygone definissant la geometrie de cet acoustic polygon.
virtual void distriSrcs()
bool operator==(const TYAcousticPolygon &other) const
Operateur ==.
virtual TYTabPoint getContour(int n=-1) const
virtual OPlan plan() const
virtual std::string toString() const
virtual int fromXML(DOM_Element domElement)
virtual TYTabPoint3D getOContour(int n=-1) const
virtual double surface() const
virtual DOM_Element toXML(DOM_Element &domElement)
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
virtual TYSourcePonctuelle srcPonctEquiv() const
virtual OVector3D normal() const
TYAcousticSurface & operator=(const TYAcousticSurface &other)
Operateur =.
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
virtual TYTabSourcePonctuelleGeoNode getSrcs() const
virtual bool setSrcsLw()
virtual DOM_Element toXML(DOM_Element &domElement)
LPTYSourceSurfacic _pSrcSurf
Source surfacique.
virtual int fromXML(DOM_Element domElement)
QString _name
Nom courant de l'element.
Definition: TYElement.h:966
bool callFromXMLIfEqual(DOM_Element &domElement, int *pRetVal=NULL)
Definition: TYElement.cpp:544
void setParent(TYElement *pParent)
Definition: TYElement.h:692
QString generateName(const char *classname)
Retourne le nom de la classe associe a un nombre.
static TYNameManager * get()
Retourne l'instance singleton.
TYRectangle getBoundingRect() const
Definition: TYPolygon.cpp:457
size_t getNbPts() const
Definition: TYPolygon.h:107
virtual OVector3D normal() const
Definition: TYPolygon.cpp:243
OPoint3D getPoint(size_t index) const
Definition: TYPolygon.h:134
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
Definition: TYPolygon.cpp:112
virtual int intersects(const TYSurfaceInterface *pSurf, OSegment3D &seg) const
Definition: TYPolygon.cpp:271
virtual TYTabPoint3D getOContour(int n=-1) const
Definition: TYPolygon.cpp:258
virtual const OBox & getBox() const
Definition: TYPolygon.h:214
virtual TYTabPoint getContour(int n=-1) const
Definition: TYPolygon.cpp:253
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYPolygon.cpp:147
virtual OPlan plan() const
Definition: TYPolygon.cpp:248
virtual double surface() const
Definition: TYPolygon.cpp:186
double getDiagSize()
TYPoint _pts[4]
Sommets.
Definition: TYRectangle.h:274
void setDirectivity(TYDirectivity *directivity_)
: Get/Set directivity to source
void setPos(const LPTYPoint pPos)
void setTypeRaynt(TYTypeRaynt type)
double getDensiteSrcsH() const
double getDensiteSrcs() const
bool addSrc(LPTYSourcePonctuelle pSrcPonct)
double getDensiteSrcsV() const