Code_TYMPAN  4.4.0
Industrial site acoustic simulation
DiffractionSelector.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 DIFFRACTION_SELECTOR
17 #define DIFFRACTION_SELECTOR
18 
19 #include "Selector.h"
20 
24 template <typename T> class DiffractionSelector : public Selector<T>
25 {
26 public:
28  DiffractionSelector(int _maxDiffractionOrder = 1, OPERATOR _op = LESS_OR_EQUAL) : Selector<T>()
29  {
30  maxDiffractionOrder = _maxDiffractionOrder;
31  op = _op;
32  }
33 
34  virtual Selector<T>* Copy()
35  {
36  // logs <<"Copie d'un filtre de diffraction avec "<<maxDiffractionOrder<<" diff"<<endl;
38  newSelector->setIsDeletable(this->deletable);
39  newSelector->setOperator(op);
40  return newSelector;
41  }
42 
43  virtual SELECTOR_RESPOND canBeInserted(T* r, unsigned long long& replace)
44  {
45  switch (op)
46  {
47  case LESS:
48  if (r->getDiff() >= static_cast<unsigned int>(maxDiffractionOrder))
49  {
50  return SELECTOR_REJECT;
51  }
52  break;
53  case LESS_OR_EQUAL:
54  if (r->getDiff() > static_cast<unsigned int>(maxDiffractionOrder))
55  {
56  return SELECTOR_REJECT;
57  }
58  break;
59  case EQUAL:
60  if (r->getDiff() != static_cast<unsigned int>(maxDiffractionOrder))
61  {
62  return SELECTOR_REJECT;
63  }
64  break;
65  case GREATER_OR_EQUAL:
66  if (r->getDiff() < static_cast<unsigned int>(maxDiffractionOrder))
67  {
68  return SELECTOR_REJECT;
69  }
70  break;
71  case GREATER:
72  if (r->getDiff() <= static_cast<unsigned int>(maxDiffractionOrder))
73  {
74  return SELECTOR_REJECT;
75  }
76  break;
77  }
78  return SELECTOR_ACCEPT;
79  }
80 
81  virtual void insert(T* r)
82  {
83  return;
84  }
85  virtual bool insertWithTest(T* r)
86  {
87  switch (op)
88  {
89  case LESS:
90  if (r->getDiff() >= static_cast<unsigned int>(maxDiffractionOrder))
91  {
92  return false;
93  }
94  break;
95  case LESS_OR_EQUAL:
96  if (r->getDiff() > static_cast<unsigned int>(maxDiffractionOrder))
97  {
98  return false;
99  }
100  break;
101  case EQUAL:
102  if (r->getDiff() != static_cast<unsigned int>(maxDiffractionOrder))
103  {
104  return false;
105  }
106  break;
107  case GREATER_OR_EQUAL:
108  if (r->getDiff() < static_cast<unsigned int>(maxDiffractionOrder))
109  {
110  return false;
111  }
112  break;
113  case GREATER:
114  if (r->getDiff() <= static_cast<unsigned int>(maxDiffractionOrder))
115  {
116  return false;
117  }
118  break;
119  }
120  return true;
121  }
124  {
125  return maxDiffractionOrder;
126  }
128  void setMaximumDiffractionOrder(int _maxDiffractionOrder)
129  {
130  maxDiffractionOrder = _maxDiffractionOrder;
131  }
134  {
135  return op;
136  }
139  {
140  op = _op;
141  }
142 
146  virtual const char* getSelectorName()
147  {
148  return typeid(this).name();
149  }
150 
151 protected:
155 };
156 
157 #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
: To disable ray with a number of diffraction events greater than a threshold value
int getMaximumDiffractionOrder()
Get maxDiffractionOrder.
OPERATOR getOperator()
Get the Operator used by this Selector.
void setMaximumDiffractionOrder(int _maxDiffractionOrder)
Set maxDiffractionOrder.
void setOperator(OPERATOR _op)
Set the Operator used by this Selector.
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.
int maxDiffractionOrder
Maximal number of possible diffractions.
DiffractionSelector(int _maxDiffractionOrder=1, OPERATOR _op=LESS_OR_EQUAL)
Constructor.
virtual Selector< T > * Copy()
Copy Selector.
virtual bool insertWithTest(T *r)
Select the ray if it respects the criteria of this Selector.
virtual void insert(T *r)
Select the ray.
virtual const char * getSelectorName()
Return the class type of the selector.
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