ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
FixedRadiusIndex.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 <vector>
11 
12 #include "cloudViewer/core/Dtype.h"
16 
17 namespace cloudViewer {
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
201 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);
396  FixedRadiusIndex(const FixedRadiusIndex&) = delete;
397  FixedRadiusIndex& operator=(const FixedRadiusIndex&) = delete;
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 cloudViewer
cloudViewer
Generic file read and write utility for python interface.
Definition: CloudViewerConfig.cpp:12
RADIUS_PARAMETERS
#define RADIUS_PARAMETERS
cloudViewer::core::nns::FixedRadiusIndex::FixedRadiusIndex
FixedRadiusIndex()
Default Constructor.
Definition: FixedRadiusIndex.cpp:19
cloudViewer::core::nns::FixedRadiusIndex::hash_table_cell_splits_
Tensor hash_table_cell_splits_
Definition: FixedRadiusIndex.h:455
Device.h
cloudViewer::core::Tensor::GetShape
SizeVector GetShape() const
Definition: Tensor.h:1127
cloudViewer::core::UInt32
const Dtype UInt32
Definition: Dtype.cpp:50
cloudViewer::core::nns::FixedRadiusIndex::SearchKnn
std::pair< Tensor, Tensor > SearchKnn(const Tensor &query_points, int knn) const override
Definition: FixedRadiusIndex.h:415
AssertTensorDevice
#define AssertTensorDevice(tensor,...)
Definition: TensorCheck.h:45
cloudViewer::core::Tensor::Contiguous
Tensor Contiguous() const
Definition: Tensor.cpp:772
cloudViewer::core::nns::NNSIndex::GetDevice
Device GetDevice() const
Definition: NNSIndex.cpp:26
cloudViewer::core::nns::FixedRadiusIndex
FixedRadiusIndex for nearest neighbor range search.
Definition: FixedRadiusIndex.h:382
cloudViewer::core::Free
void Free(benchmark::State &state, int size, const Device &device, const MemoryManagerBackend &backend)
Definition: MemoryManager.cpp:75
cloudViewer::core::nns::NNSIndex::GetDatasetSize
size_t GetDatasetSize() const
Definition: NNSIndex.cpp:19
cloudViewer::core::nns::FixedRadiusIndex::hash_table_index_
Tensor hash_table_index_
Definition: FixedRadiusIndex.h:456
cloudViewer::core::nns::NNSIndex::GetDtype
Dtype GetDtype() const
Definition: NNSIndex.cpp:24
NeighborSearchCommon.h
cloudViewer::core::nns::FixedRadiusIndex::points_row_splits_
Tensor points_row_splits_
Definition: FixedRadiusIndex.h:453
cloudViewer::core::Tensor
Definition: Tensor.h:32
cloudViewer::core::Tensor::View
Tensor View(const SizeVector &dst_shape) const
Definition: Tensor.cpp:721
SYCLContext.h
SYCL queue manager.
cloudViewer::core::nns::FixedRadiusIndex::SearchRadius
std::tuple< Tensor, Tensor, Tensor > SearchRadius(const Tensor &query_points, const Tensor &radii, bool sort=true) const override
Definition: FixedRadiusIndex.h:420
cloudViewer::core::Dtype
Definition: Dtype.h:21
NNSIndex.h
cloudViewer::core::Device::IsCUDA
bool IsCUDA() const
Returns true iff device type is CUDA.
Definition: Device.h:49
CALL_BUILD
#define CALL_BUILD(type, fn)
cloudViewer::core::nns::NNSIndex::GetDimension
int GetDimension() const
Definition: NNSIndex.cpp:14
cloudViewer::core::nns::FixedRadiusIndex::~FixedRadiusIndex
~FixedRadiusIndex()
Definition: FixedRadiusIndex.cpp:35
cloudViewer::core::nns::FixedRadiusIndex::max_hash_tabls_size
const int64_t max_hash_tabls_size
Definition: FixedRadiusIndex.h:450
cloudViewer::core::Int32
const Dtype Int32
Definition: Dtype.cpp:46
Dispatch.h
cloudViewer::core::Device
Definition: Device.h:18
cloudViewer::core::nns::NNSIndex
Definition: NNSIndex.h:21
TensorCheck.h
core
cloudViewer::core::nns::Metric
Metric
Supported metrics.
Definition: NeighborSearchCommon.h:19
cloudViewer::core::nns::FixedRadiusIndex::hash_table_splits_
Tensor hash_table_splits_
Definition: FixedRadiusIndex.h:454
cloudViewer::core::nns::FixedRadiusIndex::hash_table_size_factor
const double hash_table_size_factor
Definition: FixedRadiusIndex.h:449
cloudViewer::core::Float64
const Dtype Float64
Definition: Dtype.cpp:43
points
int points
Definition: FileIOFactory.cpp:144
cloudViewer::core::Float32
const Dtype Float32
Definition: Dtype.cpp:42
SYCLUtils.h
Common SYCL utilities.
cloudViewer::core::nns::FixedRadiusSearchCPU
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:39
LogError
#define LogError(...)
Definition: Logging.h:60
cloudViewer::core::sy::SYCLContext::GetInstance
static SYCLContext & GetInstance()
Get singleton instance.
Definition: SYCLContext.cpp:25
cloudViewer::core::nns::FixedRadiusIndex::SearchHybrid
std::tuple< Tensor, Tensor, Tensor > SearchHybrid(const Tensor &query_points, double radius, int max_knn) const override
Definition: FixedRadiusIndex.cpp:188
cloudViewer::core::nns::BuildSpatialHashTableCPU
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:22
cloudViewer::core::Tensor::Item
T Item() const
Definition: Tensor.h:618
AssertTensorDtype
#define AssertTensorDtype(tensor,...)
Definition: TensorCheck.h:21
cloudViewer::core::Malloc
void Malloc(benchmark::State &state, int size, const Device &device, const MemoryManagerBackend &backend)
Definition: MemoryManager.cpp:47
cloudViewer::core::nns::NNSIndex::GetIndexDtype
Dtype GetIndexDtype() const
Definition: NNSIndex.cpp:28
cloudViewer::core::nns::FixedRadiusIndex::SetTensorData
bool SetTensorData(const Tensor &dataset_points, const Dtype &index_dtype=core::Int64) override
Definition: FixedRadiusIndex.h:400
cloudViewer::core::Tensor::Empty
static Tensor Empty(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor with uninitialized values.
Definition: Tensor.cpp:400
cloudViewer::utility::nullopt
constexpr nullopt_t nullopt
Definition: Optional.h:136
Tensor.h
FixedRadiusIndex.h
HYBRID_PARAMETERS
#define HYBRID_PARAMETERS
AssertTensorShape
#define AssertTensorShape(tensor,...)
Definition: TensorCheck.h:61
cloudViewer::core::nns::FixedRadiusIndex::operator=
FixedRadiusIndex & operator=(const FixedRadiusIndex &)=delete
cloudViewer::core::nns::NNSIndex::index_dtype_
Dtype index_dtype_
Definition: NNSIndex.h:121
cloudViewer::core::nns::HybridSearchCPU
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:75
AssertTensorDtypes
#define AssertTensorDtypes(tensor,...)
Definition: TensorCheck.h:33
cloudViewer::core::sy::SYCLContext::GetDefaultQueue
sycl::queue GetDefaultQueue(const Device &device)
Get the default SYCL queue given an CloudViewer device.
Definition: SYCLContext.cpp:43
radii
std::vector< PointCoordinateType > radii
Definition: qM3C2Tools.cpp:42
cloudViewer::core::Int64
const Dtype Int64
Definition: Dtype.cpp:47
MemoryManager.h
Dtype.h
cloudViewer::core::Tensor::To
Tensor To(Dtype dtype, bool copy=false) const
Definition: Tensor.cpp:739
DISPATCH_FLOAT_INT_DTYPE_TO_TEMPLATE
#define DISPATCH_FLOAT_INT_DTYPE_TO_TEMPLATE(FDTYPE, IDTYPE,...)
Definition: Dispatch.h:91
cloudViewer::core::nns::NNSIndex::dataset_points_
Tensor dataset_points_
Definition: NNSIndex.h:120