Open3D (C++ API)  0.17.0
NearestNeighborSearch.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 <vector>
11 
12 #include "open3d/core/Tensor.h"
17 
18 namespace open3d {
19 namespace core {
20 namespace nns {
21 
26 public:
31  // NearestNeighborSearch(const Tensor &dataset_points)
32  // : dataset_points_(dataset_points){};
33  NearestNeighborSearch(const Tensor &dataset_points,
34  const Dtype &index_dtype = core::Int32)
35  : dataset_points_(dataset_points), index_dtype_(index_dtype){};
39 
40 public:
44  bool KnnIndex();
45 
49  bool MultiRadiusIndex();
50 
56 
60  bool HybridIndex(utility::optional<double> radius = {});
61 
70  std::pair<Tensor, Tensor> KnnSearch(const Tensor &query_points, int knn);
71 
85  std::tuple<Tensor, Tensor, Tensor> FixedRadiusSearch(
86  const Tensor &query_points, double radius, bool sort = true);
87 
100  std::tuple<Tensor, Tensor, Tensor> MultiRadiusSearch(
101  const Tensor &query_points, const Tensor &radii);
102 
115  std::tuple<Tensor, Tensor, Tensor> HybridSearch(const Tensor &query_points,
116  const double radius,
117  const int max_knn) const;
118 
119 private:
120  bool SetIndex();
121 
123  void AssertNotCUDA(const Tensor &t) const;
124 
125 protected:
126  std::unique_ptr<NanoFlannIndex> nanoflann_index_;
127  std::unique_ptr<nns::FixedRadiusIndex> fixed_radius_index_;
128  std::unique_ptr<nns::KnnIndex> knn_index_;
131 };
132 } // namespace nns
133 } // namespace core
134 } // namespace open3d
Definition: Dtype.h:20
Definition: Tensor.h:32
A Class for nearest neighbor search.
Definition: NearestNeighborSearch.h:25
bool MultiRadiusIndex()
Definition: NearestNeighborSearch.cpp:38
NearestNeighborSearch(const NearestNeighborSearch &)=delete
std::unique_ptr< nns::KnnIndex > knn_index_
Definition: NearestNeighborSearch.h:128
std::tuple< Tensor, Tensor, Tensor > HybridSearch(const Tensor &query_points, const double radius, const int max_knn) const
Definition: NearestNeighborSearch.cpp:130
bool FixedRadiusIndex(utility::optional< double > radius={})
Definition: NearestNeighborSearch.cpp:40
std::tuple< Tensor, Tensor, Tensor > FixedRadiusSearch(const Tensor &query_points, double radius, bool sort=true)
Definition: NearestNeighborSearch.cpp:98
bool KnnIndex()
Definition: NearestNeighborSearch.cpp:23
std::tuple< Tensor, Tensor, Tensor > MultiRadiusSearch(const Tensor &query_points, const Tensor &radii)
Definition: NearestNeighborSearch.cpp:118
~NearestNeighborSearch()
Definition: NearestNeighborSearch.cpp:16
const Tensor dataset_points_
Definition: NearestNeighborSearch.h:129
std::unique_ptr< nns::FixedRadiusIndex > fixed_radius_index_
Definition: NearestNeighborSearch.h:127
bool HybridIndex(utility::optional< double > radius={})
Definition: NearestNeighborSearch.cpp:60
std::pair< Tensor, Tensor > KnnSearch(const Tensor &query_points, int knn)
Definition: NearestNeighborSearch.cpp:79
std::unique_ptr< NanoFlannIndex > nanoflann_index_
Definition: NearestNeighborSearch.h:126
NearestNeighborSearch & operator=(const NearestNeighborSearch &)=delete
const Dtype index_dtype_
Definition: NearestNeighborSearch.h:130
NearestNeighborSearch(const Tensor &dataset_points, const Dtype &index_dtype=core::Int32)
Definition: NearestNeighborSearch.h:33
Definition: Optional.h:259
const Dtype Int32
Definition: Dtype.cpp:46
Definition: PinholeCameraIntrinsic.cpp:16