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 
lvr2::KDTree::~KDTree
virtual ~KDTree()=default
lvr2::KDTree::nnInternal
virtual void nnInternal(const Point &point, Neighbor &neighbor, double &maxDist) const =0
SLAMScanWrapper.hpp
lvr2::KDNode
Definition: KDTree.cpp:40
lvr2::KDTree::KDTree
KDTree()=default
lvr2::KDTree::create
static std::shared_ptr< KDTree > create(SLAMScanPtr scan, int maxLeafSize=20)
Creates a new KDTree from the given Scan.
Definition: KDTree.cpp:153
lvr2::KDTree::points
boost::shared_array< Point > points
Definition: KDTree.hpp:132
lvr2::KDTreePtr
std::shared_ptr< KDTree > KDTreePtr
Definition: KDTree.hpp:135
lvr2::KDTree::nearestNeighbors
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
lvr2::SLAMScanPtr
std::shared_ptr< SLAMScanWrapper > SLAMScanPtr
Definition: SLAMScanWrapper.hpp:221
lvr2::Vector3
Eigen::Matrix< T, 3, 1 > Vector3
Eigen 3D vector.
Definition: MatrixTypes.hpp:115
lvr2::KDTree::nearestNeighbor
bool nearestNeighbor(const Vector3< T > &point, Neighbor &neighbor, double &distance, double maxDistance=std::numeric_limits< double >::infinity()) const
Finds the nearest neighbor of 'point' that is within 'maxDistance' (defaults to infinity)....
Definition: KDTree.hpp:80
lvr2::Vector3d
Eigen::Vector3d Vector3d
Eigen 3D vector, double precision.
Definition: MatrixTypes.hpp:121
TreeUtils.hpp
lvr2
Definition: BaseBufferManipulators.hpp:39
Point
Representation of a point in 3D space.
Definition: point.h:22
lvr2::KDTree::Neighbor
Point * Neighbor
Definition: KDTree.hpp:56
lvr2::KDTree::KDTreePtr
std::shared_ptr< KDTree > KDTreePtr
Definition: KDTree.hpp:57
lvr2::KDTree
a kd-Tree Implementation for nearest Neighbor searches
Definition: KDTree.hpp:51
lvr2::KDTree::PointT
float PointT
Definition: KDTree.hpp:54


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 Wed Mar 2 2022 00:37:23