EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_DCEL_Mesh.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
12#ifndef EBGEOMETRY_DCEL_MESH_HPP
13#define EBGEOMETRY_DCEL_MESH_HPP
14
15// Std includes
16#include <cstddef>
17#include <cstdint>
18#include <map>
19#include <memory>
20#include <string>
21#include <type_traits>
22#include <vector>
23
24// Our includes
25#include "EBGeometry_DCEL.hpp"
29#include "EBGeometry_GPU.hpp"
31#include "EBGeometry_Pool.hpp"
32
33namespace EBGeometry {
34
35namespace DCEL {
36
37class ReconcileSchedule;
38
100template <class T>
101class MeshT : public PoolHandle
102{
103 static_assert(std::is_floating_point_v<T>, "MeshT requires a floating-point T");
104
105public:
110 {
111 Direct,
113 Direct2
116 };
117
121 using Vec3 = Vec3T<T>;
122
127
131 using Edge = EdgeT<T>;
132
136 using Face = FaceT<T>;
137
141 using Mesh = MeshT<T>;
142
152 MeshT() noexcept = default;
153
180
191 MeshT(const Layout& a_layout, const PoolLocation& a_location) noexcept
192 : PoolHandle(a_location),
193 m_algorithm(a_layout.m_algorithm),
194 m_vertices(a_layout.m_vertices),
195 m_edges(a_layout.m_edges),
196 m_faces(a_layout.m_faces)
197 {}
198
203 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
204 Layout
205 layout() const noexcept
206 {
208 }
209
220 MeshT(const Mesh& a_otherMesh) noexcept = default;
221
229 MeshT(Mesh&& a_otherMesh) noexcept = default;
230
234 ~MeshT() noexcept = default;
235
242 Mesh&
243 operator=(const Mesh& a_otherMesh) noexcept = default;
244
251 Mesh&
252 operator=(Mesh&& a_otherMesh) noexcept = default;
253
270 [[nodiscard]] EBGEOMETRY_HOST
271 inline Mesh
272 deepCopy(Pool& a_dstPool) const;
273
284 inline void
285 sanityCheck(const std::string a_id) const;
286
292 inline void
293 setSearchAlgorithm(const SearchAlgorithm a_algorithm) noexcept;
294
304 inline void
306
319 inline void
321
327 inline void
328 flip() noexcept;
329
338 inline void
339 reserveVertices(Pool& a_pool, uint32_t a_capacity);
340
349 inline void
350 reserveEdges(Pool& a_pool, uint32_t a_capacity);
351
360 inline void
361 reserveFaces(Pool& a_pool, uint32_t a_capacity);
362
370 inline uint32_t
371 addVertex(Pool& a_pool, const Vertex& a_vertex);
372
380 inline uint32_t
381 addEdge(Pool& a_pool, const Edge& a_edge);
382
390 inline uint32_t
391 addFace(Pool& a_pool, const Face& a_face);
392
400 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
401 inline Vertex&
402 getVertex(uint32_t a_index) noexcept;
403
411 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
412 inline const Vertex&
413 getVertex(uint32_t a_index) const noexcept;
414
422 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
423 inline Edge&
424 getEdge(uint32_t a_index) noexcept;
425
433 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
434 inline const Edge&
435 getEdge(uint32_t a_index) const noexcept;
436
444 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
445 inline Face&
446 getFace(uint32_t a_index) noexcept;
447
455 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
456 inline const Face&
457 getFace(uint32_t a_index) const noexcept;
458
463 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
464 inline uint32_t
465 numVertices() const noexcept;
466
471 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
472 inline uint32_t
473 numEdges() const noexcept;
474
479 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
480 inline uint32_t
481 numFaces() const noexcept;
482
487 [[nodiscard]] EBGEOMETRY_HOST
488 inline std::vector<Vec3T<T>>
490
502 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
503 inline T
504 signedDistance(const Vec3& a_x0) const noexcept;
505
518 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
519 inline T
520 signedDistance(const Vec3& a_x0, SearchAlgorithm a_algorithm) const noexcept;
521
531 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
532 inline T
533 unsignedDistance2(const Vec3& a_x0) const noexcept;
534
565 [[nodiscard]] EBGEOMETRY_HOST
566 inline Mesh
567 rebasedView(const Pool& a_pool) const noexcept;
568
569protected:
574
579
584
589
597 inline void
598 attachTo(const Pool& a_pool) noexcept;
599
605 inline void
606 reconcileFaces() noexcept;
607
613 inline void
614 reconcileEdges() noexcept;
615
621 inline void
623
628 inline void
629 flipFaceNormals() noexcept;
630
635 inline void
636 flipEdgeNormals() noexcept;
637
642 inline void
644
651 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
652 inline T
653 DirectSignedDistance(const Vec3& a_point) const noexcept;
654
664 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
665 inline T
666 DirectSignedDistance2(const Vec3& a_point) const noexcept;
667
675 inline void
676 incrementWarning(std::map<std::string, size_t>& a_warnings, const std::string& a_warn) const;
677
684 inline void
685 printWarnings(const std::map<std::string, size_t>& a_warnings, const std::string& a_id) const;
686
700 inline bool
701 faceLoopCloses(uint32_t a_faceIndex, uint32_t& a_lastEdge, uint32_t& a_steps) const noexcept;
702
709 inline void
711
715 friend class ReconcileSchedule;
716};
717} // namespace DCEL
718
719} // namespace EBGeometry
720
721#include "EBGeometry_DCEL_MeshImplem.hpp"
722
723#endif
Namespace documentation.
Declaration of a half-edge class for use in DCEL descriptions of polygon tessellations.
Declaration of a polygon face class for use in DCEL descriptions of polygon tessellations.
Declaration of a vertex class for use in DCEL descriptions of polygon tessellations.
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
Placement-independent POD array views for the GPU memory foundation.
Growable bump arena for the GPU memory foundation.
Half-edge class for navigating a DCEL mesh.
Definition EBGeometry_DCEL_Edge.hpp:60
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
PODVector< Edge > m_edges
Mesh half-edges.
Definition EBGeometry_DCEL_Mesh.hpp:583
void reconcileVertices()
Compute each vertex's angle-weighted pseudonormal.
Layout layout() const noexcept
The mesh's arrays without its location, for storing it inside another pool-resident object.
Definition EBGeometry_DCEL_Mesh.hpp:205
T DirectSignedDistance2(const Vec3 &a_point) const noexcept
Implementation of signed distance function which iterates through all faces, comparing squared unsign...
void reserveVertices(Pool &a_pool, uint32_t a_capacity)
Reserve storage for a_capacity vertices.
void flip() noexcept
Flip the mesh, making all the normals change direction.
void flipFaceNormals() noexcept
Flip all face normals.
Mesh rebasedView(const Pool &a_pool) const noexcept
Produce a copy of this mesh's descriptor that resolves against a mirror of this mesh's Pool,...
uint32_t addVertex(Pool &a_pool, const Vertex &a_vertex)
Append a vertex into the pre-reserved capacity (see reserveVertices()).
uint32_t numFaces() const noexcept
Number of faces in this mesh.
void reserveEdges(Pool &a_pool, uint32_t a_capacity)
Reserve storage for a_capacity half-edges.
void incrementWarning(std::map< std::string, size_t > &a_warnings, const std::string &a_warn) const
Increment a warning. This is used in sanityCheck() for locating holes or bad inputs in the mesh.
void attachTo(const Pool &a_pool) noexcept
Attach this mesh to a_pool, or check that it is already attached to it.
SearchAlgorithm
Possible search algorithms for DCEL::MeshT.
Definition EBGeometry_DCEL_Mesh.hpp:110
uint32_t addFace(Pool &a_pool, const Face &a_face)
Append a face into the pre-reserved capacity (see reserveFaces()).
void sanityCheck(const std::string a_id) const
Perform a sanity check.
PODVector< Face > m_faces
Mesh faces.
Definition EBGeometry_DCEL_Mesh.hpp:588
uint32_t addEdge(Pool &a_pool, const Edge &a_edge)
Append a half-edge into the pre-reserved capacity (see reserveEdges()).
void reconcileEdges() noexcept
Function which computes internal things for the half-edges.
void flipVertexNormals() noexcept
Flip all vertex normals.
Vertex & getVertex(uint32_t a_index) noexcept
Get modifiable vertex by index.
void flipEdgeNormals() noexcept
Flip all edge normals.
void setSearchAlgorithm(const SearchAlgorithm a_algorithm) noexcept
Search algorithm for direct signed distance computations.
bool faceLoopCloses(uint32_t a_faceIndex, uint32_t &a_lastEdge, uint32_t &a_steps) const noexcept
Walk a face's half-edge loop, bounded by the number of half-edges.
T signedDistance(const Vec3 &a_x0) const noexcept
Compute the signed distance from a point to this mesh.
T DirectSignedDistance(const Vec3 &a_point) const noexcept
Implementation of signed distance function which iterates through all faces.
T unsignedDistance2(const Vec3 &a_x0) const noexcept
Compute the unsigned square distance from a point to this mesh.
void checkFaceLoops() const
Check every face's half-edge loop, aborting with a message in every build: the face has a half-edge,...
std::vector< Vec3T< T > > getAllVertexCoordinates() const
Return all vertex coordinates in the mesh.
MeshT() noexcept=default
Default constructor. Leaves the mesh empty (no vertices, edges, faces) and attached to no Pool,...
void reconcileFaces() noexcept
Function which computes internal things for the polygon faces.
MeshT(const Mesh &a_otherMesh) noexcept=default
Copy constructor.
void reconcile()
Reconcile function which computes the internal parameters in vertices, edges, and faces for use with ...
Mesh deepCopy(Pool &a_dstPool) const
Create an independent, fully-decoupled copy of this mesh's data in another Pool.
uint32_t numEdges() const noexcept
Number of half-edges in this mesh.
PODVector< Vertex > m_vertices
Mesh vertices.
Definition EBGeometry_DCEL_Mesh.hpp:578
~MeshT() noexcept=default
Destructor (does nothing; MeshT owns no resources).
void printWarnings(const std::map< std::string, size_t > &a_warnings, const std::string &a_id) const
Print all warnings to std::cerr.
SearchAlgorithm m_algorithm
Search algorithm. Only used in signed distance functions.
Definition EBGeometry_DCEL_Mesh.hpp:573
MeshT(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_DCEL_Mesh.hpp:191
Edge & getEdge(uint32_t a_index) noexcept
Get modifiable half-edge by index.
MeshT(Mesh &&a_otherMesh) noexcept=default
Move constructor.
uint32_t numVertices() const noexcept
Number of vertices in this mesh.
Face & getFace(uint32_t a_index) noexcept
Get modifiable face by index.
void setInsideOutsideAlgorithm(InsideOutsideAlgorithm a_algorithm) noexcept
Set the inside/outside algorithm to use when computing the signed distance to polygon faces.
void reserveFaces(Pool &a_pool, uint32_t a_capacity)
Reserve storage for a_capacity faces.
Which faces touch each vertex of a mesh, checked and stored once, for DCEL::reconcile().
Definition EBGeometry_DCEL_Reconcile.hpp:81
Vertex class for navigating a DCEL mesh.
Definition EBGeometry_DCEL_Vertex.hpp:63
Base of every pool-resident handle: the one PoolLocation its arrays resolve against.
Definition EBGeometry_Pool.hpp:563
PoolHandle() noexcept=default
An unset location; the first reservation attaches it.
Growable bump arena over a MemoryResource.
Definition EBGeometry_Pool.hpp:205
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
InsideOutsideAlgorithm
Supported algorithms for testing whether a point projects to the inside of a polygon face.
Definition EBGeometry_DCEL.hpp:67
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
The mesh's arrays as offsets into its pool, with no location: what another pool-resident object store...
Definition EBGeometry_DCEL_Mesh.hpp:159
PODVector< Vertex > m_vertices
Vertices.
Definition EBGeometry_DCEL_Mesh.hpp:168
PODVector< Edge > m_edges
Half-edges.
Definition EBGeometry_DCEL_Mesh.hpp:173
PODVector< Face > m_faces
Faces.
Definition EBGeometry_DCEL_Mesh.hpp:178
Placement-independent descriptor of a POD array inside a Pool.
Definition EBGeometry_PODVector.hpp:131
Where a pool-resident descriptor resolves its offsets, and the rules for moving it.
Definition EBGeometry_Pool.hpp:99