Helios++
Helios software for LiDAR simulations
Scene.h
1 #pragma once
2 
3 #include <boost/archive/text_iarchive.hpp>
4 #include <boost/archive/text_oarchive.hpp>
5 #include <boost/serialization/base_object.hpp>
6 
7 #include <glm/glm.hpp>
8 
9 #include "serial.h"
10 
11 #include "Asset.h"
12 #include "AABB.h"
13 #include "Triangle.h"
14 #include "Vertex.h"
15 #include "Voxel.h"
16 #include "DetailedVoxel.h"
17 
18 #include "KDTreeNodeRoot.h"
19 
20 #include "RaySceneIntersection.h"
21 
25 class Scene : public Asset {
26 
27 private:
28  // *** SERIALIZATION *** //
29  // *********************** //
30  friend class boost::serialization::access;
31  template<class Archive>
32  void serialize(Archive &ar, const unsigned int version)
33  {
34  // register primitive derivates
35  ar.template register_type<AABB>();
36  ar.template register_type<Triangle>();
37  ar.template register_type<Vertex>();
38  ar.template register_type<Voxel>();
39  ar.template register_type<DetailedVoxel>();
40 
41  ar & boost::serialization::base_object<Asset>(*this);
42  ar & primitives;
43  ar & bbox & bbox_crs;
44  ar & kdtree;
45  }
46  // *** ATTRIBUTES *** //
47  // ******************** //
52  std::shared_ptr<KDTreeNodeRoot> kdtree;
56  std::shared_ptr<AABB> bbox;
61  std::shared_ptr<AABB> bbox_crs;
62 public:
66  std::vector<Primitive*> primitives;
67 
68  // *** CONSTRUCTION / DESTRUCTION *** //
69  // ************************************ //
73  Scene() = default;
74  ~Scene() override {for(Primitive *p : primitives) delete p;}
75  Scene(Scene &s);
76 
77  // *** M E T H O D S *** //
78  // *********************** //
88  bool finalizeLoading();
93  std::shared_ptr<AABB> getAABB();
100  glm::dvec3 getGroundPointAt(glm::dvec3 point);
112  std::shared_ptr<RaySceneIntersection> getIntersection(
113  glm::dvec3 & rayOrigin,
114  glm::dvec3 & rayDir,
115  bool groundOnly
116  );
129  std::map<double, Primitive*> getIntersections(
130  glm::dvec3 & rayOrigin,
131  glm::dvec3 & rayDir,
132  bool groundOnly
133  );
134 
142  glm::dvec3 getShift();
143 
148  void writeObject(std::string path);
154  static Scene* readObject(std::string path);
155 };
std::shared_ptr< AABB > bbox
Axis aligned bounding box defining scene boundaries.
Definition: Scene.h:56
Base class for all assets.
Definition: Asset.h:10
glm::dvec3 getGroundPointAt(glm::dvec3 point)
Obtain the ground point at specified XY coordinates.
Definition: Scene.cpp:148
std::map< double, Primitive * > getIntersections(glm::dvec3 &rayOrigin, glm::dvec3 &rayDir, bool groundOnly)
Obtain all intersections between the ray and the scene, if any.
Definition: Scene.cpp:205
void writeObject(std::string path)
Serialize the scene and write it to given output file.
Definition: Scene.cpp:231
std::shared_ptr< AABB > getAABB()
Obtain the axis aligned bounding box defining scene boundaries.
Definition: Scene.cpp:144
std::shared_ptr< KDTreeNodeRoot > kdtree
KDTree splitting scene points/vertices to speed-up intersection computations.
Definition: Scene.h:52
std::vector< Primitive * > primitives
Vector of primitives composing the scene.
Definition: Scene.h:66
bool finalizeLoading()
Handle scene loading finish process.
Definition: Scene.cpp:59
static Scene * readObject(std::string path)
Read serialized scene from given file.
Definition: Scene.cpp:238
Scene()=default
Scene default constructor.
glm::dvec3 getShift()
Obtain the minimum boundaries of the original axis aligned bounding box containing the scene...
Definition: Scene.cpp:227
Class representing a scene asset.
Definition: Scene.h:25
Abstract class defining the common behavior for all primitives.
Definition: Primitive.h:20
std::shared_ptr< RaySceneIntersection > getIntersection(glm::dvec3 &rayOrigin, glm::dvec3 &rayDir, bool groundOnly)
Obtain the intersection between the ray and the scene, if any.
Definition: Scene.cpp:174
std::shared_ptr< AABB > bbox_crs
Original axis aligned bounding box defining scene boundaries before centering it. ...
Definition: Scene.h:61