Code_TYMPAN  4.4.0
Industrial site acoustic simulation
Ray.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
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),
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),
52  {
53  name = "unknow ray";
54  this->direction.normalize();
55  }
57  Ray(const Ray& other) : Base(other)
58  {
59  position = vec3(other.position);
60  direction = vec3(other.direction);
61  mint = other.mint;
62  maxt = other.maxt;
63  source = other.source;
64  recepteur = other.recepteur;
65  constructId = other.constructId;
66  for (unsigned int i = 0; i < other.events.size(); i++)
67  {
68  events.push_back(other.events.at(i));
69  }
70 
72  nbReflexion = other.nbReflexion;
74  cumulDelta = other.cumulDelta;
75  }
76 
77  Ray(Ray* other)
78  {
79  position = vec3(other->position);
80  direction = vec3(other->direction);
81  mint = other->mint;
82  maxt = other->maxt;
83  source = other->source;
84  recepteur = other->recepteur;
85  constructId = other->constructId;
86  for (unsigned int i = 0; i < other->events.size(); i++)
87  {
88  events.push_back(other->events.at(i));
89  }
90 
92  nbReflexion = other->nbReflexion;
94  cumulDelta = other->cumulDelta;
95  }
97  virtual ~Ray() {}
98 
104 
109  void computeLongueur();
110 
119  decimal computeTrueLength(const vec3& ref, const vec3& lastPos, vec3& closestPoint);
120 
126  decimal computePertinentLength(const vec3& ref, const vec3& lastPos, vec3& closestPoint);
127 
133 
139  {
140  if (dynamic_cast<Source*>(ev))
141  {
142  // if ev is the source
143  return dynamic_cast<Source*>(ev)->getPosition();
144  }
145  else
146  {
147  // if ev is a standard event
148  return dynamic_cast<Event*>(ev)->getPosition();
149  }
150  }
151 
157  double getLongueur() const
158  {
159  return longueur;
160  }
161 
167  unsigned int getDiff() const
168  {
169  return nbDiffraction;
170  }
171 
177  unsigned int getReflex() const
178  {
179  return nbReflexion;
180  }
181 
186  unsigned int getNbEvents() const
187  {
188  return nbDiffraction + nbReflexion;
189  }
190 
196  std::vector<boost::shared_ptr<Event>>* getEvents()
197  {
198  return &events;
199  }
200 
206  const std::vector<boost::shared_ptr<Event>>* getEvents() const
207  {
208  return &events;
209  }
210 
215  std::vector<unsigned int> getFaceHistory();
216 
221  std::vector<unsigned int> getPrimitiveHistory();
222 
229  {
230  return source;
231  }
232 
238  void* getRecepteur()
239  {
240  return recepteur;
241  }
242 
248 
254  decimal getThickness(const decimal& distance, bool diffraction);
255 
261  decimal getSolidAngle(bool& diffraction);
262 
267  inline bitSet getSRBitSet(const unsigned int& source_id, const unsigned int& receptor_id)
268  {
269  // The source id is stored in 12 bits, receptor is stored in 20 bits
270  assert((source_id < 4096) && (receptor_id < 1048576));
271  bitSet SR = source_id;
272  SR = SR << 20;
273  return SR += receptor_id;
274  }
275 
280  bitSet getEventsBitSet(const typeevent& typeEv);
281 
288  {
289  return cumulDelta;
290  }
291 
298  {
299  return cumulDistance;
300  }
301 
307  unsigned long long int getConstructId() const
308  {
309  return constructId;
310  }
311 
317  decimal getMint() const
318  {
319  return mint;
320  }
321 
327  decimal getMaxt() const
328  {
329  return maxt;
330  }
331 
338  {
339  return finalPosition;
340  }
341 
348  {
349  return direction;
350  }
351 
358  {
359  return position;
360  }
361 
367  void setPosition(vec3 _position)
368  {
369  position = _position;
370  }
371 
377  void setDirection(vec3 _direction)
378  {
379  direction = _direction;
380  direction.normalize();
381  }
382 
388  void setFinalPosition(vec3 _finalPosition)
389  {
390  finalPosition = _finalPosition;
391  }
392 
398  void setMint(decimal _mint)
399  {
400  mint = _mint;
401  }
402 
408  void setMaxt(decimal _maxt)
409  {
410  maxt = _maxt;
411  }
412 
418  void setSource(Source* _source)
419  {
420  source = _source;
421  }
422 
428  void setRecepteur(void* _recepteur)
429  {
430  recepteur = _recepteur;
431  }
432 
438  void setLongueur(decimal _longueur)
439  {
440  longueur = _longueur;
441  }
442 
448  void setConstructId(unsigned long long int _constructId)
449  {
450  constructId = _constructId;
451  }
452 
458  void setNbReflexion(unsigned int _nbReflexion)
459  {
460  nbReflexion = _nbReflexion;
461  }
462 
468  void setNbDiffraction(unsigned int _nbDiffraction)
469  {
470  nbDiffraction = _nbDiffraction;
471  }
472 
478  void setCumulDistance(decimal _cumulDistance)
479  {
480  cumulDistance = _cumulDistance;
481  }
482 
488  void setCumulDelta(decimal _cumulDelta)
489  {
490  cumulDelta = _cumulDelta;
491  }
492 
498  void addEvent(boost::shared_ptr<Event> _event)
499  {
500  events.push_back(_event);
501  }
502 
503  std::vector<unsigned int> getEventSignature();
504 
505 protected:
512  void* recepteur;
514  unsigned long long int constructId;
515  unsigned int nbReflexion;
516  unsigned int nbDiffraction;
519  std::vector<boost::shared_ptr<Event>> events;
520 };
521 
522 #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
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
: 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:517
void setDirection(vec3 _direction)
set the direction if the ray
Definition: Ray.h:377
unsigned int getReflex() const
Return the reflections number encountered by the ray.
Definition: Ray.h:177
decimal cumulDelta
Cumulative difference by the ray computed at each step.
Definition: Ray.h:518
void setPosition(vec3 _position)
set the starting point ray
Definition: Ray.h:367
void setNbDiffraction(unsigned int _nbDiffraction)
set the diffractions number for the ray
Definition: Ray.h:468
const std::vector< boost::shared_ptr< Event > > * getEvents() const
Return the events array encountered by the ray.
Definition: Ray.h:206
unsigned int nbReflexion
Reflections number for the ray.
Definition: Ray.h:515
void * getRecepteur()
Return the ray receptor.
Definition: Ray.h:238
vec3 direction
Direction vector for the ray at the source.
Definition: Ray.h:507
Ray()
Constructors.
Definition: Ray.h:42
decimal computeTrueLength(const vec3 &ref, const vec3 &lastPos, vec3 &closestPoint)
Compute ray length from source to closestPoint.
Definition: Ray.cpp:101
std::vector< boost::shared_ptr< Event > > events
Events list for the ray.
Definition: Ray.h:519
void setFinalPosition(vec3 _finalPosition)
set the ending point of the ray
Definition: Ray.h:388
void setRecepteur(void *_recepteur)
set the pointer to the receptor of the ray
Definition: Ray.h:428
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:267
decimal getSolidAngle(bool &diffraction)
Compute the solid angle associated with the ray (depends on the type of source which generated the ra...
Definition: Ray.cpp:276
Ray(Ray *other)
Definition: Ray.h:77
Source * source
Pointer to the source of the ray.
Definition: Ray.h:511
Source * getSource()
Return the ray source.
Definition: Ray.h:228
decimal getMaxt() const
Return maxt.
Definition: Ray.h:327
std::vector< unsigned int > getPrimitiveHistory()
Return the array of primitives id encountered by the ray.
Definition: Ray.cpp:251
decimal getMint() const
Return mint.
Definition: Ray.h:317
void setCumulDistance(decimal _cumulDistance)
set the cumulative distance by the ray computed at each step
Definition: Ray.h:478
vec3 finalPosition
Ending point of the ray.
Definition: Ray.h:508
void * recepteur
Pointer to the receptor of the ray.
Definition: Ray.h:512
void setNbReflexion(unsigned int _nbReflexion)
set the reflections number for the ray
Definition: Ray.h:458
decimal getThickness(const decimal &distance, bool diffraction)
Compute the thickness of the ray after having traveled a certain distance depending on the type of so...
Definition: Ray.cpp:264
vec3 getPosition() const
Return starting point ray.
Definition: Ray.h:357
Base * getLastPertinentEventOrSource(typeevent evType=DIFFRACTION)
Return a pointer to the last event of type evType or source if none.
Definition: Ray.cpp:223
Ray(const vec3 &_position, const vec3 &_direction)
Definition: Ray.h:49
std::vector< unsigned int > getEventSignature()
Definition: Ray.cpp:307
vec3 getDirection() const
Return direction of the ray.
Definition: Ray.h:347
unsigned long long int getConstructId() const
Return Ray id.
Definition: Ray.h:307
signature getSignature(const typeevent &typeEv=SPECULARREFLEXION)
Compute the signature (i.e. std::pair<unsigned int, unsigned int>) of the ray)
Definition: Ray.cpp:299
Ray(const Ray &other)
Copy constructors.
Definition: Ray.h:57
decimal mint
Definition: Ray.h:509
std::vector< unsigned int > getFaceHistory()
Return the array of faces id encountered by the ray.
Definition: Ray.cpp:238
void setMaxt(decimal _maxt)
set the maxt
Definition: Ray.h:408
decimal getCumulDelta() const
Return the cumulative difference between the rays length and its length when ignoring diffractions an...
Definition: Ray.h:287
void setSource(Source *_source)
set the pointer to the source of the ray
Definition: Ray.h:418
bitSet getEventsBitSet(const typeevent &typeEv)
Compute the bitSet associated with a list of events of type evType.
Definition: Ray.cpp:320
decimal computePertinentLength(const vec3 &ref, const vec3 &lastPos, vec3 &closestPoint)
Compute ray length from last pertinent event (i.e. source or last diffraction) to the nearest point o...
Definition: Ray.cpp:147
decimal longueur
Distance traveled by the ray.
Definition: Ray.h:513
unsigned long long int constructId
Ray id.
Definition: Ray.h:514
decimal maxt
Definition: Ray.h:510
decimal computeEventsSequenceLength()
Compute the length of the sequence of events.
Definition: Ray.cpp:74
void setCumulDelta(decimal _cumulDelta)
set the cumulative walking step difference by the ray computed at each step
Definition: Ray.h:488
unsigned int getDiff() const
Return the diffractions number encountered by the ray.
Definition: Ray.h:167
void setMint(decimal _mint)
set the Mint
Definition: Ray.h:398
double getLongueur() const
Return the traveled distance by the ray.
Definition: Ray.h:157
vec3 position
Starting point ray.
Definition: Ray.h:506
vec3 computeLocalOrigin(Base *ev)
Return position of ev which might be a source or an event.
Definition: Ray.h:138
void addEvent(boost::shared_ptr< Event > _event)
Definition: Ray.h:498
virtual ~Ray()
Destructor.
Definition: Ray.h:97
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:337
void setConstructId(unsigned long long int _constructId)
set the ray id
Definition: Ray.h:448
unsigned int nbDiffraction
Diffractions number for the ray.
Definition: Ray.h:516
void setLongueur(decimal _longueur)
set the distance traveled by the ray
Definition: Ray.h:438
decimal getCumulDistance() const
Return the cumulative length since the last reflection event.
Definition: Ray.h:297
unsigned int getNbEvents() const
Return the total number of events.
Definition: Ray.h:186
void computeLongueur()
Compute the distance traveled (length) by the ray and the result is set into the longueur attribute.
Definition: Ray.cpp:22
std::vector< boost::shared_ptr< Event > > * getEvents()
Return the events array encountered by the ray.
Definition: Ray.h:196
Acoustic source class.
Definition: Source.h:33
float decimal
Definition: mathlib.h:45
base_vec3< decimal > vec3
Definition: mathlib.h:387
unsigned int bitSet
Definition: mathlib.h:47