Open3D (C++ API)  0.17.0
FixedRadiusIndex.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/Dtype.h"
13 #include "open3d/core/Tensor.h"
16 
17 namespace open3d {
18 namespace core {
19 namespace nns {
20 
48 template <class T>
49 void BuildSpatialHashTableCPU(const Tensor& points,
50  double radius,
51  const Tensor& points_row_splits,
52  const Tensor& hash_table_splits,
53  Tensor& hash_table_index,
54  Tensor& hash_table_cell_splits);
55 
117 template <class T, class TIndex>
118 void FixedRadiusSearchCPU(const Tensor& points,
119  const Tensor& queries,
120  double radius,
121  const Tensor& points_row_splits,
122  const Tensor& queries_row_splits,
123  const Tensor& hash_table_splits,
124  const Tensor& hash_table_index,
125  const Tensor& hash_table_cell_splits,
126  const Metric metric,
127  const bool ignore_query_point,
128  const bool return_distances,
129  const bool sort,
130  Tensor& neighbors_index,
131  Tensor& neighbors_row_splits,
132  Tensor& neighbors_distance);
133 
185 template <class T, class TIndex>
186 void HybridSearchCPU(const Tensor& points,
187  const Tensor& queries,
188  double radius,
189  int max_knn,
190  const Tensor& points_row_splits,
191  const Tensor& queries_row_splits,
192  const Tensor& hash_table_splits,
193  const Tensor& hash_table_index,
194  const Tensor& hash_table_cell_splits,
195  const Metric metric,
196  Tensor& neighbors_index,
197  Tensor& neighbors_count,
198  Tensor& neighbors_distance);
199 
200 #ifdef BUILD_CUDA_MODULE
226 template <class T>
227 void BuildSpatialHashTableCUDA(const Tensor& points,
228  double radius,
229  const Tensor& points_row_splits,
230  const Tensor& hash_table_splits,
231  Tensor& hash_table_index,
232  Tensor& hash_table_cell_splits);
233 
234 // Fixed radius search. This function computes a list of neighbor indices
295 template <class T, class TIndex>
296 void FixedRadiusSearchCUDA(const Tensor& points,
297  const Tensor& queries,
298  double radius,
299  const Tensor& points_row_splits,
300  const Tensor& queries_row_splits,
301  const Tensor& hash_table_splits,
302  const Tensor& hash_table_index,
303  const Tensor& hash_table_cell_splits,
304  const Metric metric,
305  const bool ignore_query_point,
306  const bool return_distances,
307  const bool sort,
308  Tensor& neighbors_index,
309  Tensor& neighbors_row_splits,
310  Tensor& neighbors_distance);
311 
363 template <class T, class TIndex>
364 void HybridSearchCUDA(const Tensor& points,
365  const Tensor& queries,
366  double radius,
367  int max_knn,
368  const Tensor& points_row_splits,
369  const Tensor& queries_row_splits,
370  const Tensor& hash_table_splits,
371  const Tensor& hash_table_index,
372  const Tensor& hash_table_cell_splits,
373  const Metric metric,
374  Tensor& neighbors_index,
375  Tensor& neighbors_count,
376  Tensor& neighbors_distance);
377 #endif
378 
382 class FixedRadiusIndex : public NNSIndex {
383 public:
386 
391  FixedRadiusIndex(const Tensor& dataset_points, double radius);
392  FixedRadiusIndex(const Tensor& dataset_points,
393  double radius,
394  const Dtype& index_dtype);
398 
399 public:
400  bool SetTensorData(const Tensor& dataset_points,
401  const Dtype& index_dtype = core::Int64) override {
403  "FixedRadiusIndex::SetTensorData without radius not "
404  "implemented.");
405  }
406 
407  bool SetTensorData(const Tensor& dataset_points,
408  double radius,
409  const Dtype& index_dtype = core::Int64) override;
410  bool SetTensorData(const Tensor& dataset_points,
411  const Tensor& points_row_splits,
412  double radius,
413  const Dtype& index_dtype = core::Int64);
414 
415  std::pair<Tensor, Tensor> SearchKnn(const Tensor& query_points,
416  int knn) const override {
417  utility::LogError("FixedRadiusIndex::SearchKnn not implemented.");
418  }
419 
420  std::tuple<Tensor, Tensor, Tensor> SearchRadius(
421  const Tensor& query_points,
422  const Tensor& radii,
423  bool sort = true) const override {
425  "FixedRadiusIndex::SearchRadius with multi-radii not "
426  "implemented.");
427  }
428 
429  std::tuple<Tensor, Tensor, Tensor> SearchRadius(
430  const Tensor& query_points,
431  double radius,
432  bool sort = true) const override;
433  std::tuple<Tensor, Tensor, Tensor> SearchRadius(
434  const Tensor& query_points,
435  const Tensor& queries_row_splits,
436  double radius,
437  bool sort = true) const;
438 
439  std::tuple<Tensor, Tensor, Tensor> SearchHybrid(const Tensor& query_points,
440  double radius,
441  int max_knn) const override;
442 
443  std::tuple<Tensor, Tensor, Tensor> SearchHybrid(
444  const Tensor& query_points,
445  const Tensor& queries_row_splits,
446  double radius,
447  int max_knn) const;
448 
449  const double hash_table_size_factor = 1.0 / 32;
450  const int64_t max_hash_tabls_size = 33554432;
451 
452 protected:
457 };
458 
459 } // namespace nns
460 } // namespace core
461 } // namespace open3d
#define LogError(...)
Definition: Logging.h:48
Definition: Dtype.h:20
Definition: Tensor.h:32
FixedRadiusIndex for nearest neighbor range search.
Definition: FixedRadiusIndex.h:382
FixedRadiusIndex(const FixedRadiusIndex &)=delete
Tensor hash_table_splits_
Definition: FixedRadiusIndex.h:454
const int64_t max_hash_tabls_size
Definition: FixedRadiusIndex.h:450
std::tuple< Tensor, Tensor, Tensor > SearchRadius(const Tensor &query_points, const Tensor &radii, bool sort=true) const override
Definition: FixedRadiusIndex.h:420
Tensor hash_table_cell_splits_
Definition: FixedRadiusIndex.h:455
std::pair< Tensor, Tensor > SearchKnn(const Tensor &query_points, int knn) const override
Definition: FixedRadiusIndex.h:415
Tensor points_row_splits_
Definition: FixedRadiusIndex.h:453
bool SetTensorData(const Tensor &dataset_points, const Dtype &index_dtype=core::Int64) override
Definition: FixedRadiusIndex.h:400
FixedRadiusIndex & operator=(const FixedRadiusIndex &)=delete
std::tuple< Tensor, Tensor, Tensor > SearchHybrid(const Tensor &query_points, double radius, int max_knn) const override
Definition: FixedRadiusIndex.cpp:187
Tensor hash_table_index_
Definition: FixedRadiusIndex.h:456
const double hash_table_size_factor
Definition: FixedRadiusIndex.h:449
~FixedRadiusIndex()
Definition: FixedRadiusIndex.cpp:34
FixedRadiusIndex()
Default Constructor.
Definition: FixedRadiusIndex.cpp:18
Definition: NNSIndex.h:21
int points
Definition: FilePCD.cpp:54
Metric
Supported metrics.
Definition: NeighborSearchCommon.h:19
void HybridSearchCPU(const Tensor &points, const Tensor &queries, double radius, int max_knn, const Tensor &points_row_splits, const Tensor &queries_row_splits, const Tensor &hash_table_splits, const Tensor &hash_table_index, const Tensor &hash_table_cell_splits, const Metric metric, Tensor &neighbors_index, Tensor &neighbors_count, Tensor &neighbors_distance)
Definition: FixedRadiusSearchOps.cpp:74
void BuildSpatialHashTableCPU(const Tensor &points, double radius, const Tensor &points_row_splits, const Tensor &hash_table_splits, Tensor &hash_table_index, Tensor &hash_table_cell_splits)
Definition: FixedRadiusSearchOps.cpp:21
void FixedRadiusSearchCPU(const Tensor &points, const Tensor &queries, double radius, const Tensor &points_row_splits, const Tensor &queries_row_splits, const Tensor &hash_table_splits, const Tensor &hash_table_index, const Tensor &hash_table_cell_splits, const Metric metric, const bool ignore_query_point, const bool return_distances, const bool sort, Tensor &neighbors_index, Tensor &neighbors_row_splits, Tensor &neighbors_distance)
Definition: FixedRadiusSearchOps.cpp:38
const Dtype Int64
Definition: Dtype.cpp:47
Definition: PinholeCameraIntrinsic.cpp:16