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

Detailed Description

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

VolumeMesh represents a tetrahedral volume mesh.

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

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

Public Member Functions

 VolumeMesh (std::vector< VolumeElement > &&elements, std::vector< Vector3< T >> &&vertices)
 Constructor from a vector of vertices and from a vector of elements. More...
 
const VolumeElementelement (int e) const
 
const Vector3< T > & vertex (int v) const
 Returns the vertex identified by a given index. More...
 
const std::vector< Vector3< T > > & vertices () const
 
const std::vector< VolumeElement > & tetrahedra () const
 
int num_elements () const
 Returns the number of tetrahedral elements in the mesh. More...
 
int num_vertices () const
 Returns the number of vertices in the mesh. More...
 
CalcTetrahedronVolume (int e) const
 Calculates volume of a tetrahedral element. More...
 
CalcVolume () const
 Calculates the volume of this mesh by taking the sum of the volume of each tetrahedral element. More...
 
template<typename C >
Barycentric< promoted_numerical_t< T, C > > CalcBarycentric (const Vector3< C > &p_MQ, int e) const
 Calculate barycentric coordinates with respect to the tetrahedron e of the point Q. More...
 
bool Equal (const VolumeMesh< T > &mesh, double vertex_tolerance=0) const
 Checks to see whether the given VolumeMesh object is equal via deep comparison (up to a tolerance). More...
 
template<typename FieldValue >
std::optional< Vector3< promoted_numerical_t< T, FieldValue > > > MaybeCalcGradientVectorOfLinearField (const std::array< FieldValue, 4 > &field_value, int e) const
 Calculates the gradient ∇u of a linear field u on the tetrahedron e. More...
 
template<typename FieldValue >
Vector3< promoted_numerical_t< T, FieldValue > > CalcGradientVectorOfLinearField (const std::array< FieldValue, 4 > &field_value, int e) const
 Like MaybeCalcGradientVectorOfLinearField, but throws if the geometry is degenerate. More...
 
void TransformVertices (const math::RigidTransform< T > &transform)
 Transforms the vertices of this mesh from its initial frame M to the new frame N. 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
 VolumeMesh (const VolumeMesh &)=default
 
VolumeMeshoperator= (const VolumeMesh &)=default
 
 VolumeMesh (VolumeMesh &&)=default
 
VolumeMeshoperator= (VolumeMesh &&)=default
 

Friends

class VolumeMeshTester< 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 VolumeMesh, an element is a tetrahedron.

using ScalarType = T
 
template<typename U = T>
using Barycentric = Vector< U, kVertexPerElement >
 Type of barycentric coordinates on a tetrahedral element. More...
 
static constexpr int kVertexPerElement = 4
 Number of vertices per element. More...
 

Member Typedef Documentation

◆ Barycentric

Type of barycentric coordinates on a tetrahedral element.

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

◆ ScalarType

using ScalarType = T

Constructor & Destructor Documentation

◆ VolumeMesh() [1/3]

VolumeMesh ( const VolumeMesh< T > &  )
default

◆ VolumeMesh() [2/3]

VolumeMesh ( VolumeMesh< T > &&  )
default

◆ VolumeMesh() [3/3]

VolumeMesh ( std::vector< VolumeElement > &&  elements,
std::vector< Vector3< T >> &&  vertices 
)

Constructor from a vector of vertices and from a vector of elements.

Each element must be a valid VolumeElement following the vertex ordering convention documented in the VolumeElement class. This class however does not enforce this convention and it is thus the responsibility of the user.

Member Function Documentation

◆ CalcBarycentric()

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

Calculate barycentric coordinates with respect to the tetrahedron e of the point 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_MQA position expressed in the frame M of the mesh.
eThe index of a tetrahedral element.
Note
If p_MQ is outside the tetrahedral element, the barycentric coordinates (b₀, b₁, b₂, b₃) still satisfy b₀ + b₁ + b₂ + b₃ = 1; however, some bᵢ will be negative.

◆ CalcGradientVectorOfLinearField()

Vector3<promoted_numerical_t<T, FieldValue> > CalcGradientVectorOfLinearField ( const std::array< FieldValue, 4 > &  field_value,
int  e 
) const

Like MaybeCalcGradientVectorOfLinearField, but throws if the geometry is degenerate.

Exceptions
std::exceptionif the gradient could not be computed.

◆ CalcTetrahedronVolume()

T CalcTetrahedronVolume ( int  e) const

Calculates volume of a tetrahedral element.

It is a signed volume, i.e., it can be negative depending on the order of the four vertices of the tetrahedron.

Precondition
f ∈ [0, num_elements()).

◆ CalcVolume()

T CalcVolume ( ) const

Calculates the volume of this mesh by taking the sum of the volume of each tetrahedral element.

◆ element()

const VolumeElement& element ( int  e) const

◆ Equal()

bool Equal ( const VolumeMesh< T > &  mesh,
double  vertex_tolerance = 0 
) const

Checks to see whether the given VolumeMesh object is equal via deep comparison (up to a tolerance).

NaNs are treated as not equal as per the IEEE standard. The tolerance is applied to corresponding vertex positions; the ith vertex in each mesh can have a distance of no more than vertex_tolerance.

Parameters
meshThe mesh for comparison.
vertex_toleranceThe maximum distance allowed between two vertices to be considered equal.
Returns
true if the given mesh is equal.

◆ MaybeCalcGradientVectorOfLinearField()

std::optional<Vector3<promoted_numerical_t<T, FieldValue> > > MaybeCalcGradientVectorOfLinearField ( const std::array< FieldValue, 4 > &  field_value,
int  e 
) const

Calculates the gradient ∇u of a linear field u on the tetrahedron e.

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

If the return value is std::nullopt, the tetrahedron is degenerate, and no reliable gradient could be computed.

The return type depends on both the mesh's vertex position scalar type T and the given field's scalar type FieldValue. See promoted_numerical_t for details.

◆ num_elements()

int num_elements ( ) const

Returns the number of tetrahedral elements in the mesh.

◆ num_vertices()

int num_vertices ( ) const

Returns the number of vertices in the mesh.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

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

◆ tetrahedra()

const std::vector<VolumeElement>& tetrahedra ( ) const

◆ TransformVertices()

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

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

Parameters
[in]transformThe transform X_NM relating the mesh in frame M to the new frame N.

◆ 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

Friends And Related Function Documentation

◆ VolumeMeshTester< T >

friend class VolumeMeshTester< T >
friend

Member Data Documentation

◆ kVertexPerElement

constexpr int kVertexPerElement = 4
static

Number of vertices per element.

A tetrahedron has 4 vertices.


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