EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_SphereCloud.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
11#ifndef EBGEOMETRY_SPHERECLOUD_HPP
12#define EBGEOMETRY_SPHERECLOUD_HPP
13
14// Std includes
15#include <cstdint>
16#include <type_traits>
17
18// Our includes
19#include "EBGeometry_GPU.hpp"
20#include "EBGeometry_Macros.hpp"
21#include "EBGeometry_Math.hpp"
22#include "EBGeometry_Vec.hpp"
23
24namespace EBGeometry {
25
32namespace SphereCloud {
33
38inline constexpr uint32_t InvalidIndex = Math::Limits<uint32_t>::max();
39
46template <class T>
52
60template <class T>
61struct Hit
62{
63 uint32_t index = InvalidIndex;
65
70 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
71 bool
72 valid() const noexcept
73 {
74 return index != InvalidIndex;
75 }
76};
77
84template <class T>
86{
90 const Sphere<T>* m_spheres = nullptr;
91
97 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
99 operator()(const uint32_t a_index) const noexcept
100 {
101 return m_spheres[a_index];
102 }
103};
104
109template <class T>
111{
115 const T* m_radii = nullptr;
116
122 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
123 T
124 operator()(const uint32_t a_index) const noexcept
125 {
126 return m_radii[a_index];
127 }
128};
129
141template <class T, class Centers, class Radii>
143{
144 static_assert(std::is_trivially_copyable_v<Centers>,
145 "SphereCloud::FromCentersAndRadii: Centers must be trivially copyable");
146 static_assert(std::is_trivially_copyable_v<Radii>,
147 "SphereCloud::FromCentersAndRadii: Radii must be trivially copyable");
148
152 Centers m_centers;
153
157 Radii m_radii;
158
164 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
166 operator()(const uint32_t a_index) const noexcept
167 {
168 return Sphere<T>{m_centers(a_index), m_radii(a_index)};
169 }
170};
171
172} // namespace SphereCloud
173
174} // namespace EBGeometry
175
176#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
Utility macros for EBGeometry.
Scalar helpers and numeric limits that compile for both host and device.
Declaration of 2D and 3D point/vector classes with templated precision, and free functions on them.
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
constexpr uint32_t InvalidIndex
The cloud index of "no sphere": a miss.
Definition EBGeometry_SphereCloud.hpp:38
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
Numeric limits, with the meanings of the std::numeric_limits members of the same names.
Definition EBGeometry_Math.hpp:91
A source of spheres reading one array of Sphere<T>, indexed by cloud index.
Definition EBGeometry_SphereCloud.hpp:86
const Sphere< T > * m_spheres
The spheres, indexed by cloud index.
Definition EBGeometry_SphereCloud.hpp:90
Sphere< T > operator()(const uint32_t a_index) const noexcept
The sphere with a cloud index.
Definition EBGeometry_SphereCloud.hpp:99
A source of spheres combining a source of centers and a source of radii, for a caller who keeps them ...
Definition EBGeometry_SphereCloud.hpp:143
Sphere< T > operator()(const uint32_t a_index) const noexcept
The sphere with a cloud index.
Definition EBGeometry_SphereCloud.hpp:166
Centers m_centers
The centers.
Definition EBGeometry_SphereCloud.hpp:152
Radii m_radii
The radii.
Definition EBGeometry_SphereCloud.hpp:157
A source of radii reading one array of T, indexed by cloud index.
Definition EBGeometry_SphereCloud.hpp:111
T operator()(const uint32_t a_index) const noexcept
The radius of the sphere with a cloud index.
Definition EBGeometry_SphereCloud.hpp:124
const T * m_radii
The radii, indexed by cloud index.
Definition EBGeometry_SphereCloud.hpp:115
One query result: the cloud index of a sphere and the signed distance to its surface.
Definition EBGeometry_SphereCloud.hpp:62
uint32_t index
Cloud index of the sphere.
Definition EBGeometry_SphereCloud.hpp:63
T distance
Signed distance from the query to its surface.
Definition EBGeometry_SphereCloud.hpp:64
bool valid() const noexcept
Whether this is a match rather than a miss.
Definition EBGeometry_SphereCloud.hpp:72
A sphere of a sphere cloud: a center and a radius.
Definition EBGeometry_SphereCloud.hpp:48
Vec3T< T > m_center
The center.
Definition EBGeometry_SphereCloud.hpp:49
T m_radius
The radius, at least 0.
Definition EBGeometry_SphereCloud.hpp:50