Open3D (C++ API)  0.15.1
KnnIndex.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 "open3d/core/Dtype.h"
30#include "open3d/core/Tensor.h"
34
35namespace open3d {
36namespace core {
37namespace nns {
38
39#ifdef BUILD_CUDA_MODULE
40template <class T, class TIndex>
41void KnnSearchCUDA(const Tensor& points,
42 const Tensor& points_row_splits,
43 const Tensor& queries,
44 const Tensor& queries_row_splits,
45 int knn,
46 Tensor& neighbors_index,
47 Tensor& neighbors_row_splits,
48 Tensor& neighbors_distance);
49#endif
50
51class KnnIndex : public NNSIndex {
52public:
53 KnnIndex();
54
59 KnnIndex(const Tensor& dataset_points);
60 ~KnnIndex();
61 KnnIndex(const KnnIndex&) = delete;
62 KnnIndex& operator=(const KnnIndex&) = delete;
63
64public:
65 bool SetTensorData(const Tensor& dataset_points) override;
66 bool SetTensorData(const Tensor& dataset_points,
67 const Tensor& points_row_splits);
68 bool SetTensorData(const Tensor& dataset_points, double radius) override {
70 "[KnnIndex::SetTensorData with radius not implemented.");
71 }
72
73 std::pair<Tensor, Tensor> SearchKnn(const Tensor& query_points,
74 int knn) const override;
75
76 std::pair<Tensor, Tensor> SearchKnn(const Tensor& query_points,
77 const Tensor& queries_row_splits,
78 int knn) const;
79
80 std::tuple<Tensor, Tensor, Tensor> SearchRadius(const Tensor& query_points,
81 const Tensor& radii,
82 bool sort) const override {
83 utility::LogError("KnnIndex::SearchRadius not implemented.");
84 }
85
86 std::tuple<Tensor, Tensor, Tensor> SearchRadius(const Tensor& query_points,
87 double radius,
88 bool sort) const override {
89 utility::LogError("KnnIndex::SearchRadius not implemented.");
90 }
91
92 std::tuple<Tensor, Tensor, Tensor> SearchHybrid(
93 const Tensor& query_points,
94 double radius,
95 int max_knn) const override {
96 utility::LogError("KnnIndex::SearchHybrid not implemented.");
97 }
98
99protected:
101};
102
103} // namespace nns
104} // namespace core
105} // namespace open3d
#define LogError(...)
Definition: Logging.h:67
Definition: Tensor.h:51
Definition: KnnIndex.h:51
std::pair< Tensor, Tensor > SearchKnn(const Tensor &query_points, int knn) const override
Definition: KnnIndex.cpp:90
KnnIndex(const KnnIndex &)=delete
bool SetTensorData(const Tensor &dataset_points) override
Definition: KnnIndex.cpp:46
KnnIndex()
Definition: KnnIndex.cpp:38
std::tuple< Tensor, Tensor, Tensor > SearchRadius(const Tensor &query_points, double radius, bool sort) const override
Definition: KnnIndex.h:86
std::tuple< Tensor, Tensor, Tensor > SearchHybrid(const Tensor &query_points, double radius, int max_knn) const override
Definition: KnnIndex.h:92
KnnIndex & operator=(const KnnIndex &)=delete
Tensor points_row_splits_
Definition: KnnIndex.h:100
~KnnIndex()
Definition: KnnIndex.cpp:44
bool SetTensorData(const Tensor &dataset_points, double radius) override
Definition: KnnIndex.h:68
std::tuple< Tensor, Tensor, Tensor > SearchRadius(const Tensor &query_points, const Tensor &radii, bool sort) const override
Definition: KnnIndex.h:80
Definition: NNSIndex.h:40
int points
Definition: FilePCD.cpp:73
Definition: PinholeCameraIntrinsic.cpp:35