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