PolygonSurfaceMesh represents a surface comprised of polygonal elements (three or more sides).
T | The 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) |
(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 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... | |
template<typename FieldValue > | |
std::optional< Vector3< FieldValue > > | MaybeCalcGradientVectorOfLinearField (const std::array< FieldValue, 3 > &, int) const |
Like CalcGradientVectorOfLinearField above, this is a stub method, provided for compatibility with MeshFieldLinear. 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 | |
PolygonSurfaceMesh (const PolygonSurfaceMesh &)=default | |
PolygonSurfaceMesh & | operator= (const PolygonSurfaceMesh &)=default |
PolygonSurfaceMesh (PolygonSurfaceMesh &&)=default | |
PolygonSurfaceMesh & | operator= (PolygonSurfaceMesh &&)=default |
Friends | |
class | PolygonSurfaceMeshTest< 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 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... | |
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.
using ScalarType = T |
|
default |
|
default |
Advanced() Constructs an empty mesh.
This enables compatibility with STL container types and facilitates some unit tests. Otherwise, it shouldn't be used.
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.
face_data | The sequence of counts and indices which encode the faces of the mesh (see above). |
vertices | The vertex positions, measured and expressed in this mesh's frame. |
face_data
all refer to valid indices into vertices
.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. const T& area | ( | int | f | ) | const |
Returns area of a polygonal element.
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.
Calculates the axis-aligned bounding box of this surface mesh M.
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.
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).
SurfacePolygon element | ( | int | e | ) | const |
Returns the polygonal element identified by the given index e
.
Returns the geometric centroid of the element indicated be index e
, measured and expressed in the mesh's frame M.
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.
mesh | The mesh for comparison. |
true
if the given mesh is equal. const std::vector<int>& face_data | ( | ) | 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.
std::optional<Vector3<FieldValue> > MaybeCalcGradientVectorOfLinearField | ( | const std::array< FieldValue, 3 > & | , |
int | |||
) | const |
Like CalcGradientVectorOfLinearField above, this is a stub method, provided for compatibility with MeshFieldLinear.
The empty return value here will cause the caller to report errors.
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.
int num_faces | ( | ) | const |
Returns the number of polygonal elements 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 faces' indices.
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 faces 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.
Returns the vertex identified by the given index v
.
|
friend |
|
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.