Open3D (C++ API)  0.13.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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,
72  const Tensor& radii,
73  bool sort = true) const override {
75  "FixedRadiusIndex::SearchRadius with multi-radii not "
76  "implemented.");
77  }
78 
79  std::tuple<Tensor, Tensor, Tensor> SearchRadius(
80  const Tensor& query_points,
81  double radius,
82  bool sort = true) const override;
83 
84  std::pair<Tensor, Tensor> SearchHybrid(const Tensor& query_points,
85  double radius,
86  int max_knn) const override;
87 
88  const double hash_table_size_factor = 1.0 / 32;
89  const int64_t max_hash_tabls_size = 33554432;
90 
91 protected:
92  std::vector<int64_t> points_row_splits_;
93  std::vector<int64_t> hash_table_splits_;
96 };
97 
98 template <class T>
100 public:
101  NeighborSearchAllocator(Device device) : device_(device) {}
102 
103  void AllocIndices(int64_t** ptr, size_t num) {
104  indices_ = Tensor::Empty({int64_t(num)}, Dtype::Int64, device_);
105  *ptr = indices_.GetDataPtr<int64_t>();
106  }
107 
108  void AllocIndices(int64_t** ptr, size_t num, int64_t value) {
109  indices_ = Tensor::Full({int64_t(num)}, value, Dtype::Int64, device_);
110  *ptr = indices_.GetDataPtr<int64_t>();
111  }
112 
113  void AllocDistances(T** ptr, size_t num) {
114  distances_ =
115  Tensor::Empty({int64_t(num)}, Dtype::FromType<T>(), device_);
116  *ptr = distances_.GetDataPtr<T>();
117  }
118 
119  void AllocDistances(T** ptr, size_t num, T value) {
120  distances_ = Tensor::Full({int64_t(num)}, value, Dtype::FromType<T>(),
121  device_);
122  *ptr = distances_.GetDataPtr<T>();
123  }
124 
125  const int64_t* IndicesPtr() const { return indices_.GetDataPtr<int64_t>(); }
126 
127  const T* DistancesPtr() const { return distances_.GetDataPtr<T>(); }
128 
129  const Tensor& NeighborsIndex() const { return indices_; }
130  const Tensor& NeighborsDistance() const { return distances_; }
131 
132 private:
133  Tensor indices_;
134  Tensor distances_;
135  Device device_;
136 };
137 } // namespace nns
138 } // namespace core
139 } // namespace open3d
const int64_t max_hash_tabls_size
Definition: FixedRadiusIndex.h:89
FixedRadiusIndex for nearest neighbor range search.
Definition: FixedRadiusIndex.h:42
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:196
void AllocDistances(T **ptr, size_t num, T value)
Definition: FixedRadiusIndex.h:119
const int64_t * IndicesPtr() const
Definition: FixedRadiusIndex.h:125
Definition: NNSIndex.h:40
const double hash_table_size_factor
Definition: FixedRadiusIndex.h:88
std::pair< Tensor, Tensor > SearchHybrid(const Tensor &query_points, double radius, int max_knn) const override
Definition: FixedRadiusIndex.cpp:225
#define LogError(...)
Definition: Console.h:79
NeighborSearchAllocator(Device device)
Definition: FixedRadiusIndex.h:101
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 uninitialized values.
Definition: Tensor.cpp:234
const T * DistancesPtr() const
Definition: FixedRadiusIndex.h:127
~FixedRadiusIndex()
Definition: FixedRadiusIndex.cpp:47
Definition: Device.h:39
std::vector< int64_t > points_row_splits_
Definition: FixedRadiusIndex.h:92
const Tensor & NeighborsIndex() const
Definition: FixedRadiusIndex.h:129
Tensor hash_table_index_
Definition: FixedRadiusIndex.h:95
std::vector< int64_t > hash_table_splits_
Definition: FixedRadiusIndex.h:93
void AllocIndices(int64_t **ptr, size_t num, int64_t value)
Definition: FixedRadiusIndex.h:108
std::tuple< Tensor, Tensor, Tensor > SearchRadius(const Tensor &query_points, const Tensor &radii, bool sort=true) const override
Definition: FixedRadiusIndex.h:70
FixedRadiusIndex & operator=(const FixedRadiusIndex &)=delete
static const Dtype Int64
Definition: Dtype.h:47
const Tensor & NeighborsDistance() const
Definition: FixedRadiusIndex.h:130
Definition: PinholeCameraIntrinsic.cpp:35
Definition: Tensor.h:50
bool SetTensorData(const Tensor &dataset_points) override
Definition: FixedRadiusIndex.h:57
Definition: FixedRadiusIndex.h:99
std::pair< Tensor, Tensor > SearchKnn(const Tensor &query_points, int knn) const override
Definition: FixedRadiusIndex.h:65
T * GetDataPtr()
Definition: Tensor.h:1005
Tensor hash_table_cell_splits_
Definition: FixedRadiusIndex.h:94
void AllocIndices(int64_t **ptr, size_t num)
Definition: FixedRadiusIndex.h:103
void AllocDistances(T **ptr, size_t num)
Definition: FixedRadiusIndex.h:113