Code_TYMPAN  4.2.0
Industrial site acoustic simulation
TYFaceSelector.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 
16 /*
17  *
18  */
19 
20 #include "Tympan/core/defines.h"
23 #include "TYFaceSelector.h"
24 #include "TYTrajet.h"
25 #include "TYSolver.h"
26 
28  : _solver(solver)
29 {
30 
31 }
32 
34 {
35 
36 }
37 
38 void TYFaceSelector::selectFaces(std::deque<TYSIntersection>& tabIntersect, const TYTrajet& rayon)
39 {
40 
41  // Construction des plans de coupe
42  TYSPlan plan[2];
43  OSegment3D seg;
44  rayon.getPtSetPtRfromOSeg3D(seg);
45  buildPlans(plan, seg);
46 
47  size_t nbFaces = _solver.getTabPolygon().size();
48 
49  // Recuperation de l'ID de la source
50  const string source_id = rayon.asrc.volume_id;
51 
52  // Test des faces qui coupent le plan vertical
53  for (unsigned i = 0; i < nbFaces; i++)
54  {
56 
57  // FIX issue #18 (obstacles are not detected correctly)
58  if ( (SI.volume_id.size() != 0) && (source_id.size() != 0) )
59  {
60  if ((SI.volume_id == source_id) || (SI.tabPoint.size() == 0)) { continue; }
61  }
62 
63  // Plan vertical = 0 / Plan horizontal = 1
64  TYSIntersection intersection;
65  bool bVertical = CalculSegmentCoupe(SI, intersection, plan[0].pt1, plan[0].pt2, plan[0].pt3, 0);
66  bool bHorizontal = CalculSegmentCoupe(SI, intersection, plan[1].pt1, plan[1].pt2, plan[1].pt3, 1);
67 
68  if (bVertical || bHorizontal) { tabIntersect.push_back(intersection); }
69  }
70 
71  reorder_intersect(tabIntersect); // Put infrastructure elements on top
72 }
73 
74 void TYFaceSelector::reorder_intersect(std::deque<TYSIntersection>& tabIntersect)
75 {
76  std::deque<unsigned int> indices;
77  std::deque<TYSIntersection> temp;
78 
79  // 1 st pass : put infrastructure on top
80  for (size_t i=0; i<tabIntersect.size(); i++)
81  {
82  if (tabIntersect[i].isInfra)
83  {
84  temp.push_back(tabIntersect[i]);
85  }
86  else
87  {
88  indices.push_back(i);
89  }
90  }
91 
92  // 2nd pass : put remainings after
93  for (size_t i=0; i<indices.size(); i++)
94  {
95  temp.push_back(tabIntersect[indices[i]]);
96  }
97 
98  // last : replace tabIntersect
99  tabIntersect = temp;
100 }
101 
103 {
104  double planOffset = 10.0;
105  TYSPlan tmpPlan;
106  tmpPlan.pt1 = rayon._ptA;
107  tmpPlan.pt2 = rayon._ptB;
108 
109  // Construction du plan vertical
110  // 3eme point simplement en copiant le 1er et changeant l'alti
111  tmpPlan.pt3 = tmpPlan.pt1;
112  tmpPlan.pt3._z += planOffset;
113 
114  // Si A et B sont confondus (en 2D) sur le plan que l'on souhaite creer
115  if ((tmpPlan.pt1._x == tmpPlan.pt2._x) && (tmpPlan.pt1._y == tmpPlan.pt2._y))
116  {
117  // On deplace le point 2 pour choisir un plan arbitraire valide
118  tmpPlan.pt2._x += planOffset;
119  tmpPlan.pt2._y += planOffset;
120  }
121 
122  plan[0] = tmpPlan;
123 
124  // Construction du plan horizontal
125  tmpPlan.pt1 = rayon._ptA;
126  tmpPlan.pt2 = rayon._ptB;
127 
128  if (tmpPlan.pt2._x != tmpPlan.pt1._x)
129  {
130  tmpPlan.pt3._z = tmpPlan.pt1._z;
131  tmpPlan.pt3._y = tmpPlan.pt1._y + planOffset;
132  tmpPlan.pt3._x = ((tmpPlan.pt1._y - tmpPlan.pt2._y) * planOffset / (tmpPlan.pt2._x - tmpPlan.pt1._x)) + (tmpPlan.pt1._x);
133  }
134  else if (tmpPlan.pt1._y != tmpPlan.pt2._y)
135  {
136  tmpPlan.pt3._z = tmpPlan.pt1._z;
137  tmpPlan.pt3._x = tmpPlan.pt1._x + planOffset;
138  tmpPlan.pt3._y = ((tmpPlan.pt2._x - tmpPlan.pt1._x) * planOffset / (tmpPlan.pt1._y - tmpPlan.pt2._y)) + (tmpPlan.pt1._y);
139  }
140  else if (tmpPlan.pt1._z != tmpPlan.pt2._z)
141  {
142  tmpPlan.pt3._y = tmpPlan.pt1._y;
143  tmpPlan.pt3._x = tmpPlan.pt1._x + planOffset;
144  tmpPlan.pt3._z = ((tmpPlan.pt2._x - tmpPlan.pt1._x) * planOffset / (tmpPlan.pt1._z - tmpPlan.pt2._z)) + (tmpPlan.pt1._z);
145  }
146  else
147  {
148  return false;
149  }
150 
151 
152  plan[1] = tmpPlan;
153 
154 
155  return true;
156 }
157 
159  TYSIntersection& Intersect,
160  OPoint3D& pt1, OPoint3D& pt2, OPoint3D& pt3,
161  const int& indice) const
162 {
163  bool bRes = false;
164  Intersect.isInfra = false;
165  Intersect.isEcran = false;
166  Intersect.noIntersect = false;
167  Intersect.bIntersect[indice] = false;
168 
169  OSegment3D segInter;
170  OPlan planRayon(pt1, pt2, pt3);
171  if ( planRayon.intersectsSurface(FaceCourante.tabPoint, segInter) )
172  {
173  Intersect.bIntersect[indice] = true;
174  Intersect.segInter[indice] = segInter;
175  Intersect.isInfra = FaceCourante.is_infra();
176  Intersect.isEcran = Intersect.isInfra;
177  Intersect.material = FaceCourante.material;
178  bRes = true;
179  }
180 
181  return bRes;
182 }
This file provides the declaration of the entities of the model, which inherit from BaseEntity...
const std::vector< TYStructSurfIntersect > & getTabPolygon() const
Get the array of polygons.
Definition: TYSolver.h:55
TYSolver & _solver
Reference to the solver.
Structure to describe a plan defined with 3 points.
OPoint3D _ptB
Point B of the segment.
Definition: 3d.h:1199
OPoint3D _ptA
Point A of the segment.
Definition: 3d.h:1197
bool buildPlans(TYSPlan *plan, const OSegment3D &rayon)
TYFaceSelector(TYSolver &solver)
Default solver.
Definition: TYSolver.h:38
tympan::AcousticMaterialBase * material
Triangle material.
void reorder_intersect(std::deque< TYSIntersection > &tabIntersect)
put infrastructure faces on top
bool bIntersect[2]
Flag to indicate the face cuts vertical plane ([0]) or horizontal plane ([1])
int intersectsSurface(const TabPoint3D &contour, OSegment3D &segment) const
Compute intersection between a plan and a surface defined by his bounds.
Definition: plan.cpp:323
OPoint3D pt1
void getPtSetPtRfromOSeg3D(OSegment3D &seg) const
Definition: TYTrajet.h:143
bool isEcran
Flag to define if is a screen face.
This class TYTrajet (journey) links a couple Source-Receptor and a collection of paths, in addition to the direct path.
Definition: TYTrajet.h:35
string volume_id
Volume id.
double _y
y coordinate of OCoord3D
Definition: 3d.h:281
double _x
x coordinate of OCoord3D
Definition: 3d.h:280
Plan defined by its equation : ax+by+cz+d=0.
Definition: plan.h:30
TabPoint3D tabPoint
Points array used during the pre-selection.
virtual void selectFaces(std::deque< TYSIntersection > &tabIntersect, const TYTrajet &rayon)
Build the array of intersections.
OPoint3D pt2
bool isInfra
Flag to define if is a infrastructure face.
bool CalculSegmentCoupe(const TYStructSurfIntersect &FaceCourante, TYSIntersection &Intersect, OPoint3D &pt1, OPoint3D &pt2, OPoint3D &pt3, const int &indice) const
tympan::AcousticMaterialBase * material
Pointer to a material.
Data structure for intersections.
Class to define a segment.
Definition: 3d.h:1087
bool noIntersect
Flag to indicate that the face should not be tested for intersection.
Describe surface intersections.
virtual ~TYFaceSelector()
The 3D point class.
Definition: 3d.h:484
OSegment3D segInter[2]
Intersection segment between face and vertical plane ([0]) and horizontal plane ([1]) ...
double _z
z coordinate of OCoord3D
Definition: 3d.h:282
string volume_id
Volume id.
Definition: entities.hpp:330
OPoint3D pt3
tympan::AcousticSource & asrc
Business source.
Definition: TYTrajet.h:182
bool is_infra() const
Detect if a face is on a infrastructure (has a material)