EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_PointCloudHashGrid.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
12#ifndef EBGEOMETRY_POINTCLOUDHASHGRID_HPP
13#define EBGEOMETRY_POINTCLOUDHASHGRID_HPP
14
15// Std includes
16#include <cstddef>
17#include <cstdint>
18#include <type_traits>
19#include <vector>
20
21// Our includes
22#include "EBGeometry_GPU.hpp"
23#include "EBGeometry_Math.hpp"
26#include "EBGeometry_Pool.hpp"
27#include "EBGeometry_Vec.hpp"
28
29namespace EBGeometry {
30
63template <class T>
65{
66public:
73
78
90 inline PointCloudHashGrid(Pool& a_pool, const std::vector<Vec3T<T>>& a_positions, T a_targetPerCell = T(1));
91
97 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
98 inline Hit
99 closestPoint(const Vec3T<T>& a_query) const noexcept;
100
109 inline std::size_t
110 closestPoints(const Vec3T<T>& a_query, std::size_t a_k, Hit* a_out) const noexcept;
111
117 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
118 inline Hit
119 nearestNeighbor(uint32_t a_point) const noexcept;
120
129 inline std::size_t
130 nearestNeighbors(uint32_t a_point, std::size_t a_k, Hit* a_out) const noexcept;
131
140 [[nodiscard]] EBGEOMETRY_HOST
141 inline std::vector<Hit>
142 allNearestNeighbors(std::size_t a_k = 1) const;
143
148 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
149 inline std::size_t
150 numPoints() const noexcept
151 {
152 return m_positions.size();
153 }
154
160 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
161 inline const Vec3T<T>&
162 position(uint32_t a_index) const noexcept
163 {
164 EBGEOMETRY_EXPECT(a_index < m_positions.size());
165
166 return m_positions.at(this->base(), a_index);
167 }
168
173 using PoolHandle::base;
174
182 [[nodiscard]] EBGEOMETRY_HOST
183 inline PointCloudHashGrid
184 rebasedView(const Pool& a_pool) const noexcept;
185
193 [[nodiscard]] EBGEOMETRY_HOST
194 inline PointCloudHashGrid
195 deepCopy(Pool& a_dstPool) const;
196
197private:
208 inline void
209 storeArrays(Pool& a_pool,
210 const std::vector<Vec3T<T>>& a_positions,
211 const std::vector<std::uint32_t>& a_cellStart,
212 const std::vector<std::uint32_t>& a_cellPoints);
213
221 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
222 inline int
223 cellCoord(T a_x, T a_lo, int a_n) const noexcept;
224
232 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
233 inline std::size_t
234 cellIndex(int a_ix, int a_iy, int a_iz) const noexcept;
235
241 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
242 inline std::size_t
243 cellIndexOf(const Vec3T<T>& a_p) const noexcept;
244
255 inline std::size_t
256 query(const Vec3T<T>& a_query, std::size_t a_k, Hit* a_out, uint32_t a_exclude) const noexcept;
257
261 PODVector<Vec3T<T>> m_positions;
262
266 PODVector<std::uint32_t> m_cellStart;
267
271 PODVector<std::uint32_t> m_cellPoints;
272
276 Vec3T<T> m_lo;
277
281 T m_h = T(1);
282
286 T m_invH = T(1);
287
291 int m_nx = 1, m_ny = 1, m_nz = 1;
292};
293
298static_assert(std::is_trivially_copyable_v<PointCloudHashGrid<float>>,
299 "PointCloudHashGrid<float> must be trivially copyable");
300static_assert(std::is_trivially_copyable_v<PointCloudHashGrid<double>>,
301 "PointCloudHashGrid<double> must be trivially copyable");
302
303} // namespace EBGeometry
304
305#include "EBGeometry_PointCloudHashGridImplem.hpp"
306
307#endif
GPU portability layer: host/device decoration macros and backend detection.
#define EBGEOMETRY_HOST_DEVICE
Mark a function as callable from both host and device code (no-op on host compilers).
Definition EBGeometry_GPU.hpp:80
#define EBGEOMETRY_HOST
Mark a function as callable from host code only (no-op on host compilers).
Definition EBGeometry_GPU.hpp:83
#define EBGEOMETRY_EXPECT(cond)
Runtime precondition assertion for EBGeometry.
Definition EBGeometry_Macros.hpp:155
Scalar helpers and numeric limits that compile for both host and device.
Placement-independent POD array views for the GPU memory foundation.
Query results and helpers shared by the point-cloud search structures.
Growable bump arena for the GPU memory foundation.
Declaration of 2D and 3D point/vector classes with templated precision, and free functions on them.
A uniform spatial grid specialized for point clouds, with a fast build and turnkey queries.
Definition EBGeometry_PointCloudHashGrid.hpp:65
std::vector< Hit > allNearestNeighbors(std::size_t a_k=1) const
For every point, its a_k nearest other points (the k-nearest-neighbor graph).
PointCloudHashGrid deepCopy(Pool &a_dstPool) const
Duplicate this object's storage into a_dstPool.
const Vec3T< T > & position(uint32_t a_index) const noexcept
Position of the point with the given cloud index.
Definition EBGeometry_PointCloudHashGrid.hpp:162
Hit nearestNeighbor(uint32_t a_point) const noexcept
Nearest other point to a point already in the cloud.
std::size_t numPoints() const noexcept
Number of points in the cloud.
Definition EBGeometry_PointCloudHashGrid.hpp:150
PointCloudHashGrid rebasedView(const Pool &a_pool) const noexcept
Produce a copy of this object that resolves against a_pool.
PointCloudHashGrid()=delete
No default construction – a point cloud is required.
PointCloudHashGrid(Pool &a_pool, const std::vector< Vec3T< T > > &a_positions, T a_targetPerCell=T(1))
Build a uniform grid over a point cloud.
std::size_t nearestNeighbors(uint32_t a_point, std::size_t a_k, Hit *a_out) const noexcept
The a_k nearest other points to a point already in the cloud, nearest first.
std::size_t closestPoints(const Vec3T< T > &a_query, std::size_t a_k, Hit *a_out) const noexcept
The a_k closest cloud points to an arbitrary query point, nearest first.
void * base() noexcept
The base address this object's arrays are offsets from; see PoolHandle::base().
Definition EBGeometry_Pool.hpp:575
Hit closestPoint(const Vec3T< T > &a_query) const noexcept
Closest cloud point to an arbitrary query point.
Base of every pool-resident handle: the one PoolLocation its arrays resolve against.
Definition EBGeometry_Pool.hpp:499
void * base() noexcept
The base address this handle's offsets resolve against; see PoolLocation::base().
Definition EBGeometry_Pool.hpp:575
Growable bump arena over a MemoryResource.
Definition EBGeometry_Pool.hpp:183
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
Placement-independent descriptor of a POD array inside a Pool.
Definition EBGeometry_PODVector.hpp:119
One query result: the cloud index of a matched point and its squared distance.
Definition EBGeometry_PointCloud.hpp:53