KDTree.hpp
Go to the documentation of this file.
1 
35 #ifndef KDTREE_HPP_
36 #define KDTREE_HPP_
37 
38 #include "TreeUtils.hpp"
39 #include "SLAMScanWrapper.hpp"
40 
41 #include <memory>
42 #include <limits>
43 #include <boost/shared_array.hpp>
44 
45 namespace lvr2
46 {
47 
51 class KDTree
52 {
53 public:
54  using PointT = float;
56  using Neighbor = Point*;
57  using KDTreePtr = std::shared_ptr<KDTree>;
58 
66  static std::shared_ptr<KDTree> create(SLAMScanPtr scan, int maxLeafSize = 20);
67 
79  template<typename T>
81  const Vector3<T>& point,
82  Neighbor& neighbor,
83  double& distance,
84  double maxDistance = std::numeric_limits<double>::infinity()
85  ) const
86  {
87  neighbor = nullptr;
88  distance = maxDistance;
89  nnInternal(point.template cast<PointT>(), neighbor, distance);
90 
91  return neighbor != nullptr;
92  }
93 
94  virtual ~KDTree() = default;
95 
109  static size_t nearestNeighbors(KDTreePtr tree, SLAMScanPtr scan, Neighbor* neighbors, double maxDistance, Vector3d& centroid_m, Vector3d& centroid_d);
110 
122  static size_t nearestNeighbors(KDTreePtr tree, SLAMScanPtr scan, KDTree::Neighbor* neighbors, double maxDistance);
123 
124 protected:
125  KDTree() = default;
126  KDTree(const KDTree&&) = delete;
127 
128  virtual void nnInternal(const Point& point, Neighbor& neighbor, double& maxDist) const = 0;
129 
130  friend class KDNode;
131 
132  boost::shared_array<Point> points;
133 };
134 
135 using KDTreePtr = std::shared_ptr<KDTree>;
136 
137 } /* namespace lvr2 */
138 
139 #endif /* KDTREE_HPP_ */
140 
float PointT
Definition: KDTree.hpp:54
static size_t nearestNeighbors(KDTreePtr tree, SLAMScanPtr scan, Neighbor *neighbors, double maxDistance, Vector3d &centroid_m, Vector3d &centroid_d)
Finds the nearest neighbors of all points in a Scan using a pre-generated KDTree. ...
Definition: KDTree.cpp:176
std::shared_ptr< KDTree > KDTreePtr
Definition: KDTree.hpp:57
KDTree()=default
Representation of a point in 3D space.
Definition: point.h:22
Eigen::Vector3d Vector3d
Eigen 3D vector, double precision.
Point * Neighbor
Definition: KDTree.hpp:56
std::shared_ptr< KDTree > KDTreePtr
Definition: KDTree.hpp:135
a kd-Tree Implementation for nearest Neighbor searches
Definition: KDTree.hpp:51
Eigen::Matrix< T, 3, 1 > Vector3
Eigen 3D vector.
static std::shared_ptr< KDTree > create(SLAMScanPtr scan, int maxLeafSize=20)
Creates a new KDTree from the given Scan.
Definition: KDTree.cpp:153
bool nearestNeighbor(const Vector3< T > &point, Neighbor &neighbor, double &distance, double maxDistance=std::numeric_limits< double >::infinity()) const
Finds the nearest neighbor of &#39;point&#39; that is within &#39;maxDistance&#39; (defaults to infinity). The resulting neighbor is written into &#39;neighbor&#39; (or nullptr if none is found).
Definition: KDTree.hpp:80
boost::shared_array< Point > points
Definition: KDTree.hpp:132
virtual ~KDTree()=default
std::shared_ptr< SLAMScanWrapper > SLAMScanPtr
virtual void nnInternal(const Point &point, Neighbor &neighbor, double &maxDist) const =0


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:06