Helios++
Helios software for LiDAR simulations
AABB.h
1 #pragma once
2 #include <set>
3 #include <unordered_set>
4 #include "Primitive.h"
5 #include "Vertex.h"
6 
10 class AABB : public Primitive {
11 private:
12  // *** SERIALIZATION *** //
13  // *********************** //
14  friend class boost::serialization::access;
21  template <typename Archive>
22  void serialize(Archive& ar, const unsigned int version) {
23  boost::serialization::void_cast_register<AABB, Primitive>();
24  ar & boost::serialization::base_object<Primitive>(*this);
25  ar & vertices;
26  ar & bounds;
27  }
28 
29 public:
30  // *** ATTRIBUTES *** //
31  // ******************** //
38  Vertex vertices[2]; // 0 min, 1 max
42  glm::dvec3 bounds[2];
43 
44  // *** CONSTRUCTION / DESTRUCTION *** //
45  // ************************************ //
49  AABB() = default;
56  AABB(glm::dvec3 min, glm::dvec3 max);
69  double const ax,
70  double const ay,
71  double const az,
72  double const bx,
73  double const by,
74  double const bz
75  ) :
76  AABB(glm::dvec3(ax, ay, az), glm::dvec3(bx, by, bz))
77  {}
81  ~AABB() override = default;
87  Primitive* clone() override;
93  void _clone(Primitive *p) override;
94 
95 
96  // *** M E T H O D S *** //
97  // *********************** //
103  inline glm::dvec3 const & getMin() const {return vertices[0].pos;}
109  inline glm::dvec3 const & getMax() const {return vertices[1].pos;}
115  AABB* getAABB() override;
121  glm::dvec3 getCentroid() override;
125  double getIncidenceAngle_rad(
126  const glm::dvec3& rayOrigin,
127  const glm::dvec3& rayDir,
128  const glm::dvec3& intersectionPoint
129  ) override;
133  std::vector<double> getRayIntersection(
134  const glm::dvec3& rayOrigin,
135  const glm::dvec3& rayDir
136  ) override;
141  const glm::dvec3& rayOrigin,
142  const glm::dvec3& rayDir
143  )override;
147  size_t getNumVertices() override {return 2;}
151  Vertex* getVertices() override;
152 
158  static std::shared_ptr<AABB> getForPrimitives(
159  std::vector<Primitive*> & primitives
160  );
166  static std::shared_ptr<AABB> getForVertices(
167  std::vector<Vertex> & verts
168  );
174  static std::shared_ptr<AABB> getForVertices(
175  std::unordered_set<Vertex *, VertexKeyHash, VertexKeyEqual> & verts
176  );
180  void update() override {}
181 
186  glm::dvec3 getSize();
191  std::string toString();
192 };
193 
194 namespace boost {
195  namespace serialization {
196 
197  template<class Archive>
198  inline void save_construct_data(
199  Archive & ar, const AABB * t, const unsigned int file_version)
200  {
201  // save data required to construct instance
202  ar << t->vertices[0].pos;
203  ar << t->vertices[1].pos;
204  }
205 
206  template<class Archive>
207  inline void load_construct_data(
208  Archive & ar, AABB * t, const unsigned int file_version)
209  {
210  // retrieve data from archive required to construct new instance
211  glm::dvec3 min, max;
212  ar >> min;
213  ar >> max;
214 
215  // invoke inplace constructor to initialize instance of my_class
216  ::new(t)AABB(min, max);
217  }
218  }
219 }
Class representing an Axis Aligned Bounding Box (AABB)
Definition: AABB.h:10
~AABB() override=default
Default destructor for axis aligned bounding box.
std::vector< double > getRayIntersection(const glm::dvec3 &rayOrigin, const glm::dvec3 &rayDir) override
Definition: AABB.cpp:157
void serialize(Archive &ar, const unsigned int version)
Serialize an axis-aligned bounding box to a stream of bytes.
Definition: AABB.h:22
glm::dvec3 const & getMax() const
Get the max value for each coordinate of the axis aligned bounding box.
Definition: AABB.h:109
Vertex * getVertices() override
Definition: AABB.cpp:218
static std::shared_ptr< AABB > getForVertices(std::vector< Vertex > &verts)
Build an axis aligned bounding box containing given vertices.
Vertex vertices[2]
Vertices defining the axis aligned bounding box.
Definition: AABB.h:38
AABB()=default
Default constructor for axis aligned bounding box.
void update() override
Definition: AABB.h:180
static std::shared_ptr< AABB > getForPrimitives(std::vector< Primitive * > &primitives)
Build an axis aligned bounding box containing given primitives.
Definition: AABB.cpp:44
glm::dvec3 getSize()
Obtain size along each axis for the axis aligned bounding box.
Definition: AABB.cpp:40
glm::dvec3 const & getMin() const
Get the min value for each coordinate of the axis aligned bounding box.
Definition: AABB.h:103
AABB * getAABB() override
Obtain this axis aligned bounding box.
Definition: AABB.cpp:214
std::string toString()
Bbuild a string representing the axis aligned bounding box.
Definition: AABB.cpp:153
void _clone(Primitive *p) override
Assist clone function.
Definition: AABB.cpp:23
glm::dvec3 getCentroid() override
Get the centroid of the axis aligned bounding box.
Definition: AABB.cpp:35
AABB(double const ax, double const ay, double const az, double const bx, double const by, double const bz)
Build an axis aligned bounding box through given points and which are the minimum and maximum verte...
Definition: AABB.h:68
Primitive * clone() override
Generate a clone of the primitive.
Definition: AABB.cpp:17
double getRayIntersectionDistance(const glm::dvec3 &rayOrigin, const glm::dvec3 &rayDir) override
Definition: AABB.cpp:186
double getIncidenceAngle_rad(const glm::dvec3 &rayOrigin, const glm::dvec3 &rayDir, const glm::dvec3 &intersectionPoint) override
Definition: AABB.cpp:222
size_t getNumVertices() override
Definition: AABB.h:147
glm::dvec3 bounds[2]
Cached bounds to speed-up intersection computation.
Definition: AABB.h:42
Abstract class defining the common behavior for all primitives.
Definition: Primitive.h:24
Class representing a vertex.
Definition: Vertex.h:14
glm::dvec3 pos
Vertex 3D position.
Definition: Vertex.h:39