Code_TYMPAN  4.4.0
Industrial site acoustic simulation
Event.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 EVENT_H
17 #define EVENT_H
18 
19 #include <vector>
20 #include "Geometry/Sampler.h"
21 #include "Base.h"
22 
24 {
25  UNKNOWN = -1,
28  NOTHING
29 };
30 
31 class Shape;
32 
36 class Event : public Base
37 {
38 public:
40  Event(const vec3& position = vec3(0.0, 0.0, 0.0), const vec3& incomingDirection = vec3(0.0, 0.0, 0.0),
41  Shape* _shape = NULL)
42  : Base(), pos(position), from(incomingDirection), nbResponseLeft(0), initialNbResponse(0),
43  sampler(NULL), shape(_shape), type(UNKNOWN)
44  {
45  name = "unknown event";
46  }
48  Event(const Event& other) : Base(other)
49  {
50  pos = vec3(other.pos);
51  from = vec3(other.pos);
54  type = other.type;
55  shape = other.shape;
56  if (other.sampler)
57  {
58  sampler = new Sampler(*(other.sampler));
59  }
60  else
61  {
62  sampler = NULL;
63  }
64  }
66  virtual ~Event()
67  {
68  if (sampler)
69  {
70  delete sampler;
71  }
72  };
73 
74  // Unused function:
75  // virtual bool isDiffuse() { return false; }
76 
82  const vec3& getPosition() const
83  {
84  return pos;
85  }
86 
92  void setPosition(const vec3& _pos)
93  {
94  pos = vec3(_pos);
95  }
96 
103  {
104  return from;
105  }
106 
112  void setIncomingDirection(const vec3& _from)
113  {
114  from = vec3(_from);
115  }
116 
119  {
120  return nbResponseLeft > 0;
121  }
124  {
125  return nbResponseLeft;
126  }
128  virtual void setNbResponseLeft(int _nbResponseLeft)
129  {
130  nbResponseLeft = _nbResponseLeft;
131  }
133  virtual int getInitialNbResponseLeft() const
134  {
135  return initialNbResponse;
136  }
137 
144  {
145  return shape;
146  }
147 
148  const Shape* getShape() const
149  {
150  return shape;
151  }
152 
157  void setShape(Shape* _shape)
158  {
159  shape = _shape;
160  }
161 
167  virtual bool getResponse(vec3& r, bool force = false)
168  {
169  return false;
170  }
171 
178  virtual bool isAcceptableResponse(vec3& test)
179  {
180  return false;
181  }
182 
183  virtual bool generateTest(std::vector<vec3>& succededTest, std::vector<vec3>& failTest,
184  unsigned int nbResponses)
185  {
186  return true;
187  }
188 
189  virtual bool generateResponse(std::vector<vec3>& responses, unsigned int nbResponses)
190  {
191  return false;
192  }
193 
194  virtual bool appendTarget(vec3 target, bool force = false)
195  {
196  return false;
197  }
198 
205  virtual int getType() const
206  {
207  return type;
208  }
209 
214  virtual void setType(const typeevent& _type)
215  {
216  type = _type;
217  }
218 
220  virtual double getAngle() const
221  {
222  return 0.0;
223  }
224 
230  const decimal distance(const Event& other) const
231  {
232  return this->pos.distance(other.getPosition());
233  }
234 
235 protected:
243 
244 #ifdef _ALLOW_TARGETING_
245  std::vector<vec3> targets;
246 #endif
247 };
248 
249 #endif
typeevent
Definition: Event.h:24
@ DIFFRACTION
Definition: Event.h:27
@ UNKNOWN
Definition: Event.h:25
@ SPECULARREFLEXION
Definition: Event.h:26
@ NOTHING
Definition: Event.h:28
Base class of Event, Material, PostFilter, Ray, Repere, Scene, Shape, Simulation, Source.
Definition: Base.h:25
std::string name
Each instantiated object may be named.
Definition: Base.h:52
Class describing an event (reflection, diffraction, ...)
Definition: Event.h:37
int nbResponseLeft
Number of remaining rays to launch.
Definition: Event.h:238
Shape * shape
The impact primitive.
Definition: Event.h:241
virtual bool getResponse(vec3 &r, bool force=false)
Return a direction vector for the impact. Ray direction vector in response of the event.
Definition: Event.h:167
vec3 from
Direction vector of the incoming ray.
Definition: Event.h:237
vec3 pos
Location point of the event.
Definition: Event.h:236
Shape * getShape()
Return the primitive of the impact.
Definition: Event.h:143
void setIncomingDirection(const vec3 &_from)
Set a new incoming vector.
Definition: Event.h:112
int initialNbResponse
Number of rays to launch after event.
Definition: Event.h:239
virtual int getType() const
Return the event type.
Definition: Event.h:205
virtual void setNbResponseLeft(int _nbResponseLeft)
Set the number of remaining rays to launch.
Definition: Event.h:128
typeevent type
Event type.
Definition: Event.h:242
virtual bool generateResponse(std::vector< vec3 > &responses, unsigned int nbResponses)
Definition: Event.h:189
const decimal distance(const Event &other) const
Return distance from another event.
Definition: Event.h:230
virtual int getInitialNbResponseLeft() const
Return the number of rays to launch after event.
Definition: Event.h:133
virtual bool generateTest(std::vector< vec3 > &succededTest, std::vector< vec3 > &failTest, unsigned int nbResponses)
Definition: Event.h:183
const Shape * getShape() const
Definition: Event.h:148
Sampler * sampler
Pointer to a Sampler.
Definition: Event.h:240
const vec3 & getPosition() const
Return a reference to the event location point.
Definition: Event.h:82
bool isReponseLeft()
Return true if it remains rays to launch.
Definition: Event.h:118
void setShape(Shape *_shape)
Set the impacted primitive of the event.
Definition: Event.h:157
virtual bool appendTarget(vec3 target, bool force=false)
Definition: Event.h:194
vec3 getIncomingDirection()
Return the direction of the incoming vector.
Definition: Event.h:102
Event(const Event &other)
Copy constructor.
Definition: Event.h:48
virtual double getAngle() const
Get incident angle.
Definition: Event.h:220
virtual ~Event()
Destructor.
Definition: Event.h:66
void setPosition(const vec3 &_pos)
Set a new point to the event.
Definition: Event.h:92
virtual bool isAcceptableResponse(vec3 &test)
Return true if the ray direction vector in response of the event is acceptable.
Definition: Event.h:178
int getNbResponseLeft()
Return the number of remaining rays to launch.
Definition: Event.h:123
Event(const vec3 &position=vec3(0.0, 0.0, 0.0), const vec3 &incomingDirection=vec3(0.0, 0.0, 0.0), Shape *_shape=NULL)
Default constructor.
Definition: Event.h:40
virtual void setType(const typeevent &_type)
Added by DTh to make possible simple test of rays.
Definition: Event.h:214
Sampler class and its sub-classes describe ray generators used in AcousticRayTracer....
Definition: Sampler.h:30
base class for shapes (Cylindre, Mesh, Sphere, Triangle,...)
Definition: Shape.h:57
float decimal
Definition: mathlib.h:45
base_vec3< decimal > vec3
Definition: mathlib.h:381