EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_SurfaceRef.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
12#ifndef EBGEOMETRY_SURFACEREF_HPP
13#define EBGEOMETRY_SURFACEREF_HPP
14
15// Std includes
16#include <cstdint>
17#include <type_traits>
18#include <utility>
19
20// Our includes
21#include "EBGeometry_GPU.hpp"
23#include "EBGeometry_Vec.hpp"
24
25namespace EBGeometry {
26
37template <class T>
39{
43 static constexpr uint32_t None = 0xFFFFFFFFU;
44
48 uint32_t m_surface = None;
49
53 uint32_t m_leaf = None;
54
60
65 uint32_t m_part = 0;
66
74 uint32_t m_ownerRegion = None;
75
81
86
91
97};
98
99namespace SurfaceDetail {
100
107template <class S, class T, class = void>
108struct HasSurfaces : std::false_type
109{
110};
111
118template <class S, class T>
119struct HasSurfaces<S,
120 T,
121 std::void_t<decltype(std::declval<const S&>().getNumSurfaces()),
122 decltype(std::declval<const S&>().closestSurface(std::declval<const Vec3T<T>&>()))>>
123 : std::is_same<std::decay_t<decltype(std::declval<const S&>().closestSurface(std::declval<const Vec3T<T>&>()))>,
124 SurfaceRef<T>>
125{
126};
127
128} // namespace SurfaceDetail
129
139template <class S, class T>
141
142namespace SurfaceDetail {
143
150template <class S, class T, class = void>
151struct HasParts : std::false_type
152{
153};
154
161template <class S, class T>
162struct HasParts<S,
163 T,
164 std::void_t<decltype(std::declval<const S&>().getNumParts()),
165 decltype(std::declval<const S&>().closestPart(std::declval<const Vec3T<T>&>()))>>
166 : std::true_type
167{
168};
169
170} // namespace SurfaceDetail
171
181template <class S, class T>
183
184namespace SurfaceDetail {
185
194template <class T, class S>
195[[nodiscard]] EBGEOMETRY_HOST
196inline uint32_t
197numPartsOf(const S& a_shape)
198{
199 if constexpr (hasParts<S, T>) {
200 return a_shape.getNumParts();
201 }
202 else {
203 return 1U;
204 }
205}
206
215template <class T, class S>
216[[nodiscard]] EBGEOMETRY_HOST
217inline uint32_t
218numSurfacesOf(const S& a_shape)
219{
220 if constexpr (hasSurfaces<S, T>) {
221 return a_shape.getNumSurfaces();
222 }
223 else {
224 return 1U;
225 }
226}
227
240template <class T, class S>
241[[nodiscard]] EBGEOMETRY_HOST_DEVICE
243inline SurfaceRef<T>
244closestSurfaceOf(const S& a_shape, const Vec3T<T>& a_point) noexcept
245{
246 if constexpr (hasSurfaces<S, T>) {
247 return a_shape.closestSurface(a_point);
248 }
249 else {
250 SurfaceRef<T> surface;
251
252 surface.m_surface = 0U;
253 surface.m_localPoint = a_point;
254
255 if constexpr (hasParts<S, T>) {
256 surface.m_part = a_shape.closestPart(a_point);
257 }
258
259 return surface;
260 }
261}
262
263} // namespace SurfaceDetail
264
275template <class T, class S>
276[[nodiscard]] EBGEOMETRY_HOST_DEVICE
277inline SurfaceRef<T>
278closestSurface(const S& a_shape, const Vec3T<T>& a_point) noexcept
279{
280 return SurfaceDetail::closestSurfaceOf<T>(a_shape, a_point);
281}
282
283} // namespace EBGeometry
284
285#endif
GPU portability layer: host/device decoration macros and backend detection.
#define EBGEOMETRY_DEVICE_NOINLINE
Keep a function out of line in the device pass (CUDA/HIP); nothing on the host.
Definition EBGeometry_GPU.hpp:110
#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
LabelId: the number of a label, typed by what it labels (SurfaceLabelId, MaterialLabelId).
uint32_t numPartsOf(const S &a_shape)
How many parts a shape has: its getNumParts(), 1 for a shape without parts.
Definition EBGeometry_SurfaceRef.hpp:197
SurfaceRef< T > closestSurfaceOf(const S &a_shape, const Vec3T< T > &a_point) noexcept
The surface of a shape that decides its value at a point: a container's closestSurface(),...
Definition EBGeometry_SurfaceRef.hpp:244
uint32_t numSurfacesOf(const S &a_shape)
How many surfaces a shape holds: a container's getNumSurfaces(), 1 for any other shape.
Definition EBGeometry_SurfaceRef.hpp:218
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
static constexpr Vec3T< T > zeros() noexcept
Return a vector with x = y = z = 0.
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
constexpr bool hasSurfaces
Whether a shape holds several surfaces: it has uint32_t getNumSurfaces() const (host) and SurfaceRef<...
Definition EBGeometry_SurfaceRef.hpp:140
constexpr bool hasParts
Whether a shape has several parts: it has uint32_t getNumParts() const (host) and uint32_t closestPar...
Definition EBGeometry_SurfaceRef.hpp:182
SurfaceRef< T > closestSurface(const S &a_shape, const Vec3T< T > &a_point) noexcept
The surface of any shape that decides its value at a point: a container's closestSurface() (a tape,...
Definition EBGeometry_SurfaceRef.hpp:278
Part detection: the primary template is a shape with one part.
Definition EBGeometry_SurfaceRef.hpp:152
Container detection: the primary template is a shape with one surface.
Definition EBGeometry_SurfaceRef.hpp:109
The surface that decides a shape's value at a point, as closestSurface() reports it.
Definition EBGeometry_SurfaceRef.hpp:39
Vec3T< T > m_localPoint
The point in the frame of the deepest shape reached: the primitive, or the container member,...
Definition EBGeometry_SurfaceRef.hpp:96
uint32_t m_ownerRegion
Set by a tape's region queries: the owner, the region the surface is reported from at the queried poi...
Definition EBGeometry_SurfaceRef.hpp:74
SurfaceLabelId m_surfaceLabel
Set by a tape: the surface's label, or none. A part labeled through face groups (SurfaceLabel(shape,...
Definition EBGeometry_SurfaceRef.hpp:59
uint32_t m_part
The part of the deepest shape reached, read from its own formula at the local point (see hasParts): a...
Definition EBGeometry_SurfaceRef.hpp:65
uint32_t m_leaf
Set by a tape: the leaf the surface belongs to, as Tape::closestLeaf() numbers it.
Definition EBGeometry_SurfaceRef.hpp:53
uint32_t m_neighborRegion
Set by a tape's region queries: the neighbor, the region across the surface from the owner at the que...
Definition EBGeometry_SurfaceRef.hpp:80
MaterialLabelId m_ownerMaterial
Set with the sides: the owner's material (m_ownerRegion's MaterialLabel()), or none.
Definition EBGeometry_SurfaceRef.hpp:85
uint32_t m_surface
The surface, numbered within the shape that was asked (across the scene when that is a tape).
Definition EBGeometry_SurfaceRef.hpp:48
MaterialLabelId m_neighborMaterial
Set with the sides: the neighbor's material (m_neighborRegion's), or none.
Definition EBGeometry_SurfaceRef.hpp:90
static constexpr uint32_t None
No surface (an empty shape), no leaf or no label.
Definition EBGeometry_SurfaceRef.hpp:43