Code_TYMPAN  4.4.0
Industrial site acoustic simulation
ReflectionSelector.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
16 #ifndef REFLECTION_SELECTOR
17 #define REFLECTION_SELECTOR
18 
19 #include "Selector.h"
21 
26 template <typename T> class ReflectionSelector : public Selector<T>
27 {
28 public:
30  ReflectionSelector(int _maxReflectionOrder = 1, bool _acceptGround = false, OPERATOR _op = LESS_OR_EQUAL)
31  : Selector<T>()
32  {
33  maxReflectionOrder = _maxReflectionOrder;
34  acceptGround = _acceptGround;
35  op = _op;
36  }
37 
38  virtual Selector<T>* Copy()
39  {
41  newSelector->setIsDeletable(this->deletable);
42  newSelector->setOperator(op);
43  return newSelector;
44  }
45 
46  virtual SELECTOR_RESPOND canBeInserted(T* r, unsigned long long& replace)
47  {
48  switch (op)
49  {
50  case LESS:
51  if (r->getReflex() >= static_cast<unsigned int>(maxReflectionOrder))
52  {
53  return SELECTOR_REJECT;
54  }
55  break;
56  case LESS_OR_EQUAL:
57  if (r->getReflex() > static_cast<unsigned int>(maxReflectionOrder))
58  {
59  return SELECTOR_REJECT;
60  }
61  break;
62  case EQUAL:
63  if (r->getReflex() != static_cast<unsigned int>(maxReflectionOrder))
64  {
65  return SELECTOR_REJECT;
66  }
67  break;
68  case GREATER_OR_EQUAL:
69  if (r->getReflex() < static_cast<unsigned int>(maxReflectionOrder))
70  {
71  return SELECTOR_REJECT;
72  }
73  break;
74  case GREATER:
75  if (r->getReflex() <= static_cast<unsigned int>(maxReflectionOrder))
76  {
77  return SELECTOR_REJECT;
78  }
79  break;
80  }
81 
82  // Check if the ray is reflected on the ground if necessary
83  if (!acceptGround)
84  {
85 
86  // loop on evets
87  std::vector<boost::shared_ptr<Event>>* tabEvent = r->getEvents();
88  for (unsigned int i = 0; i < tabEvent->size(); i++)
89  {
90 
91  // check if the ith event is a reflexion on the ground
92  SpecularReflexion* reflex = dynamic_cast<SpecularReflexion*>(tabEvent->at(i).get());
93  if (reflex && reflex->getShape()->isSol())
94  {
95  return SELECTOR_REJECT;
96  }
97  }
98  }
99  return SELECTOR_ACCEPT;
100  }
101 
102  virtual void insert(T* r)
103  {
104  return;
105  }
106 
107  virtual bool insertWithTest(T* r)
108  {
109  switch (op)
110  {
111  case LESS:
112  if (r->getReflex() >= static_cast<unsigned int>(maxReflectionOrder))
113  {
114  return false;
115  }
116  break;
117  case LESS_OR_EQUAL:
118  if (r->getReflex() > static_cast<unsigned int>(maxReflectionOrder))
119  {
120  return false;
121  }
122  break;
123  case EQUAL:
124  if (r->getReflex() != static_cast<unsigned int>(maxReflectionOrder))
125  {
126  return false;
127  }
128  break;
129  case GREATER_OR_EQUAL:
130  if (r->getReflex() < static_cast<unsigned int>(maxReflectionOrder))
131  {
132  return false;
133  }
134  break;
135  case GREATER:
136  if (r->getReflex() <= static_cast<unsigned int>(maxReflectionOrder))
137  {
138  return false;
139  }
140  break;
141  }
142 
143  // Check if the ray is reflected on the ground if necessary
144  if (!acceptGround)
145  {
146 
147  // loop on evets
148  std::vector<boost::shared_ptr<Event>>* tabEvent = r->getEvents();
149  for (unsigned int i = 0; i < tabEvent->size(); i++)
150  {
151 
152  // check if the ith event is a reflexion on the ground
153  SpecularReflexion* reflex = dynamic_cast<SpecularReflexion*>(tabEvent->at(i).get());
154  if (reflex && reflex->getShape()->isSol())
155  {
156  return false;
157  }
158  }
159  }
160  return true;
161  }
162 
167  {
168  return maxReflectionOrder;
169  }
170 
174  void setMaximumReflectionOrder(int _maxReflectionOrder)
175  {
176  maxReflectionOrder = _maxReflectionOrder;
177  }
178 
183  {
184  return acceptGround;
185  }
186 
190  void setGroundAccepted(bool _acceptGround)
191  {
192  acceptGround = _acceptGround;
193  }
194 
199  {
200  return op;
201  }
202 
207  {
208  op = _op;
209  }
210 
214  virtual const char* getSelectorName()
215  {
216  return typeid(this).name();
217  }
218 
219 protected:
223 };
224 
225 #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.