Code_TYMPAN  4.4.0
Industrial site acoustic simulation
ReflectionSelector.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 #ifndef REFLECTION_SELECTOR
17 #define REFLECTION_SELECTOR
18 
19 #include "Selector.h"
21 #include "Geometry/Shape.h"
22 
27 template <typename T> class ReflectionSelector : public Selector<T>
28 {
29 public:
31  ReflectionSelector(int _maxReflectionOrder = 1, bool _acceptGround = false, OPERATOR _op = LESS_OR_EQUAL)
32  : Selector<T>()
33  {
34  maxReflectionOrder = _maxReflectionOrder;
35  acceptGround = _acceptGround;
36  op = _op;
37  }
38 
39  virtual Selector<T>* Copy()
40  {
42  newSelector->setIsDeletable(this->deletable);
43  newSelector->setOperator(op);
44  return newSelector;
45  }
46 
47  virtual SELECTOR_RESPOND canBeInserted(T* r, unsigned long long& replace)
48  {
49  switch (op)
50  {
51  case LESS:
52  if (r->getReflex() >= static_cast<unsigned int>(maxReflectionOrder))
53  {
54  return SELECTOR_REJECT;
55  }
56  break;
57  case LESS_OR_EQUAL:
58  if (r->getReflex() > static_cast<unsigned int>(maxReflectionOrder))
59  {
60  return SELECTOR_REJECT;
61  }
62  break;
63  case EQUAL:
64  if (r->getReflex() != static_cast<unsigned int>(maxReflectionOrder))
65  {
66  return SELECTOR_REJECT;
67  }
68  break;
69  case GREATER_OR_EQUAL:
70  if (r->getReflex() < static_cast<unsigned int>(maxReflectionOrder))
71  {
72  return SELECTOR_REJECT;
73  }
74  break;
75  case GREATER:
76  if (r->getReflex() <= static_cast<unsigned int>(maxReflectionOrder))
77  {
78  return SELECTOR_REJECT;
79  }
80  break;
81  }
82 
83  // Check if the ray is reflected on the ground if necessary
84  if (!acceptGround)
85  {
86 
87  // loop on evets
88  std::vector<boost::shared_ptr<Event>>* tabEvent = r->getEvents();
89  for (unsigned int i = 0; i < tabEvent->size(); i++)
90  {
91 
92  // check if the ith event is a reflexion on the ground
93  SpecularReflexion* reflex = dynamic_cast<SpecularReflexion*>(tabEvent->at(i).get());
94  if (reflex && reflex->getShape()->isSol())
95  {
96  return SELECTOR_REJECT;
97  }
98  }
99  }
100  return SELECTOR_ACCEPT;
101  }
102 
103  virtual void insert(T* r)
104  {
105  return;
106  }
107 
108  virtual bool insertWithTest(T* r)
109  {
110  switch (op)
111  {
112  case LESS:
113  if (r->getReflex() >= static_cast<unsigned int>(maxReflectionOrder))
114  {
115  return false;
116  }
117  break;
118  case LESS_OR_EQUAL:
119  if (r->getReflex() > static_cast<unsigned int>(maxReflectionOrder))
120  {
121  return false;
122  }
123  break;
124  case EQUAL:
125  if (r->getReflex() != static_cast<unsigned int>(maxReflectionOrder))
126  {
127  return false;
128  }
129  break;
130  case GREATER_OR_EQUAL:
131  if (r->getReflex() < static_cast<unsigned int>(maxReflectionOrder))
132  {
133  return false;
134  }
135  break;
136  case GREATER:
137  if (r->getReflex() <= static_cast<unsigned int>(maxReflectionOrder))
138  {
139  return false;
140  }
141  break;
142  }
143 
144  // Check if the ray is reflected on the ground if necessary
145  if (!acceptGround)
146  {
147 
148  // loop on evets
149  std::vector<boost::shared_ptr<Event>>* tabEvent = r->getEvents();
150  for (unsigned int i = 0; i < tabEvent->size(); i++)
151  {
152 
153  // check if the ith event is a reflexion on the ground
154  SpecularReflexion* reflex = dynamic_cast<SpecularReflexion*>(tabEvent->at(i).get());
155  if (reflex && reflex->getShape()->isSol())
156  {
157  return false;
158  }
159  }
160  }
161  return true;
162  }
163 
168  {
169  return maxReflectionOrder;
170  }
171 
175  void setMaximumReflectionOrder(int _maxReflectionOrder)
176  {
177  maxReflectionOrder = _maxReflectionOrder;
178  }
179 
184  {
185  return acceptGround;
186  }
187 
191  void setGroundAccepted(bool _acceptGround)
192  {
193  acceptGround = _acceptGround;
194  }
195 
200  {
201  return op;
202  }
203 
208  {
209  op = _op;
210  }
211 
215  virtual const char* getSelectorName()
216  {
217  return typeid(this).name();
218  }
219 
220 protected:
224 };
225 
226 #endif
OPERATOR
Definition: Selector.h:31
@ GREATER
Definition: Selector.h:36
@ EQUAL
Definition: Selector.h:34
@ LESS
Definition: Selector.h:32
@ GREATER_OR_EQUAL
Definition: Selector.h:35
@ LESS_OR_EQUAL
Definition: Selector.h:33
SELECTOR_RESPOND
Definition: Selector.h:24
@ SELECTOR_ACCEPT
Definition: Selector.h:25
@ SELECTOR_REJECT
Definition: Selector.h:26
const char * name
Shape * getShape()
Return the primitive of the impact.
Definition: Event.h:143
: To disable the rays which have a number of reflection events greater than a given threshold or refl...
virtual void insert(T *r)
Select the ray.
void setMaximumReflectionOrder(int _maxReflectionOrder)
Set the reflection maximal number.
OPERATOR op
OPERATOR being used for the criteria (by default, LESS_OR_EQUAL)
int maxReflectionOrder
Reflection maximal number for this Selector criteria.
virtual bool insertWithTest(T *r)
Select the ray if it respects the criteria of this Selector.
OPERATOR getOperator()
Get the OPERATOR of this Selector.
virtual Selector< T > * Copy()
Copy Selector.
bool isGroundAccepted()
Return true if ground reflection is accepted.
bool acceptGround
Flag to accept or not the reflection on the ground.
void setOperator(OPERATOR _op)
Set the OPERATOR of this Selector.
ReflectionSelector(int _maxReflectionOrder=1, bool _acceptGround=false, OPERATOR _op=LESS_OR_EQUAL)
Constructor.
virtual SELECTOR_RESPOND canBeInserted(T *r, unsigned long long &replace)
Check if the ray respects the criteria of this Selector and return a SELECTOR_RESPOND.
virtual const char * getSelectorName()
Return the class type of the selector.
int getMaximumReflectionOrder()
Get the reflection maximal number.
void setGroundAccepted(bool _acceptGround)
Set flag acceptGround.
Base class for Selector (used to keep or disable rays according different criterias)
Definition: Selector.h:78
void setIsDeletable(bool _isDeletable)
Set deletable flag.
Definition: Selector.h:103
bool deletable
Flag to know if the selector may be deleted or not.
Definition: Selector.h:130
bool isSol() const
Get/Set the flag _isSol (ground or not)
Definition: Shape.h:194
Specular reflection class Event.