Code_TYMPAN  4.4.0
Industrial site acoustic simulation
LengthSelector.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 LENGTH_SELECTOR
17 #define LENGTH_SELECTOR
18 
19 #include "Selector.h"
20 
24 template <typename T> class LengthSelector : public Selector<T>
25 {
26 public:
28  LengthSelector(double _maxLength = 2000, OPERATOR _op = LESS_OR_EQUAL) : Selector<T>()
29  {
30  maxLength = _maxLength;
31  op = _op;
32  }
33  virtual Selector<T>* Copy()
34  {
35  LengthSelector* newSelector = new LengthSelector(maxLength);
36  newSelector->setIsDeletable(this->deletable);
37  newSelector->setOperator(op);
38  return newSelector;
39  }
40 
41  virtual SELECTOR_RESPOND canBeInserted(T* r, unsigned long long& replace)
42  {
43  r->computeLongueur();
44  switch (op)
45  {
46  case LESS:
47  if (r->getLongueur() >= maxLength)
48  {
49  return SELECTOR_REJECT;
50  }
51  break;
52  case LESS_OR_EQUAL:
53  if (r->getLongueur() > maxLength)
54  {
55  return SELECTOR_REJECT;
56  }
57  break;
58  case EQUAL:
59  if (r->getLongueur() != maxLength)
60  {
61  return SELECTOR_REJECT;
62  }
63  break;
64  case GREATER_OR_EQUAL:
65  if (r->getLongueur() < maxLength)
66  {
67  return SELECTOR_REJECT;
68  }
69  break;
70  case GREATER:
71  if (r->getLongueur() <= maxLength)
72  {
73  return SELECTOR_REJECT;
74  }
75  break;
76  }
77  return SELECTOR_ACCEPT;
78  }
80  virtual void insert(T* r, unsigned long long& replace)
81  {
82  return;
83  }
84 
85  virtual bool insertWithTest(T* r)
86  {
87  r->computeLongueur();
88  switch (op)
89  {
90  case LESS:
91  if (r->getLongueur() >= maxLength)
92  {
93  return false;
94  }
95  break;
96  case LESS_OR_EQUAL:
97  if (r->getLongueur() > maxLength)
98  {
99  return false;
100  }
101  break;
102  case EQUAL:
103  if (r->getLongueur() != maxLength)
104  {
105  return false;
106  }
107  break;
108  case GREATER_OR_EQUAL:
109  if (r->getLongueur() < maxLength)
110  {
111  return false;
112  }
113  break;
114  case GREATER:
115  if (r->getLongueur() <= maxLength)
116  {
117  return false;
118  }
119  break;
120  }
121  return true;
122  }
127  {
128  return maxLength;
129  }
130 
134  void setMaximumLength(double _maximumLength)
135  {
136  this->maximumLength = _maximumLength;
137  }
138 
143  {
144  return op;
145  }
146 
151  {
152  op = _op;
153  }
154 
158  virtual const char* getSelectorName()
159  {
160  return typeid(this).name();
161  }
162 
163 protected:
164  double maxLength;
167 };
168 
169 #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
: Rejects rays which have traveled a distance greater than a given length
virtual bool insertWithTest(T *r)
Select the ray if it respects the criteria of this Selector.
virtual void insert(T *r, unsigned long long &replace)
Keep the ray.
virtual const char * getSelectorName()
Return the class type of the selector.
virtual Selector< T > * Copy()
Copy Selector.
void setMaximumLength(double _maximumLength)
Set the maximal length.
double getMaximumLength()
Get the maximal length.
OPERATOR getOperator()
Get the OPERATOR of this Selector.
double maxLength
Maximal length criteria.
void setOperator(OPERATOR _op)
Set the OPERATOR of this Selector.
LengthSelector(double _maxLength=2000, OPERATOR _op=LESS_OR_EQUAL)
Default 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.
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