Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYVolumeInterface.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 #include "TYVolumeInterface.h"
18 
20 {
21  TYBox res;
22  OPoint3D ptMin, ptMax;
23 
24  TYTabPoint tabPts = sommets();
25  size_t nbPts = tabPts.size();
26 
27  if (nbPts <= 0)
28  {
29  return res;
30  }
31 
32  OPoint3D* pts = new OPoint3D[nbPts];
33  for (size_t i = 0; i < tabPts.size(); i++)
34  {
35  pts[i] = tabPts[i];
36  }
37 
38  OGeometrie::boundingBox(pts, static_cast<int>(nbPts), ptMin, ptMax);
39 
40  delete[] pts;
41 
42  res._sizeX = ptMax._x - ptMin._x;
43  res._sizeY = ptMax._y - ptMin._y;
44  res._sizeZ = ptMax._z - ptMin._z;
45 
46  res.setPosition(OVector3D(ptMin) + (OVector3D(ptMin, ptMax) * 0.5));
47 
48  return res;
49 }
50 
52 {
53  _rayonSphere = 1.0 / 2.0 *
56 }
57 
58 int TYVolumeInterface::intersects(const OSegment3D& seg, TYTabPoint& ptList) const
59 {
60  int res = INTERS_NULLE;
61  OPoint3D pt;
62  int nbIntersects = 0;
63 
64  // Pour eviter des calculs inutiles...
65  TYTabPoint pointTest;
66  if (volEnglob().intersects(seg, pointTest) == INTERS_NULLE)
67  {
68  return res;
69  }
70 
71  // Recherche de l'intersection du segment avec chacune des faces
72  // composant ce volume
73  TYTabLPPolygon tabFaces = faces();
74 
75  for (unsigned int i = 0; i < tabFaces.size(); i++)
76  {
77  LPTYPolygon pFace = tabFaces[i];
78  assert(pFace);
79 
80  if (pFace->intersects(seg, pt) != INTERS_NULLE)
81  {
82  // Ajout du pt d'intersection trouve a la liste
83  ptList.push_back(pt);
84 
85  // Increment du nb d'intersections trouvees
86  nbIntersects++;
87  }
88  }
89 
90  // Une intersection a-t-elle ete trouvee ?
91  if (nbIntersects > 0)
92  {
93  res = INTERS_OUI;
94  }
95 
96  return res;
97 }
#define INTERS_OUI
The intersection exists.
Definition: 3d.h:33
#define INTERS_NULLE
No intersection.
Definition: 3d.h:35
std::vector< TYPoint > TYTabPoint
Collection de TYPoint.
Definition: TYDefines.h:340
std::vector< LPTYPolygon > TYTabLPPolygon
Collection de pointeurs de TYPolygon.
Definition: TYDefines.h:349
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
The 3D point class.
Definition: 3d.h:487
Class to define a segment.
Definition: 3d.h:1089
The 3D vector class.
Definition: 3d.h:298
Definition: TYBox.h:34
void setPosition(const TYPoint &position)
Definition: TYBox.h:106
double _sizeX
Dimension en X.
Definition: TYBox.h:128
double _sizeZ
Dimension en Z.
Definition: TYBox.h:132
double _sizeY
Dimension en Y.
Definition: TYBox.h:130
virtual int intersects(const TYSurfaceInterface *pSurf, OSegment3D &seg) const
Definition: TYPolygon.cpp:271
virtual int intersects(const OSegment3D &seg, TYTabPoint &ptList) const
virtual TYTabLPPolygon faces() const =0
virtual TYBox volEnglob() const
void calculRayonSphere(const TYBox &volEnglob)
virtual TYTabPoint sommets() const =0