EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_MeshDistanceFunctions.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2023 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
11#ifndef EBGEOMETRY_MESHDISTANCEFUNCTIONS_HPP
12#define EBGEOMETRY_MESHDISTANCEFUNCTIONS_HPP
13
14// Std includes
15#include <cstddef>
16#include <cstdint>
17#include <limits>
18#include <memory>
19#include <type_traits>
20#include <utility>
21#include <vector>
22
23// Our includes
24#include "EBGeometry_BVH.hpp"
31#include "EBGeometry_Vec.hpp"
32
33namespace EBGeometry {
34
42template <class T, class Meta = DCEL::DefaultMetaData>
44{
45 static_assert(std::is_floating_point_v<T>, "FlatMeshSDF requires a floating-point T");
46
47public:
52
56 FlatMeshSDF() = delete;
57
62 FlatMeshSDF(const std::shared_ptr<Mesh>& a_mesh) noexcept;
63
67 ~FlatMeshSDF() override = default;
68
75 FlatMeshSDF(const FlatMeshSDF& a_other) = default;
76
83 operator=(const FlatMeshSDF& a_other) = default;
84
91 FlatMeshSDF(FlatMeshSDF&& a_other) noexcept = default;
92
99 operator=(FlatMeshSDF&& a_other) noexcept = default;
100
106 [[nodiscard]] T
107 signedDistance(const Vec3T<T>& a_point) const noexcept override;
108
113 [[nodiscard]] const std::shared_ptr<Mesh>
115
121 template <class BV>
122 [[nodiscard]] BV
124
129 std::shared_ptr<Mesh> m_mesh;
130};
131
148template <class T, class Meta, size_t K>
150{
151 static_assert(std::is_floating_point_v<T>, "MeshSDF requires a floating-point T");
152 static_assert(K >= 2, "MeshSDF requires branching factor K >= 2");
153
154public:
159
164
169
173 using Node = typename Root::Node;
174
178 MeshSDF() = delete;
179
188 MeshSDF(const std::shared_ptr<Mesh>& a_mesh, const BVH::Build a_build);
189
193 ~MeshSDF() override = default;
194
201 MeshSDF(const MeshSDF& a_other) = default;
202
208 MeshSDF&
209 operator=(const MeshSDF& a_other) = default;
210
217 MeshSDF(MeshSDF&& a_other) noexcept = default;
218
224 MeshSDF&
225 operator=(MeshSDF&& a_other) noexcept = default;
226
232 [[nodiscard]] T
233 signedDistance(const Vec3T<T>& a_point) const noexcept override;
234
244 [[nodiscard]] virtual std::vector<std::pair<std::shared_ptr<const Face>, T>>
245 getClosestFaces(const Vec3T<T>& a_point, const bool a_sorted) const;
246
251 [[nodiscard]] virtual std::shared_ptr<Root>&
253
258 [[nodiscard]] virtual const std::shared_ptr<Root>&
259 getRoot() const noexcept;
260
265 [[nodiscard]] EBGeometry::BoundingVolumes::AABBT<T>
267
272 std::shared_ptr<Root> m_bvh;
273
280 std::shared_ptr<Mesh> m_mesh;
281};
282
309template <class T,
310 class Meta,
311 size_t K,
312 size_t W,
313 class StoragePolicy = BVH::ValueStorage<EBGeometry::TriangleAoSoA<T, Meta, W>>>
315{
316 static_assert(std::is_floating_point_v<T>, "TriMeshSDF<T,Meta,K,W> requires a floating-point T");
317 static_assert(K >= 2, "TriMeshSDF requires branching factor K >= 2");
318 static_assert(W > 0, "TriMeshSDF requires SoA width W > 0");
319
320public:
325
330
335
340
348 {
349 T signedDistance = std::numeric_limits<T>::max();
350 Meta metaData{};
351 };
352
356 TriMeshSDF() = delete;
357
376 TriMeshSDF(const std::shared_ptr<Mesh>& a_mesh, const BVH::Build a_build, const size_t a_maxLeafGroups) noexcept;
377
385 TriMeshSDF(const std::vector<std::shared_ptr<Tri>>& a_triangles,
386 const BVH::Build a_build,
387 const size_t a_maxLeafGroups) noexcept;
388
392 ~TriMeshSDF() override = default;
393
400 TriMeshSDF(const TriMeshSDF& a_other) = default;
401
408 operator=(const TriMeshSDF& a_other) = default;
409
416 TriMeshSDF(TriMeshSDF&& a_other) noexcept = default;
417
424 operator=(TriMeshSDF&& a_other) noexcept = default;
425
431 [[nodiscard]] T
432 signedDistance(const Vec3T<T>& a_point) const noexcept override;
433
446 getClosestTriangle(const Vec3T<T>& a_point) const noexcept;
447
452 [[nodiscard]] virtual std::shared_ptr<Root>&
454
459 [[nodiscard]] virtual const std::shared_ptr<Root>&
460 getRoot() const noexcept;
461
466 [[nodiscard]] EBGeometry::BoundingVolumes::AABBT<T>
468
473 std::shared_ptr<Root> m_bvh;
474
485 [[nodiscard]] static std::vector<TriAoSoA>
486 groupTrianglesIntoSoA(const std::vector<std::shared_ptr<const Tri>>& a_triangles,
489};
490
491} // namespace EBGeometry
492
493#include "EBGeometry_MeshDistanceFunctionsImplem.hpp"
494
495#endif
Declaration of bounding volume hierarchy (BVH) classes.
Declarations of bounding volume types used in bounding volume hierarchies.
Declaration of a mesh class which stores a DCEL mesh (with signed distance functions)
Abstract base class for representing a signed distance function.
Declaration of a metadata-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. Used with DCEL tools.
Forward declaration of the linearised BVH. Needed so that TreeBVH::pack() and TreeBVH::packWith() can...
Definition EBGeometry_BVH.hpp:1264
Face class for navigating a DCEL mesh.
Definition EBGeometry_DCEL_Face.hpp:54
DCEL mesh class - stores a doubly-connected edge mesh.
Definition EBGeometry_DCEL_Mesh.hpp:50
Signed distance function for a DCEL mesh. Does not use BVHs.
Definition EBGeometry_MeshDistanceFunctions.hpp:44
FlatMeshSDF()=delete
Disallowed constructor.
FlatMeshSDF(const FlatMeshSDF &a_other)=default
Copy constructor.
FlatMeshSDF(FlatMeshSDF &&a_other) noexcept=default
Move constructor.
FlatMeshSDF & operator=(FlatMeshSDF &&a_other) noexcept=default
Move assignment operator.
~FlatMeshSDF() override=default
Destructor.
FlatMeshSDF & operator=(const FlatMeshSDF &a_other)=default
Copy assignment operator.
FlatMeshSDF(const std::shared_ptr< Mesh > &a_mesh) noexcept
Full constructor.
T signedDistance(const Vec3T< T > &a_point) const noexcept override
Compute the signed distance from a_point to the mesh.
const std::shared_ptr< Mesh > getMesh() const noexcept
Get the underlying DCEL mesh.
std::shared_ptr< Mesh > m_mesh
DCEL mesh.
Definition EBGeometry_MeshDistanceFunctions.hpp:129
BV computeBoundingVolume() const
Compute the axis-aligned bounding volume enclosing the mesh.
Signed distance function for a DCEL mesh. Stores the mesh in a PackedBVH for SIMD-accelerated travers...
Definition EBGeometry_MeshDistanceFunctions.hpp:150
typename EBGeometry::DCEL::MeshT< T, Meta > Mesh
Alias for DCEL mesh type.
Definition EBGeometry_MeshDistanceFunctions.hpp:163
MeshSDF(const std::shared_ptr< Mesh > &a_mesh, const BVH::Build a_build)
Full constructor. Takes the input mesh and creates the BVH.
MeshSDF(const MeshSDF &a_other)=default
Copy constructor.
T signedDistance(const Vec3T< T > &a_point) const noexcept override
Compute the signed distance from a_point to the mesh.
MeshSDF()=delete
Default disallowed constructor.
virtual std::vector< std::pair< std::shared_ptr< const Face >, T > > getClosestFaces(const Vec3T< T > &a_point, const bool a_sorted) const
Return faces within BVH-pruned candidate distance of a_point.
virtual std::shared_ptr< Root > & getRoot() noexcept
Get the PackedBVH enclosing the mesh.
typename EBGeometry::DCEL::FaceT< T, Meta > Face
Alias for DCEL face type.
Definition EBGeometry_MeshDistanceFunctions.hpp:158
typename Root::Node Node
Alias for a single linearized node.
Definition EBGeometry_MeshDistanceFunctions.hpp:173
~MeshSDF() override=default
Destructor.
MeshSDF & operator=(MeshSDF &&a_other) noexcept=default
Move assignment operator.
MeshSDF(MeshSDF &&a_other) noexcept=default
Move constructor.
MeshSDF & operator=(const MeshSDF &a_other)=default
Copy assignment operator.
Abstract representation of a signed distance function.
Definition EBGeometry_SignedDistanceFunction.hpp:34
Signed distance function for a pure triangle mesh using SoA-grouped primitives in a compact (lineariz...
Definition EBGeometry_MeshDistanceFunctions.hpp:315
typename EBGeometry::BVH::PackedBVH< T, TriAoSoA, K, StoragePolicy > Root
Alias for which BVH root node.
Definition EBGeometry_MeshDistanceFunctions.hpp:339
TriMeshSDF(const std::shared_ptr< Mesh > &a_mesh, const BVH::Build a_build, const size_t a_maxLeafGroups) noexcept
Full constructor. Takes a DCEL mesh and creates the input triangles. Then creates the BVH.
TriMeshSDF(const TriMeshSDF &a_other)=default
Copy constructor.
ClosestTriangle getClosestTriangle(const Vec3T< T > &a_point) const noexcept
Signed distance to the closest triangle, together with that triangle's metadata.
TriMeshSDF & operator=(TriMeshSDF &&a_other) noexcept=default
Move assignment operator.
TriMeshSDF()=delete
Default disallowed constructor.
typename EBGeometry::Triangle< T, Meta > Tri
Alias for DCEL face type.
Definition EBGeometry_MeshDistanceFunctions.hpp:329
TriMeshSDF & operator=(const TriMeshSDF &a_other)=default
Copy assignment operator.
T signedDistance(const Vec3T< T > &a_point) const noexcept override
Compute the signed distance from a_point to the triangle mesh.
TriMeshSDF(const std::vector< std::shared_ptr< Tri > > &a_triangles, const BVH::Build a_build, const size_t a_maxLeafGroups) noexcept
Full constructor. Takes the input triangles and creates the BVH.
~TriMeshSDF() override=default
Destructor.
TriMeshSDF(TriMeshSDF &&a_other) noexcept=default
Move constructor.
virtual std::shared_ptr< Root > & getRoot() noexcept
Get the PackedBVH storing SoA triangle groups.
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:225
Build
Enum for specifying the BVH construction strategy.
Definition EBGeometry_BVH.hpp:48
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:31
Compact BVH node stored in the flat node array.
Definition EBGeometry_BVH.hpp:1288
Result of getClosestTriangle(): the signed distance to the closest triangle and that triangle's metad...
Definition EBGeometry_MeshDistanceFunctions.hpp:348
Metadata-carrying wrapper around a single TriangleSoAT<T, W>.
Definition EBGeometry_TriangleAoSoA.hpp:52