Open3D (C++ API)  0.18.0+252c867
NeighborSearchCommon.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <nanoflann.hpp>
11 
12 #include "open3d/utility/MiniVec.h"
13 
14 namespace open3d {
15 namespace ml {
16 namespace impl {
17 
19 enum Metric { L1, L2, Linf };
20 
21 #ifdef __CUDACC__
22 #define HOST_DEVICE __host__ __device__
23 #else
24 #define HOST_DEVICE
25 #endif
26 
28 HOST_DEVICE inline size_t SpatialHash(int x, int y, int z) {
29  return x * 73856096 ^ y * 193649663 ^ z * 83492791;
30 }
31 
33  return SpatialHash(xyz[0], xyz[1], xyz[2]);
34 }
35 
41 template <class TVecf>
43  const TVecf& pos, const typename TVecf::Scalar_t& inv_voxel_size) {
44  TVecf ref_coord = pos * inv_voxel_size;
45 
46  utility::MiniVec<int, 3> voxel_index;
47  voxel_index = floor(ref_coord).template cast<int>();
48  return voxel_index;
49 }
50 #undef HOST_DEVICE
51 
53 template <class T>
54 class Adaptor {
55 public:
56  Adaptor(size_t num_points, const T* const data)
57  : num_points(num_points), data(data) {}
58 
59  inline size_t kdtree_get_point_count() const { return num_points; }
60 
61  inline T kdtree_get_pt(const size_t idx, int dim) const {
62  return data[3 * idx + dim];
63  }
64 
65  template <class BBOX>
66  bool kdtree_get_bbox(BBOX&) const {
67  return false;
68  }
69 
70 private:
71  size_t num_points;
72  const T* const data;
73 };
74 
75 template <int METRIC, class T>
77 
78 template <class T>
80  typedef nanoflann::L2_Adaptor<T, Adaptor<T>> Adaptor_t;
81 };
82 
83 template <class T>
85  typedef nanoflann::L1_Adaptor<T, Adaptor<T>> Adaptor_t;
86 };
87 
88 } // namespace impl
89 } // namespace ml
90 } // namespace open3d
Adaptor for nanoflann.
Definition: NeighborSearchCommon.h:54
Adaptor(size_t num_points, const T *const data)
Definition: NeighborSearchCommon.h:56
size_t kdtree_get_point_count() const
Definition: NeighborSearchCommon.h:59
bool kdtree_get_bbox(BBOX &) const
Definition: NeighborSearchCommon.h:66
T kdtree_get_pt(const size_t idx, int dim) const
Definition: NeighborSearchCommon.h:61
#define HOST_DEVICE
Definition: NeighborSearchCommon.h:24
HOST_DEVICE size_t SpatialHash(int x, int y, int z)
Spatial hashing function for integer coordinates.
Definition: NeighborSearchCommon.h:28
Metric
Supported metrics.
Definition: NeighborSearchCommon.h:19
@ Linf
Definition: NeighborSearchCommon.h:19
@ L1
Definition: NeighborSearchCommon.h:19
@ L2
Definition: NeighborSearchCommon.h:19
HOST_DEVICE utility::MiniVec< int, 3 > ComputeVoxelIndex(const TVecf &pos, const typename TVecf::Scalar_t &inv_voxel_size)
Definition: NeighborSearchCommon.h:42
FN_SPECIFIERS MiniVec< float, N > floor(const MiniVec< float, N > &a)
Definition: MiniVec.h:75
Definition: PinholeCameraIntrinsic.cpp:16
nanoflann::L1_Adaptor< T, Adaptor< T > > Adaptor_t
Definition: NeighborSearchCommon.h:85
nanoflann::L2_Adaptor< T, Adaptor< T > > Adaptor_t
Definition: NeighborSearchCommon.h:80
Definition: NeighborSearchCommon.h:76
Definition: MiniVec.h:24