EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
EBGeometry::DCEL::MeshT< T, Meta > Class Template Reference

DCEL mesh class - stores a doubly-connected edge mesh. More...

#include <EBGeometry_DCEL_Mesh.hpp>

Collaboration diagram for EBGeometry::DCEL::MeshT< T, Meta >:
Collaboration graph
[legend]

Public Types

enum class  SearchAlgorithm { Direct , Direct2 }
 Possible search algorithms for DCEL::MeshT. More...
 
using Vec3 = Vec3T< T >
 Alias for vector type.
 
using Vertex = VertexT< T, Meta >
 Alias for vertex type.
 
using Edge = EdgeT< T, Meta >
 Alias for edge type.
 
using Face = FaceT< T, Meta >
 Alias for face type.
 
using Mesh = MeshT< T, Meta >
 Alias for mesh type.
 
using VertexPtr = std::shared_ptr< Vertex >
 Alias for vertex pointer type.
 
using EdgePtr = std::shared_ptr< Edge >
 Alias for edge pointer type.
 
using FacePtr = std::shared_ptr< Face >
 Alias for face pointer type.
 

Public Member Functions

 MeshT () noexcept=default
 Default constructor.
 
 MeshT (const Mesh &a_otherMesh)=delete
 Disallowed copy construction.
 
 MeshT (Mesh &&a_otherMesh) noexcept=default
 Move constructor.
 
 MeshT (std::vector< FacePtr > &a_faces, std::vector< EdgePtr > &a_edges, std::vector< VertexPtr > &a_vertices) noexcept
 Full constructor. This provides the faces, edges, and vertices to the mesh.
 
 ~MeshT () noexcept=default
 Destructor (does nothing)
 
Meshoperator= (const Mesh &a_otherMesh)=delete
 Disallowed copy assignment.
 
Meshoperator= (Mesh &&a_otherMesh) noexcept=default
 Move assignment operator.
 
std::shared_ptr< MeshdeepCopy () const
 Create an independent, fully-decoupled copy of this mesh.
 
void sanityCheck (const std::string a_id) const
 Perform a sanity check.
 
void setSearchAlgorithm (const SearchAlgorithm a_algorithm) noexcept
 Search algorithm for direct signed distance computations.
 
void setInsideOutsideAlgorithm (typename Polygon2D< T >::InsideOutsideAlgorithm a_algorithm) noexcept
 Set the inside/outside algorithm to use when computing the signed distance to polygon faces.
 
void reconcile (const DCEL::VertexNormalWeight a_weight=DCEL::VertexNormalWeight::Angle) noexcept
 Reconcile function which computes the internal parameters in vertices, edges, and faces for use with signed distance functionality.
 
void flip () noexcept
 Flip the mesh, making all the normals change direction.
 
std::vector< VertexPtr > & getVertices () noexcept
 Get modifiable vertices in this mesh.
 
const std::vector< VertexPtr > & getVertices () const noexcept
 Get immutable vertices in this mesh.
 
std::vector< Vec3T< T > > getAllVertexCoordinates () const noexcept
 Return all vertex coordinates in the mesh.
 
std::vector< EdgePtr > & getEdges () noexcept
 Get modifiable half-edges in this mesh.
 
const std::vector< EdgePtr > & getEdges () const noexcept
 Get immutable half-edges in this mesh.
 
std::vector< FacePtr > & getFaces () noexcept
 Get modifiable faces in this mesh.
 
const std::vector< FacePtr > & getFaces () const noexcept
 Get immutable faces in this mesh.
 
signedDistance (const Vec3 &a_x0) const noexcept
 Compute the signed distance from a point to this mesh.
 
signedDistance (const Vec3 &a_x0, SearchAlgorithm a_algorithm) const noexcept
 Compute the signed distance from a point to this mesh.
 
unsignedDistance2 (const Vec3 &a_x0) const noexcept
 Compute the unsigned square distance from a point to this mesh.
 

Protected Member Functions

void reconcileFaces () noexcept
 Function which computes internal things for the polygon faces.
 
void reconcileEdges () noexcept
 Function which computes internal things for the half-edges.
 
void reconcileVertices (const DCEL::VertexNormalWeight a_weight) noexcept
 Function which computes internal things for the vertices.
 
void flipFaceNormals () noexcept
 Flip all face normals.
 
void flipEdgeNormals () noexcept
 Flip all edge normals.
 
void flipVertexNormals () noexcept
 Flip all vertex normals.
 
DirectSignedDistance (const Vec3 &a_point) const noexcept
 Implementation of signed distance function which iterates through all faces.
 
DirectSignedDistance2 (const Vec3 &a_point) const noexcept
 Implementation of squared signed distance function which iterates through all faces.
 
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 printWarnings (const std::map< std::string, size_t > &a_warnings, const std::string &a_id) const
 Print all warnings to std::cerr.
 

Protected Attributes

SearchAlgorithm m_algorithm = SearchAlgorithm::Direct2
 Search algorithm. Only used in signed distance functions.
 
std::vector< VertexPtrm_vertices
 Mesh vertices.
 
std::vector< EdgePtrm_edges
 Mesh half-edges.
 
std::vector< FacePtrm_faces
 Mesh faces.
 

Detailed Description

template<class T, class Meta>
class EBGeometry::DCEL::MeshT< T, Meta >

DCEL mesh class - stores a doubly-connected edge mesh.

Mesh class which stores a full DCEL mesh (with signed distance functions)

Template Parameters
TFloating-point precision type.
MetaUser-defined metadata type.

This encapsulates a full DCEL mesh, and also includes DIRECT signed distance functions. The mesh consists of a set of vertices, half-edges, and polygon faces who each have references to other vertices, half-edges, and polygon faces. The signed distance functions DIRECT, which means that they go through ALL of the polygon faces and compute the signed distance to them. This is extremely inefficient, which is why this class is almost always embedded into a bounding volume hierarchy.

Note
This class is not for the light of heart – it will almost always be instantiated through a file parser which reads vertices and edges from file and builds the mesh from that. Do not try to build a MeshT object yourself, use file parsers!
Template Parameters
TFloating-point precision type.
MetaUser-defined metadata type.

Member Enumeration Documentation

◆ SearchAlgorithm

Possible search algorithms for DCEL::MeshT.

Enumerator
Direct 

Computes the signed distance to every face and returns the one with the smallest magnitude. See DirectSignedDistance().

Direct2 

Computes the squared unsigned distance to every face to find the closest one, then returns the signed distance to only that face. Equivalent to Direct but usually faster since it avoids a square root per face. See DirectSignedDistance2().

Constructor & Destructor Documentation

◆ MeshT() [1/4]

template<class T , class Meta >
EBGeometry::DCEL::MeshT< T, Meta >::MeshT ( )
defaultnoexcept

Default constructor.

Leaves the mesh empty (no vertices, edges, or faces) with the default search algorithm; use define() or the mutable getVertices()/getEdges()/getFaces() to populate it.

◆ MeshT() [2/4]

template<class T , class Meta >
EBGeometry::DCEL::MeshT< T, Meta >::MeshT ( const Mesh a_otherMesh)
delete

Disallowed copy construction.

Copying is deliberately disallowed: a shallow copy of m_vertices/m_edges/m_faces would share the same underlying vertex/edge/face objects as the original (they reference each other internally), so it would not behave like an independent mesh – mutating the "copy" would also mutate the original. Use a file parser to build an independent mesh instead. Moving is allowed (see the move constructor), since that transfers ownership rather than aliasing it.

Parameters
[in]a_otherMeshOther mesh.

◆ MeshT() [3/4]

template<class T , class Meta >
EBGeometry::DCEL::MeshT< T, Meta >::MeshT ( Mesh &&  a_otherMesh)
defaultnoexcept

Move constructor.

Parameters
[in,out]a_otherMeshOther mesh.

◆ MeshT() [4/4]

template<class T , class Meta >
EBGeometry::DCEL::MeshT< T, Meta >::MeshT ( std::vector< FacePtr > &  a_faces,
std::vector< EdgePtr > &  a_edges,
std::vector< VertexPtr > &  a_vertices 
)
noexcept

Full constructor. This provides the faces, edges, and vertices to the mesh.

Copies the three vectors directly into m_faces/m_edges/m_vertices. This only associates pointer structures through the mesh; internal parameters like face area and normal are computed by reconcile().

Parameters
[in]a_facesPolygon faces
[in]a_edgesHalf-edges
[in]a_verticesVertices
Note
The constructor arguments should provide a complete DCEL mesh description. This is usually done through a file parser which reads a mesh file format and creates the DCEL mesh structure

Member Function Documentation

◆ deepCopy()

template<class T , class Meta >
std::shared_ptr< Mesh > EBGeometry::DCEL::MeshT< T, Meta >::deepCopy ( ) const
inline

Create an independent, fully-decoupled copy of this mesh.

Since copy construction/assignment are disallowed (see their documentation), this is the supported way to duplicate a mesh. Unlike a shallow copy, this creates brand new VertexT/EdgeT/FaceT objects and relinks all of their internal pointers (outgoing edge, pair edge, next edge, half edge, adjacent faces) so that the copy shares no vertex, edge, or face with the original – mutating one mesh does not affect the other. Every field is preserved exactly (position, normal vector, centroid, area, meta-data, search algorithm) rather than recomputed, so a mesh that has had flipNormal()/flip() called on it and not yet been re-reconciled will be copied faithfully rather than silently "un-flipped".

Returns
A new mesh, independent of this one.

◆ DirectSignedDistance()

template<class T , class Meta >
T EBGeometry::DCEL::MeshT< T, Meta >::DirectSignedDistance ( const Vec3 a_point) const
inlineprotectednoexcept

Implementation of signed distance function which iterates through all faces.

Parameters
[in]a_point3D point
Returns
Signed distance to the nearest face.

◆ DirectSignedDistance2()

template<class T , class Meta >
T EBGeometry::DCEL::MeshT< T, Meta >::DirectSignedDistance2 ( const Vec3 a_point) const
inlineprotectednoexcept

Implementation of squared signed distance function which iterates through all faces.

This first find the face with the smallest unsigned square distance, and the returns the signed distance to that face (more efficient than the other version).

Parameters
[in]a_point3D point
Returns
Signed distance to the nearest face.

◆ flip()

template<class T , class Meta >
void EBGeometry::DCEL::MeshT< T, Meta >::flip ( )
inlinenoexcept

Flip the mesh, making all the normals change direction.

Note
Should be called AFTER all normals have been computed.

◆ getAllVertexCoordinates()

template<class T , class Meta >
std::vector< Vec3T< T > > EBGeometry::DCEL::MeshT< T, Meta >::getAllVertexCoordinates ( ) const
inlinenoexcept

Return all vertex coordinates in the mesh.

Returns
Vector of 3D coordinates of all vertices.

◆ getEdges() [1/2]

template<class T , class Meta >
const std::vector< EdgePtr > & EBGeometry::DCEL::MeshT< T, Meta >::getEdges ( ) const
inlinenoexcept

Get immutable half-edges in this mesh.

Returns
Const reference to the vector of half-edges.

◆ getEdges() [2/2]

template<class T , class Meta >
std::vector< EdgePtr > & EBGeometry::DCEL::MeshT< T, Meta >::getEdges ( )
inlinenoexcept

Get modifiable half-edges in this mesh.

Returns
Reference to the vector of half-edges.

◆ getFaces() [1/2]

template<class T , class Meta >
const std::vector< FacePtr > & EBGeometry::DCEL::MeshT< T, Meta >::getFaces ( ) const
inlinenoexcept

Get immutable faces in this mesh.

Returns
Const reference to the vector of polygon faces.

◆ getFaces() [2/2]

template<class T , class Meta >
std::vector< FacePtr > & EBGeometry::DCEL::MeshT< T, Meta >::getFaces ( )
inlinenoexcept

Get modifiable faces in this mesh.

Returns
Reference to the vector of polygon faces.

◆ getVertices() [1/2]

template<class T , class Meta >
const std::vector< VertexPtr > & EBGeometry::DCEL::MeshT< T, Meta >::getVertices ( ) const
inlinenoexcept

Get immutable vertices in this mesh.

Returns
Const reference to the vector of vertices.

◆ getVertices() [2/2]

template<class T , class Meta >
std::vector< VertexPtr > & EBGeometry::DCEL::MeshT< T, Meta >::getVertices ( )
inlinenoexcept

Get modifiable vertices in this mesh.

Returns
Reference to the vector of vertices.

◆ incrementWarning()

template<class T , class Meta >
void EBGeometry::DCEL::MeshT< T, Meta >::incrementWarning ( std::map< std::string, size_t > &  a_warnings,
const std::string &  a_warn 
) const
inlineprotected

Increment a warning. This is used in sanityCheck() for locating holes or bad inputs in the mesh.

Parameters
[in]a_warningsMap of all registered warnings
[in]a_warnCurrent warning to increment by

◆ operator=() [1/2]

template<class T , class Meta >
Mesh & EBGeometry::DCEL::MeshT< T, Meta >::operator= ( const Mesh a_otherMesh)
delete

Disallowed copy assignment.

Has the same rationale as the disallowed copy constructor; see its documentation.

Parameters
[in]a_otherMeshOther mesh.
Returns
Reference to (*this).

◆ operator=() [2/2]

template<class T , class Meta >
Mesh & EBGeometry::DCEL::MeshT< T, Meta >::operator= ( Mesh &&  a_otherMesh)
defaultnoexcept

Move assignment operator.

Parameters
[in,out]a_otherMeshOther mesh.
Returns
Reference to (*this).

◆ printWarnings()

template<class T , class Meta >
void EBGeometry::DCEL::MeshT< T, Meta >::printWarnings ( const std::map< std::string, size_t > &  a_warnings,
const std::string &  a_id 
) const
inlineprotected

Print all warnings to std::cerr.

Parameters
[in]a_warningsList of warnings (generated by sanityCheck)
[in]a_idIdentifier used when printing warnings (can be empty string)

◆ reconcile()

template<class T , class Meta >
void EBGeometry::DCEL::MeshT< T, Meta >::reconcile ( const DCEL::VertexNormalWeight  a_weight = DCEL::VertexNormalWeight::Angle)
inlinenoexcept

Reconcile function which computes the internal parameters in vertices, edges, and faces for use with signed distance functionality.

Parameters
[in]a_weightVertex angle weighting function. Either VertexNormalWeight::None for unweighted vertex normals or VertexNormalWeight::Angle for the pseudonormal

This will reconcile faces, edges, and vertices, e.g. computing the area and normal vector for faces

◆ reconcileEdges()

template<class T , class Meta >
void EBGeometry::DCEL::MeshT< T, Meta >::reconcileEdges ( )
inlineprotectednoexcept

Function which computes internal things for the half-edges.

Note
This calls DCEL::EdgeT<T, Meta>::reconcile()

◆ reconcileFaces()

template<class T , class Meta >
void EBGeometry::DCEL::MeshT< T, Meta >::reconcileFaces ( )
inlineprotectednoexcept

Function which computes internal things for the polygon faces.

Note
This calls DCEL::FaceT<T, Meta>::reconcile()

◆ reconcileVertices()

template<class T , class Meta >
void EBGeometry::DCEL::MeshT< T, Meta >::reconcileVertices ( const DCEL::VertexNormalWeight  a_weight)
inlineprotectednoexcept

Function which computes internal things for the vertices.

Parameters
[in]a_weightVertex angle weighting
Note
This calls DCEL::VertexT<T, Meta>::computeVertexNormalAverage() or DCEL::VertexT<T, Meta>::computeVertexNormalAngleWeighted()

◆ sanityCheck()

template<class T , class Meta >
void EBGeometry::DCEL::MeshT< T, Meta >::sanityCheck ( const std::string  a_id) const
inline

Perform a sanity check.

This will provide error messages if vertices are badly linked, faces are nullptr, and so on. These messages are logged by calling incrementWarning() which identifies types of errors that can occur, and how many of those errors have occurred.

Parameters
[in]a_idIdentifier when printing error messages (can be empty string).

◆ setInsideOutsideAlgorithm()

template<class T , class Meta >
void EBGeometry::DCEL::MeshT< T, Meta >::setInsideOutsideAlgorithm ( typename Polygon2D< T >::InsideOutsideAlgorithm  a_algorithm)
inlinenoexcept

Set the inside/outside algorithm to use when computing the signed distance to polygon faces.

Computing the signed distance to faces requires testing if a point projected to a polygo face plane falls inside or outside the polygon face. There are multiple algorithms to use here.

Parameters
[in]a_algorithmAlgorithm to use

◆ setSearchAlgorithm()

template<class T , class Meta >
void EBGeometry::DCEL::MeshT< T, Meta >::setSearchAlgorithm ( const SearchAlgorithm  a_algorithm)
inlinenoexcept

Search algorithm for direct signed distance computations.

Parameters
[in]a_algorithmAlgorithm to use

◆ signedDistance() [1/2]

template<class T , class Meta >
T EBGeometry::DCEL::MeshT< T, Meta >::signedDistance ( const Vec3 a_x0) const
inlinenoexcept

Compute the signed distance from a point to this mesh.

Parameters
[in]a_x03D point in space.

This function will iterate through ALL faces in the mesh and return the value with the smallest magnitude. This is horrendously slow, which is why this function is almost never called. Rather, MeshT<T, Meta> can be embedded in a bounding volume hierarchy for faster access.

Note
This will call the other version with the object's search algorithm.
Returns
Signed distance to the mesh; negative inside, positive outside. Returns +infinity if the mesh has no faces.

◆ signedDistance() [2/2]

template<class T , class Meta >
T EBGeometry::DCEL::MeshT< T, Meta >::signedDistance ( const Vec3 a_x0,
SearchAlgorithm  a_algorithm 
) const
inlinenoexcept

Compute the signed distance from a point to this mesh.

Parameters
[in]a_x03D point in space.
[in]a_algorithmSearch algorithm

This function will iterate through ALL faces in the mesh and return the value with the smallest magnitude. This is horrendously slow, which is why this function is almost never called. Rather, MeshT<T, Meta> can be embedded in a bounding volume hierarchy for faster access.

Returns
Signed distance to the mesh; negative inside, positive outside. Returns +infinity if the mesh has no faces.

◆ unsignedDistance2()

template<class T , class Meta >
T EBGeometry::DCEL::MeshT< T, Meta >::unsignedDistance2 ( const Vec3 a_x0) const
inlinenoexcept

Compute the unsigned square distance from a point to this mesh.

Parameters
[in]a_x03D point in space.

This function will iterate through ALL faces in the mesh and return the value with the smallest magnitude. This is horrendously slow, which is why this function is almost never called. Rather, MeshT<T, Meta> can be embedded in a bounding volume hierarchy for faster access.

Returns
Squared unsigned distance to the nearest face, or +infinity if the mesh has no faces.

The documentation for this class was generated from the following files: