Helios++
Helios software for LiDAR simulations
DetailedVoxel.h
1 #pragma once
2 
3 #include <string>
4 #include <Voxel.h>
5 
6 #include <boost/serialization/map.hpp>
7 
15 class DetailedVoxel : public Voxel{
16  // *** BOOST SERIALIZATION *** //
17  // ***************************** //
18  friend class boost::serialization::access;
19  template <typename Archive>
20  void serialize(Archive &ar, const unsigned int version){
21  boost::serialization::void_cast_register<DetailedVoxel, Voxel>();
22  ar & boost::serialization::base_object<Voxel>(*this);
23  ar & intValues;
24  ar & doubleValues;
25  ar & identifiers;
26  ar & maxPad;
27  }
28 protected:
29  // *** ATTRIBUTES *** //
30  // ******************** //
38  std::vector<int> intValues;
57  std::vector<double> doubleValues;
58 
62  std::map<std::string, size_t> identifiers = std::map<std::string, size_t>({
63  {"PadBVTotal", 0}, {"angleMean", 1}, {"bsEntering", 2},
64  {"bsIntercepted", 3}, {"bsPotential", 4}, {"ground_distance", 5},
65  {"lMeanTotal", 6}, {"lgTotal", 7}, {"transmittance", 8},
66  {"attenuation", 9}, {"attenuationBiasCorrection", 10}
67  });
68 
72  double maxPad = 0.0;
73 
74 public:
75  // *** CONSTRUCTION *** //
76  // ********************** //
90  glm::dvec3 center,
91  double voxelSize,
92  std::vector<int> intValues,
93  std::vector<double> doubleValues
94  ) :
95  Voxel(center, voxelSize),
96  intValues(std::move(intValues)),
97  doubleValues(std::move(doubleValues))
98  {}
110  double x,
111  double y,
112  double z,
113  double halfVoxelSize,
114  std::vector<int> intValues,
115  std::vector<double> doubleValues
116  ) :
117  Voxel(x, y, z, halfVoxelSize),
118  intValues(std::move(intValues)),
119  doubleValues(std::move(doubleValues))
120  {}
121 
125  Primitive* clone() override;
129  void _clone(Primitive *p) override;
130 
131 
132 
133  // *** ACCESS OPERATORS *** //
134  // ************************** //
140  inline double & operator[] (size_t index)
141  {return doubleValues[index];}
147  inline double &operator[] (std::string const &id)
148  {return doubleValues[identifiers[id]];}
149 
150  // *** GETTERS and SETTERS *** //
151  // ***************************** //
156  inline int getNbEchos()
157  {return intValues[0];}
163  inline DetailedVoxel & setNbEchos(int const nbEchos)
164  {intValues[0] = nbEchos; return *this;}
169  inline int getNbSampling()
170  {return intValues[1];}
176  inline DetailedVoxel & setNbSampling(int nbSampling)
177  {intValues[1] = nbSampling; return *this;}
178 
179  // *** GETTERS and SETTERS *** //
180  // *************************** //
185  inline size_t getNumberOfIntValues() const
186  {return intValues.size();}
191  inline size_t getNumberOfDoubleValues() const
192  {return doubleValues.size();}
199  inline DetailedVoxel & setIntValue(size_t index, int value)
200  {intValues[index] = value; return *this;}
206  inline int getIntValue(size_t index) const
207  {return intValues[index];}
214  inline DetailedVoxel & setDoubleValue(size_t index, double value)
215  {doubleValues[index] = value; return *this;}
221  inline double getDoubleValue(size_t index) const
222  {return doubleValues[index];}
227  inline double getMaxPad() const {return maxPad;}
232  inline void setMaxPad(double maxPad) {this->maxPad = maxPad;}
233 
234  // *** M E T H O D S *** //
235  // *********************** //
241  inline bool canHandleIntersections() override {return true;}
247  NoiseSource<double> &uniformNoiseSource,
248  glm::dvec3 &rayDirection,
249  glm::dvec3 const &insideIntersectionPoint,
250  glm::dvec3 const &outsideIntersectionPoint,
251  double rayIntensity
252  ) override;
253 
258  NoiseSource<double> &uniformNoiseSource,
259  glm::dvec3 &rayDirection,
260  glm::dvec3 const &insideIntersectionPoint,
261  glm::dvec3 const &outsideIntersectionPoint,
262  double rayIntensity
263  );
268  NoiseSource<double> &uniformNoiseSource,
269  glm::dvec3 &rayDirection,
270  glm::dvec3 const &insideIntersectionPoint,
271  glm::dvec3 const &outsideIntersectionPoint,
272  double rayIntensity,
273  double scaleFactor
274  );
279  NoiseSource<double> &uniformNoiseSource,
280  glm::dvec3 &rayDirection,
281  glm::dvec3 const &insideIntersectionPoint,
282  glm::dvec3 const &outsideIntersectionPoint,
283  double rayIntensity,
284  double fixedSize
285  );
286 
290  void onFinishLoading(NoiseSource<double> &uniformNoiseSource) override;
291 
292  // *** S I G M A *** //
293  // ******************* //
298  {return part->ladlut != nullptr;}
302  double computeSigmaWithLadLut(glm::dvec3 const &direction) override;
303 };
304 
305 // *** BOOST SERIALIZATION *** //
306 // ***************************** //
307 /*
308  * Below code is commented because it is not necessary and it might cause
309  * memory leaks when called from external sources (i.e. from python)
310  */
311 /*namespace boost{
312 namespace serialization{
313  template<class Archive>
314  inline void save_construct_data(
315  Archive &ar, const DetailedVoxel *t, const unsigned int file_version
316  ){
317  ar << t->v.pos.x << t->v.pos.y << t->v.pos.z;
318  ar << t->halfSize;
319  ar << t->getMaxPad();
320  ar << t->getNumberOfIntValues();
321  for(size_t i = 0 ; i < t->getNumberOfIntValues() ; i++)
322  ar << t->getIntValue(i);
323  ar << t->getNumberOfDoubleValues();
324  for(size_t i = 0 ; i < t->getNumberOfDoubleValues() ; i++)
325  ar << t->getDoubleValue(i);
326  ar << t->material;
327  }
328 
329  template<class Archive>
330  inline void load_construct_data(
331  Archive &ar, DetailedVoxel *t, const unsigned int file_version
332  ){
333  double x = 0.0, y = 0.0, z = 0.0;
334  double halfVoxelSize = 0.0;
335  double maxPad = 0.0;
336  size_t nIntValues = 0;
337  int intVal = 0;
338  std::vector<int> intValues;
339  size_t nDoubleValues = 0;
340  double doubleVal = 0.0;
341  std::vector<double> doubleValues;
342  std::shared_ptr<Material> mat;
343 
344  ar >> x; ar >> y; ar >> z;
345  ar >> halfVoxelSize;
346  ar >> maxPad;
347  ar >> nIntValues;
348  for(size_t i = 0 ; i < nIntValues ; i++){
349  ar >> intVal;
350  intValues.push_back(intVal);
351  }
352  ar >> nDoubleValues;
353  for(size_t i = 0 ; i < nDoubleValues ; i++){
354  ar >> doubleVal;
355  doubleValues.push_back(doubleVal);
356  }
357  ar >> mat;
358 
359  ::new(t)DetailedVoxel(x, y, z, halfVoxelSize, intValues, doubleValues);
360  t->setMaxPad(maxPad);
361  t->material = mat;
362  }
363 }
364 }*/
Class which extends Voxel to support AMAPVox format with extra features.
Definition: DetailedVoxel.h:15
bool canHandleIntersections() override
Specify DetailedVoxel can handle intersections.
Definition: DetailedVoxel.h:241
void _clone(Primitive *p) override
Definition: DetailedVoxel.cpp:11
bool canComputeSigmaWithLadLut() override
Definition: DetailedVoxel.h:297
DetailedVoxel & setDoubleValue(size_t index, double value)
Set the double value at given index.
Definition: DetailedVoxel.h:214
double computeSigmaWithLadLut(glm::dvec3 const &direction) override
Definition: DetailedVoxel.cpp:158
int getNbSampling()
Obtain the number of pulses entering the voxel.
Definition: DetailedVoxel.h:169
std::vector< int > intValues
All integers defining the detailed voxel.
Definition: DetailedVoxel.h:38
int getNbEchos()
Obtain the number of total echoes count inside the voxel.
Definition: DetailedVoxel.h:156
double getMaxPad() const
The the max pad value.
Definition: DetailedVoxel.h:227
DetailedVoxel & setIntValue(size_t index, int value)
Set integer value at given index.
Definition: DetailedVoxel.h:199
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 & setNbEchos(int const nbEchos)
Set the number of total echoes count inside the voxel.
Definition: DetailedVoxel.h:163
void setMaxPad(double maxPad)
Set the max pad value.
Definition: DetailedVoxel.h:232
void onFinishLoading(NoiseSource< double > &uniformNoiseSource) override
Configure DetailedVoxel size for scaled mode.
Definition: DetailedVoxel.cpp:131
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:116
double & operator[](size_t index)
Obtain the value at specified index (position)
Definition: DetailedVoxel.h:140
std::vector< double > doubleValues
All decimals defining the detailed voxel.
Definition: DetailedVoxel.h:57
DetailedVoxel(double x, double y, double z, double halfVoxelSize, std::vector< int > intValues, std::vector< double > doubleValues)
Detailed voxel constructor.
Definition: DetailedVoxel.h:109
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:100
double maxPad
Maximum plant area density.
Definition: DetailedVoxel.h:72
size_t getNumberOfDoubleValues() const
Obtain the number of double values defining the detailed voxel.
Definition: DetailedVoxel.h:191
int getIntValue(size_t index) const
Obtain integer value at given index.
Definition: DetailedVoxel.h:206
std::map< std::string, size_t > identifiers
Identifiers for doubleValues vector.
Definition: DetailedVoxel.h:62
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(glm::dvec3 center, double voxelSize, std::vector< int > intValues, std::vector< double > doubleValues)
Detailed voxel constructor.
Definition: DetailedVoxel.h:89
Primitive * clone() override
Definition: DetailedVoxel.cpp:6
DetailedVoxel & setNbSampling(int nbSampling)
Set the number of pulses entering the voxel.
Definition: DetailedVoxel.h:176
DetailedVoxel()
Defualt constructor for detailed voxel.
Definition: DetailedVoxel.h:80
double getDoubleValue(size_t index) const
Get the double value at given index.
Definition: DetailedVoxel.h:221
size_t getNumberOfIntValues() const
Obtain the number of integer values defining the detailed voxel.
Definition: DetailedVoxel.h:185
Output class for intersection handling methods.
Definition: IntersectionHandlingResult.h:14
Abstract class defining the common behavior for all primitives.
Definition: Primitive.h:24
std::shared_ptr< ScenePart > part
Shared pointer to the scene part the primitive belongs to.
Definition: Primitive.h:57
Class representing a voxel primitive.
Definition: Voxel.h:11