ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
FixedRadiusSearchOps.cpp
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 
9 #include <Logging.h>
10 
16 
17 namespace cloudViewer {
18 namespace core {
19 namespace nns {
20 
21 template <class T>
23  double radius,
24  const Tensor& points_row_splits,
25  const Tensor& hash_table_splits,
26  Tensor& hash_table_index,
27  Tensor& hash_table_cell_splits) {
29  points.GetShape()[0], points.GetDataPtr<T>(), T(radius),
30  points_row_splits.GetShape()[0],
31  points_row_splits.GetDataPtr<int64_t>(),
32  hash_table_splits.GetDataPtr<uint32_t>(),
33  hash_table_cell_splits.GetShape()[0],
34  hash_table_cell_splits.GetDataPtr<uint32_t>(),
35  hash_table_index.GetDataPtr<uint32_t>());
36 }
37 
38 template <class T, class TIndex>
40  const Tensor& queries,
41  double radius,
42  const Tensor& points_row_splits,
43  const Tensor& queries_row_splits,
44  const Tensor& hash_table_splits,
45  const Tensor& hash_table_index,
46  const Tensor& hash_table_cell_splits,
47  const Metric metric,
48  const bool ignore_query_point,
49  const bool return_distances,
50  const bool sort,
51  Tensor& neighbors_index,
52  Tensor& neighbors_row_splits,
53  Tensor& neighbors_distance) {
54  Device device = points.GetDevice();
55  NeighborSearchAllocator<T, TIndex> output_allocator(device);
56 
57  impl::FixedRadiusSearchCPU<T, TIndex>(
58  neighbors_row_splits.GetDataPtr<int64_t>(), points.GetShape()[0],
59  points.GetDataPtr<T>(), queries.GetShape()[0],
60  queries.GetDataPtr<T>(), T(radius), points_row_splits.GetShape()[0],
61  points_row_splits.GetDataPtr<int64_t>(),
62  queries_row_splits.GetShape()[0],
63  queries_row_splits.GetDataPtr<int64_t>(),
64  hash_table_splits.GetDataPtr<uint32_t>(),
65  hash_table_cell_splits.GetShape()[0],
66  hash_table_cell_splits.GetDataPtr<uint32_t>(),
67  hash_table_index.GetDataPtr<uint32_t>(), metric, ignore_query_point,
68  return_distances, output_allocator);
69 
70  neighbors_index = output_allocator.NeighborsIndex();
71  neighbors_distance = output_allocator.NeighborsDistance();
72 }
73 
74 template <class T, class TIndex>
76  const Tensor& queries,
77  double radius,
78  int max_knn,
79  const Tensor& points_row_splits,
80  const Tensor& queries_row_splits,
81  const Tensor& hash_table_splits,
82  const Tensor& hash_table_index,
83  const Tensor& hash_table_cell_splits,
84  const Metric metric,
85  Tensor& neighbors_index,
86  Tensor& neighbors_count,
87  Tensor& neighbors_distance) {
88  utility::LogError("Not implemented.");
89 }
90 
91 #define INSTANTIATE_BUILD(T) \
92  template void BuildSpatialHashTableCPU<T>( \
93  const Tensor& points, double radius, \
94  const Tensor& points_row_splits, const Tensor& hash_table_splits, \
95  Tensor& hash_table_index, Tensor& hash_table_cell_splits);
96 
97 #define INSTANTIATE_RADIUS(T, TIndex) \
98  template void FixedRadiusSearchCPU<T, TIndex>( \
99  const Tensor& points, const Tensor& queries, double radius, \
100  const Tensor& points_row_splits, const Tensor& queries_row_splits, \
101  const Tensor& hash_table_splits, const Tensor& hash_table_index, \
102  const Tensor& hash_table_cell_splits, const Metric metric, \
103  const bool ignore_query_point, const bool return_distances, \
104  const bool sort, Tensor& neighbors_index, \
105  Tensor& neighbors_row_splits, Tensor& neighbors_distance);
106 
107 #define INSTANTIATE_HYBRID(T, TIndex) \
108  template void HybridSearchCPU<T, TIndex>( \
109  const Tensor& points, const Tensor& queries, double radius, \
110  int max_knn, const Tensor& points_row_splits, \
111  const Tensor& queries_row_splits, const Tensor& hash_table_splits, \
112  const Tensor& hash_table_index, \
113  const Tensor& hash_table_cell_splits, const Metric metric, \
114  Tensor& neighbors_index, Tensor& neighbors_count, \
115  Tensor& neighbors_distance);
116 
119 
120 INSTANTIATE_RADIUS(float, int32_t)
121 INSTANTIATE_RADIUS(float, int64_t)
122 INSTANTIATE_RADIUS(double, int32_t)
123 INSTANTIATE_RADIUS(double, int64_t)
124 
125 INSTANTIATE_HYBRID(float, int32_t)
126 INSTANTIATE_HYBRID(float, int64_t)
127 INSTANTIATE_HYBRID(double, int32_t)
128 INSTANTIATE_HYBRID(double, int64_t)
129 } // namespace nns
130 } // namespace core
131 } // namespace cloudViewer
int points
#define INSTANTIATE_RADIUS(T, TIndex)
#define INSTANTIATE_HYBRID(T, TIndex)
#define INSTANTIATE_BUILD(T)
SizeVector GetShape() const
Definition: Tensor.h:1127
#define LogError(...)
Definition: Logging.h:60
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)
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)
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)
Generic file read and write utility for python interface.