29 const Dtype &index_dtype) {
31 assert(index_dtype ==
Int32 || index_dtype ==
Int64);
39 const Dtype &index_dtype) {
40 const int64_t num_dataset_points = dataset_points.
GetShape()[0];
41 Tensor points_row_splits(std::vector<int64_t>({0, num_dataset_points}), {2},
43 return SetTensorData(dataset_points, points_row_splits, radius,
48 const Tensor &points_row_splits,
50 const Dtype &index_dtype) {
52 assert(index_dtype ==
Int32 || index_dtype ==
Int64);
59 if (dataset_points.
GetShape()[0] != points_row_splits[-1].
Item<int64_t>()) {
61 "dataset_points and points_row_splits have incompatible "
70 const int64_t num_batch = points_row_splits.
GetShape()[0] - 1;
74 std::vector<uint32_t> hash_table_splits(num_batch + 1, 0);
75 for (
int i = 0; i < num_batch; ++i) {
76 int64_t num_dataset_points_i =
79 int64_t hash_table_size = std::min<int64_t>(
83 hash_table_splits[i + 1] =
84 hash_table_splits[i] + (uint32_t)hash_table_size;
92 #define BUILD_PARAMETERS \
93 dataset_points_, radius, points_row_splits_, hash_table_splits_, \
94 hash_table_index_, hash_table_cell_splits_
96 #define CALL_BUILD(type, fn) \
97 if (Dtype::FromType<type>() == dtype) { \
98 fn<type>(BUILD_PARAMETERS); \
103 #ifdef BUILD_CUDA_MODULE
108 "-DBUILD_CUDA_MODULE=OFF. Please compile Open3d with "
109 "-DBUILD_CUDA_MODULE=ON.");
119 const Tensor &query_points,
double radius,
bool sort)
const {
120 const int64_t num_query_points = query_points.
GetShape()[0];
121 Tensor queries_row_splits(std::vector<int64_t>({0, num_query_points}), {2},
123 return SearchRadius(query_points, queries_row_splits, radius, sort);
127 const Tensor &query_points,
128 const Tensor &queries_row_splits,
145 const int64_t num_query_points = query_points.
GetShape()[0];
146 if (num_query_points != queries_row_splits[-1].Item<int64_t>()) {
148 "query_points and queries_row_splits have incompatible "
159 Tensor neighbors_index, neighbors_distance;
162 #define RADIUS_PARAMETERS \
163 dataset_points_, query_points_, radius, points_row_splits_, \
164 queries_row_splits_, hash_table_splits_, hash_table_index_, \
165 hash_table_cell_splits_, Metric::L2, false, true, sort, \
166 neighbors_index, neighbors_row_splits, neighbors_distance
169 #ifdef BUILD_CUDA_MODULE
175 "-DBUILD_CUDA_MODULE=OFF. Please compile Open3d with "
176 "-DBUILD_CUDA_MODULE=ON.");
184 return std::make_tuple(neighbors_index, neighbors_distance,
185 neighbors_row_splits.
To(index_dtype));
189 const Tensor &query_points,
double radius,
int max_knn)
const {
190 const int64_t num_query_points = query_points.
GetShape()[0];
191 Tensor queries_row_splits(std::vector<int64_t>({0, num_query_points}), {2},
193 return SearchHybrid(query_points, queries_row_splits, radius, max_knn);
197 const Tensor &query_points,
198 const Tensor &queries_row_splits,
215 const int64_t num_query_points = query_points.
GetShape()[0];
216 if (num_query_points != queries_row_splits[-1].Item<int64_t>()) {
218 "query_points and queries_row_splits have incompatible "
229 Tensor neighbors_index, neighbors_distance, neighbors_count;
231 #define HYBRID_PARAMETERS \
232 dataset_points_, query_points_, radius, max_knn, points_row_splits_, \
233 queries_row_splits_, hash_table_splits_, hash_table_index_, \
234 hash_table_cell_splits_, Metric::L2, neighbors_index, \
235 neighbors_count, neighbors_distance
238 #ifdef BUILD_CUDA_MODULE
244 "-DBUILD_CUDA_MODULE=OFF. Please compile Open3d with "
245 "-DBUILD_CUDA_MODULE=ON.");
253 return std::make_tuple(neighbors_index.
View({num_query_points, max_knn}),
254 neighbors_distance.
View({num_query_points, max_knn}),
255 neighbors_count.
View({num_query_points}));
#define DISPATCH_FLOAT_INT_DTYPE_TO_TEMPLATE(FDTYPE, IDTYPE,...)
#define CALL_BUILD(type, fn)
#define HYBRID_PARAMETERS
#define RADIUS_PARAMETERS
#define AssertTensorDevice(tensor,...)
#define AssertTensorDtype(tensor,...)
#define AssertTensorDtypes(tensor,...)
#define AssertTensorShape(tensor,...)
bool IsCUDA() const
Returns true iff device type is CUDA.
Tensor Contiguous() const
Tensor View(const SizeVector &dst_shape) const
static Tensor Empty(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor with uninitialized values.
SizeVector GetShape() const
Tensor To(Dtype dtype, bool copy=false) const
std::tuple< Tensor, Tensor, Tensor > SearchHybrid(const Tensor &query_points, double radius, int max_knn) const override
FixedRadiusIndex()
Default Constructor.
Tensor hash_table_splits_
bool SetTensorData(const Tensor &dataset_points, const Dtype &index_dtype=core::Int64) override
Tensor hash_table_cell_splits_
std::tuple< Tensor, Tensor, Tensor > SearchRadius(const Tensor &query_points, const Tensor &radii, bool sort=true) const override
const double hash_table_size_factor
Tensor points_row_splits_
const int64_t max_hash_tabls_size
Dtype GetIndexDtype() const
size_t GetDatasetSize() const
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)
constexpr nullopt_t nullopt
Generic file read and write utility for python interface.