Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.14.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
KDTreeFlann.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018-2021 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <Eigen/Core>
30 #include <memory>
31 #include <vector>
32 
36 
38 namespace nanoflann {
39 struct metric_L2;
40 template <class MatrixType, int DIM, class Distance, bool row_major>
41 struct KDTreeEigenMatrixAdaptor;
42 } // namespace nanoflann
44 
45 namespace open3d {
46 namespace geometry {
47 
51 class KDTreeFlann {
52 public:
54  KDTreeFlann();
58  KDTreeFlann(const Eigen::MatrixXd &data);
62  KDTreeFlann(const Geometry &geometry);
68  ~KDTreeFlann();
69  KDTreeFlann(const KDTreeFlann &) = delete;
70  KDTreeFlann &operator=(const KDTreeFlann &) = delete;
71 
72 public:
76  bool SetMatrixData(const Eigen::MatrixXd &data);
80  bool SetGeometry(const Geometry &geometry);
84  bool SetFeature(const pipelines::registration::Feature &feature);
85 
86  template <typename T>
87  int Search(const T &query,
88  const KDTreeSearchParam &param,
89  std::vector<int> &indices,
90  std::vector<double> &distance2) const;
91 
92  template <typename T>
93  int SearchKNN(const T &query,
94  int knn,
95  std::vector<int> &indices,
96  std::vector<double> &distance2) const;
97 
98  template <typename T>
99  int SearchRadius(const T &query,
100  double radius,
101  std::vector<int> &indices,
102  std::vector<double> &distance2) const;
103 
104  template <typename T>
105  int SearchHybrid(const T &query,
106  double radius,
107  int max_nn,
108  std::vector<int> &indices,
109  std::vector<double> &distance2) const;
110 
111 private:
116  bool SetRawData(const Eigen::Map<const Eigen::MatrixXd> &data);
117 
118 protected:
119  using KDTree_t = nanoflann::KDTreeEigenMatrixAdaptor<
120  Eigen::Map<const Eigen::MatrixXd>,
121  -1,
122  nanoflann::metric_L2,
123  false>;
124 
125  std::vector<double> data_;
126  std::unique_ptr<Eigen::Map<const Eigen::MatrixXd>> data_interface_;
127  std::unique_ptr<KDTree_t> nanoflann_index_;
128  size_t dimension_ = 0;
129  size_t dataset_size_ = 0;
130 };
131 
132 } // namespace geometry
133 } // namespace open3d
std::unique_ptr< Eigen::Map< const Eigen::MatrixXd > > data_interface_
Definition: KDTreeFlann.h:126
The base geometry class.
Definition: Geometry.h:37
nanoflann::KDTreeEigenMatrixAdaptor< Eigen::Map< const Eigen::MatrixXd >, -1, nanoflann::metric_L2, false > KDTree_t
Definition: KDTreeFlann.h:123
Class to store featrues for registration.
Definition: Feature.h:47
Base class for KDTree search parameters.
Definition: KDTreeSearchParam.h:35
KDTree with FLANN for nearest neighbor search.
Definition: KDTreeFlann.h:51
Definition: PinholeCameraIntrinsic.cpp:35
std::vector< double > data_
Definition: KDTreeFlann.h:125
std::unique_ptr< KDTree_t > nanoflann_index_
Definition: KDTreeFlann.h:127
const char const char value recording_handle imu_sample recording_handle uint8_t data
Definition: K4aPlugin.cpp:274