11#ifndef EBGEOMETRY_MESHDISTANCEFUNCTIONS_HPP
12#define EBGEOMETRY_MESHDISTANCEFUNCTIONS_HPP
100 static_assert(std::is_floating_point_v<T>,
"FlatMeshSDF requires a floating-point T");
140 :
PoolHandle(a_location), m_meshLayout(a_layout.m_mesh)
151 return Layout{m_meshLayout};
289static_assert(std::is_trivially_copyable_v<
FlatMeshSDF<
float>>, "
FlatMeshSDF<
float> must be trivially copyable");
290static_assert(std::is_trivially_copyable_v<
FlatMeshSDF<
double>>, "
FlatMeshSDF<
double> must be trivially copyable");
312template <class T,
size_t K>
315 static_assert(std::is_floating_point_v<T>,
"MeshSDF requires a floating-point T");
316 static_assert(K >= 2,
"MeshSDF requires branching factor K >= 2");
343 using Node =
typename Root::Node;
379 :
PoolHandle(a_location), m_meshLayout(a_layout.m_mesh), m_bvhLayout(a_layout.m_bvh)
390 return Layout{m_meshLayout, m_bvhLayout};
419 inline
MeshSDF(const
Mesh& a_mesh,
Pool& a_pool, const BVH::Construction a_construction);
433 const BVH::Construction a_construction,
434 const BVH::ConstructionOptions& a_options);
520 getRoot() const noexcept
544 return this->getRoot().getBoundingVolume();
581 buildBVH(
const Mesh& a_mesh,
590 typename Mesh::Layout m_meshLayout;
595 typename Root::Layout m_bvhLayout;
624template <
class T,
size_t K,
size_t W>
627 static_assert(std::is_floating_point_v<T>,
"TriMeshSDF<T,K,W> requires a floating-point T");
628 static_assert(K >= 2,
"TriMeshSDF requires branching factor K >= 2");
629 static_assert(W > 0,
"TriMeshSDF requires SoA width W > 0");
684 :
PoolHandle(a_location), m_bvhLayout(a_layout.m_bvh)
695 return Layout{m_bvhLayout};
740 const size_t a_maxLeafGroups);
755 const size_t a_maxLeafGroups);
859 closestPart(const
Vec3T<T>& a_point) const noexcept;
867 getRoot() const noexcept
869 return Root(m_bvhLayout, this->location());
880 return this->getRoot().getBoundingVolume();
911 static inline std::vector<Tri>
912 extractTriangles(
const Mesh& a_mesh);
924 buildBVH(
const std::vector<Tri>& a_triangles,
940 buildClusterSAH(
const std::vector<Tri>& a_triangles,
Pool& a_pool,
const BVH::ClusterSpec& a_spec);
949 template <
class GetTriangle>
951 static inline std::vector<TriAoSoA>
952 groupTriangles(
const GetTriangle& a_getTriangle, uint32_t a_count);
964 static std::vector<TriAoSoA>
965 groupTrianglesIntoSoA(
const std::vector<std::shared_ptr<const Tri>>& a_triangles,
981 typename Root::Layout m_bvhLayout;
988static_assert(std::is_trivially_copyable_v<MeshSDF<float, 4>>,
"MeshSDF<float, 4> must be trivially copyable");
989static_assert(std::is_trivially_copyable_v<MeshSDF<double, 4>>,
"MeshSDF<double, 4> must be trivially copyable");
990static_assert(std::is_trivially_copyable_v<TriMeshSDF<float, 4, 4>>,
991 "TriMeshSDF<float, 4, 4> must be trivially copyable");
992static_assert(std::is_trivially_copyable_v<TriMeshSDF<double, 4, 4>>,
993 "TriMeshSDF<double, 4, 4> must be trivially copyable");
997#include "EBGeometry_MeshDistanceFunctionsImplem.hpp"
Bounding volume hierarchies: everything in EBGeometry_PackedBVH.hpp, EBGeometry_TreeBVH....
Declarations of bounding volume types used in bounding volume hierarchies.
Declaration of a mesh class which stores a DCEL mesh (with signed distance functions)
How far a function's value can be trusted as a distance: DistanceQuality, and the distanceQualityOf t...
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
Scalar helpers and numeric limits that compile for both host and device.
Growable bump arena for the GPU memory foundation.
Declaration of a face-id-carrying wrapper around TriangleSoAT.
Declaration of SoA triangle group for SIMD signed-distance evaluation.
Declaration of a triangle class with signed distance functionality.
Declaration of 2D and 3D point/vector classes with templated precision, and free functions on them.
Axis-aligned bounding box (AABB) enclosing a set of 3D points.
Definition EBGeometry_BoundingVolumes.hpp:37
Face class for navigating a DCEL mesh.
Definition EBGeometry_DCEL_Face.hpp:68
DCEL mesh class - stores a doubly-connected edge mesh.
Definition EBGeometry_DCEL_Mesh.hpp:102
Signed distance function for a DCEL mesh. Does not use BVHs.
Definition EBGeometry_MeshDistanceFunctions.hpp:99
FlatMeshSDF(const Layout &a_layout, const PoolLocation &a_location) noexcept
Rebuild a handle from a stored layout and the location of the pool that holds it.
Definition EBGeometry_MeshDistanceFunctions.hpp:139
T signedDistance(const Vec3T< T > &a_point) const noexcept
Compute the signed distance from a_point to the mesh.
ClosestPoint< T > closestPoint(const Vec3T< T > &a_point) const noexcept
The point of the mesh closest to a_point, the face it lies on, and the pseudonormal there.
uint32_t closestPart(const Vec3T< T > &a_point) const noexcept
The part that decides the value at a point (see hasParts): the closest face's id, getClosestFace(a_po...
Mesh getMesh() const noexcept
Get the underlying DCEL mesh descriptor.
Definition EBGeometry_MeshDistanceFunctions.hpp:241
ClosestFace< T > getClosestFace(const Vec3T< T > &a_point) const noexcept
Find the face closest to a_point, and the signed distance to it.
Layout layout() const noexcept
The object's arrays without its location, for storing it inside another pool-resident object.
Definition EBGeometry_MeshDistanceFunctions.hpp:149
uint32_t getNumParts() const noexcept
How many parts the mesh has (see hasParts): one per face, the mesh's numFaces().
FlatMeshSDF(const Mesh &a_mesh, Pool &a_pool) noexcept
Full constructor.
Vec3T< T > gradient(const Vec3T< T > &a_point) const noexcept
The gradient of the signed distance at a_point, in closed form from the closest point.
EBGeometry::DCEL::MeshT< T > Mesh
Alias for DCEL mesh type.
Definition EBGeometry_MeshDistanceFunctions.hpp:112
FlatMeshSDF rebasedView(const Pool &a_pool) const noexcept
Produce a copy of this object that resolves against a_pool.
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: the Euclidean distance to a watertight mesh.
Definition EBGeometry_MeshDistanceFunctions.hpp:107
FlatMeshSDF deepCopy(Pool &a_dstPool) const
Duplicate the mesh's storage into a_dstPool.
FlatMeshSDF()=delete
Disallowed constructor.
EBGeometry::BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
Compute the AABB enclosing the entire mesh.
A FlatMeshSDF must be trivially copyable: that is what lets a rebasedView() be byte-copied into a dev...
Definition EBGeometry_MeshDistanceFunctions.hpp:314
Mesh getMesh() const noexcept
Get the DCEL mesh descriptor the BVH's faces resolve against.
Definition EBGeometry_MeshDistanceFunctions.hpp:531
Layout layout() const noexcept
The object's arrays without its location, for storing it inside another pool-resident object.
Definition EBGeometry_MeshDistanceFunctions.hpp:388
typename Root::Node Node
Alias for a single linearized node.
Definition EBGeometry_MeshDistanceFunctions.hpp:343
MeshSDF(const Layout &a_layout, const PoolLocation &a_location) noexcept
Rebuild a handle from a stored layout and the location of the pool that holds it.
Definition EBGeometry_MeshDistanceFunctions.hpp:378
static BVH::ConstructionOptions defaultConstructionOptions() noexcept
The leaf-size settings the constructor without options uses.
EBGeometry::BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
Compute the AABB enclosing the entire mesh.
Definition EBGeometry_MeshDistanceFunctions.hpp:542
MeshSDF rebasedView(const Pool &a_pool) const noexcept
Produce a copy of this object that resolves against a_pool.
typename EBGeometry::DCEL::MeshT< T > Mesh
Alias for DCEL mesh type.
Definition EBGeometry_MeshDistanceFunctions.hpp:333
MeshSDF deepCopy(Pool &a_dstPool) const
Duplicate the mesh's and the BVH's storage into a_dstPool.
MeshSDF()=delete
Default disallowed constructor.
typename EBGeometry::DCEL::FaceT< T > Face
Alias for DCEL face type.
Definition EBGeometry_MeshDistanceFunctions.hpp:328
Base of every pool-resident handle: the one PoolLocation its arrays resolve against.
Definition EBGeometry_Pool.hpp:573
PoolLocation location() const noexcept
Where this handle's arrays live.
Definition EBGeometry_Pool.hpp:581
PoolHandle() noexcept=default
An unset location; the first reservation attaches it.
Growable bump arena over a MemoryResource.
Definition EBGeometry_Pool.hpp:210
Signed distance function for a pure triangle mesh using SoA-grouped primitives in a compact (lineariz...
Definition EBGeometry_MeshDistanceFunctions.hpp:626
typename EBGeometry::BVH::PackedBVH< T, TriAoSoA, K > Root
Alias for which BVH root node.
Definition EBGeometry_MeshDistanceFunctions.hpp:656
TriMeshSDF(const std::vector< Tri > &a_triangles, Pool &a_pool, const BVH::Construction a_construction, const size_t a_maxLeafGroups)
Full constructor. Takes the input triangles and creates the BVH.
TriMeshSDF(const std::vector< Tri > &a_triangles, Pool &a_pool, const BVH::Construction a_construction, const BVH::ConstructionOptions &a_options)
Full constructor from a triangle soup, with leaf-size settings.
uint32_t getNumParts() const noexcept
How many parts the mesh has (see hasParts): one per face, one more than the largest face id its trian...
TriMeshSDF()=delete
Default disallowed constructor.
TriMeshSDF(const Mesh &a_mesh, Pool &a_pool, const BVH::Construction a_construction, const size_t a_maxLeafGroups)
Full constructor. Extracts flat triangles from a DCEL mesh, then builds the BVH.
typename EBGeometry::Triangle< T > Tri
Alias for the flat triangle type the BVH is built from.
Definition EBGeometry_MeshDistanceFunctions.hpp:646
EBGeometry::BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
Compute the AABB enclosing the entire triangle mesh.
Definition EBGeometry_MeshDistanceFunctions.hpp:878
Layout layout() const noexcept
The object's arrays without its location, for storing it inside another pool-resident object.
Definition EBGeometry_MeshDistanceFunctions.hpp:693
T signedDistance(const Vec3T< T > &a_point) const noexcept
Compute the signed distance from a_point to the triangle mesh.
TriMeshSDF rebasedView(const Pool &a_pool) const noexcept
Produce a copy of this object that resolves against a_pool.
static BVH::ConstructionOptions defaultConstructionOptions(const size_t a_maxLeafGroups) noexcept
The leaf-size settings the constructors taking a_maxLeafGroups use.
TriMeshSDF(const Layout &a_layout, const PoolLocation &a_location) noexcept
Rebuild a handle from a stored layout and the location of the pool that holds it.
Definition EBGeometry_MeshDistanceFunctions.hpp:683
TriMeshSDF(const Mesh &a_mesh, Pool &a_pool, const BVH::Construction a_construction, const BVH::ConstructionOptions &a_options)
Full constructor from a DCEL mesh, with leaf-size settings.
ClosestFace< T > getClosestFace(const Vec3T< T > &a_point) const noexcept
Find the face closest to a_point, and the signed distance to it.
Vec3T< T > gradient(const Vec3T< T > &a_point) const noexcept
The gradient of the signed distance at a_point, in closed form from the closest point.
ClosestPoint< T > closestPoint(const Vec3T< T > &a_point) const noexcept
The point of the mesh closest to a_point, the face it lies on, and the pseudonormal there.
TriMeshSDF deepCopy(Pool &a_dstPool) const
Duplicate the BVH's storage into a_dstPool.
Triangle class with signed distance functionality.
Definition EBGeometry_Triangle.hpp:52
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.
Construction
The preset BVH construction methods that the library's own BVH users accept.
Definition EBGeometry_PackedBVH.hpp:65
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
DistanceQuality
How far the value of a signed distance function can be trusted, from strongest to weakest.
Definition EBGeometry_DistanceQuality.hpp:25
@ Exact
The value's magnitude is the Euclidean distance to the surface.
Configuration for the ClusterSAH direct PackedBVH construction path.
Definition EBGeometry_PackedBVH.hpp:94
Leaf-size settings for the preset construction methods, one per family of methods.
Definition EBGeometry_PackedBVH.hpp:115
The face of a mesh closest to a query point, as the mesh SDFs' getClosestFace() returns it.
Definition EBGeometry_MeshDistanceFunctions.hpp:46
uint32_t faceId
Id of the closest face; UINT32_MAX for an empty mesh.
Definition EBGeometry_MeshDistanceFunctions.hpp:48
T signedDistance
Signed distance to the closest face; negative inside.
Definition EBGeometry_MeshDistanceFunctions.hpp:47
The point of a mesh closest to a query point, as the mesh SDFs' closestPoint() returns it.
Definition EBGeometry_MeshDistanceFunctions.hpp:64
T signedDistance
Signed distance, as signedDistance() returns it.
Definition EBGeometry_MeshDistanceFunctions.hpp:65
Vec3T< T > normal
Unit pseudonormal of the face, edge or vertex it lies on.
Definition EBGeometry_MeshDistanceFunctions.hpp:68
Vec3T< T > point
The closest point on the mesh.
Definition EBGeometry_MeshDistanceFunctions.hpp:67
uint32_t faceId
Id of the face the point lies on, as getClosestFace().
Definition EBGeometry_MeshDistanceFunctions.hpp:66
The mesh's arrays as offsets into its pool, with no location: what another pool-resident object store...
Definition EBGeometry_DCEL_Mesh.hpp:159
The object's arrays as offsets into its pool, with no location (see PoolHandle).
Definition EBGeometry_MeshDistanceFunctions.hpp:123
Mesh::Layout m_mesh
The mesh.
Definition EBGeometry_MeshDistanceFunctions.hpp:127
Numeric limits, with the meanings of the std::numeric_limits members of the same names.
Definition EBGeometry_Math.hpp:91
The object's arrays as offsets into its pool, with no location (see PoolHandle).
Definition EBGeometry_MeshDistanceFunctions.hpp:357
Mesh::Layout m_mesh
The mesh.
Definition EBGeometry_MeshDistanceFunctions.hpp:361
Root::Layout m_bvh
The BVH over the mesh's face ids.
Definition EBGeometry_MeshDistanceFunctions.hpp:366
Where a pool-resident descriptor resolves its offsets, and the rules for moving it.
Definition EBGeometry_Pool.hpp:99
The object's arrays as offsets into its pool, with no location (see PoolHandle).
Definition EBGeometry_MeshDistanceFunctions.hpp:667
Root::Layout m_bvh
The BVH over SoA triangle groups.
Definition EBGeometry_MeshDistanceFunctions.hpp:671
Face-id-carrying wrapper around a single TriangleSoAT<T, W>.
Definition EBGeometry_TriangleAoSoA.hpp:50