Open3D (C++ API)  0.16.1
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-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 <vector>
30
31#include "open3d/core/Dtype.h"
32#include "open3d/core/Tensor.h"
35
36namespace open3d {
37namespace core {
38namespace nns {
39
67template <class T>
68void BuildSpatialHashTableCPU(const Tensor& points,
69 double radius,
70 const Tensor& points_row_splits,
71 const Tensor& hash_table_splits,
72 Tensor& hash_table_index,
73 Tensor& hash_table_cell_splits);
74
136template <class T, class TIndex>
137void FixedRadiusSearchCPU(const Tensor& points,
138 const Tensor& queries,
139 double radius,
140 const Tensor& points_row_splits,
141 const Tensor& queries_row_splits,
142 const Tensor& hash_table_splits,
143 const Tensor& hash_table_index,
144 const Tensor& hash_table_cell_splits,
145 const Metric metric,
146 const bool ignore_query_point,
147 const bool return_distances,
148 const bool sort,
149 Tensor& neighbors_index,
150 Tensor& neighbors_row_splits,
151 Tensor& neighbors_distance);
152
204template <class T, class TIndex>
205void HybridSearchCPU(const Tensor& points,
206 const Tensor& queries,
207 double radius,
208 int max_knn,
209 const Tensor& points_row_splits,
210 const Tensor& queries_row_splits,
211 const Tensor& hash_table_splits,
212 const Tensor& hash_table_index,
213 const Tensor& hash_table_cell_splits,
214 const Metric metric,
215 Tensor& neighbors_index,
216 Tensor& neighbors_count,
217 Tensor& neighbors_distance);
218
219#ifdef BUILD_CUDA_MODULE
245template <class T>
246void BuildSpatialHashTableCUDA(const Tensor& points,
247 double radius,
248 const Tensor& points_row_splits,
249 const Tensor& hash_table_splits,
250 Tensor& hash_table_index,
251 Tensor& hash_table_cell_splits);
252
253// Fixed radius search. This function computes a list of neighbor indices
314template <class T, class TIndex>
315void FixedRadiusSearchCUDA(const Tensor& points,
316 const Tensor& queries,
317 double radius,
318 const Tensor& points_row_splits,
319 const Tensor& queries_row_splits,
320 const Tensor& hash_table_splits,
321 const Tensor& hash_table_index,
322 const Tensor& hash_table_cell_splits,
323 const Metric metric,
324 const bool ignore_query_point,
325 const bool return_distances,
326 const bool sort,
327 Tensor& neighbors_index,
328 Tensor& neighbors_row_splits,
329 Tensor& neighbors_distance);
330
382template <class T, class TIndex>
383void HybridSearchCUDA(const Tensor& points,
384 const Tensor& queries,
385 double radius,
386 int max_knn,
387 const Tensor& points_row_splits,
388 const Tensor& queries_row_splits,
389 const Tensor& hash_table_splits,
390 const Tensor& hash_table_index,
391 const Tensor& hash_table_cell_splits,
392 const Metric metric,
393 Tensor& neighbors_index,
394 Tensor& neighbors_count,
395 Tensor& neighbors_distance);
396#endif
397
402public:
405
410 FixedRadiusIndex(const Tensor& dataset_points, double radius);
411 FixedRadiusIndex(const Tensor& dataset_points,
412 double radius,
413 const Dtype& index_dtype);
417
418public:
419 bool SetTensorData(const Tensor& dataset_points,
420 const Dtype& index_dtype = core::Int64) override {
422 "FixedRadiusIndex::SetTensorData without radius not "
423 "implemented.");
424 }
425
426 bool SetTensorData(const Tensor& dataset_points,
427 double radius,
428 const Dtype& index_dtype = core::Int64) override;
429 bool SetTensorData(const Tensor& dataset_points,
430 const Tensor& points_row_splits,
431 double radius,
432 const Dtype& index_dtype = core::Int64);
433
434 std::pair<Tensor, Tensor> SearchKnn(const Tensor& query_points,
435 int knn) const override {
436 utility::LogError("FixedRadiusIndex::SearchKnn not implemented.");
437 }
438
439 std::tuple<Tensor, Tensor, Tensor> SearchRadius(
440 const Tensor& query_points,
441 const Tensor& radii,
442 bool sort = true) const override {
444 "FixedRadiusIndex::SearchRadius with multi-radii not "
445 "implemented.");
446 }
447
448 std::tuple<Tensor, Tensor, Tensor> SearchRadius(
449 const Tensor& query_points,
450 double radius,
451 bool sort = true) const override;
452 std::tuple<Tensor, Tensor, Tensor> SearchRadius(
453 const Tensor& query_points,
454 const Tensor& queries_row_splits,
455 double radius,
456 bool sort = true) const;
457
458 std::tuple<Tensor, Tensor, Tensor> SearchHybrid(const Tensor& query_points,
459 double radius,
460 int max_knn) const override;
461
462 std::tuple<Tensor, Tensor, Tensor> SearchHybrid(
463 const Tensor& query_points,
464 const Tensor& queries_row_splits,
465 double radius,
466 int max_knn) const;
467
468 const double hash_table_size_factor = 1.0 / 32;
469 const int64_t max_hash_tabls_size = 33554432;
470
471protected:
476};
477
478} // namespace nns
479} // namespace core
480} // namespace open3d
#define LogError(...)
Definition: Logging.h:67
Definition: Dtype.h:39
Definition: Tensor.h:51
FixedRadiusIndex for nearest neighbor range search.
Definition: FixedRadiusIndex.h:401
FixedRadiusIndex(const FixedRadiusIndex &)=delete
Tensor hash_table_splits_
Definition: FixedRadiusIndex.h:473
const int64_t max_hash_tabls_size
Definition: FixedRadiusIndex.h:469
Tensor hash_table_cell_splits_
Definition: FixedRadiusIndex.h:474
Tensor points_row_splits_
Definition: FixedRadiusIndex.h:472
bool SetTensorData(const Tensor &dataset_points, const Dtype &index_dtype=core::Int64) override
Definition: FixedRadiusIndex.h:419
std::tuple< Tensor, Tensor, Tensor > SearchHybrid(const Tensor &query_points, double radius, int max_knn) const override
Definition: FixedRadiusIndex.cpp:206
Tensor hash_table_index_
Definition: FixedRadiusIndex.h:475
const double hash_table_size_factor
Definition: FixedRadiusIndex.h:468
~FixedRadiusIndex()
Definition: FixedRadiusIndex.cpp:53
FixedRadiusIndex()
Default Constructor.
Definition: FixedRadiusIndex.cpp:37
std::tuple< Tensor, Tensor, Tensor > SearchRadius(const Tensor &query_points, const Tensor &radii, bool sort=true) const override
Definition: FixedRadiusIndex.h:439
std::pair< Tensor, Tensor > SearchKnn(const Tensor &query_points, int knn) const override
Definition: FixedRadiusIndex.h:434
FixedRadiusIndex & operator=(const FixedRadiusIndex &)=delete
Definition: NNSIndex.h:40
int points
Definition: FilePCD.cpp:73
Metric
Supported metrics.
Definition: NeighborSearchCommon.h:38
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)
Definition: FixedRadiusSearchOps.cpp:93
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)
Definition: FixedRadiusSearchOps.cpp:40
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)
Definition: FixedRadiusSearchOps.cpp:57
const Dtype Int64
Definition: Dtype.cpp:66
Definition: PinholeCameraIntrinsic.cpp:35