ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
NeighborSearchAllocator.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 
11 #include "cloudViewer/core/Dtype.h"
13 
14 namespace cloudViewer {
15 namespace core {
16 namespace nns {
17 
18 template <class T, class TIndex = int32_t>
20 public:
21  NeighborSearchAllocator(Device device) : device_(device) {}
22 
23  void AllocIndices(TIndex** ptr, size_t num) {
24  indices_ = Tensor::Empty({int64_t(num)}, Dtype::FromType<TIndex>(),
25  device_);
26  *ptr = indices_.GetDataPtr<TIndex>();
27  }
28 
29  void AllocIndices(TIndex** ptr, size_t num, TIndex value) {
30  indices_ = Tensor::Full({int64_t(num)}, value,
31  Dtype::FromType<TIndex>(), device_);
32  *ptr = indices_.GetDataPtr<TIndex>();
33  }
34 
35  void AllocDistances(T** ptr, size_t num) {
36  distances_ =
37  Tensor::Empty({int64_t(num)}, Dtype::FromType<T>(), device_);
38  *ptr = distances_.GetDataPtr<T>();
39  }
40 
41  void AllocDistances(T** ptr, size_t num, T value) {
42  distances_ = Tensor::Full({int64_t(num)}, value, Dtype::FromType<T>(),
43  device_);
44  *ptr = distances_.GetDataPtr<T>();
45  }
46 
47  void AllocCounts(TIndex** ptr, size_t num) {
48  counts_ = Tensor::Empty({int64_t(num)}, Dtype::FromType<TIndex>(),
49  device_);
50  *ptr = counts_.GetDataPtr<TIndex>();
51  }
52 
53  void AllocCounts(TIndex** ptr, size_t num, TIndex value) {
54  counts_ = Tensor::Full({int64_t(num)}, value, Dtype::FromType<TIndex>(),
55  device_);
56  *ptr = counts_.GetDataPtr<TIndex>();
57  }
58 
59  const TIndex* IndicesPtr() const { return indices_.GetDataPtr<TIndex>(); }
60 
61  const T* DistancesPtr() const { return distances_.GetDataPtr<T>(); }
62 
63  const TIndex* CountsPtr() const { return counts_.GetDataPtr<TIndex>(); }
64 
65  const Tensor& NeighborsIndex() const { return indices_; }
66  Tensor& NeighborsIndex_() { return indices_; }
67  const Tensor& NeighborsDistance() const { return distances_; }
68  Tensor& NeighborsDistance_() { return distances_; }
69  const Tensor& NeighborsCount() const { return counts_; }
70 
71 private:
72  Tensor indices_;
73  Tensor distances_;
74  Tensor counts_;
75  Device device_;
76 };
77 
78 } // namespace nns
79 } // namespace core
80 } // namespace cloudViewer
static Tensor Empty(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor with uninitialized values.
Definition: Tensor.cpp:400
static Tensor Full(const SizeVector &shape, T fill_value, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor fill with specified value.
Definition: Tensor.h:253
void AllocIndices(TIndex **ptr, size_t num, TIndex value)
void AllocCounts(TIndex **ptr, size_t num, TIndex value)
void AllocDistances(T **ptr, size_t num, T value)
Generic file read and write utility for python interface.