Code_TYMPAN  4.4.0
Industrial site acoustic simulation
FermatSelector.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 FERMAT_SELECTOR
17 #define FERMAT_SELECTOR
18 
19 #include "Selector.h"
20 
26 template <typename T> class FermatSelector : public Selector<T>
27 {
28 public:
31  virtual Selector<T>* Copy()
32  {
33  FermatSelector* newSelector = new FermatSelector();
34  newSelector->setIsDeletable(this->deletable);
35  return newSelector;
36  }
37 
38  virtual SELECTOR_RESPOND canBeInserted(T* r, unsigned long long& replace)
39  {
40  vec3 receptorPos(static_cast<Recepteur*>(r->getRecepteur())->getPosition());
41  vec3 finalPos(r->getFinalPosition());
42 
43  vec3 closestPoint;
44  // find closest position (closestPoint) from the receptor on the segment receptorPos-finalPos and
45  // compute the trueLength (ray length from source to closestPoint)
46  decimal trueLength = r->computeTrueLength(receptorPos, finalPos, closestPoint);
47 
48  // compute the thickness of the ray for the previsouly computed trueLength
49  decimal epaisseur = r->getThickness(trueLength, false);
50 
51  // compute the distance from the receptor and its closest point on the ray
52  decimal closestDistance =
53  static_cast<Recepteur*>(r->getRecepteur())->getPosition().distance(closestPoint);
54 
55  // ray should be rejected if the receptor is outside the cone of the ray (i.e thickness/2 <=
56  // closestsDistance)
57  if (closestDistance >= (epaisseur / 2.))
58  {
59  return SELECTOR_REJECT;
60  }
61 
62  return SELECTOR_ACCEPT;
63  }
65  virtual void insert(T* r, unsigned long long& replace)
66  {
67  return;
68  }
69 
70  virtual bool insertWithTest(T* r)
71  {
72  vec3 receptorPos(static_cast<Recepteur*>(r->getRecepteur())->getPosition());
73  vec3 finalPos(r->getFinalPosition());
74 
75  vec3 closestPoint;
76  // find closest position (closestPoint) from the receptor on the segment receptorPos-finalPos ray and
77  // compute the trueLength (ray length from source to closestPoint)
78  decimal trueLength = r->computeTrueLength(receptorPos, finalPos, closestPoint);
79 
80  // compute the thickness of the ray for the previsouly computed trueLength
81  decimal epaisseur = r->getThickness(trueLength, false);
82 
83  // compute the distance from the receptor and its closest point on the ray
84  decimal closestDistance =
85  static_cast<Recepteur*>(r->getRecepteur())->getPosition().distance(closestPoint);
86 
87  // ray should be rejected if the receptor is outside the cone of the ray (i.e thickness/2 <=
88  // closestsDistance)
89  if (closestDistance >= (epaisseur / 2.))
90  {
91  return false;
92  }
93 
94  return true;
95  }
96 
100  virtual const char* getSelectorName()
101  {
102  return typeid(this).name();
103  }
104 
105 protected:
106 }; // FERMAT_SELECTOR
107 
108 #endif
SELECTOR_RESPOND
Definition: Selector.h:24
@ SELECTOR_ACCEPT
Definition: Selector.h:25
@ SELECTOR_REJECT
Definition: Selector.h:26
const char * name
: Rays can be seen as long cones that get thicker as their length increases based on their associated...
virtual const char * getSelectorName()
Return the class type of the selector.
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.
FermatSelector()
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 Selector< T > * Copy()
Copy Selector.
Receptor inherits from a Sphere Shape.
Definition: Recepteur.h:28
vec3 getPosition()
Get the center of the bounding box.
Definition: Recepteur.h:51
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
float decimal
Definition: mathlib.h:45
base_vec3< decimal > vec3
Definition: mathlib.h:381