Code_TYMPAN  4.2.0
Industrial site acoustic simulation
LengthSelector.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 LENGTH_SELECTOR
17 #define LENGTH_SELECTOR
18 
19 #include "Selector.h"
20 
24 template<typename T>
25 class LengthSelector : public Selector<T>
26 {
27 public :
29  LengthSelector(double _maxLength = 2000, OPERATOR _op = LESS_OR_EQUAL) : Selector<T>() { maxLength = _maxLength; op = _op;}
30  virtual Selector<T>* Copy()
31  {
32  LengthSelector* newSelector = new LengthSelector(maxLength);
33  newSelector->setIsDeletable(this->deletable);
34  newSelector->setOperator(op);
35  return newSelector;
36  }
37 
38  virtual SELECTOR_RESPOND canBeInserted(T* r, unsigned long long& replace)
39  {
40  r->computeLongueur();
41  switch (op)
42  {
43  case LESS:
44  if (r->getLongueur() >= maxLength)
45  {
46  return SELECTOR_REJECT;
47  }
48  break;
49  case LESS_OR_EQUAL:
50  if (r->getLongueur() > maxLength)
51  {
52  return SELECTOR_REJECT;
53  }
54  break;
55  case EQUAL:
56  if (r->getLongueur() != maxLength)
57  {
58  return SELECTOR_REJECT;
59  }
60  break;
61  case GREATER_OR_EQUAL:
62  if (r->getLongueur() < maxLength)
63  {
64  return SELECTOR_REJECT;
65  }
66  break;
67  case GREATER:
68  if (r->getLongueur() <= maxLength)
69  {
70  return SELECTOR_REJECT;
71  }
72  break;
73  }
74  return SELECTOR_ACCEPT;
75  }
77  virtual void insert(T* r, unsigned long long& replace) { return; }
78 
79  virtual bool insertWithTest(T* r)
80  {
81  r->computeLongueur();
82  switch (op)
83  {
84  case LESS:
85  if (r->getLongueur() >= maxLength)
86  {
87  return false;
88  }
89  break;
90  case LESS_OR_EQUAL:
91  if (r->getLongueur() > maxLength)
92  {
93  return false;
94  }
95  break;
96  case EQUAL:
97  if (r->getLongueur() != maxLength)
98  {
99  return false;
100  }
101  break;
102  case GREATER_OR_EQUAL:
103  if (r->getLongueur() < maxLength)
104  {
105  return false;
106  }
107  break;
108  case GREATER:
109  if (r->getLongueur() <= maxLength)
110  {
111  return false;
112  }
113  break;
114  }
115  return true;
116  }
120  double getMaximumLength() { return maxLength; }
121 
125  void setMaximumLength(double _maximumLength) { this->maximumLength = _maximumLength; }
126 
130  OPERATOR getOperator() { return op; }
131 
135  void setOperator(OPERATOR _op) { op = _op; }
136 
140  virtual const char* getSelectorName(){
141  return typeid(this).name();
142  }
143 
144 protected:
145  double maxLength;
147 
148 };
149 
150 #endif
const char * name
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
virtual const char * getSelectorName()
Return the class type of the selector.
double maxLength
Maximal length criteria.
: Rejects rays which have traveled a distance greater than a given length
virtual Selector< T > * Copy()
Copy Selector.
virtual void insert(T *r, unsigned long long &replace)
Keep the ray.
OPERATOR getOperator()
Get the OPERATOR of this Selector.
OPERATOR
Definition: Selector.h:30
void setOperator(OPERATOR _op)
Set the OPERATOR of this Selector.
double getMaximumLength()
Get the maximal length.
Base class for Selector (used to keep or disable rays according different criterias) ...
Definition: Selector.h:77
Definition: Selector.h:34
OPERATOR op
OPERATOR used (by default LESS_OR_EQUAL, which means this Selector keeps only ray with travelled dist...
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.
LengthSelector(double _maxLength=2000, OPERATOR _op=LESS_OR_EQUAL)
Default constructor.
virtual bool insertWithTest(T *r)
Select the ray if it respects the criteria of this Selector.
void setIsDeletable(bool _isDeletable)
Set deletable flag.
Definition: Selector.h:92
void setMaximumLength(double _maximumLength)
Set the maximal length.