TriangleSurfaceMesh represents a union of triangles.
The surface is not necessarily continuous.
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) |
(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 | |
TriangleSurfaceMesh & | operator= (const TriangleSurfaceMesh &)=default |
TriangleSurfaceMesh (TriangleSurfaceMesh &&)=default | |
TriangleSurfaceMesh & | operator= (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 SurfaceTriangle & | element (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... | |
using Barycentric = Vector<U, kVertexPerElement> |
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.
using ScalarType = T |
|
default |
|
default |
TriangleSurfaceMesh | ( | std::vector< SurfaceTriangle > && | triangles, |
std::vector< Vector3< T >> && | vertices | ||
) |
Constructs a TriangleSurfaceMesh from triangles and vertices.
triangles | The triangular triangles. |
vertices | The vertices. |
const T& area | ( | int | t | ) | const |
Returns area of triangle t
.
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.
p_MQ | The position of point Q measured and expressed in the mesh's frame M. |
t | The index of a triangle. |
b_Q' | The barycentric coordinates of Q' (projection of Q onto t 's plane) relative to triangle t. |
Calculates the axis-aligned bounding box of this surface mesh M.
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.
element_index
∈ {0, 1, 2,..., num_triangles()-1}. 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.
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.
const SurfaceTriangle& element | ( | int | e | ) | const |
Returns the triangular element identified by a given index.
e | The index of the triangular element. |
Returns the centroid of a triangle measured and expressed in the mesh's frame.
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.
mesh | The mesh for comparison. |
true
if the given mesh is equal. 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.
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.
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.
int num_triangles | ( | ) | const |
Returns the number of triangles in the mesh.
int num_vertices | ( | ) | const |
Returns the number of vertices in the mesh.
|
default |
|
default |
void ReverseFaceWinding | ( | ) |
(Internal use only) Reverses the ordering of all the triangles' indices – see SurfaceTriangle::ReverseWinding().
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.
p_MVs | Vertex 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). |
std::exception | if p_MVs.size() != 3 * num_vertices() |
const T& total_area | ( | ) | const |
Returns the total area of all the triangles of this surface mesh.
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.
const std::vector<SurfaceTriangle>& triangles | ( | ) | const |
Returns the triangles.
Returns the vertex identified by a given index.
v | The index of the vertex. |
const std::vector<Vector3<T> >& vertices | ( | ) | const |
Returns the vertices.
|
friend |
|
static |
Number of vertices per element.
A triangle has 3 vertices.