Code_TYMPAN  4.4.0
Industrial site acoustic simulation
Ray.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 RAY_H
17 #define RAY_H
18 
19 #include <memory>
20 #include <boost/shared_ptr.hpp>
21 
22 #include "Base.h"
23 #include "Geometry/mathlib.h"
24 #include "Acoustic/Source.h"
25 #include "Acoustic/Event.h"
26 #include "Acoustic/Diffraction.h"
27 
28 using namespace std;
29 
30 typedef std::pair<bitSet, bitSet> signature;
37 class Ray : public Base
38 {
39 
40 public:
42  Ray()
43  : Base(), position(), direction(), mint(0), maxt(100000), source(NULL), recepteur(NULL),
44  nbReflexion(0), nbDiffraction(0), cumulDistance(0.), cumulDelta(0.)
45  {
46  name = "unknow ray";
47  }
48 
49  Ray(const vec3& _position, const vec3& _direction)
50  : Base(), position(_position), direction(_direction), mint(0), maxt(100000), source(NULL),
51  recepteur(NULL), nbReflexion(0), nbDiffraction(0), cumulDistance(0.), cumulDelta(0.)
52  {
53  name = "unknow ray";
54  }
56  Ray(const Ray& other) : Base(other)
57  {
58  position = vec3(other.position);
59  direction = vec3(other.direction);
60  mint = other.mint;
61  maxt = other.maxt;
62  source = other.source;
63  recepteur = other.recepteur;
64  constructId = other.constructId;
65  for (unsigned int i = 0; i < other.events.size(); i++)
66  {
67  events.push_back(other.events.at(i));
68  }
69 
70  nbDiffraction = other.nbDiffraction;
71  nbReflexion = other.nbReflexion;
72  cumulDistance = other.cumulDistance;
73  cumulDelta = other.cumulDelta;
74  }
75 
76  Ray(Ray* other)
77  {
78  position = vec3(other->position);
79  direction = vec3(other->direction);
80  mint = other->mint;
81  maxt = other->maxt;
82  source = other->source;
83  recepteur = other->recepteur;
84  constructId = other->constructId;
85  for (unsigned int i = 0; i < other->events.size(); i++)
86  {
87  events.push_back(other->events.at(i));
88  }
89 
90  nbDiffraction = other->nbDiffraction;
91  nbReflexion = other->nbReflexion;
92  cumulDistance = other->cumulDistance;
93  cumulDelta = other->cumulDelta;
94  }
96  virtual ~Ray() {}
97 
102  decimal computeEventsSequenceLength();
103 
108  void computeLongueur();
109 
118  decimal computeTrueLength(const vec3& ref, const vec3& lastPos, vec3& closestPoint);
119 
125  decimal computePertinentLength(const vec3& ref, const vec3& lastPos, vec3& closestPoint);
126 
131  Base* getLastPertinentEventOrSource(typeevent evType = DIFFRACTION);
132 
138  {
139  if (dynamic_cast<Source*>(ev))
140  {
141  // if ev is the source
142  return dynamic_cast<Source*>(ev)->getPosition();
143  }
144  else
145  {
146  // if ev is a standard event
147  return dynamic_cast<Event*>(ev)->getPosition();
148  }
149  }
150 
156  double getLongueur() const
157  {
158  return longueur;
159  }
160 
166  unsigned int getDiff() const
167  {
168  return nbDiffraction;
169  }
170 
176  unsigned int getReflex() const
177  {
178  return nbReflexion;
179  }
180 
185  unsigned int getNbEvents() const
186  {
187  return nbDiffraction + nbReflexion;
188  }
189 
195  std::vector<boost::shared_ptr<Event>>* getEvents()
196  {
197  return &events;
198  }
199 
205  const std::vector<boost::shared_ptr<Event>>* getEvents() const
206  {
207  return &events;
208  }
209 
214  vector<unsigned int> getFaceHistory();
215 
220  vector<unsigned int> getPrimitiveHistory();
221 
228  {
229  return source;
230  }
231 
237  void* getRecepteur()
238  {
239  return recepteur;
240  }
241 
246  signature getSignature(const typeevent& typeEv = SPECULARREFLEXION);
247 
253  decimal getThickness(const decimal& distance, bool diffraction);
254 
260  decimal getSolidAngle(bool& diffraction);
261 
266  inline bitSet getSRBitSet(const unsigned int& source_id, const unsigned int& receptor_id)
267  {
268  // The source id is stored in 12 bits, receptor is stored in 20 bits
269  assert((source_id < 4096) && (receptor_id < 1048576));
270  bitSet SR = source_id;
271  SR = SR << 20;
272  return SR += receptor_id;
273  }
274 
279  bitSet getEventsBitSet(const typeevent& typeEv);
280 
287  {
288  return cumulDelta;
289  }
290 
297  {
298  return cumulDistance;
299  }
300 
306  unsigned long long int getConstructId() const
307  {
308  return constructId;
309  }
310 
316  decimal getMint() const
317  {
318  return mint;
319  }
320 
326  decimal getMaxt() const
327  {
328  return maxt;
329  }
330 
337  {
338  return finalPosition;
339  }
340 
347  {
348  return direction;
349  }
350 
357  {
358  return position;
359  }
360 
366  void setPosition(vec3 _position)
367  {
368  position = _position;
369  }
370 
376  void setDirection(vec3 _direction)
377  {
378  direction = _direction;
379  }
380 
386  void setFinalPosition(vec3 _finalPosition)
387  {
388  finalPosition = _finalPosition;
389  }
390 
396  void setMint(decimal _mint)
397  {
398  mint = _mint;
399  }
400 
406  void setMaxt(decimal _maxt)
407  {
408  maxt = _maxt;
409  }
410 
416  void setSource(Source* _source)
417  {
418  source = _source;
419  }
420 
426  void setRecepteur(void* _recepteur)
427  {
428  recepteur = _recepteur;
429  }
430 
436  void setLongueur(decimal _longueur)
437  {
438  longueur = _longueur;
439  }
440 
446  void setConstructId(unsigned long long int _constructId)
447  {
448  constructId = _constructId;
449  }
450 
456  void setNbReflexion(unsigned int _nbReflexion)
457  {
458  nbReflexion = _nbReflexion;
459  }
460 
466  void setNbDiffraction(unsigned int _nbDiffraction)
467  {
468  nbDiffraction = _nbDiffraction;
469  }
470 
476  void setCumulDistance(decimal _cumulDistance)
477  {
478  cumulDistance = _cumulDistance;
479  }
480 
486  void setCumulDelta(decimal _cumulDelta)
487  {
488  cumulDelta = _cumulDelta;
489  }
490 
496  void addEvent(boost::shared_ptr<Event> _event)
497  {
498  events.push_back(_event);
499  }
500 
501  vector<unsigned int> getEventSignature();
502 
503 protected:
510  void* recepteur;
512  unsigned long long int constructId;
513  unsigned int nbReflexion;
514  unsigned int nbDiffraction;
517  std::vector<boost::shared_ptr<Event>> events;
518 };
519 
520 #endif
typeevent
Definition: Event.h:24
@ DIFFRACTION
Definition: Event.h:27
@ SPECULARREFLEXION
Definition: Event.h:26
std::pair< bitSet, bitSet > signature
Definition: Ray.h:30
const char * name
Base class of Event, Material, PostFilter, Ray, Repere, Scene, Shape, Simulation, Source.
Definition: Base.h:25
Class describing an event (reflection, diffraction, ...)
Definition: Event.h:37
: Describes a ray by a pair of unsigned int. The first one gives the source number (in the range 0-40...
Definition: Ray.h:38
decimal cumulDistance
Cumulative length since last valid reflexion.
Definition: Ray.h:515
void setDirection(vec3 _direction)
set the direction if the ray
Definition: Ray.h:376
unsigned int getReflex() const
Return the reflections number encountered by the ray.
Definition: Ray.h:176
decimal cumulDelta
Cumulative difference by the ray computed at each step.
Definition: Ray.h:516
void setPosition(vec3 _position)
set the starting point ray
Definition: Ray.h:366
void setNbDiffraction(unsigned int _nbDiffraction)
set the diffractions number for the ray
Definition: Ray.h:466
const std::vector< boost::shared_ptr< Event > > * getEvents() const
Return the events array encountered by the ray.
Definition: Ray.h:205
unsigned int nbReflexion
Reflections number for the ray.
Definition: Ray.h:513
void * getRecepteur()
Return the ray receptor.
Definition: Ray.h:237
vec3 direction
Direction vector for the ray at the source.
Definition: Ray.h:505
Ray()
Constructors.
Definition: Ray.h:42
std::vector< boost::shared_ptr< Event > > events
Events list for the ray.
Definition: Ray.h:517
void setFinalPosition(vec3 _finalPosition)
set the ending point of the ray
Definition: Ray.h:386
void setRecepteur(void *_recepteur)
set the pointer to the receptor of the ray
Definition: Ray.h:426
bitSet getSRBitSet(const unsigned int &source_id, const unsigned int &receptor_id)
Compute the bitSet associated with a source and a receptor.
Definition: Ray.h:266
Ray(Ray *other)
Definition: Ray.h:76
Source * source
Pointer to the source of the ray.
Definition: Ray.h:509
Source * getSource()
Return the ray source.
Definition: Ray.h:227
decimal getMaxt() const
Return maxt.
Definition: Ray.h:326
decimal getMint() const
Return mint.
Definition: Ray.h:316
void setCumulDistance(decimal _cumulDistance)
set the cumulative distance by the ray computed at each step
Definition: Ray.h:476
vec3 finalPosition
Ending point of the ray.
Definition: Ray.h:506
void * recepteur
Pointer to the receptor of the ray.
Definition: Ray.h:510
void setNbReflexion(unsigned int _nbReflexion)
set the reflections number for the ray
Definition: Ray.h:456
vec3 getPosition() const
Return starting point ray.
Definition: Ray.h:356
Ray(const vec3 &_position, const vec3 &_direction)
Definition: Ray.h:49
vec3 getDirection() const
Return direction of the ray.
Definition: Ray.h:346
unsigned long long int getConstructId() const
Return Ray id.
Definition: Ray.h:306
Ray(const Ray &other)
Copy constructors.
Definition: Ray.h:56
decimal mint
Definition: Ray.h:507
void setMaxt(decimal _maxt)
set the maxt
Definition: Ray.h:406
decimal getCumulDelta() const
Return the cumulative difference between the rays length and its length when ignoring diffractions an...
Definition: Ray.h:286
void setSource(Source *_source)
set the pointer to the source of the ray
Definition: Ray.h:416
decimal longueur
Distance traveled by the ray.
Definition: Ray.h:511
unsigned long long int constructId
Ray id.
Definition: Ray.h:512
decimal maxt
Definition: Ray.h:508
void setCumulDelta(decimal _cumulDelta)
set the cumulative walking step difference by the ray computed at each step
Definition: Ray.h:486
unsigned int getDiff() const
Return the diffractions number encountered by the ray.
Definition: Ray.h:166
void setMint(decimal _mint)
set the Mint
Definition: Ray.h:396
double getLongueur() const
Return the traveled distance by the ray.
Definition: Ray.h:156
vec3 position
Starting point ray.
Definition: Ray.h:504
vec3 computeLocalOrigin(Base *ev)
Return position of ev which might be a source or an event.
Definition: Ray.h:137
void addEvent(boost::shared_ptr< Event > _event)
Definition: Ray.h:496
virtual ~Ray()
Destructor.
Definition: Ray.h:96
vec3 getFinalPosition() const
Return ending point of the ray (this ending point is set when a the ray hits a receptor in engine....
Definition: Ray.h:336
void setConstructId(unsigned long long int _constructId)
set the ray id
Definition: Ray.h:446
unsigned int nbDiffraction
Diffractions number for the ray.
Definition: Ray.h:514
void setLongueur(decimal _longueur)
set the distance traveled by the ray
Definition: Ray.h:436
decimal getCumulDistance() const
Return the cumulative length since the last reflection event.
Definition: Ray.h:296
unsigned int getNbEvents() const
Return the total number of events.
Definition: Ray.h:185
std::vector< boost::shared_ptr< Event > > * getEvents()
Return the events array encountered by the ray.
Definition: Ray.h:195
Acoustic source class.
Definition: Source.h:33
float decimal
Definition: mathlib.h:45
base_vec3< decimal > vec3
Definition: mathlib.h:381
unsigned int bitSet
Definition: mathlib.h:47