Open3D (C++ API)  0.15.1
NeighborSearchAllocator.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/Device.h"
30 #include "open3d/core/Dtype.h"
31 #include "open3d/core/Tensor.h"
32 
33 namespace open3d {
34 namespace core {
35 namespace nns {
36 
37 template <class T, class TIndex = int32_t>
39 public:
40  NeighborSearchAllocator(Device device) : device_(device) {}
41 
42  void AllocIndices(TIndex** ptr, size_t num) {
43  indices_ = Tensor::Empty({int64_t(num)}, Dtype::FromType<TIndex>(),
44  device_);
45  *ptr = indices_.GetDataPtr<TIndex>();
46  }
47 
48  void AllocIndices(TIndex** ptr, size_t num, TIndex value) {
49  indices_ = Tensor::Full({int64_t(num)}, value,
50  Dtype::FromType<TIndex>(), device_);
51  *ptr = indices_.GetDataPtr<TIndex>();
52  }
53 
54  void AllocDistances(T** ptr, size_t num) {
55  distances_ =
56  Tensor::Empty({int64_t(num)}, Dtype::FromType<T>(), device_);
57  *ptr = distances_.GetDataPtr<T>();
58  }
59 
60  void AllocDistances(T** ptr, size_t num, T value) {
61  distances_ = Tensor::Full({int64_t(num)}, value, Dtype::FromType<T>(),
62  device_);
63  *ptr = distances_.GetDataPtr<T>();
64  }
65 
66  void AllocCounts(TIndex** ptr, size_t num) {
67  counts_ = Tensor::Empty({int64_t(num)}, Dtype::FromType<TIndex>(),
68  device_);
69  *ptr = counts_.GetDataPtr<TIndex>();
70  }
71 
72  void AllocCounts(TIndex** ptr, size_t num, TIndex value) {
73  counts_ = Tensor::Full({int64_t(num)}, value, Dtype::FromType<TIndex>(),
74  device_);
75  *ptr = counts_.GetDataPtr<TIndex>();
76  }
77 
78  const TIndex* IndicesPtr() const { return indices_.GetDataPtr<TIndex>(); }
79 
80  const T* DistancesPtr() const { return distances_.GetDataPtr<T>(); }
81 
82  const TIndex* CountsPtr() const { return counts_.GetDataPtr<TIndex>(); }
83 
84  const Tensor& NeighborsIndex() const { return indices_; }
85  Tensor& NeighborsIndex_() { return indices_; }
86  const Tensor& NeighborsDistance() const { return distances_; }
87  Tensor& NeighborsDistance_() { return distances_; }
88  const Tensor& NeighborsCount() const { return counts_; }
89 
90 private:
91  Tensor indices_;
92  Tensor distances_;
93  Tensor counts_;
94  Device device_;
95 };
96 
97 } // namespace nns
98 } // namespace core
99 } // namespace open3d
Definition: Device.h:39
Definition: Tensor.h:51
T * GetDataPtr()
Definition: Tensor.h:1108
static Tensor Empty(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor with uninitialized values.
Definition: Tensor.cpp:374
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:230
Definition: NeighborSearchAllocator.h:38
void AllocCounts(TIndex **ptr, size_t num, TIndex value)
Definition: NeighborSearchAllocator.h:72
const T * DistancesPtr() const
Definition: NeighborSearchAllocator.h:80
void AllocDistances(T **ptr, size_t num)
Definition: NeighborSearchAllocator.h:54
const TIndex * IndicesPtr() const
Definition: NeighborSearchAllocator.h:78
const Tensor & NeighborsIndex() const
Definition: NeighborSearchAllocator.h:84
void AllocDistances(T **ptr, size_t num, T value)
Definition: NeighborSearchAllocator.h:60
const Tensor & NeighborsDistance() const
Definition: NeighborSearchAllocator.h:86
void AllocIndices(TIndex **ptr, size_t num)
Definition: NeighborSearchAllocator.h:42
Tensor & NeighborsDistance_()
Definition: NeighborSearchAllocator.h:87
const Tensor & NeighborsCount() const
Definition: NeighborSearchAllocator.h:88
void AllocCounts(TIndex **ptr, size_t num)
Definition: NeighborSearchAllocator.h:66
NeighborSearchAllocator(Device device)
Definition: NeighborSearchAllocator.h:40
Tensor & NeighborsIndex_()
Definition: NeighborSearchAllocator.h:85
const TIndex * CountsPtr() const
Definition: NeighborSearchAllocator.h:82
void AllocIndices(TIndex **ptr, size_t num, TIndex value)
Definition: NeighborSearchAllocator.h:48
Definition: PinholeCameraIntrinsic.cpp:35