Simbody
|
This ContactGeometry subclass represents an arbitrary shape described by a mesh of triangular faces. More...
#include <ContactGeometry.h>
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 Vec3 & | getVertexPosition (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 UnitVec3 & | getFaceNormal (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 TriangleMeshImpl & | getImpl () const |
Internal use only. | |
TriangleMeshImpl & | updImpl () |
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 TriangleMesh & | getAs (const ContactGeometry &geo) |
Cast the supplied ContactGeometry object to a const triangle mesh. | |
static TriangleMesh & | updAs (ContactGeometry &geo) |
Cast the supplied ContactGeometry object to a writable triangle mesh. | |
static ContactGeometryTypeId | classTypeId () |
Obtain the unique id for TriangleMesh contact geometry. |
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.
SimTK::ContactGeometry::TriangleMesh::TriangleMesh | ( | const ArrayViewConst_< Vec3 > & | vertices, |
const ArrayViewConst_< int > & | faceIndices, | ||
bool | smooth = false |
||
) |
Create a TriangleMesh.
vertices | The positions of all vertices in the mesh. |
faceIndices | The 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. |
smooth | If 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.
mesh | The PolygonalMesh from which to construct a triangle mesh. |
smooth | If 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. |
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.
index | The index of the vertex to get. |
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.
face | The index of the face. |
edge | The index of the edge within the face (0, 1, or 2). |
int SimTK::ContactGeometry::TriangleMesh::getFaceVertex | ( | int | face, |
int | vertex | ||
) | const |
Get the index of one of the vertices of a face.
face | The index of the face. |
vertex | The index of the vertex within the face (0, 1, or 2). |
int SimTK::ContactGeometry::TriangleMesh::getEdgeFace | ( | int | edge, |
int | face | ||
) | const |
Get the index of one of the faces shared by an edge.
edge | The index of the edge. |
face | The index of the face within the edge (0 or 1). |
int SimTK::ContactGeometry::TriangleMesh::getEdgeVertex | ( | int | edge, |
int | vertex | ||
) | const |
Get the index of one of the vertices shared by an edge.
edge | The index of the edge. |
vertex | The index of the vertex within the edge (0 or 1). |
void SimTK::ContactGeometry::TriangleMesh::findVertexEdges | ( | int | vertex, |
Array_< int > & | edges | ||
) | const |
Find all edges that intersect a vertex.
vertex | The index of the vertex. |
edges | The 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.
face | The index of the face. |
Real SimTK::ContactGeometry::TriangleMesh::getFaceArea | ( | int | face | ) | const |
Get the area of a face.
face | The index of the face. |
Calculate the location of a point on the surface, in the local frame of the TriangleMesh.
Cost is 11 flops.
face | The index of the face containing the point. |
uv | The 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).
face | The 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.
face | The index of the face containing the point. |
uv | The 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.
position | The point in question. |
inside | On exit, this is set to true if the specified point is inside this object, false otherwise. |
normal | On exit, this contains the surface normal at the returned 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.
position | The point in question. |
inside | On exit, this is set to true if the specified point is inside this object, false otherwise. |
face | On exit, this contains the index of the face containing the returned point. |
uv | On exit, this contains the barycentric coordinates (u and v) of the returned point within its face. |
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.
origin | The position at which the ray begins. |
direction | The ray direction. |
distance | If an intersection is found, the distance from the ray origin to the intersection point is stored in this. Otherwise, it is left unchanged. |
normal | If an intersection is found, the surface normal of the intersection point is stored in this. Otherwise, it is left unchanged. |
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.
origin | The position at which the ray begins. |
direction | The ray direction. |
distance | If an intersection is found, the distance from the ray origin to the intersection point is stored in this. Otherwise, it is left unchanged. |
face | If an intersection is found, the index of the face hit by the ray is stored in this. Otherwise, it is left unchanged. |
uv | If 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. |
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.