ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
NearestNeighborSearch.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <Optional.h>
11 
12 #include <vector>
13 
18 
19 namespace cloudViewer {
20 namespace core {
21 namespace nns {
22 
27 public:
32  // NearestNeighborSearch(const Tensor &dataset_points)
33  // : dataset_points_(dataset_points){};
34  NearestNeighborSearch(const Tensor &dataset_points,
35  const Dtype &index_dtype = core::Int32)
36  : dataset_points_(dataset_points), index_dtype_(index_dtype) {
38  };
42 
43 public:
47  bool KnnIndex();
48 
52  bool MultiRadiusIndex();
53 
59 
63  bool HybridIndex(utility::optional<double> radius = {});
64 
73  std::pair<Tensor, Tensor> KnnSearch(const Tensor &query_points, int knn);
74 
88  std::tuple<Tensor, Tensor, Tensor> FixedRadiusSearch(
89  const Tensor &query_points, double radius, bool sort = true);
90 
103  std::tuple<Tensor, Tensor, Tensor> MultiRadiusSearch(
104  const Tensor &query_points, const Tensor &radii);
105 
118  std::tuple<Tensor, Tensor, Tensor> HybridSearch(const Tensor &query_points,
119  const double radius,
120  const int max_knn) const;
121 
122 private:
123  bool SetIndex();
124 
126  void AssertNotCUDA(const Tensor &t) const;
127 
128 protected:
129  std::unique_ptr<NanoFlannIndex> nanoflann_index_;
130  std::unique_ptr<nns::FixedRadiusIndex> fixed_radius_index_;
131  std::unique_ptr<nns::KnnIndex> knn_index_;
134 };
135 } // namespace nns
136 } // namespace core
137 } // namespace cloudViewer
cloudViewer::utility::optional::value
constexpr T const & value() const &
Definition: Optional.h:465
cloudViewer
Generic file read and write utility for python interface.
Definition: CloudViewerConfig.cpp:12
cloudViewer::core::Tensor::GetDtype
Dtype GetDtype() const
Definition: Tensor.h:1164
Optional.h
cloudViewer::utility::optional::has_value
constexpr bool has_value() const noexcept
Definition: Optional.h:440
cloudViewer::core::nns::NearestNeighborSearch::~NearestNeighborSearch
~NearestNeighborSearch()
Definition: NearestNeighborSearch.cpp:16
cloudViewer::core::nns::NearestNeighborSearch::fixed_radius_index_
std::unique_ptr< nns::FixedRadiusIndex > fixed_radius_index_
Definition: NearestNeighborSearch.h:130
cloudViewer::core::IsDevice::IsCUDA
bool IsCUDA() const
Definition: Device.h:99
cloudViewer::core::AssertNotSYCL
void AssertNotSYCL(const Tensor &tensor)
Definition: Tensor.h:1436
AssertTensorDevice
#define AssertTensorDevice(tensor,...)
Definition: TensorCheck.h:45
cloudViewer::core::nns::FixedRadiusIndex
FixedRadiusIndex for nearest neighbor range search.
Definition: FixedRadiusIndex.h:382
cloudViewer::core::nns::NearestNeighborSearch::NearestNeighborSearch
NearestNeighborSearch(const Tensor &dataset_points, const Dtype &index_dtype=core::Int32)
Definition: NearestNeighborSearch.h:34
NanoFlannIndex.h
cloudViewer::core::nns::NearestNeighborSearch::FixedRadiusIndex
bool FixedRadiusIndex(utility::optional< double > radius={})
Definition: NearestNeighborSearch.cpp:40
cloudViewer::core::Tensor
Definition: Tensor.h:32
cloudViewer::core::nns::NearestNeighborSearch::KnnIndex
bool KnnIndex()
Definition: NearestNeighborSearch.cpp:23
cloudViewer::core::Dtype
Definition: Dtype.h:21
cloudViewer::core::nns::NearestNeighborSearch::knn_index_
std::unique_ptr< nns::KnnIndex > knn_index_
Definition: NearestNeighborSearch.h:131
cloudViewer::core::nns::NearestNeighborSearch
A Class for nearest neighbor search.
Definition: NearestNeighborSearch.h:26
cloudViewer::core::nns::KnnIndex
Definition: KnnIndex.h:33
cloudViewer::core::Int32
const Dtype Int32
Definition: Dtype.cpp:46
cloudViewer::core::nns::NearestNeighborSearch::MultiRadiusSearch
std::tuple< Tensor, Tensor, Tensor > MultiRadiusSearch(const Tensor &query_points, const Tensor &radii)
Definition: NearestNeighborSearch.cpp:118
cloudViewer::core::nns::NearestNeighborSearch::index_dtype_
const Dtype index_dtype_
Definition: NearestNeighborSearch.h:133
cloudViewer::core::nns::NearestNeighborSearch::KnnSearch
std::pair< Tensor, Tensor > KnnSearch(const Tensor &query_points, int knn)
Definition: NearestNeighborSearch.cpp:79
core
cloudViewer::core::Tensor::GetDevice
Device GetDevice() const override
Definition: Tensor.cpp:1435
cloudViewer::core::nns::NearestNeighborSearch::dataset_points_
const Tensor dataset_points_
Definition: NearestNeighborSearch.h:132
NearestNeighborSearch.h
cloudViewer::core::nns::NanoFlannIndex
Definition: NanoFlannIndex.h:25
cloudViewer::utility::optional
Definition: Optional.h:44
LogError
#define LogError(...)
Definition: Logging.h:60
KnnIndex.h
AssertTensorDtype
#define AssertTensorDtype(tensor,...)
Definition: TensorCheck.h:21
Tensor.h
cloudViewer::core::nns::NearestNeighborSearch::FixedRadiusSearch
std::tuple< Tensor, Tensor, Tensor > FixedRadiusSearch(const Tensor &query_points, double radius, bool sort=true)
Definition: NearestNeighborSearch.cpp:98
cloudViewer::core::nns::NearestNeighborSearch::MultiRadiusIndex
bool MultiRadiusIndex()
Definition: NearestNeighborSearch.cpp:38
cloudViewer::core::nns::NearestNeighborSearch::nanoflann_index_
std::unique_ptr< NanoFlannIndex > nanoflann_index_
Definition: NearestNeighborSearch.h:129
FixedRadiusIndex.h
cloudViewer::core::nns::NearestNeighborSearch::HybridIndex
bool HybridIndex(utility::optional< double > radius={})
Definition: NearestNeighborSearch.cpp:60
radii
std::vector< PointCoordinateType > radii
Definition: qM3C2Tools.cpp:42
cloudViewer::core::nns::NearestNeighborSearch::operator=
NearestNeighborSearch & operator=(const NearestNeighborSearch &)=delete
cloudViewer::core::nns::NearestNeighborSearch::HybridSearch
std::tuple< Tensor, Tensor, Tensor > HybridSearch(const Tensor &query_points, const double radius, const int max_knn) const
Definition: NearestNeighborSearch.cpp:130