Code_TYMPAN  4.2.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>
27 class FermatSelector : public Selector<T>
28 {
29 public :
32  virtual Selector<T>* Copy()
33  {
34  FermatSelector* newSelector = new FermatSelector();
35  newSelector->setIsDeletable(this->deletable);
36  return newSelector;
37  }
38 
39  virtual SELECTOR_RESPOND canBeInserted(T* r, unsigned long long& replace)
40  {
41  vec3 receptorPos( static_cast<Recepteur*> (r->getRecepteur())->getPosition() );
42  vec3 finalPos( r->getFinalPosition() );
43 
44  vec3 closestPoint;
45  //find closest position (closestPoint) from the receptor on the segment receptorPos-finalPos and 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 = static_cast<Recepteur*> ( r->getRecepteur() )->getPosition().distance(closestPoint);
53 
54  //ray should be rejected if the receptor is outside the cone of the ray (i.e thickness/2 <= closestsDistance)
55  if ( closestDistance >= ( epaisseur/2. ) )
56  {
57  return SELECTOR_REJECT;
58  }
59 
60  return SELECTOR_ACCEPT;
61  }
63  virtual void insert(T* r, unsigned long long& replace) { return; }
64 
65  virtual bool insertWithTest(T* r)
66  {
67  vec3 receptorPos( static_cast<Recepteur*> (r->getRecepteur())->getPosition() );
68  vec3 finalPos( r->getFinalPosition() );
69 
70  vec3 closestPoint;
71  //find closest position (closestPoint) from the receptor on the segment receptorPos-finalPos ray and compute the trueLength (ray length from source to closestPoint)
72  decimal trueLength = r->computeTrueLength(receptorPos, finalPos, closestPoint);
73 
74  //compute the thickness of the ray for the previsouly computed trueLength
75  decimal epaisseur = r->getThickness( trueLength, false );
76 
77  //compute the distance from the receptor and its closest point on the ray
78  decimal closestDistance = static_cast<Recepteur*> ( r->getRecepteur() )->getPosition().distance(closestPoint);
79 
80  //ray should be rejected if the receptor is outside the cone of the ray (i.e thickness/2 <= closestsDistance)
81  if ( closestDistance >= ( epaisseur/2.) )
82  {
83  return false;
84  }
85 
86  return true;
87  }
88 
92  virtual const char* getSelectorName(){
93  return typeid(this).name();
94  }
95 
96 protected:
97 }; // FERMAT_SELECTOR
98 
99 #endif
virtual void insert(T *r, unsigned long long &replace)
Keep the ray.
const char * name
SELECTOR_RESPOND
Definition: Selector.h:23
FermatSelector()
Constructor.
bool deletable
Flag to know if the selector may be deleted or not.
Definition: Selector.h:103
base_vec3< decimal > vec3
Definition: mathlib.h:269
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.
: Rays can be seen as long cones that get thicker as their length increases based on their associated...
Base class for Selector (used to keep or disable rays according different criterias) ...
Definition: Selector.h:77
float decimal
Definition: mathlib.h:46
virtual const char * getSelectorName()
Return the class type of the selector.
virtual Selector< T > * Copy()
Copy Selector.
void setIsDeletable(bool _isDeletable)
Set deletable flag.
Definition: Selector.h:92
virtual bool insertWithTest(T *r)
Select the ray if it respects the criteria of this Selector.
Receptor inherits from a Sphere Shape.
Definition: Recepteur.h:27