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

Detailed Description

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

PolygonSurfaceMesh represents a surface comprised of polygonal elements (three or more sides).

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

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

Public Member Functions

 PolygonSurfaceMesh ()
 Advanced() Constructs an empty mesh. More...
 
 PolygonSurfaceMesh (std::vector< int > face_data, std::vector< Vector3< T >> vertices)
 Constructs a mesh from specified vertex and mesh data. 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. More...
 
int num_faces () const
 Returns the number of polygonal elements in the mesh. More...
 
const T & area (int f) const
 Returns area of a polygonal 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 (int f) const
 Returns the unit face normal vector of a polygon. More...
 
const Vector3< T > & element_centroid (int e) const
 Returns the geometric centroid of the element indicated be index e, measured and expressed in the mesh's frame M. More...
 
const Vector3< T > & centroid () const
 Returns the geometric centroid of this mesh measured and expressed in the mesh's frame M. More...
 
template<typename C >
Barycentric< promoted_numerical_t< T, C > > CalcBarycentric (const Vector3< C > &p_MQ, int p) const
 See TriangleSurfaceMesh::CalcBaryCentric(). More...
 
std::pair< Vector3< T >, Vector3< T > > CalcBoundingBox () const
 Calculates the axis-aligned bounding box of this surface mesh M. More...
 
bool Equal (const PolygonSurfaceMesh< T > &mesh) const
 Checks to see whether the given PolygonSurfaceMesh object is equal via deep exact comparison. More...
 
const std::vector< int > & face_data () const
 
template<typename FieldValue >
Vector3< FieldValue > CalcGradientVectorOfLinearField (const std::array< FieldValue, 3 > &field_value, int p) const
 This is a stub method. More...
 
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 PolygonSurfaceMesh (const PolygonSurfaceMesh &)=default
 
PolygonSurfaceMeshoperator= (const PolygonSurfaceMesh &)=default
 
 PolygonSurfaceMesh (PolygonSurfaceMesh &&)=default
 
PolygonSurfaceMeshoperator= (PolygonSurfaceMesh &&)=default
 

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 element and barycentric coordinates. For PolygonSurfaceMesh, an element is a polygon.

using ScalarType = T
 
template<typename U = T>
using Barycentric = Vector< U, 0 >
 PolygonSurfaceMesh doesn't actually support barycentric coordinates. More...
 
static constexpr int kVertexPerElement = -1
 A definition that satisfies the interface that MeshFieldLinear requires. More...
 
SurfacePolygon element (int e) const
 Returns the polygonal element identified by the given index e. More...
 
const Vector3< T > & vertex (int v) const
 Returns the vertex identified by the given index v. More...
 
int num_vertices () const
 Returns the number of vertices in the mesh. More...
 
int num_elements () const
 Returns the number of elements in the mesh. More...
 

Member Typedef Documentation

◆ Barycentric

using Barycentric = Vector<U, 0>

PolygonSurfaceMesh doesn't actually support barycentric coordinates.

This is here to satisfy the MeshFieldLinear interface. The dimension is selected to be zero to minimize memory footprint in case one is inadvertently instantiated.

◆ ScalarType

using ScalarType = T

Constructor & Destructor Documentation

◆ PolygonSurfaceMesh() [1/4]

PolygonSurfaceMesh ( const PolygonSurfaceMesh< T > &  )
default

◆ PolygonSurfaceMesh() [2/4]

PolygonSurfaceMesh ( PolygonSurfaceMesh< T > &&  )
default

◆ PolygonSurfaceMesh() [3/4]

Advanced() Constructs an empty mesh.

This enables compatibility with STL container types and facilitates some unit tests. Otherwise, it shouldn't be used.

◆ PolygonSurfaceMesh() [4/4]

PolygonSurfaceMesh ( std::vector< int face_data,
std::vector< Vector3< T >>  vertices 
)

Constructs a mesh from specified vertex and mesh data.

The vertices are simply a vector of position vectors (interpreted as being measured and expressed in the mesh's frame M).

The polygon data is more complex. Syntactically, it is a sequence of integers which encodes P polygons. Each polygon can have an arbitrary number of vertices. The encoding of the P polygons is as follows:

|c₁|v₁₀|v₁₁|...|cᵢ|cᵢ₀|cᵢ₁|...|cₚ|cₚ₀|cₚ₁|...|

Each polygon is defined in sequence. The definition consists of an integer indicating the number of vertices in that polygon (c₁, cᵢ, and cₘ in the illustration above). The next cᵢ integers in the sequence are zero-based indices into the vector of vertex positions (indicating which vertices the polygon spans). The vertex indices are sorted such that the plane normal found by applying the right-handed rule is used as the face normal.

This implies the following: Polygon one: Located at index i₁ = 0 in face_data. c₁ = face_data[i₁] is the number of vertices in polygon one. Polygon two: Located at index i₂ = i₁ + c₁ + 1 in face_data. c₂ = face_data[i₂] is the number of vertices in polygon zero. Polygon j: Located at index iⱼ = iⱼ₋₁ + cⱼ₋₁ + 1 cⱼ = face_data[iⱼ]

The polygons must all be planar and convex.

Parameters
face_dataThe sequence of counts and indices which encode the faces of the mesh (see above).
verticesThe vertex positions, measured and expressed in this mesh's frame.
Precondition
The indices in face_data all refer to valid indices into vertices.
Note
If face_data includes a zero-area polygon, that polygon will have a non-NaN centroid chosen arbitrarily. For hydroelastics, this is acceptable because its zero area will neutralize its contribution to computation of contact wrench. If all polygons have zero area, the mesh's centroid will be chosen arbitrarily as well.

Member Function Documentation

◆ area()

const T& area ( int  f) const

Returns area of a polygonal element.

Precondition
f ∈ {0, 1, 2, ..., num_faces()-1}.

◆ CalcBarycentric()

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

See TriangleSurfaceMesh::CalcBaryCentric().

This implementation is provided to maintain compatibility with MeshFieldLinear. However, it only throws. PolygonSurfaceMesh does not support barycentric coordinates.

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

◆ CalcGradientVectorOfLinearField()

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

This is a stub method.

It is provided so that PolygonSurfaceMesh provides a sufficient API to compile against MeshFieldLinear. However, we expect that the gradients of the field will always be provided when defining a MeshFieldLinear with a PolygonSurfaceMesh. Failure to provide those gradients will cause this method to be invoked which will, in turn, throw.

◆ centroid()

const Vector3<T>& centroid ( ) const

Returns the geometric centroid of this mesh measured and expressed in the mesh's 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).

◆ element()

SurfacePolygon element ( int  e) const

Returns the polygonal element identified by the given index e.

Precondition
e ∈ {0, 1, 2, ..., num_faces()-1}.

◆ element_centroid()

const Vector3<T>& element_centroid ( int  e) const

Returns the geometric centroid of the element indicated be index e, measured and expressed in the mesh's frame M.

Precondition
f ∈ {0, 1, 2, ..., num_faces()-1}.

◆ Equal()

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

Checks to see whether the given PolygonSurfaceMesh 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_data()

const std::vector<int>& face_data ( ) const

◆ face_normal()

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

Returns the unit face normal vector of a polygon.

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

◆ num_elements()

int num_elements ( ) const

Returns the number of elements in the mesh.

For PolygonSurfaceMesh, an element is a polygon. 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 polygonal elements in the mesh.

◆ num_vertices()

int num_vertices ( ) const

Returns the number of vertices in the mesh.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ ReverseFaceWinding()

void ReverseFaceWinding ( )

Reverses the ordering of all the faces' indices.

◆ 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 Vector3<T>& vertex ( int  v) const

Returns the vertex identified by the given index v.

Precondition
v ∈ {0, 1, 2, ..., num_vertices()-1}.

Member Data Documentation

◆ kVertexPerElement

constexpr int kVertexPerElement = -1
static

A definition that satisfies the interface that MeshFieldLinear requires.

The value -1 indicates "unbounded" (as opposed to 3 for TriangleSurfaceMesh or 4 for VolumeMesh). It is up to MeshFieldLinear (and any other MeshType-compatible classes that pair with PolygonSurfaceMesh) to decide how they handle this unbounded value.


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