Open3D (C++ API)  0.18.0
KDTreeFlann.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <Eigen/Core>
11 #include <memory>
12 #include <vector>
13 
17 
19 namespace nanoflann {
20 struct metric_L2;
21 template <class MatrixType, int DIM, class Distance, bool row_major>
22 struct KDTreeEigenMatrixAdaptor;
23 } // namespace nanoflann
25 
26 namespace open3d {
27 namespace geometry {
28 
32 class KDTreeFlann {
33 public:
35  KDTreeFlann();
39  KDTreeFlann(const Eigen::MatrixXd &data);
43  KDTreeFlann(const Geometry &geometry);
49  ~KDTreeFlann();
50  KDTreeFlann(const KDTreeFlann &) = delete;
51  KDTreeFlann &operator=(const KDTreeFlann &) = delete;
52 
53 public:
57  bool SetMatrixData(const Eigen::MatrixXd &data);
61  bool SetGeometry(const Geometry &geometry);
65  bool SetFeature(const pipelines::registration::Feature &feature);
66 
67  template <typename T>
68  int Search(const T &query,
69  const KDTreeSearchParam &param,
70  std::vector<int> &indices,
71  std::vector<double> &distance2) const;
72 
73  template <typename T>
74  int SearchKNN(const T &query,
75  int knn,
76  std::vector<int> &indices,
77  std::vector<double> &distance2) const;
78 
79  template <typename T>
80  int SearchRadius(const T &query,
81  double radius,
82  std::vector<int> &indices,
83  std::vector<double> &distance2) const;
84 
85  template <typename T>
86  int SearchHybrid(const T &query,
87  double radius,
88  int max_nn,
89  std::vector<int> &indices,
90  std::vector<double> &distance2) const;
91 
92 private:
97  bool SetRawData(const Eigen::Map<const Eigen::MatrixXd> &data);
98 
99 protected:
100  using KDTree_t = nanoflann::KDTreeEigenMatrixAdaptor<
101  Eigen::Map<const Eigen::MatrixXd>,
102  -1,
103  nanoflann::metric_L2,
104  false>;
105 
106  std::vector<double> data_;
107  std::unique_ptr<Eigen::Map<const Eigen::MatrixXd>> data_interface_;
108  std::unique_ptr<KDTree_t> nanoflann_index_;
109  size_t dimension_ = 0;
110  size_t dataset_size_ = 0;
111 };
112 
113 } // namespace geometry
114 } // namespace open3d
The base geometry class.
Definition: Geometry.h:18
KDTree with FLANN for nearest neighbor search.
Definition: KDTreeFlann.h:32
int Search(const T &query, const KDTreeSearchParam &param, std::vector< int > &indices, std::vector< double > &distance2) const
Definition: KDTreeFlann.cpp:69
KDTreeFlann()
Default Constructor.
Definition: KDTreeFlann.cpp:25
bool SetGeometry(const Geometry &geometry)
Definition: KDTreeFlann.cpp:42
std::vector< double > data_
Definition: KDTreeFlann.h:106
bool SetMatrixData(const Eigen::MatrixXd &data)
Definition: KDTreeFlann.cpp:37
nanoflann::KDTreeEigenMatrixAdaptor< Eigen::Map< const Eigen::MatrixXd >, -1, nanoflann::metric_L2, false > KDTree_t
Definition: KDTreeFlann.h:104
std::unique_ptr< Eigen::Map< const Eigen::MatrixXd > > data_interface_
Definition: KDTreeFlann.h:107
int SearchRadius(const T &query, double radius, std::vector< int > &indices, std::vector< double > &distance2) const
Definition: KDTreeFlann.cpp:116
int SearchKNN(const T &query, int knn, std::vector< int > &indices, std::vector< double > &distance2) const
Definition: KDTreeFlann.cpp:93
~KDTreeFlann()
Definition: KDTreeFlann.cpp:35
bool SetFeature(const pipelines::registration::Feature &feature)
Definition: KDTreeFlann.cpp:64
int SearchHybrid(const T &query, double radius, int max_nn, std::vector< int > &indices, std::vector< double > &distance2) const
Definition: KDTreeFlann.cpp:142
size_t dataset_size_
Definition: KDTreeFlann.h:110
KDTreeFlann & operator=(const KDTreeFlann &)=delete
size_t dimension_
Definition: KDTreeFlann.h:109
std::unique_ptr< KDTree_t > nanoflann_index_
Definition: KDTreeFlann.h:108
KDTreeFlann(const KDTreeFlann &)=delete
Base class for KDTree search parameters.
Definition: KDTreeSearchParam.h:16
Class to store featrues for registration.
Definition: Feature.h:30
const char const char value recording_handle imu_sample recording_handle uint8_t data
Definition: K4aPlugin.cpp:269
Definition: PinholeCameraIntrinsic.cpp:16