Open3D (C++ API)  0.20.0
Loading...
Searching...
No Matches
KnnIndex.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// Copyright (c) 2018-2026 www.open3d.org
5// SPDX-License-Identifier: MIT
6// ----------------------------------------------------------------------------
7
8#pragma once
9
10#include "open3d/Macro.h"
11#include "open3d/core/Dtype.h"
12#include "open3d/core/Tensor.h"
16
17#ifdef BUILD_CUDA_MODULE
18struct CUstream_st;
19using cudaStream_t = CUstream_st*;
20#endif
21
22namespace open3d {
23namespace core {
24namespace nns {
25
26#ifdef BUILD_CUDA_MODULE
33template <class T, class TIndex>
34void KnnSearchCUDA(const Tensor& points,
35 const Tensor& points_row_splits,
36 const Tensor& queries,
37 const Tensor& queries_row_splits,
38 int knn,
39 Tensor& neighbors_index,
40 Tensor& neighbors_row_splits,
41 Tensor& neighbors_distance,
42 cudaStream_t user_stream = nullptr);
43#endif
44
45#ifdef BUILD_SYCL_MODULE
59template <class T, class TIndex>
60OPEN3D_API void KnnSearchSYCL(const Tensor& points,
61 const Tensor& points_row_splits,
62 const Tensor& queries,
63 const Tensor& queries_row_splits,
64 int knn,
65 Tensor& neighbors_index,
66 Tensor& neighbors_row_splits,
67 Tensor& neighbors_distance,
68 int64_t tile_bytes,
69 int64_t max_tile_queries = 2048,
70 int64_t tile_points_alignment = 128,
71 bool force_addmm_path = false);
72#endif
73
74class KnnIndex : public NNSIndex {
75public:
76 KnnIndex();
77
84 KnnIndex(const Tensor& dataset_points);
85 KnnIndex(const Tensor& dataset_points, const Dtype& index_dtype);
86
95 KnnIndex(const Tensor& dataset_points,
96 const Dtype& index_dtype,
97 int64_t tile_bytes);
98
99 ~KnnIndex();
100 KnnIndex(const KnnIndex&) = delete;
101 KnnIndex& operator=(const KnnIndex&) = delete;
102
103public:
104 bool SetTensorData(const Tensor& dataset_points,
105 const Dtype& index_dtype = core::Int64) override;
106 bool SetTensorData(const Tensor& dataset_points,
107 const Tensor& points_row_splits,
108 const Dtype& index_dtype = core::Int64);
109 bool SetTensorData(const Tensor& dataset_points,
110 double radius,
111 const Dtype& index_dtype = core::Int64) override {
112 utility::LogError(
113 "[KnnIndex::SetTensorData with radius not implemented.");
114 }
115
116 std::pair<Tensor, Tensor> SearchKnn(const Tensor& query_points,
117 int knn) const override;
118
119 std::pair<Tensor, Tensor> SearchKnn(const Tensor& query_points,
120 const Tensor& queries_row_splits,
121 int knn) const;
122
123 std::tuple<Tensor, Tensor, Tensor> SearchRadius(const Tensor& query_points,
124 const Tensor& radii,
125 bool sort) const override {
126 utility::LogError("KnnIndex::SearchRadius not implemented.");
127 }
128
129 std::tuple<Tensor, Tensor, Tensor> SearchRadius(const Tensor& query_points,
130 const double radius,
131 bool sort) const override {
132 utility::LogError("KnnIndex::SearchRadius not implemented.");
133 }
134
135 std::tuple<Tensor, Tensor, Tensor> SearchHybrid(
136 const Tensor& query_points,
137 const double radius,
138 const int max_knn) const override {
139 utility::LogError("KnnIndex::SearchHybrid not implemented.");
140 }
141
142protected:
146};
147
148} // namespace nns
149} // namespace core
150} // namespace open3d
#define OPEN3D_API
Definition Macro.h:32
int knn
Definition PointCloudSmoothing.cpp:131
Definition Dtype.h:20
Definition Tensor.h:32
Definition KnnIndex.h:74
std::pair< Tensor, Tensor > SearchKnn(const Tensor &query_points, int knn) const override
Definition KnnIndex.cpp:99
std::tuple< Tensor, Tensor, Tensor > SearchRadius(const Tensor &query_points, const double radius, bool sort) const override
Definition KnnIndex.h:129
KnnIndex(const KnnIndex &)=delete
KnnIndex()
Definition KnnIndex.cpp:21
std::tuple< Tensor, Tensor, Tensor > SearchHybrid(const Tensor &query_points, const double radius, const int max_knn) const override
Definition KnnIndex.h:135
bool SetTensorData(const Tensor &dataset_points, const Dtype &index_dtype=core::Int64) override
Definition KnnIndex.cpp:40
int64_t tile_bytes_
Distance tile budget for SYCL (bytes). See kSYCLKnnDefaultTileBytes.
Definition KnnIndex.h:145
KnnIndex & operator=(const KnnIndex &)=delete
Tensor points_row_splits_
Definition KnnIndex.h:143
~KnnIndex()
Definition KnnIndex.cpp:38
bool SetTensorData(const Tensor &dataset_points, double radius, const Dtype &index_dtype=core::Int64) override
Definition KnnIndex.h:109
std::tuple< Tensor, Tensor, Tensor > SearchRadius(const Tensor &query_points, const Tensor &radii, bool sort) const override
Definition KnnIndex.h:123
Definition NNSIndex.h:21
Shared types and SYCL nearest-neighbor search tuning defaults.
int points
Definition FilePCD.cpp:55
void KnnSearchSYCL(const Tensor &points, const Tensor &points_row_splits, const Tensor &queries, const Tensor &queries_row_splits, int knn, Tensor &neighbors_index, Tensor &neighbors_row_splits, Tensor &neighbors_distance, int64_t tile_bytes, int64_t max_tile_queries, int64_t tile_points_alignment, bool force_addmm_path)
Definition KnnSearchOpsSYCL.cpp:277
constexpr int64_t kSYCLKnnDefaultTileBytes
SYCL NNS defaults for KnnIndex and FixedRadiusIndex constructors.
Definition NeighborSearchCommon.h:64
const Dtype Int64
Definition Dtype.cpp:47
Definition PinholeCameraIntrinsic.cpp:16