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 <memory>
18#include <type_traits>
19#include <utility>
20#include <vector>
21
22// Our includes
23#include "EBGeometry_BVH.hpp"
29#include "EBGeometry_Vec.hpp"
30
31namespace EBGeometry {
32
40template <class T, class Meta = DCEL::DefaultMetaData>
42{
43 static_assert(std::is_floating_point_v<T>, "FlatMeshSDF requires a floating-point T");
44
45public:
50
54 FlatMeshSDF() = delete;
55
60 FlatMeshSDF(const std::shared_ptr<Mesh>& a_mesh) noexcept;
61
65 ~FlatMeshSDF() override = default;
66
73 FlatMeshSDF(const FlatMeshSDF& a_other) = default;
74
81 operator=(const FlatMeshSDF& a_other) = default;
82
89 FlatMeshSDF(FlatMeshSDF&& a_other) noexcept = default;
90
97 operator=(FlatMeshSDF&& a_other) noexcept = default;
98
104 [[nodiscard]] T
105 signedDistance(const Vec3T<T>& a_point) const noexcept override;
106
111 [[nodiscard]] const std::shared_ptr<Mesh>
113
119 template <class BV>
120 [[nodiscard]] BV
122
127 std::shared_ptr<Mesh> m_mesh;
128};
129
146template <class T, class Meta, size_t K>
148{
149 static_assert(std::is_floating_point_v<T>, "MeshSDF requires a floating-point T");
150 static_assert(K >= 2, "MeshSDF requires branching factor K >= 2");
151
152public:
157
162
167
171 using Node = typename Root::Node;
172
176 MeshSDF() = delete;
177
186 MeshSDF(const std::shared_ptr<Mesh>& a_mesh, const BVH::Build a_build);
187
191 ~MeshSDF() override = default;
192
199 MeshSDF(const MeshSDF& a_other) = default;
200
206 MeshSDF&
207 operator=(const MeshSDF& a_other) = default;
208
215 MeshSDF(MeshSDF&& a_other) noexcept = default;
216
222 MeshSDF&
223 operator=(MeshSDF&& a_other) noexcept = default;
224
230 [[nodiscard]] T
231 signedDistance(const Vec3T<T>& a_point) const noexcept override;
232
242 [[nodiscard]] virtual std::vector<std::pair<std::shared_ptr<const Face>, T>>
243 getClosestFaces(const Vec3T<T>& a_point, const bool a_sorted) const;
244
249 [[nodiscard]] virtual std::shared_ptr<Root>&
251
256 [[nodiscard]] virtual const std::shared_ptr<Root>&
257 getRoot() const noexcept;
258
263 [[nodiscard]] EBGeometry::BoundingVolumes::AABBT<T>
265
270 std::shared_ptr<Root> m_bvh;
271
278 std::shared_ptr<Mesh> m_mesh;
279};
280
303template <class T,
304 class Meta,
305 size_t K,
306 size_t W,
307 class StoragePolicy = BVH::ValueStorage<EBGeometry::TriangleSoAT<T, W>>>
309{
310 static_assert(std::is_floating_point_v<T>, "TriMeshSDF<T,Meta,K,W> requires a floating-point T");
311 static_assert(K >= 2, "TriMeshSDF requires branching factor K >= 2");
312 static_assert(W > 0, "TriMeshSDF requires SoA width W > 0");
313
314public:
319
324
329
334
338 TriMeshSDF() = delete;
339
358 TriMeshSDF(const std::shared_ptr<Mesh>& a_mesh, const BVH::Build a_build, const size_t a_maxLeafGroups) noexcept;
359
367 TriMeshSDF(const std::vector<std::shared_ptr<Tri>>& a_triangles,
368 const BVH::Build a_build,
369 const size_t a_maxLeafGroups) noexcept;
370
374 ~TriMeshSDF() override = default;
375
382 TriMeshSDF(const TriMeshSDF& a_other) = default;
383
390 operator=(const TriMeshSDF& a_other) = default;
391
398 TriMeshSDF(TriMeshSDF&& a_other) noexcept = default;
399
406 operator=(TriMeshSDF&& a_other) noexcept = default;
407
413 [[nodiscard]] T
414 signedDistance(const Vec3T<T>& a_point) const noexcept override;
415
420 [[nodiscard]] virtual std::shared_ptr<Root>&
422
427 [[nodiscard]] virtual const std::shared_ptr<Root>&
428 getRoot() const noexcept;
429
434 [[nodiscard]] EBGeometry::BoundingVolumes::AABBT<T>
436
441 std::shared_ptr<Root> m_bvh;
442
453 [[nodiscard]] static std::vector<TriSoA>
454 groupTrianglesIntoSoA(const std::vector<std::shared_ptr<const Tri>>& a_triangles,
457};
458
459} // namespace EBGeometry
460
461#include "EBGeometry_MeshDistanceFunctionsImplem.hpp"
462
463#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 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:1238
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:42
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:127
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:148
typename EBGeometry::DCEL::MeshT< T, Meta > Mesh
Alias for DCEL mesh type.
Definition EBGeometry_MeshDistanceFunctions.hpp:161
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:156
typename Root::Node Node
Alias for a single linearized node.
Definition EBGeometry_MeshDistanceFunctions.hpp:171
~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:309
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.
typename EBGeometry::BVH::PackedBVH< T, TriSoA, K, StoragePolicy > Root
Alias for which BVH root node.
Definition EBGeometry_MeshDistanceFunctions.hpp:333
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:323
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:1262
SoA (Structure of Arrays) layout for W triangles, enabling SIMD evaluation.
Definition EBGeometry_TriangleSoA.hpp:101