Helios++
Helios software for LiDAR simulations
DetailedVoxel.h
1 #pragma once
2 
3 #include <Voxel.h>
4 
12 class DetailedVoxel : public Voxel{
13  // *** BOOST SERIALIZATION *** //
14  // ***************************** //
15  friend class boost::serialization::access;
16  template <typename Archive>
17  void serialize(Archive &ar, const unsigned int version){
18  boost::serialization::void_cast_register<DetailedVoxel, Primitive>();
19  ar & boost::serialization::base_object<Voxel>(*this);
20  ar & intValues;
21  ar & doubleValues;
22  ar & maxPad;
23  ar & material;
24  }
25 protected:
26  // *** ATTRIBUTES *** //
27  // ******************** //
35  std::vector<int> intValues;
54  std::vector<double> doubleValues;
55 
59  std::map<std::string, size_t> identifiers = std::map<std::string, size_t>({
60  {"PadBVTotal", 0}, {"angleMean", 1}, {"bsEntering", 2},
61  {"bsIntercepted", 3}, {"bsPotential", 4}, {"ground_distance", 5},
62  {"lMeanTotal", 6}, {"lgTotal", 7}, {"transmittance", 8},
63  {"attenuation", 9}, {"attenuationBiasCorrection", 10}
64  });
65 
69  double maxPad = 0.0;
70 
71 public:
72  // *** CONSTRUCTION *** //
73  // ********************** //
77  DetailedVoxel() = default;
87  glm::dvec3 center,
88  double voxelSize,
89  std::vector<int> intValues,
90  std::vector<double> doubleValues
91  ) :
92  Voxel(center, voxelSize),
93  intValues(std::move(intValues)),
94  doubleValues(std::move(doubleValues))
95  {}
107  double x,
108  double y,
109  double z,
110  double halfVoxelSize,
111  std::vector<int> intValues,
112  std::vector<double> doubleValues
113  ) :
114  Voxel(x, y, z, halfVoxelSize),
115  intValues(std::move(intValues)),
116  doubleValues(std::move(doubleValues))
117  {}
118 
122  Primitive* clone() override;
126  void _clone(Primitive *p) override;
127 
128 
129 
130  // *** ACCESS OPERATORS *** //
131  // ************************** //
137  inline double & operator[] (size_t index)
138  {return doubleValues[index];}
144  inline double &operator[] (std::string const &id)
145  {return doubleValues[identifiers[id]];}
146 
147  // *** GETTERS and SETTERS *** //
148  // ***************************** //
153  inline int getNbEchos()
154  {return intValues[0];}
160  inline DetailedVoxel & setNbEchos(int const nbEchos)
161  {intValues[0] = nbEchos; return *this;}
166  inline int getNbSampling()
167  {return intValues[1];}
173  inline DetailedVoxel & setNbSampling(int nbSampling)
174  {intValues[1] = nbSampling; return *this;}
175 
176  // *** GETTERS and SETTERS *** //
177  // *************************** //
182  inline size_t getNumberOfIntValues() const
183  {return intValues.size();}
188  inline size_t getNumberOfDoubleValues() const
189  {return doubleValues.size();}
196  inline DetailedVoxel & setIntValue(size_t index, int value)
197  {intValues[index] = value; return *this;}
203  inline int getIntValue(size_t index) const
204  {return intValues[index];}
211  inline DetailedVoxel & setDoubleValue(size_t index, double value)
212  {doubleValues[index] = value; return *this;}
218  inline double getDoubleValue(size_t index) const
219  {return doubleValues[index];}
224  inline double getMaxPad() const {return maxPad;}
229  inline void setMaxPad(double maxPad) {this->maxPad = maxPad;}
230 
231  // *** M E T H O D S *** //
232  // *********************** //
238  inline bool canHandleIntersections() override {return true;}
244  NoiseSource<double> &uniformNoiseSource,
245  glm::dvec3 &rayDirection,
246  glm::dvec3 const &insideIntersectionPoint,
247  glm::dvec3 const &outsideIntersectionPoint,
248  double rayIntensity
249  ) override;
250 
255  NoiseSource<double> &uniformNoiseSource,
256  glm::dvec3 &rayDirection,
257  glm::dvec3 const &insideIntersectionPoint,
258  glm::dvec3 const &outsideIntersectionPoint,
259  double rayIntensity
260  );
265  NoiseSource<double> &uniformNoiseSource,
266  glm::dvec3 &rayDirection,
267  glm::dvec3 const &insideIntersectionPoint,
268  glm::dvec3 const &outsideIntersectionPoint,
269  double rayIntensity,
270  double scaleFactor
271  );
276  NoiseSource<double> &uniformNoiseSource,
277  glm::dvec3 &rayDirection,
278  glm::dvec3 const &insideIntersectionPoint,
279  glm::dvec3 const &outsideIntersectionPoint,
280  double rayIntensity,
281  double fixedSize
282  );
283 
287  void onFinishLoading(NoiseSource<double> &uniformNoiseSource) override;
288 
289  // *** S I G M A *** //
290  // ******************* //
295  {return part->ladlut != nullptr;}
299  double computeSigmaWithLadLut(glm::dvec3 const &direction) override;
300 };
301 
302 // *** BOOST SERIALIZATION *** //
303 // ***************************** //
304 /*
305  * Below code is commented because it is not necessary and it might cause
306  * memory leaks when called from external sources (i.e. from python)
307  */
308 /*namespace boost{
309 namespace serialization{
310  template<class Archive>
311  inline void save_construct_data(
312  Archive &ar, const DetailedVoxel *t, const unsigned int file_version
313  ){
314  ar << t->v.pos.x << t->v.pos.y << t->v.pos.z;
315  ar << t->halfSize;
316  ar << t->getMaxPad();
317  ar << t->getNumberOfIntValues();
318  for(size_t i = 0 ; i < t->getNumberOfIntValues() ; i++)
319  ar << t->getIntValue(i);
320  ar << t->getNumberOfDoubleValues();
321  for(size_t i = 0 ; i < t->getNumberOfDoubleValues() ; i++)
322  ar << t->getDoubleValue(i);
323  ar << t->material;
324  }
325 
326  template<class Archive>
327  inline void load_construct_data(
328  Archive &ar, DetailedVoxel *t, const unsigned int file_version
329  ){
330  double x = 0.0, y = 0.0, z = 0.0;
331  double halfVoxelSize = 0.0;
332  double maxPad = 0.0;
333  size_t nIntValues = 0;
334  int intVal = 0;
335  std::vector<int> intValues;
336  size_t nDoubleValues = 0;
337  double doubleVal = 0.0;
338  std::vector<double> doubleValues;
339  std::shared_ptr<Material> mat;
340 
341  ar >> x; ar >> y; ar >> z;
342  ar >> halfVoxelSize;
343  ar >> maxPad;
344  ar >> nIntValues;
345  for(size_t i = 0 ; i < nIntValues ; i++){
346  ar >> intVal;
347  intValues.push_back(intVal);
348  }
349  ar >> nDoubleValues;
350  for(size_t i = 0 ; i < nDoubleValues ; i++){
351  ar >> doubleVal;
352  doubleValues.push_back(doubleVal);
353  }
354  ar >> mat;
355 
356  ::new(t)DetailedVoxel(x, y, z, halfVoxelSize, intValues, doubleValues);
357  t->setMaxPad(maxPad);
358  t->material = mat;
359  }
360 }
361 }*/
void setMaxPad(double maxPad)
Set the max pad value.
Definition: DetailedVoxel.h:229
IntersectionHandlingResult onRayIntersection(NoiseSource< double > &uniformNoiseSource, glm::dvec3 &rayDirection, glm::dvec3 const &insideIntersectionPoint, glm::dvec3 const &outsideIntersectionPoint, double rayIntensity) override
Define ray intersection handling for DetailedVoxel primitive.
Definition: DetailedVoxel.cpp:25
DetailedVoxel & setNbEchos(int const nbEchos)
Set the number of total echoes count inside the voxel.
Definition: DetailedVoxel.h:160
size_t getNumberOfIntValues() const
Obtain the number of integer values defining the detailed voxel.
Definition: DetailedVoxel.h:182
double getMaxPad() const
The the max pad value.
Definition: DetailedVoxel.h:224
int getIntValue(size_t index) const
Obtain integer value at given index.
Definition: DetailedVoxel.h:203
double maxPad
Maximum plant area density.
Definition: DetailedVoxel.h:69
IntersectionHandlingResult onRayIntersectionTransmittive(NoiseSource< double > &uniformNoiseSource, glm::dvec3 &rayDirection, glm::dvec3 const &insideIntersectionPoint, glm::dvec3 const &outsideIntersectionPoint, double rayIntensity)
Transmittive handler for ray intersections.
Definition: DetailedVoxel.cpp:64
DetailedVoxel(glm::dvec3 center, double voxelSize, std::vector< int > intValues, std::vector< double > doubleValues)
Detailed voxel constructor.
Definition: DetailedVoxel.h:86
std::shared_ptr< Material > material
Shared pointer to the material defining certain properties such as reflectance, specularity, ...
Definition: Primitive.h:43
std::vector< double > doubleValues
All decimals defining the detailed voxel.
Definition: DetailedVoxel.h:54
double computeSigmaWithLadLut(glm::dvec3 const &direction) override
Definition: DetailedVoxel.cpp:161
int getNbEchos()
Obtain the number of total echoes count inside the voxel.
Definition: DetailedVoxel.h:153
void onFinishLoading(NoiseSource< double > &uniformNoiseSource) override
Configure DetailedVoxel size for scaled mode.
Definition: DetailedVoxel.cpp:134
IntersectionHandlingResult onRayIntersectionScaled(NoiseSource< double > &uniformNoiseSource, glm::dvec3 &rayDirection, glm::dvec3 const &insideIntersectionPoint, glm::dvec3 const &outsideIntersectionPoint, double rayIntensity, double scaleFactor)
Scaled handler for ray intersections.
Definition: DetailedVoxel.cpp:103
Class which extends Voxel to support AMAPVox format with extra features.
Definition: DetailedVoxel.h:12
Output class for intersection handling methods.
Definition: IntersectionHandlingResult.h:13
bool canComputeSigmaWithLadLut() override
Definition: DetailedVoxel.h:294
DetailedVoxel & setDoubleValue(size_t index, double value)
Set the double value at given index.
Definition: DetailedVoxel.h:211
DetailedVoxel & setNbSampling(int nbSampling)
Set the number of pulses entering the voxel.
Definition: DetailedVoxel.h:173
bool canHandleIntersections() override
Specify DetailedVoxel can handle intersections.
Definition: DetailedVoxel.h:238
std::map< std::string, size_t > identifiers
Identifiers for doubleValues vector.
Definition: DetailedVoxel.h:59
int getNbSampling()
Obtain the number of pulses entering the voxel.
Definition: DetailedVoxel.h:166
Class representing a voxel primitive.
Definition: Voxel.h:11
DetailedVoxel(double x, double y, double z, double halfVoxelSize, std::vector< int > intValues, std::vector< double > doubleValues)
Detailed voxel constructor.
Definition: DetailedVoxel.h:106
std::vector< int > intValues
All integers defining the detailed voxel.
Definition: DetailedVoxel.h:35
DetailedVoxel()=default
Defualt constructor for detailed voxel.
IntersectionHandlingResult onRayIntersectionFixed(NoiseSource< double > &uniformNoiseSource, glm::dvec3 &rayDirection, glm::dvec3 const &insideIntersectionPoint, glm::dvec3 const &outsideIntersectionPoint, double rayIntensity, double fixedSize)
Fixed handler for ray intersections.
Definition: DetailedVoxel.cpp:119
double getDoubleValue(size_t index) const
Get the double value at given index.
Definition: DetailedVoxel.h:218
std::shared_ptr< ScenePart > part
Shared pointer to the scene part the primitive belongs to.
Definition: Primitive.h:37
Abstract class defining the common behavior for all primitives.
Definition: Primitive.h:20
void _clone(Primitive *p) override
Definition: DetailedVoxel.cpp:11
size_t getNumberOfDoubleValues() const
Obtain the number of double values defining the detailed voxel.
Definition: DetailedVoxel.h:188
DetailedVoxel & setIntValue(size_t index, int value)
Set integer value at given index.
Definition: DetailedVoxel.h:196
Primitive * clone() override
Definition: DetailedVoxel.cpp:6
double & operator[](size_t index)
Obtain the value at specified index (position)
Definition: DetailedVoxel.h:137