Drake
Drake C++ Documentation
TriangleSurfaceMesh< T > Class Template Reference

Detailed Description

template<class T>
class drake::geometry::TriangleSurfaceMesh< T >

TriangleSurfaceMesh represents a union of triangles.

The surface is not necessarily continuous.

Template Parameters
TThe scalar type, which must be one of the default nonsymbolic scalars.

#include <drake/geometry/proximity/triangle_surface_mesh.h>

Public Member Functions

 TriangleSurfaceMesh (std::vector< SurfaceTriangle > &&triangles, std::vector< Vector3< T >> &&vertices)
 Constructs a TriangleSurfaceMesh from triangles and vertices. More...
 
void TransformVertices (const math::RigidTransform< T > &X_NM)
 (Internal use only) Transforms the vertices of this mesh from its initial frame M to the new frame N. More...
 
void ReverseFaceWinding ()
 (Internal use only) Reverses the ordering of all the triangles' indices – see SurfaceTriangle::ReverseWinding(). More...
 
int num_triangles () const
 Returns the number of triangles in the mesh. More...
 
const T & area (int t) const
 Returns area of triangle t. More...
 
const T & total_area () const
 Returns the total area of all the triangles of this surface mesh. More...
 
const Vector3< T > & face_normal (int t) const
 Returns the unit face normal vector of a triangle. More...
 
const Vector3< T > & centroid () const
 Returns the area-weighted geometric centroid of this surface mesh. More...
 
template<typename B >
Vector3< promoted_numerical_t< T, B > > CalcCartesianFromBarycentric (int element_index, const Barycentric< B > &b_Q) const
 Maps the barycentric coordinates Q_barycentric of a point Q in element_index to its position vector p_MQ. More...
 
template<typename C >
Barycentric< promoted_numerical_t< T, C > > CalcBarycentric (const Vector3< C > &p_MQ, int t) const
 Calculate barycentric coordinates with respect to the triangle t of the point Q'. More...
 
std::pair< Vector3< T >, Vector3< T > > CalcBoundingBox () const
 Calculates the axis-aligned bounding box of this surface mesh M. More...
 
bool Equal (const TriangleSurfaceMesh< T > &mesh) const
 Checks to see whether the given TriangleSurfaceMesh object is equal via deep exact comparison. More...
 
template<typename FieldValue >
Vector3< FieldValue > CalcGradientVectorOfLinearField (const std::array< FieldValue, 3 > &field_value, int t) const
 Calculates the gradient ∇u of a linear field u on the triangle t. More...
 
template<typename FieldValue >
std::optional< Vector3< FieldValue > > MaybeCalcGradientVectorOfLinearField (const std::array< FieldValue, 3 > &field_value, int t) const
 Calculates the gradient ∇u of a linear field u on the triangle t. More...
 
void SetAllPositions (const Eigen::Ref< const VectorX< T >> &p_MVs)
 Updates the position of all vertices in the mesh. More...
 
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 TriangleSurfaceMesh (const TriangleSurfaceMesh &)=default
 
TriangleSurfaceMeshoperator= (const TriangleSurfaceMesh &)=default
 
 TriangleSurfaceMesh (TriangleSurfaceMesh &&)=default
 
TriangleSurfaceMeshoperator= (TriangleSurfaceMesh &&)=default
 

Friends

class TriangleSurfaceMeshTester< T >
 

Mesh type traits

A collection of type traits to enable mesh consumers to be templated on mesh type.

Each mesh type provides specific definitions of vertex, element, and barycentric coordinates. For TriangleSurfaceMesh, an element is a triangle.

using ScalarType = T
 
template<typename U = T>
using Barycentric = Vector< U, kVertexPerElement >
 Type of barycentric coordinates on a triangular element. More...
 
static constexpr int kVertexPerElement = 3
 Number of vertices per element. More...
 
const SurfaceTriangleelement (int e) const
 Returns the triangular element identified by a given index. More...
 
Vector3< T > element_centroid (int t) const
 Returns the centroid of a triangle measured and expressed in the mesh's frame. More...
 
const std::vector< SurfaceTriangle > & triangles () const
 Returns the triangles. More...
 
const std::vector< Vector3< T > > & vertices () const
 Returns the vertices. More...
 
const Vector3< T > & vertex (int v) const
 Returns the vertex identified by a given index. More...
 
int num_vertices () const
 Returns the number of vertices in the mesh. More...
 
int num_elements () const
 Returns the number of triangles in the mesh. More...
 

Member Typedef Documentation

◆ Barycentric

Type of barycentric coordinates on a triangular element.

Barycentric coordinates (b₀, b₁, b₂) satisfy b₀ + b₁ + b₂ = 1. It corresponds to a position on the plane of the triangle. If all bᵢ >= 0, it corresponds to a position inside the triangle or on the edges of the triangle. If some bᵢ < 0, it corresponds to a position on the plane of the triangle that is outside the triangle. Technically we could calculate one of the bᵢ from the others; however, there is no standard way to omit one of the coordinates.

The barycentric coordinates for a point Q are notated a b_Q.

◆ ScalarType

using ScalarType = T

Constructor & Destructor Documentation

◆ TriangleSurfaceMesh() [1/3]

TriangleSurfaceMesh ( const TriangleSurfaceMesh< T > &  )
default

◆ TriangleSurfaceMesh() [2/3]

◆ TriangleSurfaceMesh() [3/3]

TriangleSurfaceMesh ( std::vector< SurfaceTriangle > &&  triangles,
std::vector< Vector3< T >> &&  vertices 
)

Constructs a TriangleSurfaceMesh from triangles and vertices.

Parameters
trianglesThe triangular triangles.
verticesThe vertices.

Member Function Documentation

◆ area()

const T& area ( int  t) const

Returns area of triangle t.

Precondition
t ∈ {0, 1, 2,..., num_triangles()-1}.

◆ CalcBarycentric()

Barycentric<promoted_numerical_t<T, C> > CalcBarycentric ( const Vector3< C > &  p_MQ,
int  t 
) const

Calculate barycentric coordinates with respect to the triangle t of the point Q'.

Q' is the projection of the provided point Q on the plane of triangle t. If Q lies on the plane, Q = Q'. This operation is expensive compared with going from barycentric to Cartesian.

The return type depends on both the mesh's vertex position scalar type T and the Cartesian coordinate type C of the query point. See promoted_numerical_t for details.

Parameters
p_MQThe position of point Q measured and expressed in the mesh's frame M.
tThe index of a triangle.
Return values
b_Q'The barycentric coordinates of Q' (projection of Q onto t's plane) relative to triangle t.
Note
If Q' is outside the triangle, the barycentric coordinates (b₀, b₁, b₂) still satisfy b₀ + b₁ + b₂ = 1; however, some bᵢ will be negative.
Precondition
t ∈ {0, 1, 2,..., num_triangles()-1}.

◆ CalcBoundingBox()

std::pair<Vector3<T>, Vector3<T> > CalcBoundingBox ( ) const

Calculates the axis-aligned bounding box of this surface mesh M.

Returns
the center and the size vector of the box expressed in M's frame.

◆ CalcCartesianFromBarycentric()

Vector3<promoted_numerical_t<T, B> > CalcCartesianFromBarycentric ( int  element_index,
const Barycentric< B > &  b_Q 
) const

Maps the barycentric coordinates Q_barycentric of a point Q in element_index to its position vector p_MQ.

The return type depends on both the mesh's vertex position scalar type T and the Barycentric coordinate type B of the query point. See promoted_numerical_t for details.

Precondition
element_index ∈ {0, 1, 2,..., num_triangles()-1}.

◆ CalcGradientVectorOfLinearField()

Vector3<FieldValue> CalcGradientVectorOfLinearField ( const std::array< FieldValue, 3 > &  field_value,
int  t 
) const

Calculates the gradient ∇u of a linear field u on the triangle t.

Field u is defined by the three field values field_value[i] at the i-th vertex of the triangle. The gradient ∇u is expressed in the coordinates frame of this mesh M.

◆ centroid()

const Vector3<T>& centroid ( ) const

Returns the area-weighted geometric centroid of this surface mesh.

The returned value is the position vector p_MSc from M's origin to the centroid Sc, expressed in frame M. (M is the frame in which this mesh's vertices are measured and expressed.) Note that the centroid is not necessarily a point on the surface. If the total mesh area is exactly zero, we define the centroid to be (0,0,0).

The centroid location is calculated per face not per vertex so is insensitive to whether vertices are shared by triangles.

◆ element()

const SurfaceTriangle& element ( int  e) const

Returns the triangular element identified by a given index.

Parameters
eThe index of the triangular element.
Precondition
e ∈ {0, 1, 2,..., num_triangles()-1}.

◆ element_centroid()

Vector3<T> element_centroid ( int  t) const

Returns the centroid of a triangle measured and expressed in the mesh's frame.

◆ Equal()

bool Equal ( const TriangleSurfaceMesh< T > &  mesh) const

Checks to see whether the given TriangleSurfaceMesh object is equal via deep exact comparison.

NaNs are treated as not equal as per the IEEE standard.

Parameters
meshThe mesh for comparison.
Returns
true if the given mesh is equal.

◆ face_normal()

const Vector3<T>& face_normal ( int  t) const

Returns the unit face normal vector of a triangle.

It respects the right-handed normal rule. A near-zero-area triangle may get an unreliable normal vector. A zero-area triangle will get a zero vector.

Precondition
t ∈ {0, 1, 2,..., num_triangles()-1}.

◆ MaybeCalcGradientVectorOfLinearField()

std::optional<Vector3<FieldValue> > MaybeCalcGradientVectorOfLinearField ( const std::array< FieldValue, 3 > &  field_value,
int  t 
) const

Calculates the gradient ∇u of a linear field u on the triangle t.

Field u is defined by the three field values field_value[i] at the i-th vertex of the triangle. The gradient ∇u is expressed in the coordinates frame of this mesh M.

◆ num_elements()

int num_elements ( ) const

Returns the number of triangles in the mesh.

For TriangleSurfaceMesh, an element is a triangle. Returns the same number as num_triangles() and enables mesh consumers to be templated on mesh type.

◆ num_triangles()

int num_triangles ( ) const

Returns the number of triangles in the mesh.

◆ num_vertices()

int num_vertices ( ) const

Returns the number of vertices in the mesh.

◆ operator=() [1/2]

TriangleSurfaceMesh& operator= ( TriangleSurfaceMesh< T > &&  )
default

◆ operator=() [2/2]

TriangleSurfaceMesh& operator= ( const TriangleSurfaceMesh< T > &  )
default

◆ ReverseFaceWinding()

void ReverseFaceWinding ( )

(Internal use only) Reverses the ordering of all the triangles' indices – see SurfaceTriangle::ReverseWinding().

◆ SetAllPositions()

void SetAllPositions ( const Eigen::Ref< const VectorX< T >> &  p_MVs)

Updates the position of all vertices in the mesh.

Each sequential triple in p_MVs (e.g., 3i, 3i + 1, 3i + 2), i ∈ ℤ, is interpreted as a position vector associated with the iᵗʰ vertex. The position values are interpreted to be measured and expressed in the same frame as the mesh to be deformed.

Parameters
p_MVsVertex positions for the mesh's N vertices flattened into a vector (where each position vector is measured and expressed in the mesh's original frame).
Exceptions
std::exceptionif p_MVs.size() != 3 * num_vertices()

◆ total_area()

const T& total_area ( ) const

Returns the total area of all the triangles of this surface mesh.

◆ TransformVertices()

void TransformVertices ( const math::RigidTransform< T > &  X_NM)

(Internal use only) Transforms the vertices of this mesh from its initial frame M to the new frame N.

◆ triangles()

const std::vector<SurfaceTriangle>& triangles ( ) const

Returns the triangles.

◆ vertex()

const Vector3<T>& vertex ( int  v) const

Returns the vertex identified by a given index.

Parameters
vThe index of the vertex.
Precondition
v ∈ {0, 1, 2,...,num_vertices()-1}.

◆ vertices()

const std::vector<Vector3<T> >& vertices ( ) const

Returns the vertices.

Friends And Related Function Documentation

◆ TriangleSurfaceMeshTester< T >

friend class TriangleSurfaceMeshTester< T >
friend

Member Data Documentation

◆ kVertexPerElement

constexpr int kVertexPerElement = 3
static

Number of vertices per element.

A triangle has 3 vertices.


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