Code_TYMPAN  4.2.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>
28 class ReflectionSelector : public Selector<T>
29 {
30 public :
32  ReflectionSelector(int _maxReflectionOrder = 1, bool _acceptGround = false, OPERATOR _op = LESS_OR_EQUAL) : 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 
48  virtual SELECTOR_RESPOND canBeInserted(T* r, unsigned long long& replace)
49  {
50  switch (op)
51  {
52  case LESS:
53  if (r->getReflex() >= static_cast<unsigned int>(maxReflectionOrder))
54  {
55  return SELECTOR_REJECT;
56  }
57  break;
58  case LESS_OR_EQUAL:
59  if (r->getReflex() > static_cast<unsigned int>(maxReflectionOrder))
60  {
61  return SELECTOR_REJECT;
62  }
63  break;
64  case EQUAL:
65  if (r->getReflex() != static_cast<unsigned int>(maxReflectionOrder))
66  {
67  return SELECTOR_REJECT;
68  }
69  break;
70  case GREATER_OR_EQUAL:
71  if (r->getReflex() < static_cast<unsigned int>(maxReflectionOrder))
72  {
73  return SELECTOR_REJECT;
74  }
75  break;
76  case GREATER:
77  if (r->getReflex() <= static_cast<unsigned int>(maxReflectionOrder))
78  {
79  return SELECTOR_REJECT;
80  }
81  break;
82 
83  }
84 
85  // Check if the ray is reflected on the ground if necessary
86  if (!acceptGround){
87 
88  //loop on evets
89  std::vector<boost::shared_ptr<Event> >* tabEvent = r->getEvents();
90  for(unsigned int i=0;i<tabEvent->size();i++){
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  return SELECTOR_REJECT;
96  }
97  }
98  }
99  return SELECTOR_ACCEPT;
100  }
101 
102  virtual void insert(T* r) { return; }
103 
104  virtual bool insertWithTest(T* r)
105  {
106  switch (op)
107  {
108  case LESS:
109  if (r->getReflex() >= static_cast<unsigned int>(maxReflectionOrder))
110  {
111  return false;
112  }
113  break;
114  case LESS_OR_EQUAL:
115  if (r->getReflex() > static_cast<unsigned int>(maxReflectionOrder))
116  {
117  return false;
118  }
119  break;
120  case EQUAL:
121  if (r->getReflex() != static_cast<unsigned int>(maxReflectionOrder))
122  {
123  return false;
124  }
125  break;
126  case GREATER_OR_EQUAL:
127  if (r->getReflex() < static_cast<unsigned int>(maxReflectionOrder))
128  {
129  return false;
130  }
131  break;
132  case GREATER:
133  if (r->getReflex() <= static_cast<unsigned int>(maxReflectionOrder))
134  {
135  return false;
136  }
137  break;
138 
139  }
140 
141  // Check if the ray is reflected on the ground if necessary
142  if (!acceptGround){
143 
144  //loop on evets
145  std::vector<boost::shared_ptr<Event> >* tabEvent = r->getEvents();
146  for(unsigned int i=0;i<tabEvent->size();i++){
147 
148  //check if the ith event is a reflexion on the ground
149  SpecularReflexion* reflex = dynamic_cast<SpecularReflexion*>(tabEvent->at(i).get());
150  if (reflex && reflex->getShape()->isSol()){
151  return false;
152  }
153  }
154  }
155  return true;
156  }
157 
162 
166  void setMaximumReflectionOrder(int _maxReflectionOrder) { maxReflectionOrder = _maxReflectionOrder; }
167 
171  bool isGroundAccepted() { return acceptGround; }
172 
176  void setGroundAccepted(bool _acceptGround) { acceptGround = _acceptGround; }
177 
181  OPERATOR getOperator() { return op; }
182 
186  void setOperator(OPERATOR _op) { op = _op; }
187 
188 
192  virtual const char* getSelectorName(){
193  return typeid(this).name();
194  }
195 
196 protected:
200 
201 };
202 
203 #endif
Shape * getShape()
Return the primitive of the impact.
Definition: Event.h:116
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.
bool isGroundAccepted()
Return true if ground reflection is accepted.
const char * name
: To disable the rays which have a number of reflection events greater than a given threshold or refl...
void setMaximumReflectionOrder(int _maxReflectionOrder)
Set the reflection maximal number.
Definition: Selector.h:32
SELECTOR_RESPOND
Definition: Selector.h:23
bool deletable
Flag to know if the selector may be deleted or not.
Definition: Selector.h:103
ReflectionSelector(int _maxReflectionOrder=1, bool _acceptGround=false, OPERATOR _op=LESS_OR_EQUAL)
Constructor.
void setGroundAccepted(bool _acceptGround)
Set flag acceptGround.
OPERATOR
Definition: Selector.h:30
Base class for Selector (used to keep or disable rays according different criterias) ...
Definition: Selector.h:77
Definition: Selector.h:34
virtual Selector< T > * Copy()
Copy Selector.
OPERATOR getOperator()
Get the OPERATOR of this Selector.
bool isSol() const
Get/Set the flag _isSol (ground or not)
Definition: Shape.h:134
virtual void insert(T *r)
Select the ray.
void setOperator(OPERATOR _op)
Set the OPERATOR of this Selector.
Specular reflection class Event.
virtual bool insertWithTest(T *r)
Select the ray if it respects the criteria of this Selector.
virtual const char * getSelectorName()
Return the class type of the selector.
void setIsDeletable(bool _isDeletable)
Set deletable flag.
Definition: Selector.h:92
int getMaximumReflectionOrder()
Get the reflection maximal number.
OPERATOR op
OPERATOR being used for the criteria (by default, LESS_OR_EQUAL)
bool acceptGround
Flag to accept or not the reflection on the ground.
int maxReflectionOrder
Reflection maximal number for this Selector criteria.