Drake
SurfaceMesh< T > Class Template Reference

Detailed Description

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

SurfaceMesh represents a triangulated surface.

Template Parameters
TThe underlying scalar type for coordinates, e.g., double or AutoDiffXd. Must be a valid Eigen scalar.

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

Public Member Functions

 SurfaceMesh (std::vector< SurfaceFace > &&faces, std::vector< SurfaceVertex< T >> &&vertices)
 Constructs a SurfaceMesh from faces and vertices. More...
 
void TransformVertices (const math::RigidTransform< T > &X_NM)
 Transforms the vertices of this mesh from its initial frame M to the new frame N. More...
 
void ReverseFaceWinding ()
 Reverses the ordering of all the faces' indices – see SurfaceFace::ReverseWinding(). More...
 
int num_faces () const
 Returns the number of triangular elements in the mesh. More...
 
const T & area (SurfaceFaceIndex f) const
 Returns area of a triangular element. More...
 
const T & total_area () const
 Returns the total area of all the faces of this surface mesh. More...
 
const Vector3< T > & face_normal (SurfaceFaceIndex f) 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 (ElementIndex 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 >
Vector3< promoted_numerical_t< T, C > > CalcBarycentric (const Vector3< C > &p_MQ, SurfaceFaceIndex f) const
 Calculate barycentric coordinates with respect to the triangular face f 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 SurfaceMesh< T > &mesh) const
 Checks to see whether the given SurfaceMesh object is equal via deep exact comparison. More...
 
template<typename FieldValue >
Vector3< FieldValue > CalcGradientVectorOfLinearField (const std::array< FieldValue, 3 > &field_value, SurfaceFaceIndex f) const
 Calculates the gradient ∇u of a linear field u on the triangle f. More...
 
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 SurfaceMesh (const SurfaceMesh &)=default
 
SurfaceMeshoperator= (const SurfaceMesh &)=default
 
 SurfaceMesh (SurfaceMesh &&)=default
 
SurfaceMeshoperator= (SurfaceMesh &&)=default
 

Friends

class internal::MeshDeformer< SurfaceMesh< T > >
 
class SurfaceMeshTester< 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 SurfaceMesh, an element is a triangle.

using ScalarType = T
 
using VertexIndex = SurfaceVertexIndex
 Index for identifying a vertex. More...
 
template<typename U = T>
using VertexType = SurfaceVertex< U >
 
using ElementIndex = SurfaceFaceIndex
 Index for identifying a triangular element. More...
 
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 SurfaceFaceelement (ElementIndex e) const
 Returns the triangular element identified by a given index. More...
 
const std::vector< SurfaceFace > & faces () const
 Returns the faces. More...
 
const std::vector< SurfaceVertex< T > > & vertices () const
 Returns the vertices. More...
 
const SurfaceVertex< T > & vertex (VertexIndex 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.

◆ ElementIndex

Index for identifying a triangular element.

◆ ScalarType

using ScalarType = T

◆ VertexIndex

Index for identifying a vertex.

◆ VertexType

Constructor & Destructor Documentation

◆ SurfaceMesh() [1/3]

SurfaceMesh ( const SurfaceMesh< T > &  )
default

◆ SurfaceMesh() [2/3]

SurfaceMesh ( SurfaceMesh< T > &&  )
default

◆ SurfaceMesh() [3/3]

SurfaceMesh ( std::vector< SurfaceFace > &&  faces,
std::vector< SurfaceVertex< T >> &&  vertices 
)

Constructs a SurfaceMesh from faces and vertices.

Parameters
facesThe triangular faces.
verticesThe vertices.

Member Function Documentation

◆ area()

const T& area ( SurfaceFaceIndex  f) const

Returns area of a triangular element.

◆ CalcBarycentric()

Vector3<promoted_numerical_t<T, C> > CalcBarycentric ( const Vector3< C > &  p_MQ,
SurfaceFaceIndex  f 
) const

Calculate barycentric coordinates with respect to the triangular face f of the point Q'.

Q' is the projection of the provided point Q on the plane of triangle f. 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.
fThe index of a triangular face.
Return values
b_Q'The barycentric coordinates of Q' (projection of Q onto f's plane) relative to triangle f.
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.

◆ 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 ( ElementIndex  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.

◆ CalcGradientVectorOfLinearField()

Vector3<FieldValue> CalcGradientVectorOfLinearField ( const std::array< FieldValue, 3 > &  field_value,
SurfaceFaceIndex  f 
) const

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

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 faces.

◆ element()

const SurfaceFace& element ( ElementIndex  e) const

Returns the triangular element identified by a given index.

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

◆ Equal()

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

Checks to see whether the given SurfaceMesh 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 ( SurfaceFaceIndex  f) 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
f ∈ {0, 1, 2,..., num_faces()-1}.

◆ faces()

const std::vector<SurfaceFace>& faces ( ) const

Returns the faces.

◆ num_elements()

int num_elements ( ) const

Returns the number of triangles in the mesh.

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

◆ num_faces()

int num_faces ( ) const

Returns the number of triangular elements in the mesh.

◆ num_vertices()

int num_vertices ( ) const

Returns the number of vertices in the mesh.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ ReverseFaceWinding()

void ReverseFaceWinding ( )

Reverses the ordering of all the faces' indices – see SurfaceFace::ReverseWinding().

◆ total_area()

const T& total_area ( ) const

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

◆ TransformVertices()

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

Transforms the vertices of this mesh from its initial frame M to the new frame N.

◆ vertex()

const SurfaceVertex<T>& vertex ( VertexIndex  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<SurfaceVertex<T> >& vertices ( ) const

Returns the vertices.

Friends And Related Function Documentation

◆ internal::MeshDeformer< SurfaceMesh< T > >

friend class internal::MeshDeformer< SurfaceMesh< T > >
friend

◆ SurfaceMeshTester< T >

friend class SurfaceMeshTester< 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: