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
 T The 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)
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 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...

Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
TriangleSurfaceMesh (const TriangleSurfaceMesh &)=default

TriangleSurfaceMeshoperator= (const TriangleSurfaceMesh &)=default

TriangleSurfaceMesh (TriangleSurfaceMesh &&)=default

TriangleSurfaceMeshoperator= (TriangleSurfaceMesh &&)=default

## Friends

class internal::MeshDeformer< TriangleSurfaceMesh< T > >

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

## ◆ Barycentric

 using Barycentric = Vector

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

## ◆ TriangleSurfaceMesh() [1/3]

 TriangleSurfaceMesh ( const TriangleSurfaceMesh< T > & )
default

## ◆ TriangleSurfaceMesh() [2/3]

 TriangleSurfaceMesh ( TriangleSurfaceMesh< T > && )
default

## ◆ TriangleSurfaceMesh() [3/3]

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

Constructs a TriangleSurfaceMesh from triangles and vertices.

Parameters
 triangles The triangular triangles. vertices The vertices.

## ◆ area()

 const T& area ( int t ) const

Returns area of triangle t.

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

## ◆ CalcBarycentric()

 Barycentric > 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_MQ The position of point Q measured and expressed in the mesh's frame M. t The 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 > 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 > 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}.

 Vector3 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& 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
 e The index of the triangular element.
Precondition
e ∈ {0, 1, 2,..., num_triangles()-1}.

## ◆ element_centroid()

 Vector3 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
 mesh The mesh for comparison.
Returns
true if the given mesh is equal.

## ◆ face_normal()

 const Vector3& 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}.

## ◆ 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 ( )

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

## ◆ 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 )

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

## ◆ triangles()

 const std::vector& triangles ( ) const

Returns the triangles.

## ◆ vertex()

 const Vector3& vertex ( int v ) const

Returns the vertex identified by a given index.

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

## ◆ vertices()

 const std::vector >& vertices ( ) const

Returns the vertices.

## ◆ internal::MeshDeformer< TriangleSurfaceMesh< T > >

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

## ◆ TriangleSurfaceMeshTester< T >

 friend class TriangleSurfaceMeshTester< T >
friend

## ◆ 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: