Code_TYMPAN  4.2.0
Industrial site acoustic simulation
CloseEventSelector.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 CLOSE_EVENT_SELECTOR
17 #define CLOSE_EVENT_SELECTOR
18 
19 #include "Geometry/Cylindre.h"
20 
21 #include "Selector.h"
22 
27 template<typename T>
28 class CloseEventSelector : public Selector<T>
29 {
30 public :
33  virtual Selector<T>* Copy()
34  {
35  CloseEventSelector* newSelector = new CloseEventSelector();
36  newSelector->setIsDeletable(this->deletable);
37  return newSelector;
38  }
39 
40  virtual SELECTOR_RESPOND canBeInserted(T* r, unsigned long long& replace)
41  {
42  vector<boost::shared_ptr<Event> >* events = r->getEvents();
43 
44  if (events->size() < 2) { return SELECTOR_ACCEPT; }
45 
46  for (unsigned int i = 0 ; i < events->size() - 1 ; i++)
47  {
48  boost::shared_ptr<Event> ev1 = events->at(i);
49  boost::shared_ptr<Event> ev2 = events->at(i + 1);
50  int type1 = events->at(i)->getType();
51  int type2 = events->at(i + 1)->getType();
52  Shape* sh1 = NULL, *sh2 = NULL, *sh3 = NULL;
53 
54  // if events type are different and occur on same shape, the ray is suppressed
55  // Note : Diffraction event have two faces
56  if ((type1 != type2))
57  {
58  if (type1 == DIFFRACTION)
59  {
60  sh1 = dynamic_cast<Cylindre*>(ev1->getShape())->getFirstShape();
61  sh2 = dynamic_cast<Cylindre*>(ev1->getShape())->getSecondShape();
62  sh3 = ev2->getShape();
63  }
64  else
65  {
66  sh1 = dynamic_cast<Cylindre*>(ev2->getShape())->getFirstShape();
67  sh2 = dynamic_cast<Cylindre*>(ev2->getShape())->getSecondShape();
68  sh3 = ev1->getShape();
69  }
70 
71  if ((sh3 == sh1) || (sh3 == sh2)) { return SELECTOR_REJECT; }
72  }
73  }
74 
75  return SELECTOR_ACCEPT;
76  }
77 
78  virtual bool insertWithTest(T* r)
79  {
80  vector<boost::shared_ptr<Event> >* events = r->getEvents();
81 
82  if (events->size() < 2) { return true; }
83 
84  for (unsigned int i = 0 ; i < events->size() - 1 ; i++)
85  {
86  boost::shared_ptr<Event> ev1 = events->at(i);
87  boost::shared_ptr<Event> ev2 = events->at(i + 1);
88  int type1 = events->at(i)->getType();
89  int type2 = events->at(i + 1)->getType();
90  Shape* sh1 = NULL, *sh2 = NULL, *sh3 = NULL;
91 
92  // if events type are different and occur on same shape, the ray is suppressed
93  // Note : Diffraction event have two faces
94  if ((type1 != type2))
95  {
96  if (type1 == DIFFRACTION)
97  {
98  sh1 = dynamic_cast<Cylindre*>(ev1->getShape())->getFirstShape();
99  sh2 = dynamic_cast<Cylindre*>(ev1->getShape())->getSecondShape();
100  sh3 = ev2->getShape();
101  }
102  else
103  {
104  sh1 = dynamic_cast<Cylindre*>(ev2->getShape())->getFirstShape();
105  sh2 = dynamic_cast<Cylindre*>(ev2->getShape())->getSecondShape();
106  sh3 = ev1->getShape();
107  }
108 
109  if ((sh3 == sh1) || (sh3 == sh2)) { return false; }
110  }
111  }
112 
113  return true;
114  }
115 
119  virtual const char* getSelectorName(){
120  return typeid(this).name();
121  }
122 
123 protected:
124 };
125 
126 #endif //CLOSE_EVENT_SELECTOR
CloseEventSelector()
Constructor.
const char * name
Cylinder class.
Definition: Cylindre.h:26
SELECTOR_RESPOND
Definition: Selector.h:23
bool deletable
Flag to know if the selector may be deleted or not.
Definition: Selector.h:103
Rejects a ray if two of its events occur on the same shape (for example a diffraction close to a refl...
virtual Selector< T > * Copy()
Copy Selector.
virtual bool insertWithTest(T *r)
Select the ray if it respects the criteria of this Selector.
Base class for Selector (used to keep or disable rays according different criterias) ...
Definition: Selector.h:77
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 const char * getSelectorName()
Return the class type of the selector.
void setIsDeletable(bool _isDeletable)
Set deletable flag.
Definition: Selector.h:92
base class for shapes (Cylindre, Mesh, Sphere, Triangle,...)
Definition: Shape.h:57