Simbody
Classes | Public Member Functions | Static Public Member Functions

SimTK::ContactGeometry::TriangleMesh Class Reference

This ContactGeometry subclass represents an arbitrary shape described by a mesh of triangular faces. More...

#include <ContactGeometry.h>

Inheritance diagram for SimTK::ContactGeometry::TriangleMesh:

List of all members.

Classes

class  OBBTreeNode
 This class represents a node in the Oriented Bounding Box Tree for a TriangleMesh. More...

Public Member Functions

 TriangleMesh (const ArrayViewConst_< Vec3 > &vertices, const ArrayViewConst_< int > &faceIndices, bool smooth=false)
 Create a TriangleMesh.
 TriangleMesh (const PolygonalMesh &mesh, bool smooth=false)
 Create a TriangleMesh based on a PolygonalMesh object.
int getNumEdges () const
 Get the number of edges in the mesh.
int getNumFaces () const
 Get the number of faces in the mesh.
int getNumVertices () const
 Get the number of vertices in the mesh.
const Vec3getVertexPosition (int index) const
 Get the position of a vertex in the mesh.
int getFaceEdge (int face, int edge) const
 Get the index of one of the edges of a face.
int getFaceVertex (int face, int vertex) const
 Get the index of one of the vertices of a face.
int getEdgeFace (int edge, int face) const
 Get the index of one of the faces shared by an edge.
int getEdgeVertex (int edge, int vertex) const
 Get the index of one of the vertices shared by an edge.
void findVertexEdges (int vertex, Array_< int > &edges) const
 Find all edges that intersect a vertex.
const UnitVec3getFaceNormal (int face) const
 Get the normal vector for a face.
Real getFaceArea (int face) const
 Get the area of a face.
Vec3 findPoint (int face, const Vec2 &uv) const
 Calculate the location of a point on the surface, in the local frame of the TriangleMesh.
Vec3 findCentroid (int face) const
 Calculate the location of a face's centroid, that is, the point uv=(1/3,1/3) which is the average of the three vertex locations.
UnitVec3 findNormalAtPoint (int face, const Vec2 &uv) const
 Calculate the normal vector at a point on the surface.
Vec3 findNearestPoint (const Vec3 &position, bool &inside, UnitVec3 &normal) const
 Given a point, find the nearest point on the surface of this object.
Vec3 findNearestPoint (const Vec3 &position, bool &inside, int &face, Vec2 &uv) const
 Given a point, find the nearest point on the surface of this object.
bool intersectsRay (const Vec3 &origin, const UnitVec3 &direction, Real &distance, UnitVec3 &normal) const
 Determine whether this mesh intersects a ray, and if so, find the intersection point.
bool intersectsRay (const Vec3 &origin, const UnitVec3 &direction, Real &distance, int &face, Vec2 &uv) const
 Determine whether this mesh intersects a ray, and if so, find what face it hit.
OBBTreeNode getOBBTreeNode () const
 Get the OBBTreeNode which forms the root of this mesh's Oriented Bounding Box Tree.
PolygonalMesh createPolygonalMesh () const
 Generate a PolygonalMesh from this TriangleMesh; useful mostly for debugging because you can create a DecorativeMesh from this and then look at it.
const TriangleMeshImplgetImpl () const
 Internal use only.
TriangleMeshImplupdImpl ()
 Internal use only.

Static Public Member Functions

static bool isInstance (const ContactGeometry &geo)
 Return true if the supplied ContactGeometry object is a triangle mesh.
static const TriangleMeshgetAs (const ContactGeometry &geo)
 Cast the supplied ContactGeometry object to a const triangle mesh.
static TriangleMeshupdAs (ContactGeometry &geo)
 Cast the supplied ContactGeometry object to a writable triangle mesh.
static ContactGeometryTypeId classTypeId ()
 Obtain the unique id for TriangleMesh contact geometry.

Detailed Description

This ContactGeometry subclass represents an arbitrary shape described by a mesh of triangular faces.

The mesh surface must satisfy the following requirements:

It is your responsibility to ensure that any mesh you create meets these requirements. The constructor will detect many incorrect meshes and signal them by throwing an exception, but it is not guaranteed to detect all possible problems. If a mesh fails to satisfy any of these requirements, the results of calculations performed with it are undefined. For example, collisions involving it might fail to be detected, or contact forces on it might be calculated incorrectly.


Constructor & Destructor Documentation

SimTK::ContactGeometry::TriangleMesh::TriangleMesh ( const ArrayViewConst_< Vec3 > &  vertices,
const ArrayViewConst_< int > &  faceIndices,
bool  smooth = false 
)

Create a TriangleMesh.

Parameters:
verticesThe positions of all vertices in the mesh.
faceIndicesThe indices of the vertices that make up each face. The first three elements are the vertices in the first face, the next three elements are the vertices in the second face, etc.
smoothIf true, the mesh will be treated as a smooth surface, and normal vectors will be smoothly interpolated between vertices. If false, it will be treated as a faceted mesh with a constant normal vector over each face.
SimTK::ContactGeometry::TriangleMesh::TriangleMesh ( const PolygonalMesh mesh,
bool  smooth = false 
) [explicit]

Create a TriangleMesh based on a PolygonalMesh object.

If any faces of the PolygonalMesh have more than three vertices, they are automatically triangulated.

Parameters:
meshThe PolygonalMesh from which to construct a triangle mesh.
smoothIf true, the mesh will be treated as a smooth surface, and normal vectors will be smoothly interpolated between vertices. If false, it will be treated as a faceted mesh with a constant normal vector over each face.

Member Function Documentation

int SimTK::ContactGeometry::TriangleMesh::getNumEdges ( ) const

Get the number of edges in the mesh.

int SimTK::ContactGeometry::TriangleMesh::getNumFaces ( ) const

Get the number of faces in the mesh.

int SimTK::ContactGeometry::TriangleMesh::getNumVertices ( ) const

Get the number of vertices in the mesh.

const Vec3& SimTK::ContactGeometry::TriangleMesh::getVertexPosition ( int  index) const

Get the position of a vertex in the mesh.

Parameters:
indexThe index of the vertex to get.
Returns:
The position of the specified vertex.
int SimTK::ContactGeometry::TriangleMesh::getFaceEdge ( int  face,
int  edge 
) const

Get the index of one of the edges of a face.

Edge 0 connects vertices 0 and 1. Edge 1 connects vertices 1 and 2. Edge 2 connects vertices 0 and 2.

Parameters:
faceThe index of the face.
edgeThe index of the edge within the face (0, 1, or 2).
Returns:
The index of the specified edge.
int SimTK::ContactGeometry::TriangleMesh::getFaceVertex ( int  face,
int  vertex 
) const

Get the index of one of the vertices of a face.

Parameters:
faceThe index of the face.
vertexThe index of the vertex within the face (0, 1, or 2).
Returns:
The index of the specified vertex.
int SimTK::ContactGeometry::TriangleMesh::getEdgeFace ( int  edge,
int  face 
) const

Get the index of one of the faces shared by an edge.

Parameters:
edgeThe index of the edge.
faceThe index of the face within the edge (0 or 1).
Returns:
The index of the specified face.
int SimTK::ContactGeometry::TriangleMesh::getEdgeVertex ( int  edge,
int  vertex 
) const

Get the index of one of the vertices shared by an edge.

Parameters:
edgeThe index of the edge.
vertexThe index of the vertex within the edge (0 or 1).
Returns:
The index of the specified vertex.
void SimTK::ContactGeometry::TriangleMesh::findVertexEdges ( int  vertex,
Array_< int > &  edges 
) const

Find all edges that intersect a vertex.

Parameters:
vertexThe index of the vertex.
edgesThe indices of all edges intersecting the vertex will be added to this.
const UnitVec3& SimTK::ContactGeometry::TriangleMesh::getFaceNormal ( int  face) const

Get the normal vector for a face.

This points outward from the mesh.

Parameters:
faceThe index of the face.
Real SimTK::ContactGeometry::TriangleMesh::getFaceArea ( int  face) const

Get the area of a face.

Parameters:
faceThe index of the face.
Vec3 SimTK::ContactGeometry::TriangleMesh::findPoint ( int  face,
const Vec2 uv 
) const

Calculate the location of a point on the surface, in the local frame of the TriangleMesh.

Cost is 11 flops.

Parameters:
faceThe index of the face containing the point.
uvThe point within the face, specified by its barycentric uv coordinates.
Vec3 SimTK::ContactGeometry::TriangleMesh::findCentroid ( int  face) const

Calculate the location of a face's centroid, that is, the point uv=(1/3,1/3) which is the average of the three vertex locations.

This is a common special case of findPoint() that can be calculated more quickly (7 flops).

Parameters:
faceThe index of the face whose centroid is of interest.
UnitVec3 SimTK::ContactGeometry::TriangleMesh::findNormalAtPoint ( int  face,
const Vec2 uv 
) const

Calculate the normal vector at a point on the surface.

Parameters:
faceThe index of the face containing the point.
uvThe point within the face, specified by its barycentric uv coordinates.
Vec3 SimTK::ContactGeometry::TriangleMesh::findNearestPoint ( const Vec3 position,
bool &  inside,
UnitVec3 normal 
) const

Given a point, find the nearest point on the surface of this object.

If multiple points on the surface are equally close to the specified point, this may return any of them.

Parameters:
positionThe point in question.
insideOn exit, this is set to true if the specified point is inside this object, false otherwise.
normalOn exit, this contains the surface normal at the returned point.
Returns:
The point on the surface of the object which is closest to the specified point.

Reimplemented from SimTK::ContactGeometry.

Vec3 SimTK::ContactGeometry::TriangleMesh::findNearestPoint ( const Vec3 position,
bool &  inside,
int &  face,
Vec2 uv 
) const

Given a point, find the nearest point on the surface of this object.

If multiple points on the surface are equally close to the specified point, this may return any of them.

Parameters:
positionThe point in question.
insideOn exit, this is set to true if the specified point is inside this object, false otherwise.
faceOn exit, this contains the index of the face containing the returned point.
uvOn exit, this contains the barycentric coordinates (u and v) of the returned point within its face.
Returns:
The point on the surface of the object which is closest to the specified point.
bool SimTK::ContactGeometry::TriangleMesh::intersectsRay ( const Vec3 origin,
const UnitVec3 direction,
Real &  distance,
UnitVec3 normal 
) const

Determine whether this mesh intersects a ray, and if so, find the intersection point.

Parameters:
originThe position at which the ray begins.
directionThe ray direction.
distanceIf an intersection is found, the distance from the ray origin to the intersection point is stored in this. Otherwise, it is left unchanged.
normalIf an intersection is found, the surface normal of the intersection point is stored in this. Otherwise, it is left unchanged.
Returns:
true if an intersection is found, false otherwise.

Reimplemented from SimTK::ContactGeometry.

bool SimTK::ContactGeometry::TriangleMesh::intersectsRay ( const Vec3 origin,
const UnitVec3 direction,
Real &  distance,
int &  face,
Vec2 uv 
) const

Determine whether this mesh intersects a ray, and if so, find what face it hit.

Parameters:
originThe position at which the ray begins.
directionThe ray direction.
distanceIf an intersection is found, the distance from the ray origin to the intersection point is stored in this. Otherwise, it is left unchanged.
faceIf an intersection is found, the index of the face hit by the ray is stored in this. Otherwise, it is left unchanged.
uvIf an intersection is found, the barycentric coordinates (u and v) of the intersection point within the hit face are stored in this. Otherwise, it is left unchanged.
Returns:
true if an intersection is found, false otherwise.
OBBTreeNode SimTK::ContactGeometry::TriangleMesh::getOBBTreeNode ( ) const

Get the OBBTreeNode which forms the root of this mesh's Oriented Bounding Box Tree.

PolygonalMesh SimTK::ContactGeometry::TriangleMesh::createPolygonalMesh ( ) const

Generate a PolygonalMesh from this TriangleMesh; useful mostly for debugging because you can create a DecorativeMesh from this and then look at it.

static bool SimTK::ContactGeometry::TriangleMesh::isInstance ( const ContactGeometry geo) [inline, static]

Return true if the supplied ContactGeometry object is a triangle mesh.

static const TriangleMesh& SimTK::ContactGeometry::TriangleMesh::getAs ( const ContactGeometry geo) [inline, static]

Cast the supplied ContactGeometry object to a const triangle mesh.

static TriangleMesh& SimTK::ContactGeometry::TriangleMesh::updAs ( ContactGeometry geo) [inline, static]

Cast the supplied ContactGeometry object to a writable triangle mesh.

static ContactGeometryTypeId SimTK::ContactGeometry::TriangleMesh::classTypeId ( ) [static]

Obtain the unique id for TriangleMesh contact geometry.

const TriangleMeshImpl& SimTK::ContactGeometry::TriangleMesh::getImpl ( ) const

Internal use only.

Reimplemented from SimTK::ContactGeometry.

TriangleMeshImpl& SimTK::ContactGeometry::TriangleMesh::updImpl ( )

Internal use only.

Reimplemented from SimTK::ContactGeometry.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines