Simbody
Public Member Functions

SimTK::PolygonalMesh Class Reference

This class provides a description of a mesh made of polygonal faces. More...

#include <PolygonalMesh.h>

Inheritance diagram for SimTK::PolygonalMesh:

List of all members.

Public Member Functions

 PolygonalMesh ()
 Create a PolygonalMesh, which initially contains no vertices or faces.
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 vertex) const
 Get the position of a vertex in the mesh.
int getNumVerticesForFace (int face) const
 Get the number of vertices that make up a face.
int getFaceVertex (int face, int vertex) const
 Get the index of one of the vertices of a face.
int addVertex (const Vec3 &position)
 Add a vertex to the mesh.
int addFace (const Array_< int > &vertices)
 Add a face to the mesh.
void scaleMesh (Real scale)
 Scale a mesh by multiplying every vertex by a fixed value.
void transformMesh (const Transform &transform)
 Transform a mesh by applying a Transform to every vertex.
void loadObjFile (std::istream &file)
 Load a Wavefront OBJ file, adding the vertices and faces it contains to this mesh.
void loadVtpFile (const String &pathname)
 Load a VTK PolyData (.vtp) file, adding the vertices and faces it contains to this mesh.

Detailed Description

This class provides a description of a mesh made of polygonal faces.

Its primary purpose is for loading geometry from files, which can then be used for visualization or collision detection. For example, the following lines load a mesh from a Wavefront OBJ file, then create a DecorativeMesh from it.

    PolygonalMesh mesh;
    std::ifstream file;
    file.open("teapot.obj");
    mesh.loadObjFile(file);
    file.close();
    DecorativeMesh decoration(mesh);

You can also read a polygon mesh from a VTK PolyData (.vtp) file.

We expect this to be a large object so give it shared (reference) semantics; that is, the copy constructor and copy assignment default to shallow copies (both handles will refer to the same data). If you want to make a deep (non-shared) copy of a PolygonalMesh, use the copyAssign() method provided by the PIMPLHandle base class.


Constructor & Destructor Documentation

SimTK::PolygonalMesh::PolygonalMesh ( ) [inline]

Create a PolygonalMesh, which initially contains no vertices or faces.


Member Function Documentation

int SimTK::PolygonalMesh::getNumFaces ( ) const

Get the number of faces in the mesh.

int SimTK::PolygonalMesh::getNumVertices ( ) const

Get the number of vertices in the mesh.

const Vec3& SimTK::PolygonalMesh::getVertexPosition ( int  vertex) const

Get the position of a vertex in the mesh.

Parameters:
vertexthe index of the vertex to get
Returns:
the position of the specified vertex
int SimTK::PolygonalMesh::getNumVerticesForFace ( int  face) const

Get the number of vertices that make up a face.

Parameters:
facethe index of the face
int SimTK::PolygonalMesh::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 (from 0, 1, or 2 for a triangular face, etc.)
Returns:
the index of the specified vertex
int SimTK::PolygonalMesh::addVertex ( const Vec3 position)

Add a vertex to the mesh.

Parameters:
positionthe position of the vertex to add
Returns:
the index of the newly added vertex
int SimTK::PolygonalMesh::addFace ( const Array_< int > &  vertices)

Add a face to the mesh.

Parameters:
verticesindices of the vertices which make up the new face
Returns:
the index of the newly added face
void SimTK::PolygonalMesh::scaleMesh ( Real  scale)

Scale a mesh by multiplying every vertex by a fixed value.

void SimTK::PolygonalMesh::transformMesh ( const Transform transform)

Transform a mesh by applying a Transform to every vertex.

void SimTK::PolygonalMesh::loadObjFile ( std::istream &  file)

Load a Wavefront OBJ file, adding the vertices and faces it contains to this mesh.

Parameters:
filean input stream from which to load the file contents
void SimTK::PolygonalMesh::loadVtpFile ( const String pathname)

Load a VTK PolyData (.vtp) file, adding the vertices and faces it contains to this mesh.

Parameters:
pathnamethe name of a .vtp file

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