Open3D (C++ API)  0.16.1
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
38namespace nanoflann {
39struct metric_L2;
40template <class MatrixType, int DIM, class Distance, bool row_major>
41struct KDTreeEigenMatrixAdaptor;
42} // namespace nanoflann
44
45namespace open3d {
46namespace geometry {
47
52public:
58 KDTreeFlann(const Eigen::MatrixXd &data);
62 KDTreeFlann(const Geometry &geometry);
69 KDTreeFlann(const KDTreeFlann &) = delete;
70 KDTreeFlann &operator=(const KDTreeFlann &) = delete;
71
72public:
76 bool SetMatrixData(const Eigen::MatrixXd &data);
80 bool SetGeometry(const Geometry &geometry);
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
111private:
116 bool SetRawData(const Eigen::Map<const Eigen::MatrixXd> &data);
117
118protected:
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
The base geometry class.
Definition: Geometry.h:37
KDTree with FLANN for nearest neighbor search.
Definition: KDTreeFlann.h:51
int Search(const T &query, const KDTreeSearchParam &param, std::vector< int > &indices, std::vector< double > &distance2) const
Definition: KDTreeFlann.cpp:88
KDTreeFlann()
Default Constructor.
Definition: KDTreeFlann.cpp:44
bool SetGeometry(const Geometry &geometry)
Definition: KDTreeFlann.cpp:61
std::vector< double > data_
Definition: KDTreeFlann.h:125
bool SetMatrixData(const Eigen::MatrixXd &data)
Definition: KDTreeFlann.cpp:56
nanoflann::KDTreeEigenMatrixAdaptor< Eigen::Map< const Eigen::MatrixXd >, -1, nanoflann::metric_L2, false > KDTree_t
Definition: KDTreeFlann.h:123
std::unique_ptr< Eigen::Map< const Eigen::MatrixXd > > data_interface_
Definition: KDTreeFlann.h:126
int SearchRadius(const T &query, double radius, std::vector< int > &indices, std::vector< double > &distance2) const
Definition: KDTreeFlann.cpp:135
int SearchKNN(const T &query, int knn, std::vector< int > &indices, std::vector< double > &distance2) const
Definition: KDTreeFlann.cpp:112
~KDTreeFlann()
Definition: KDTreeFlann.cpp:54
bool SetFeature(const pipelines::registration::Feature &feature)
Definition: KDTreeFlann.cpp:83
KDTreeFlann & operator=(const KDTreeFlann &)=delete
int SearchHybrid(const T &query, double radius, int max_nn, std::vector< int > &indices, std::vector< double > &distance2) const
Definition: KDTreeFlann.cpp:161
size_t dataset_size_
Definition: KDTreeFlann.h:129
size_t dimension_
Definition: KDTreeFlann.h:128
std::unique_ptr< KDTree_t > nanoflann_index_
Definition: KDTreeFlann.h:127
KDTreeFlann(const KDTreeFlann &)=delete
Base class for KDTree search parameters.
Definition: KDTreeSearchParam.h:35
Class to store featrues for registration.
Definition: Feature.h:47
const char const char value recording_handle imu_sample recording_handle uint8_t data
Definition: K4aPlugin.cpp:288
Definition: PinholeCameraIntrinsic.cpp:35