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

Triangle class with signed distance functionality. More...

#include <EBGeometry_Triangle.hpp>

Collaboration diagram for EBGeometry::Triangle< T >:
Collaboration graph
[legend]

Public Types

using Vec2 = Vec2T< T >
 Alias for 2D vector type.
 
using Vec3 = Vec3T< T >
 Alias for 3D vector type.
 

Public Member Functions

 Triangle () noexcept=default
 Default constructor. Does not put the triangle in a usable state.
 
 Triangle (const Triangle &a_otherTriangle) noexcept=default
 Copy constructor.
 
 Triangle (Triangle &&a_otherTriangle) noexcept=default
 Move constructor.
 
 Triangle (const Array< Vec3, 3 > &a_vertexPositions) noexcept
 Full constructor.
 
 ~Triangle () noexcept=default
 Destructor (does nothing).
 
Triangle & operator= (const Triangle &a_otherTriangle) noexcept=default
 Copy assignment.
 
Triangle & operator= (Triangle &&a_otherTriangle) noexcept=default
 Move assignment.
 
void setNormal (const Vec3 &a_normal) noexcept
 Set the triangle normal vector.
 
void setVertexPositions (const Array< Vec3, 3 > &a_vertexPositions) noexcept
 Set the triangle vertex positions.
 
void setVertexNormals (const Array< Vec3, 3 > &a_vertexNormals) noexcept
 Set the triangle vertex normals.
 
void setEdgeNormals (const Array< Vec3, 3 > &a_edgeNormals) noexcept
 Set the triangle edge normals.
 
void setFaceId (const uint32_t a_faceId) noexcept
 Set the face id.
 
void computeNormal () noexcept
 Compute the triangle normal vector.
 
const Vec3 & getNormal () const noexcept
 Get the triangle normal vector.
 
const Array< Vec3, 3 > & getVertexPositions () const noexcept
 Get the vertex positions.
 
const Array< Vec3, 3 > & getVertexNormals () const noexcept
 Get the vertex normals.
 
const Array< Vec3, 3 > & getEdgeNormals () const noexcept
 Get the edge normals.
 
uint32_t getFaceId () const noexcept
 Get the face id.
 
T signedDistance (const Vec3 &a_point) const noexcept
 Compute the signed distance from the input point x to the triangle.
 

Protected Attributes

Vec3 m_triangleNormal = Vec3::max()
 Triangle face normal.
 
Array< Vec3, 3 > m_vertexPositions {Vec3::max(), Vec3::max(), Vec3::max()}
 Triangle vertex positions.
 
Array< Vec3, 3 > m_vertexNormals {Vec3::max(), Vec3::max(), Vec3::max()}
 Triangle vertex normals.
 
Array< Vec3, 3 > m_edgeNormals {Vec3::max(), Vec3::max(), Vec3::max()}
 Triangle edge normals.
 
uint32_t m_faceId = UINT32_MAX
 Id of the face this triangle belongs to, UINT32_MAX if unset.
 

Detailed Description

template<class T>
class EBGeometry::Triangle< T >

Triangle class with signed distance functionality.

This class represents a planar triangle and has a signed distance functionality. It is self-contained: it stores all of its own data and holds no external references. The class contains a triangle face normal vector; three vertex positions, and normal vectors for the three vertices and three edges.

This class assumes that the vertices are organized with the right-hand rule. I.e., edges are enumerated as follows:

Edge 0 points from vertex 0 to vertex 1 Edge 1 points from vertex 1 to vertex 2 Edge 2 points from vertex 2 to vertex 0

This class can compute its own normal vector from the vertex positions, and the triangle orientation is then implicitly given by the vertex order.

To compute the distance from a point to the triangle, one must determine if the point projects to the "inside" or "outside" of the triangle. If the query point projects to the inside of the triangle, the distance is simply the projected distance onto the triangle plane. If it projects to the outside of the triangle, we check the distance against the triangle edges and vertices.

A triangle also carries a face id: the index of the mesh face it was cut from (see Parser::readIntoTriangles and TriMeshSDF), or any id the caller assigns. It plays no part in the distance computation; TriMeshSDF::getClosestFace() reports it.

Template Parameters
TFloating-point precision.

Constructor & Destructor Documentation

◆ Triangle() [1/3]

template<class T >
EBGeometry::Triangle< T >::Triangle ( const Triangle< T > &  a_otherTriangle)
defaultnoexcept

Copy constructor.

Parameters
[in]a_otherTriangleOther triangle.

◆ Triangle() [2/3]

template<class T >
EBGeometry::Triangle< T >::Triangle ( Triangle< T > &&  a_otherTriangle)
defaultnoexcept

Move constructor.

Parameters
[in,out]a_otherTriangleOther triangle.

◆ Triangle() [3/3]

template<class T >
EBGeometry::Triangle< T >::Triangle ( const Array< Vec3, 3 > &  a_vertexPositions)
noexcept

Full constructor.

Parameters
[in]a_vertexPositionsTriangle vertex positions.

Member Function Documentation

◆ computeNormal()

template<class T >
void EBGeometry::Triangle< T >::computeNormal ( )
noexcept

Compute the triangle normal vector.

This computes the normal vector from two of the triangle edges, using the right-hand rule and vertex ordering to infer the normal vector. A zero-area triangle (collinear or coincident vertices) gets a zero normal.

◆ getEdgeNormals()

template<class T >
const Array< Vec3, 3 > & EBGeometry::Triangle< T >::getEdgeNormals ( ) const
noexcept

Get the edge normals.

Const-only; use setEdgeNormals to update.

Returns
m_edgeNormals

◆ getFaceId()

template<class T >
uint32_t EBGeometry::Triangle< T >::getFaceId ( ) const
noexcept

Get the face id.

Returns
m_faceId

◆ getNormal()

template<class T >
const Vec3 & EBGeometry::Triangle< T >::getNormal ( ) const
noexcept

Get the triangle normal vector.

Const-only: mutating this in place would desynchronize it from the vertex positions it was derived from. Use setNormal or setVertexPositions instead.

Returns
m_triangleNormal

◆ getVertexNormals()

template<class T >
const Array< Vec3, 3 > & EBGeometry::Triangle< T >::getVertexNormals ( ) const
noexcept

Get the vertex normals.

Const-only; use setVertexNormals to update.

Returns
m_vertexNormals

◆ getVertexPositions()

template<class T >
const Array< Vec3, 3 > & EBGeometry::Triangle< T >::getVertexPositions ( ) const
noexcept

Get the vertex positions.

Const-only: mutating positions in place would leave m_triangleNormal stale. Use setVertexPositions instead.

Returns
m_vertexPositions

◆ operator=() [1/2]

template<class T >
Triangle & EBGeometry::Triangle< T >::operator= ( const Triangle< T > &  a_otherTriangle)
defaultnoexcept

Copy assignment.

Parameters
[in]a_otherTriangleOther triangle.
Returns
Reference to (*this).

◆ operator=() [2/2]

template<class T >
Triangle & EBGeometry::Triangle< T >::operator= ( Triangle< T > &&  a_otherTriangle)
defaultnoexcept

Move assignment.

Parameters
[in,out]a_otherTriangleOther triangle.
Returns
Reference to (*this).

◆ setEdgeNormals()

template<class T >
void EBGeometry::Triangle< T >::setEdgeNormals ( const Array< Vec3, 3 > &  a_edgeNormals)
noexcept

Set the triangle edge normals.

Parameters
[in]a_edgeNormalsEdge normals. Each must be finite and unit length, or zero for an edge on a fold (a mesh loaded with Parser::OnDefect::Warn can have one).

◆ setFaceId()

template<class T >
void EBGeometry::Triangle< T >::setFaceId ( const uint32_t  a_faceId)
noexcept

Set the face id.

Parameters
[in]a_faceIdId of the face this triangle belongs to.

◆ setNormal()

template<class T >
void EBGeometry::Triangle< T >::setNormal ( const Vec3 &  a_normal)
noexcept

Set the triangle normal vector.

Parameters
[in]a_normalNormal vector. Must be finite and unit length.
Note
The input normal should be consistent with the vertex ordering.

◆ setVertexNormals()

template<class T >
void EBGeometry::Triangle< T >::setVertexNormals ( const Array< Vec3, 3 > &  a_vertexNormals)
noexcept

Set the triangle vertex normals.

Parameters
[in]a_vertexNormalsVertex normals. Each must be finite and unit length, or zero for a vertex on a fold (a mesh loaded with Parser::OnDefect::Warn can have one).

◆ setVertexPositions()

template<class T >
void EBGeometry::Triangle< T >::setVertexPositions ( const Array< Vec3, 3 > &  a_vertexPositions)
noexcept

Set the triangle vertex positions.

Also recomputes the triangle face normal from the new vertex positions (see computeNormal). If the three vertices are collinear or coincident the normal is set to zero: such a triangle has no interior, and its signed distance is not meaningful.

Parameters
[in]a_vertexPositionsVertex positions. Each component must be finite.

◆ signedDistance()

template<class T >
T EBGeometry::Triangle< T >::signedDistance ( const Vec3 &  a_point) const
noexcept

Compute the signed distance from the input point x to the triangle.

Requires the triangle to be fully initialized with a non-degenerate (non-collinear) set of vertex positions; see setVertexPositions.

Parameters
[in]a_pointQuery point. Must be finite.
Returns
Signed distance; negative inside, positive outside.

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