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;
15  template <typename Archive>
16  void serialize(Archive& ar, const unsigned int version) {
17  boost::serialization::void_cast_register<AABB, Primitive>();
18  ar & boost::serialization::base_object<Primitive>(*this);
19  ar & vertices;
20  }
21 
22 public:
23  // *** ATTRIBUTES *** //
24  // ******************** //
31  Vertex vertices[2]; // 0 min, 1 max
35  glm::dvec3 bounds[2];
36 
37  // *** CONSTRUCTION / DESTRUCTION *** //
38  // ************************************ //
42  AABB() = default;
49  AABB(glm::dvec3 min, glm::dvec3 max);
53  ~AABB() override = default;
59  Primitive* clone() override;
65  void _clone(Primitive *p) override;
66 
67 
68  // *** M E T H O D S *** //
69  // *********************** //
75  inline glm::dvec3 const & getMin() const {return vertices[0].pos;}
81  inline glm::dvec3 const & getMax() const {return vertices[1].pos;}
87  AABB* getAABB() override;
93  glm::dvec3 getCentroid() override;
97  double getIncidenceAngle_rad(
98  const glm::dvec3& rayOrigin,
99  const glm::dvec3& rayDir,
100  const glm::dvec3& intersectionPoint
101  ) override;
105  std::vector<double> getRayIntersection(
106  const glm::dvec3& rayOrigin,
107  const glm::dvec3& rayDir
108  ) override;
113  const glm::dvec3& rayOrigin,
114  const glm::dvec3& rayDir
115  )override;
119  size_t getNumVertices() override {return 2;}
123  Vertex* getVertices() override;
124 
130  static std::shared_ptr<AABB> getForPrimitives(
131  std::vector<Primitive*> & primitives
132  );
138  static std::shared_ptr<AABB> getForVertices(
139  std::vector<Vertex> & verts
140  );
146  static std::shared_ptr<AABB> getForVertices(
147  std::unordered_set<Vertex *, VertexKeyHash, VertexKeyEqual> & verts
148  );
152  void update() override {}
153 
158  glm::dvec3 getSize();
163  std::string toString();
164 };
165 
166 namespace boost {
167  namespace serialization {
168 
169  template<class Archive>
170  inline void save_construct_data(
171  Archive & ar, const AABB * t, const unsigned int file_version)
172  {
173  // save data required to construct instance
174  ar << t->vertices[0].pos;
175  ar << t->vertices[1].pos;
176  }
177 
178  template<class Archive>
179  inline void load_construct_data(
180  Archive & ar, AABB * t, const unsigned int file_version)
181  {
182  // retrieve data from archive required to construct new instance
183  glm::dvec3 min, max;
184  ar >> min;
185  ar >> max;
186 
187  // invoke inplace constructor to initialize instance of my_class
188  ::new(t)AABB(min, max);
189  }
190  }
191 }
size_t getNumVertices() override
Definition: AABB.h:119
glm::dvec3 const & getMin() const
Get the min value for each coordinate of the axis aligned bounding box.
Definition: AABB.h:75
~AABB() override=default
Default destructor for axis aligned bounding box.
Definition: AABB.h:166
AABB()=default
Default constructor for axis aligned bounding box.
void _clone(Primitive *p) override
Assist clone function.
Definition: AABB.cpp:23
std::vector< double > getRayIntersection(const glm::dvec3 &rayOrigin, const glm::dvec3 &rayDir) override
Definition: AABB.cpp:172
double getRayIntersectionDistance(const glm::dvec3 &rayOrigin, const glm::dvec3 &rayDir) override
Definition: AABB.cpp:198
std::string toString()
Bbuild a string representing the axis aligned bounding box.
Definition: AABB.cpp:168
glm::dvec3 bounds[2]
Cached bounds to speed-up intersection computation.
Definition: AABB.h:35
Vertex vertices[2]
Vertices defining the axis aligned bounding box.
Definition: AABB.h:31
static std::shared_ptr< AABB > getForPrimitives(std::vector< Primitive *> &primitives)
Build an axis aligned bounding box containing given primitives.
Definition: AABB.cpp:44
void update() override
Definition: AABB.h:152
AABB * getAABB() override
Obtain this axis aligned bounding box.
Definition: AABB.cpp:226
glm::dvec3 const & getMax() const
Get the max value for each coordinate of the axis aligned bounding box.
Definition: AABB.h:81
Class representing an Axis Aligned Bounding Box (AABB)
Definition: AABB.h:10
Vertex * getVertices() override
Definition: AABB.cpp:230
glm::dvec3 pos
Vertex 3D position.
Definition: Vertex.h:32
double getIncidenceAngle_rad(const glm::dvec3 &rayOrigin, const glm::dvec3 &rayDir, const glm::dvec3 &intersectionPoint) override
Definition: AABB.cpp:234
glm::dvec3 getCentroid() override
Get the centroid of the axis aligned bounding box.
Definition: AABB.cpp:35
glm::dvec3 getSize()
Obtain size along each axis for the axis aligned bounding box.
Definition: AABB.cpp:40
Abstract class defining the common behavior for all primitives.
Definition: Primitive.h:20
Primitive * clone() override
Generate a clone of the primitive.
Definition: AABB.cpp:17
static std::shared_ptr< AABB > getForVertices(std::vector< Vertex > &verts)
Build an axis aligned bounding box containing given vertices.
Class representing a vertex.
Definition: Vertex.h:14