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::FaceT< T, Meta > Class Template Reference

Face class for navigating a DCEL mesh. More...

#include <EBGeometry_DCEL_Face.hpp>

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

Public Types

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 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.
 
using EdgeIterator = EdgeIteratorT< T, Meta >
 Alias for edge iterator.
 

Public Member Functions

 FaceT ()=default
 Default constructor. Sets the half-edge to zero and the inside/outside algorithm to crossing number algorithm.
 
 FaceT (const EdgePtr &a_edge)
 Partial constructor. Calls default constructor but associates a half-edge.
 
 FaceT (const Face &a_otherFace)
 Copy constructor.
 
 FaceT (Face &&a_otherFace)=default
 Move constructor.
 
 ~FaceT ()=default
 Destructor (does nothing)
 
Faceoperator= (const Face &a_otherFace) noexcept
 Copy assignment operator.
 
Faceoperator= (Face &&a_otherFace)=default
 Move assignment operator.
 
void define (const Vec3 &a_normal, const EdgePtr &a_edge) noexcept
 Define function which sets the normal vector and half-edge.
 
void reconcile ()
 Reconcile face. This will compute the normal vector, area, centroid, and the 2D embedding of the polygon.
 
void computePolygon2D ()
 Compute the 2D embedding of this polygon from the current normal vector and topology, without touching the normal vector, centroid, or area.
 
void flipNormal () noexcept
 Flip the normal vector.
 
void setHalfEdge (const EdgePtr &a_halfEdge) noexcept
 Set the half edge.
 
void setMetaData (const Meta &a_metaData) noexcept
 Set the meta-data.
 
void setInsideOutsideAlgorithm (typename Polygon2D< T >::InsideOutsideAlgorithm &a_algorithm) noexcept
 Set the inside/outside algorithm when determining if a point projects to the inside or outside of the polygon.
 
EdgePtr getHalfEdge () noexcept
 Get the starting half-edge.
 
EdgePtr getHalfEdge () const noexcept
 Get the starting half-edge (const overload).
 
Vec3T< T > & getCentroid () noexcept
 Get modifiable centroid.
 
const Vec3T< T > & getCentroid () const noexcept
 Get immutable centroid.
 
T & getCentroid (const size_t a_dir) noexcept
 Get modifiable centroid position in specified coordinate direction.
 
const T & getCentroid (const size_t a_dir) const noexcept
 Get immutable centroid position in specified coordinate direction.
 
Vec3T< T > & getNormal () noexcept
 Get modifiable normal vector.
 
const Vec3T< T > & getNormal () const noexcept
 Get immutable normal vector.
 
T & getArea () noexcept
 Get modifiable polygon area (computed during reconcile()).
 
const T & getArea () const noexcept
 Get immutable polygon area (computed during reconcile()).
 
MetagetMetaData () noexcept
 Get meta-data.
 
const MetagetMetaData () const noexcept
 Get meta-data (const overload)
 
signedDistance (const Vec3 &a_x0) const noexcept
 Compute the signed distance to a point.
 
unsignedDistance2 (const Vec3 &a_x0) const noexcept
 Compute the unsigned squared distance to a point.
 
std::vector< Vec3T< T > > getAllVertexCoordinates () const
 Return the coordinates of all the vertices on this polygon.
 
std::vector< VertexPtrgatherVertices () const
 Return all the vertices on this polygon.
 
std::vector< EdgePtrgatherEdges () const
 Return all the half-edges on this polygon.
 
Vec3T< T > getSmallestCoordinate () const
 Get the lower-left-most coordinate of this polygon face.
 
Vec3T< T > getHighestCoordinate () const
 Get the upper-right-most coordinate of this polygon face.
 

Protected Member Functions

void computeCentroid ()
 Compute the centroid position of this polygon.
 
void computeNormal ()
 Compute the normal position of this polygon.
 
void computeArea ()
 Compute the area of this polygon and cache it in m_area.
 
void normalizeNormalVector () noexcept
 Normalize the normal vector, ensuring it has a length of 1.
 
Vec3T< T > projectPointIntoFacePlane (const Vec3 &a_p) const noexcept
 Compute the projection of a point onto the polygon face plane.
 
bool isPointInsideFace (const Vec3 &a_p) const noexcept
 Check if a point projects to inside or outside the polygon face.
 

Protected Attributes

std::weak_ptr< Edgem_halfEdge
 This polygon's half-edge. A valid face will always have this set.
 
Vec3 m_normal = Vec3::zeros()
 Polygon face normal vector.
 
Vec3 m_centroid = Vec3::zeros()
 Polygon face centroid position.
 
Meta m_metaData {}
 Meta-data attached to this face.
 
m_area {T(0)}
 Cached polygon face area (stored by reconcile()).
 
std::shared_ptr< Polygon2D< T > > m_poly2 = nullptr
 2D embedding of this polygon. This is the 2D view of the current object projected along its normal vector cardinal.
 
Polygon2D< T >::InsideOutsideAlgorithm m_poly2Algorithm = Polygon2D<T>::InsideOutsideAlgorithm::CrossingNumber
 Algorithm for inside/outside tests.
 

Detailed Description

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

Face class for navigating a DCEL mesh.

Class which represents a polygon face in a double-edge connected list (DCEL).

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

This class is a polygon face in a DCEL mesh. It contains pointer storage to one of the half-edges that circulate the inside of the polygon face, as well as having a normal vector, a centroid, and an area. This class supports signed distance computations. These computations require algorithms that compute e.g. the winding number of the polygon, or the number of times a ray cast passes through it. Thus, one of its central features is that it can be embedded in 2D by projecting it along the cardinal direction of its normal vector. To be fully consistent with a DCEL structure the class stores a reference to one of its half edges, but for performance reasons it also stores references to the other half edges.

Note
To compute the distance from a point to the face one must determine if the point projects "inside" or "outside" the polygon. There are several algorithms for this, and by default this class uses a crossing number algorithm.
Template Parameters
TFloating-point precision type.
MetaUser-defined metadata type.

Constructor & Destructor Documentation

◆ FaceT() [1/3]

template<class T , class Meta >
EBGeometry::DCEL::FaceT< T, Meta >::FaceT ( const EdgePtr a_edge)

Partial constructor. Calls default constructor but associates a half-edge.

Parameters
[in]a_edgeHalf-edge

◆ FaceT() [2/3]

template<class T , class Meta >
EBGeometry::DCEL::FaceT< T, Meta >::FaceT ( const Face a_otherFace)

Copy constructor.

Copies the normal vector, half-edge pointer, centroid, and area from the other face. Meta-data (m_metaData), the 2D embedding (m_poly2), and the inside/outside algorithm (m_poly2Algorithm) are deliberately NOT copied – they default-construct instead; use setMetaData() and reconcile() afterwards if they need to be (re)populated. Rationale: m_halfEdge is a back-reference into a specific mesh's topology (same as VertexT/EdgeT's copy constructors), so copying it wholesale is not topologically meaningful in general, but is occasionally useful. m_normal, m_centroid, and m_area are plain geometric/cached values with no such concern, so they are copied like any other value. operator=(const Face&) has identical semantics.

Parameters
[in]a_otherFaceOther face to copy from.

◆ FaceT() [3/3]

template<class T , class Meta >
EBGeometry::DCEL::FaceT< T, Meta >::FaceT ( Face &&  a_otherFace)
default

Move constructor.

Unlike the copy constructor, this transfers the entire state (including m_metaData, m_poly2, and m_poly2Algorithm) from a_otherFace, since moving relocates a single object's identity. Defaulted (memberwise move) rather than hand-written: explicitly defaulting is required here since the presence of a user-declared copy constructor would otherwise suppress the implicitly-generated move constructor. Not marked noexcept since Meta is an unconstrained template parameter whose move constructor is not guaranteed to be noexcept.

Parameters
[in,out]a_otherFaceOther face.

Member Function Documentation

◆ computePolygon2D()

template<class T , class Meta >
void EBGeometry::DCEL::FaceT< T, Meta >::computePolygon2D ( )
inline

Compute the 2D embedding of this polygon from the current normal vector and topology, without touching the normal vector, centroid, or area.

Unlike reconcile(), this does not recompute the normal vector, so it is safe to call after manually restoring a normal vector (e.g. when deep-copying a face and preserving whatever normal it had, including one set via flipNormal()) without having that normal silently overwritten by a geometrically-derived one.

Note
The face must be complete with half edges and there can be no dangling edges.

◆ define()

template<class T , class Meta >
void EBGeometry::DCEL::FaceT< T, Meta >::define ( const Vec3 a_normal,
const EdgePtr a_edge 
)
inlinenoexcept

Define function which sets the normal vector and half-edge.

Parameters
[in]a_normalNormal vector
[in]a_edgeHalf edge

◆ gatherEdges()

template<class T , class Meta >
std::vector< EdgePtr > EBGeometry::DCEL::FaceT< T, Meta >::gatherEdges ( ) const
inline

Return all the half-edges on this polygon.

This builds a list of all the edges and returns it.

Returns
Vector of shared pointers to all half-edges on this polygon.

◆ gatherVertices()

template<class T , class Meta >
std::vector< VertexPtr > EBGeometry::DCEL::FaceT< T, Meta >::gatherVertices ( ) const
inline

Return all the vertices on this polygon.

This builds a list of all the vertices and returns it.

Returns
Vector of shared pointers to all vertices on this polygon.

◆ getAllVertexCoordinates()

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

Return the coordinates of all the vertices on this polygon.

This builds a list of all the vertex coordinates and returns it.

Returns
Vector of 3D coordinates of all vertices on this polygon.

◆ getArea() [1/2]

template<class T , class Meta >
const T & EBGeometry::DCEL::FaceT< T, Meta >::getArea ( ) const
inlinenoexcept

Get immutable polygon area (computed during reconcile()).

Returns
Const reference to m_area.

◆ getArea() [2/2]

template<class T , class Meta >
T & EBGeometry::DCEL::FaceT< T, Meta >::getArea ( )
inlinenoexcept

Get modifiable polygon area (computed during reconcile()).

Returns
Reference to m_area.

◆ getCentroid() [1/4]

template<class T , class Meta >
const Vec3T< T > & EBGeometry::DCEL::FaceT< T, Meta >::getCentroid ( ) const
inlinenoexcept

Get immutable centroid.

Returns
Const reference to the centroid vector.

◆ getCentroid() [2/4]

template<class T , class Meta >
Vec3T< T > & EBGeometry::DCEL::FaceT< T, Meta >::getCentroid ( )
inlinenoexcept

Get modifiable centroid.

Returns
Reference to the centroid vector.

◆ getCentroid() [3/4]

template<class T , class Meta >
const T & EBGeometry::DCEL::FaceT< T, Meta >::getCentroid ( const size_t  a_dir) const
inlinenoexcept

Get immutable centroid position in specified coordinate direction.

Parameters
[in]a_dirCoordinate direction
Returns
Const reference to the a_dir-th coordinate of the centroid.

◆ getCentroid() [4/4]

template<class T , class Meta >
T & EBGeometry::DCEL::FaceT< T, Meta >::getCentroid ( const size_t  a_dir)
inlinenoexcept

Get modifiable centroid position in specified coordinate direction.

Parameters
[in]a_dirCoordinate direction
Returns
Reference to the a_dir-th coordinate of the centroid.

◆ getHalfEdge() [1/2]

template<class T , class Meta >
EdgePtr EBGeometry::DCEL::FaceT< T, Meta >::getHalfEdge ( ) const
inlinenoexcept

Get the starting half-edge (const overload).

Returns
Starting half-edge, or nullptr.

◆ getHalfEdge() [2/2]

template<class T , class Meta >
EdgePtr EBGeometry::DCEL::FaceT< T, Meta >::getHalfEdge ( )
inlinenoexcept

Get the starting half-edge.

Returns a shared_ptr obtained by locking the internal weak_ptr (see the class-level note on ownership near m_halfEdge). Returns nullptr if the edge has been destroyed, which should not happen while the owning mesh is alive.

Returns
Starting half-edge, or nullptr.

◆ getHighestCoordinate()

template<class T , class Meta >
Vec3T< T > EBGeometry::DCEL::FaceT< T, Meta >::getHighestCoordinate ( ) const
inline

Get the upper-right-most coordinate of this polygon face.

Returns
Upper-right-most coordinate of this polygon face.

◆ getMetaData() [1/2]

template<class T , class Meta >
const Meta & EBGeometry::DCEL::FaceT< T, Meta >::getMetaData ( ) const
inlinenoexcept

Get meta-data (const overload)

Returns
Const reference to the metadata.

◆ getMetaData() [2/2]

template<class T , class Meta >
Meta & EBGeometry::DCEL::FaceT< T, Meta >::getMetaData ( )
inlinenoexcept

Get meta-data.

Returns
Reference to the metadata.

◆ getNormal() [1/2]

template<class T , class Meta >
const Vec3T< T > & EBGeometry::DCEL::FaceT< T, Meta >::getNormal ( ) const
inlinenoexcept

Get immutable normal vector.

Returns
Const reference to the normal vector.

◆ getNormal() [2/2]

template<class T , class Meta >
Vec3T< T > & EBGeometry::DCEL::FaceT< T, Meta >::getNormal ( )
inlinenoexcept

Get modifiable normal vector.

Returns
Reference to the normal vector.

◆ getSmallestCoordinate()

template<class T , class Meta >
Vec3T< T > EBGeometry::DCEL::FaceT< T, Meta >::getSmallestCoordinate ( ) const
inline

Get the lower-left-most coordinate of this polygon face.

Returns
Lower-left-most coordinate of this polygon face.

◆ isPointInsideFace()

template<class T , class Meta >
bool EBGeometry::DCEL::FaceT< T, Meta >::isPointInsideFace ( const Vec3 a_p) const
inlineprotectednoexcept

Check if a point projects to inside or outside the polygon face.

Parameters
[in]a_pPoint in space
Returns
Returns true if a_p projects to inside the polygon and false otherwise.

◆ operator=() [1/2]

template<class T , class Meta >
Face & EBGeometry::DCEL::FaceT< T, Meta >::operator= ( const Face a_otherFace)
noexcept

Copy assignment operator.

Has the same semantics as the copy constructor; see its documentation.

Parameters
[in]a_otherFaceOther face.
Returns
Reference to (*this).

◆ operator=() [2/2]

template<class T , class Meta >
Face & EBGeometry::DCEL::FaceT< T, Meta >::operator= ( Face &&  a_otherFace)
default

Move assignment operator.

Has the same full-state-transfer semantics as the move constructor (defaulted memberwise move; see its documentation for why this must be defaulted explicitly).

Parameters
[in,out]a_otherFaceOther face.
Returns
Reference to (*this).

◆ projectPointIntoFacePlane()

template<class T , class Meta >
Vec3T< T > EBGeometry::DCEL::FaceT< T, Meta >::projectPointIntoFacePlane ( const Vec3 a_p) const
inlineprotectednoexcept

Compute the projection of a point onto the polygon face plane.

Parameters
[in]a_pPoint in space
Returns
Projected point in the face plane.

◆ reconcile()

template<class T , class Meta >
void EBGeometry::DCEL::FaceT< T, Meta >::reconcile ( )
inline

Reconcile face. This will compute the normal vector, area, centroid, and the 2D embedding of the polygon.

Note
"Everything" must be set before doing this, i.e. the face must be complete with half edges and there can be no dangling edges.

◆ setHalfEdge()

template<class T , class Meta >
void EBGeometry::DCEL::FaceT< T, Meta >::setHalfEdge ( const EdgePtr a_halfEdge)
inlinenoexcept

Set the half edge.

Parameters
[in]a_halfEdgeHalf edge

◆ setInsideOutsideAlgorithm()

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

Set the inside/outside algorithm when determining if a point projects to the inside or outside of the polygon.

Parameters
[in]a_algorithmDesired algorithm
Note
See CD_DCELAlgorithms.H for options (and CD_DCELPolyImplem.H for how the algorithms operate).

◆ setMetaData()

template<class T , class Meta >
void EBGeometry::DCEL::FaceT< T, Meta >::setMetaData ( const Meta a_metaData)
inlinenoexcept

Set the meta-data.

Parameters
[in]a_metaDataMeta-data.

◆ signedDistance()

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

Compute the signed distance to a point.

Parameters
[in]a_x0Point in space

This algorithm operates by checking if the input point projects to the inside of the polygon. If it does then the distance is just the projected distance onto the polygon plane and the sign is well-defined. Otherwise, we check the distance to the edges of the polygon.

Returns
Signed distance to the face; sign determined by normal direction.

◆ unsignedDistance2()

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

Compute the unsigned squared distance to a point.

Parameters
[in]a_x0Point in space

This algorithm operates by checking if the input point projects to the inside of the polygon. If it does then the distance is just the projected distance onto the polygon plane. Otherwise, we check the distance to the edges of the polygon.

Returns
Squared unsigned distance to the face.

Member Data Documentation

◆ m_halfEdge

template<class T , class Meta >
std::weak_ptr<Edge> EBGeometry::DCEL::FaceT< T, Meta >::m_halfEdge
protected

This polygon's half-edge. A valid face will always have this set.

Stored as a weak_ptr: the edge is owned by the mesh's own edge list, and a plain shared_ptr here would form a reference cycle with EdgeT::m_face (and, transitively, with EdgeT::m_nextEdge/m_pairEdge and VertexT::m_outgoingEdge) that shared_ptr's reference counting can never collect.

◆ m_metaData

template<class T , class Meta >
Meta EBGeometry::DCEL::FaceT< T, Meta >::m_metaData {}
protected

Meta-data attached to this face.

Value-initialized so that every constructor leaves it in a defined state: for a fundamental Meta type (e.g. short, int), a member with no initializer and no explicit mention in a constructor's member-initializer list is left indeterminate, not zero.


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