Helios++
Helios software for LiDAR simulations
KDTreeRaycaster.h
1 #pragma once
2 
3 // TODO 4: Merge search_recursive() and search_all_recursive?
4 
5 #include <Raycaster.h>
6 #include <Primitive.h>
7 #include <Material.h>
8 #include <RaySceneIntersection.h>
9 #include <LightKDTreeNode.h>
10 
16 class KDTreeRaycaster : public Raycaster {
17 
18 
19 
20 
21 
22 
23 
24 
25 // *** NESTED DATASTRUCTURE-LIKE CLASS *** //
26 // ***************************************** //
31 public:
32  // *** ATTRIBUTES *** //
33  // ******************** //
37  glm::dvec3 const rayDir;
41  glm::dvec3 const rayOrigin;
46  bool const groundOnly;
53  std::vector<double> rayDirArray;
60  std::vector<double> rayOriginArray;
72  std::map<double, Primitive*> collectedPoints;
73 
74  // *** CONSTRUCTION / DESTRUCTION *** //
75  // ************************************ //
80  glm::dvec3 const rayDir,
81  glm::dvec3 const rayOrigin,
82  bool const groundOnly=false
83  ):
84  rayDir(rayDir),
87  closestHitDistance(std::numeric_limits<double>::max())
88  {}
89  virtual ~KDTreeRaycasterSearch() = default;
90 };
91 
92 
93 
94 
95 
96 
97 
98 
99 public:
100  // *** ATTRIBUTES *** //
101  // ******************** //
105  double epsilon = 0.0001;
109  std::shared_ptr<LightKDTreeNode> root;
110 
111  // *** CONSTRUCTION / DESTRUCTION *** //
112  // ************************************ //
117  KDTreeRaycaster(std::shared_ptr<LightKDTreeNode> root) : root(root) {}
118  virtual ~KDTreeRaycaster() = default;
119 
120  // *** RAYCASTING METHODS *** //
121  // **************************** //
126  std::map<double, Primitive*> searchAll(
127  glm::dvec3 const rayOrigin,
128  glm::dvec3 const rayDir,
129  double const tmin,
130  double const tmax,
131  bool const groundOnly
132  ) override;
138  glm::dvec3 const rayOrigin,
139  glm::dvec3 const rayDir,
140  double const tmin,
141  double const tmax,
142  bool const groundOnly
143  ) override;
144 
145 protected:
146  // *** RAYCASTING UTILS *** //
147  // ************************** //
161  void searchAll_recursive(
162  LightKDTreeNode* node,
163  double const tmin,
164  double const tmax,
165  KDTreeRaycasterSearch &search
166  );
182  LightKDTreeNode* node,
183  double const tmin,
184  double const tmax,
185  KDTreeRaycasterSearch &search
186  ) const;
187 };
Data for search operations of KDTree raycaster.
Definition: KDTreeRaycaster.h:30
double closestHitDistance
Distance of closest hit. It is numeric_limits<double>::max() by default.
Definition: KDTreeRaycaster.h:65
std::vector< double > rayOriginArray
Vector containing components of ray origin. It is filled at the start of a search operation.
Definition: KDTreeRaycaster.h:60
KDTreeRaycasterSearch(glm::dvec3 const rayDir, glm::dvec3 const rayOrigin, bool const groundOnly=false)
Default constructo for KDTreeRaycasterSearch.
Definition: KDTreeRaycaster.h:79
bool const groundOnly
Flag to specify if only ground points must be considered (true) or not (false)
Definition: KDTreeRaycaster.h:46
std::vector< double > rayDirArray
Vector containing components of ray director vector. It is filled at the start of a search operation.
Definition: KDTreeRaycaster.h:53
std::map< double, Primitive * > collectedPoints
Map of primitives identified by its distance with respect to ray origin. Only primitives which inters...
Definition: KDTreeRaycaster.h:72
glm::dvec3 const rayDir
Ray 3D director vector.
Definition: KDTreeRaycaster.h:37
glm::dvec3 const rayOrigin
Ray origin 3D coordinates.
Definition: KDTreeRaycaster.h:41
Class representing a KDTree ray caster.
Definition: KDTreeRaycaster.h:16
std::map< double, Primitive * > searchAll(glm::dvec3 const rayOrigin, glm::dvec3 const rayDir, double const tmin, double const tmax, bool const groundOnly) override
Definition: KDTreeRaycaster.cpp:6
void searchAll_recursive(LightKDTreeNode *node, double const tmin, double const tmax, KDTreeRaycasterSearch &search)
Recursive search function to assist searchAll function.
Definition: KDTreeRaycaster.cpp:62
std::shared_ptr< LightKDTreeNode > root
Shared pointer to the root node of the KDTree.
Definition: KDTreeRaycaster.h:109
KDTreeRaycaster(std::shared_ptr< LightKDTreeNode > root)
KDTree ray caster constructor.
Definition: KDTreeRaycaster.h:117
RaySceneIntersection * search(glm::dvec3 const rayOrigin, glm::dvec3 const rayDir, double const tmin, double const tmax, bool const groundOnly) override
Definition: KDTreeRaycaster.cpp:29
double epsilon
Decimal precision for the ray caster.
Definition: KDTreeRaycaster.h:105
Primitive * search_recursive(LightKDTreeNode *node, double const tmin, double const tmax, KDTreeRaycasterSearch &search) const
Recursive search function to assist search function.
Definition: KDTreeRaycaster.cpp:168
Class representing a light KDTree node. It is, the basic representation of a KDTree node with uses le...
Definition: LightKDTreeNode.h:28
Abstract class defining the common behavior for all primitives.
Definition: Primitive.h:24
Class representing a the intersection of a ray over a scene made of primitives.
Definition: RaySceneIntersection.h:12
Raycaster interface declaring raycasting operations.
Definition: Raycaster.h:15