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: GPL-3.0-or-later
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
98template <class T>
99class MeshT : public PoolHandle
100{
101 static_assert(std::is_floating_point_v<T>, "MeshT requires a floating-point T");
102
103public:
108 {
109 Direct,
111 Direct2
114 };
115
119 using Vec3 = Vec3T<T>;
120
125
129 using Edge = EdgeT<T>;
130
134 using Face = FaceT<T>;
135
139 using Mesh = MeshT<T>;
140
150 MeshT() noexcept = default;
151
178
188 MeshT(const Layout& a_layout, const PoolLocation& a_location) noexcept
189 : PoolHandle(a_location),
190 m_algorithm(a_layout.m_algorithm),
191 m_vertices(a_layout.m_vertices),
192 m_edges(a_layout.m_edges),
193 m_faces(a_layout.m_faces)
194 {}
195
200 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
201 Layout
202 layout() const noexcept
203 {
205 }
206
217 MeshT(const Mesh& a_otherMesh) noexcept = default;
218
226 MeshT(Mesh&& a_otherMesh) noexcept = default;
227
231 ~MeshT() noexcept = default;
232
239 Mesh&
240 operator=(const Mesh& a_otherMesh) noexcept = default;
241
248 Mesh&
249 operator=(Mesh&& a_otherMesh) noexcept = default;
250
267 [[nodiscard]] EBGEOMETRY_HOST
268 inline Mesh
269 deepCopy(Pool& a_dstPool) const;
270
281 inline void
282 sanityCheck(const std::string a_id) const;
283
289 inline void
290 setSearchAlgorithm(const SearchAlgorithm a_algorithm) noexcept;
291
301 inline void
303
316 inline void
318
324 inline void
325 flip() noexcept;
326
335 inline void
336 reserveVertices(Pool& a_pool, uint32_t a_capacity);
337
346 inline void
347 reserveEdges(Pool& a_pool, uint32_t a_capacity);
348
357 inline void
358 reserveFaces(Pool& a_pool, uint32_t a_capacity);
359
367 inline uint32_t
368 addVertex(Pool& a_pool, const Vertex& a_vertex);
369
377 inline uint32_t
378 addEdge(Pool& a_pool, const Edge& a_edge);
379
387 inline uint32_t
388 addFace(Pool& a_pool, const Face& a_face);
389
397 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
398 inline Vertex&
399 getVertex(uint32_t a_index) noexcept;
400
408 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
409 inline const Vertex&
410 getVertex(uint32_t a_index) const noexcept;
411
419 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
420 inline Edge&
421 getEdge(uint32_t a_index) noexcept;
422
430 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
431 inline const Edge&
432 getEdge(uint32_t a_index) const noexcept;
433
441 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
442 inline Face&
443 getFace(uint32_t a_index) noexcept;
444
452 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
453 inline const Face&
454 getFace(uint32_t a_index) const noexcept;
455
460 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
461 inline uint32_t
462 numVertices() const noexcept;
463
468 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
469 inline uint32_t
470 numEdges() const noexcept;
471
476 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
477 inline uint32_t
478 numFaces() const noexcept;
479
484 [[nodiscard]] EBGEOMETRY_HOST
485 inline std::vector<Vec3T<T>>
487
499 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
500 inline T
501 signedDistance(const Vec3& a_x0) const noexcept;
502
515 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
516 inline T
517 signedDistance(const Vec3& a_x0, SearchAlgorithm a_algorithm) const noexcept;
518
528 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
529 inline T
530 unsignedDistance2(const Vec3& a_x0) const noexcept;
531
562 [[nodiscard]] EBGEOMETRY_HOST
563 inline Mesh
564 rebasedView(const Pool& a_pool) const noexcept;
565
566protected:
571
576
581
586
594 inline void
595 attachTo(const Pool& a_pool) noexcept;
596
602 inline void
603 reconcileFaces() noexcept;
604
610 inline void
611 reconcileEdges() noexcept;
612
618 inline void
620
625 inline void
626 flipFaceNormals() noexcept;
627
632 inline void
633 flipEdgeNormals() noexcept;
634
639 inline void
641
648 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
649 inline T
650 DirectSignedDistance(const Vec3& a_point) const noexcept;
651
661 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
662 inline T
663 DirectSignedDistance2(const Vec3& a_point) const noexcept;
664
672 inline void
673 incrementWarning(std::map<std::string, size_t>& a_warnings, const std::string& a_warn) const;
674
681 inline void
682 printWarnings(const std::map<std::string, size_t>& a_warnings, const std::string& a_id) const;
683
697 inline bool
698 faceLoopCloses(uint32_t a_faceIndex, uint32_t& a_lastEdge, uint32_t& a_steps) const noexcept;
699};
700} // namespace DCEL
701
702} // namespace EBGeometry
703
704#include "EBGeometry_DCEL_MeshImplem.hpp"
705
706#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:100
PODVector< Edge > m_edges
Mesh half-edges.
Definition EBGeometry_DCEL_Mesh.hpp:580
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:202
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:108
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:585
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.
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:575
~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:570
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:188
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.
Vertex class for navigating a DCEL mesh.
Definition EBGeometry_DCEL_Vertex.hpp:61
Base of every pool-resident handle: the one PoolLocation its arrays resolve against.
Definition EBGeometry_Pool.hpp:499
PoolHandle() noexcept=default
An unset location; the first reservation attaches it.
Growable bump arena over a MemoryResource.
Definition EBGeometry_Pool.hpp:183
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:157
PODVector< Vertex > m_vertices
Vertices.
Definition EBGeometry_DCEL_Mesh.hpp:166
PODVector< Edge > m_edges
Half-edges.
Definition EBGeometry_DCEL_Mesh.hpp:171
PODVector< Face > m_faces
Faces.
Definition EBGeometry_DCEL_Mesh.hpp:176
Placement-independent descriptor of a POD array inside a Pool.
Definition EBGeometry_PODVector.hpp:119
Where a pool-resident descriptor resolves its offsets, and the rules for moving it.
Definition EBGeometry_Pool.hpp:99