Code_TYMPAN  4.4.0
Industrial site acoustic simulation
LeafTreatment.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 #include "LeafTreatment.h"
17 #include "Geometry/Triangle.h"
18 
19 namespace leafTreatment
20 {
21 
22 decimal keepFunction(treatment choice, std::list<Intersection>& currentIntersections, decimal currentTmin)
23 {
24  // std::cout<<"Il faut filtrer "<<currentIntersections.size()<<" intersections."<<std::endl;
25  switch (choice)
26  {
27  case FIRST:
28  return keepFirst(currentIntersections, currentTmin);
29  break;
31  return keepAllBeforeTriangle(currentIntersections, currentTmin);
32  break;
33  case ALL_BEFORE_VISIBLE:
34  return keepAllBeforeVisible(currentIntersections, currentTmin);
35  break;
36  case ALL:
37  return keepAll(currentIntersections, currentTmin);
38  break;
39  default:
40  return keepFirst(currentIntersections, currentTmin);
41  break;
42  }
43 }
44 
45 decimal keepFirst(std::list<Intersection>& currentIntersections, decimal currentTmin)
46 {
47  if (currentIntersections.empty())
48  {
49  return currentTmin;
50  }
51 
52  // Set the max tmin to currentTmin
53  decimal tmin = currentTmin;
54  std::list<Intersection>::iterator firstInter = currentIntersections.end();
55 
56  // Browse through all intersections found
57  for (std::list<Intersection>::iterator it = currentIntersections.begin();
58  it != currentIntersections.end(); it++)
59  {
60  // Check if the current intersection happens before the closest one we found so far in term of tmin
61  if (tmin < 0. || it->t <= tmin)
62  {
63  tmin = it->t;
64  firstInter = it;
65  }
66  }
67 
68  // if some intersection has been found, copy it, clear the list of intersections and put back the copy
69  // into the list
70  if (firstInter != currentIntersections.end())
71  {
72  Intersection firstIntersection;
73  firstIntersection.normal = firstInter->normal;
74  firstIntersection.p = firstInter->p;
75  firstIntersection.t = firstInter->t;
76  firstIntersection.forme = firstInter->forme;
77  currentIntersections.clear();
78  currentIntersections.push_back(firstIntersection);
79  }
80 
81  return tmin;
82 }
83 
84 decimal keepAllBeforeTriangle(std::list<Intersection>& currentIntersections, decimal currentTmin)
85 {
86  if (currentIntersections.empty())
87  {
88  return currentTmin;
89  }
90 
91  // Set the max tmin to currentTmin
92  decimal tmin = currentTmin;
93 
94  // Find the tmin of the first intersection with a triangle
95  for (std::list<Intersection>::iterator it = currentIntersections.begin();
96  it != currentIntersections.end(); it++)
97  {
98  Triangle* triangle = dynamic_cast<Triangle*>(it->p);
99  if (triangle && (tmin < 0. || it->t < tmin))
100  {
101  tmin = it->t;
102  }
103  }
104 
105  std::list<Intersection>::iterator it = currentIntersections.begin();
106  // Erase all intersections that happen after tmin
107  while (it != currentIntersections.end())
108  {
109  if (tmin > 0. && it->t > tmin)
110  currentIntersections.erase(it++);
111  else
112  it++;
113  }
114 
115  return tmin;
116 }
117 
118 decimal keepAllBeforeVisible(std::list<Intersection>& currentIntersections, decimal currentTmin)
119 {
120  if (currentIntersections.empty())
121  {
122  return currentTmin;
123  }
124 
125  // Set the max tmin to currentTmin
126  decimal tmin = currentTmin;
127 
128  // Find the tmin of the first intersection with a visible shape
129  for (std::list<Intersection>::iterator it = currentIntersections.begin();
130  it != currentIntersections.end(); it++)
131  {
132  if (it->p->isVisible() && (tmin < 0. || it->t < tmin))
133  {
134  tmin = it->t;
135  }
136  }
137 
138  std::list<Intersection>::iterator it = currentIntersections.begin();
139  // Erase all intersections that happen after tmin
140  while (it != currentIntersections.end())
141  {
142  if (tmin > 0. && it->t > tmin)
143  currentIntersections.erase(it++);
144  else
145  it++;
146  }
147 
148  return tmin;
149 }
150 
151 decimal keepAll(std::list<Intersection>& currentIntersections, decimal currentTmin)
152 {
153  if (currentIntersections.empty())
154  {
155  return currentTmin;
156  }
157 
158  // Set the max tmin to currentTmin
159  decimal tmin = currentTmin;
160 
161  // Find the tmin of the first intersection
162  for (std::list<Intersection>::iterator it = currentIntersections.begin();
163  it != currentIntersections.end(); it++)
164  {
165  if (tmin < 0. || it->t <= tmin)
166  {
167  tmin = it->t;
168  }
169  }
170 
171  return tmin;
172 }
173 
174 }; // namespace leafTreatment
Triangle class.
Definition: Triangle.h:25
float decimal
Definition: mathlib.h:45
Leaf treatment.
decimal keepAll(std::list< Intersection > &currentIntersections, decimal currentTmin)
Keep all intersections before reaching currentTmin and return the tmin of the first one encountered.
@ ALL_BEFORE_TRIANGLE
ALL_BEFORE_TRIANGLE.
Definition: LeafTreatment.h:32
@ ALL_BEFORE_VISIBLE
ALL_BEFORE_VISIBLE.
Definition: LeafTreatment.h:33
decimal keepAllBeforeVisible(std::list< Intersection > &currentIntersections, decimal currentTmin)
Keep all intersections encountered before intersecting a triangle and before reaching currentTmin,...
decimal keepAllBeforeTriangle(std::list< Intersection > &currentIntersections, decimal currentTmin)
Keep all intersections encountered before intersecting a visible shape and before reaching currentTmi...
decimal keepFunction(treatment choice, std::list< Intersection > &currentIntersections, decimal currentTmin)
decimal keepFirst(std::list< Intersection > &currentIntersections, decimal currentTmin)
Keep only the first intersection encountered before reaching currentTmin and return its corresponding...
Intersection struct.
Definition: Shape.h:46
decimal t
Definition: Shape.h:48
FORM forme
Definition: Shape.h:50
Shape * p
Definition: Shape.h:49
vec3 normal
Definition: Shape.h:47