Open3D (C++ API)  0.12.0
FixedRadiusIndex.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 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 <vector>
30 
31 #include "open3d/core/Dtype.h"
32 #include "open3d/core/Tensor.h"
34 
35 namespace open3d {
36 namespace core {
37 namespace nns {
38 
42 class FixedRadiusIndex : public NNSIndex {
43 public:
46 
51  FixedRadiusIndex(const Tensor& dataset_points, double radius);
53  FixedRadiusIndex(const FixedRadiusIndex&) = delete;
55 
56 public:
57  bool SetTensorData(const Tensor& dataset_points) override {
59  "FixedRadiusIndex::SetTensorData witout radius not "
60  "implemented.");
61  }
62 
63  bool SetTensorData(const Tensor& dataset_points, double radius) override;
64 
65  std::pair<Tensor, Tensor> SearchKnn(const Tensor& query_points,
66  int knn) const override {
67  utility::LogError("FixedRadiusIndex::SearchKnn not implemented.");
68  }
69 
70  std::tuple<Tensor, Tensor, Tensor> SearchRadius(
71  const Tensor& query_points, const Tensor& radii) const override {
73  "FixedRadiusIndex::SearchRadius with multi-radii not "
74  "implemented.");
75  }
86  std::tuple<Tensor, Tensor, Tensor> SearchRadius(
87  const Tensor& query_points, double radius) const override;
88 
89  std::pair<Tensor, Tensor> SearchHybrid(const Tensor& query_points,
90  float radius,
91  int max_knn) const override {
92  utility::LogError("FixedRadiusIndex::SearchHybrid not implemented.");
93  }
94 
95  const double hash_table_size_factor = 1 / 32;
96  const int64_t max_hash_tabls_size = 10000;
97 
98 protected:
99  std::vector<int64_t> points_row_splits_;
100  std::vector<uint32_t> hash_table_splits_;
101  std::vector<uint32_t> out_hash_table_splits_;
104 };
105 
106 template <class T>
108 public:
109  NeighborSearchAllocator(Device device) : device_(device) {}
110 
111  void AllocIndices(int32_t** ptr, size_t num) {
112  neighbors_index = Tensor::Empty({int64_t(num)}, Dtype::Int32, device_);
113  *ptr = static_cast<int32_t*>(neighbors_index.GetDataPtr());
114  }
115 
116  void AllocDistances(T** ptr, size_t num) {
117  neighbors_distance =
118  Tensor::Empty({int64_t(num)}, Dtype::FromType<T>(), device_);
119  *ptr = static_cast<T*>(neighbors_distance.GetDataPtr());
120  }
121 
122  const int32_t* IndicesPtr() const {
123  return static_cast<const int32_t*>(neighbors_index.GetDataPtr());
124  }
125 
126  const T* DistancesPtr() const {
127  return static_cast<T*>(neighbors_distance.GetDataPtr());
128  }
129 
130  const Tensor& NeighborsIndex() const { return neighbors_index; }
131  const Tensor& NeighborsDistance() const { return neighbors_distance; }
132 
133 private:
134  Tensor neighbors_index;
135  Tensor neighbors_distance;
136  Device device_;
137 };
138 } // namespace nns
139 } // namespace core
140 } // namespace open3d
const int64_t max_hash_tabls_size
Definition: FixedRadiusIndex.h:96
std::tuple< Tensor, Tensor, Tensor > SearchRadius(const Tensor &query_points, const Tensor &radii) const override
Definition: FixedRadiusIndex.h:70
FixedRadiusIndex for nearest neighbor range search.
Definition: FixedRadiusIndex.h:42
void AllocIndices(int32_t **ptr, size_t num)
Definition: FixedRadiusIndex.h:111
Definition: NNSIndex.h:40
void LogError(const char *format, const Args &... args)
Definition: Console.h:176
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t int32_t
Definition: K4aPlugin.cpp:398
const double hash_table_size_factor
Definition: FixedRadiusIndex.h:95
NeighborSearchAllocator(Device device)
Definition: FixedRadiusIndex.h:109
static const Dtype Int32
Definition: Dtype.h:44
FixedRadiusIndex()
Default Constructor.
Definition: FixedRadiusIndex.cpp:40
static Tensor Empty(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor with uninitilized values.
Definition: Tensor.cpp:176
const T * DistancesPtr() const
Definition: FixedRadiusIndex.h:126
~FixedRadiusIndex()
Definition: FixedRadiusIndex.cpp:47
Definition: Device.h:39
std::vector< int64_t > points_row_splits_
Definition: FixedRadiusIndex.h:99
const Tensor & NeighborsIndex() const
Definition: FixedRadiusIndex.h:130
Tensor hash_table_index_
Definition: FixedRadiusIndex.h:103
FixedRadiusIndex & operator=(const FixedRadiusIndex &)=delete
const Tensor & NeighborsDistance() const
Definition: FixedRadiusIndex.h:131
Definition: PinholeCameraIntrinsic.cpp:35
Definition: Tensor.h:48
std::vector< uint32_t > hash_table_splits_
Definition: FixedRadiusIndex.h:100
std::pair< Tensor, Tensor > SearchHybrid(const Tensor &query_points, float radius, int max_knn) const override
Definition: FixedRadiusIndex.h:89
bool SetTensorData(const Tensor &dataset_points) override
Definition: FixedRadiusIndex.h:57
Definition: FixedRadiusIndex.h:107
std::pair< Tensor, Tensor > SearchKnn(const Tensor &query_points, int knn) const override
Definition: FixedRadiusIndex.h:65
Tensor hash_table_cell_splits_
Definition: FixedRadiusIndex.h:102
void AllocDistances(T **ptr, size_t num)
Definition: FixedRadiusIndex.h:116
std::vector< uint32_t > out_hash_table_splits_
Definition: FixedRadiusIndex.h:101
const int32_t * IndicesPtr() const
Definition: FixedRadiusIndex.h:122