ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
NeighborSearchCommon.h
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 #pragma once
9 
10 #include <memory>
11 
13 
14 namespace cloudViewer {
15 namespace core {
16 namespace nns {
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 
55 };
56 
57 } // namespace nns
58 } // namespace core
59 } // namespace cloudViewer
#define HOST_DEVICE
utility::MiniVec< int, 3 > ComputeVoxelIndex(const TVecf &pos, const typename TVecf::Scalar_t &inv_voxel_size)
size_t SpatialHash(int x, int y, int z)
Spatial hashing function for integer coordinates.
MiniVec< float, N > floor(const MiniVec< float, N > &a)
Definition: MiniVec.h:75
Generic file read and write utility for python interface.
Base struct for NanoFlann index holder.