Files Class List
TriMesh Class Reference

Detailed Description

Triangular Mesh Class.

#include <cyTriMesh.h>

Classes

struct  Mtl
 Material definition. More...
 
struct  Str
 Simple character string. More...
 
struct  TriFace
 Triangular Mesh Face. More...
 

Public Member Functions

Constructors and Destructor
 TriMesh (TriMesh const &t)
 
Component Access Methods
Vec3f const & V (int i) const
 returns the i^th vertex
 
Vec3fV (int i)
 returns the i^th vertex
 
TriFace const & F (int i) const
 returns the i^th face
 
TriFaceF (int i)
 returns the i^th face
 
Vec3f const & VN (int i) const
 returns the i^th vertex normal
 
Vec3fVN (int i)
 returns the i^th vertex normal
 
TriFace const & FN (int i) const
 returns the i^th normal face
 
TriFaceFN (int i)
 returns the i^th normal face
 
Vec3f const & VT (int i) const
 returns the i^th vertex texture
 
Vec3fVT (int i)
 returns the i^th vertex texture
 
TriFace const & FT (int i) const
 returns the i^th texture face
 
TriFaceFT (int i)
 returns the i^th texture face
 
Mtl const & M (int i) const
 returns the i^th material
 
MtlM (int i)
 returns the i^th material
 
unsigned int NV () const
 returns the number of vertices
 
unsigned int NF () const
 returns the number of faces
 
unsigned int NVN () const
 returns the number of vertex normals
 
unsigned int NVT () const
 returns the number of texture vertices
 
unsigned int NM () const
 returns the number of materials
 
bool HasNormals () const
 returns true if the mesh has vertex normals
 
bool HasTextureVertices () const
 returns true if the mesh has texture vertices
 
Set Component Count
void Clear ()
 Deletes all components of the mesh.
 
void SetNumVertex (unsigned int n)
 Sets the number of vertices and allocates memory for vertex positions.
 
void SetNumFaces (unsigned int n)
 Sets the number of faces and allocates memory for face data. Normal faces and texture faces are also allocated, if they are used.
 
void SetNumNormals (unsigned int n)
 Sets the number of normals and allocates memory for normals and normal faces.
 
void SetNumTexVerts (unsigned int n)
 Sets the number of texture coordinates and allocates memory for texture coordinates and texture faces.
 
void SetNumMtls (unsigned int n)
 Sets the number of materials and allocates memory for material data.
 
void operator= (TriMesh const &t)
 Copies mesh data from the given mesh.
 
Get Property Methods
bool IsBoundBoxReady () const
 Returns true if the bounding box has been computed.
 
Vec3f GetBoundMin () const
 Returns the minimum values of the bounding box.
 
Vec3f GetBoundMax () const
 Returns the maximum values of the bounding box.
 
Vec3f GetVec (int faceID, Vec3f const &bc) const
 Returns the point on the given face with the given barycentric coordinates (bc).
 
Vec3f GetNormal (int faceID, Vec3f const &bc) const
 Returns the the surface normal on the given face at the given barycentric coordinates (bc). The returned vector is not normalized.
 
Vec3f GetTexCoord (int faceID, Vec3f const &bc) const
 Returns the texture coordinate on the given face at the given barycentric coordinates (bc).
 
int GetMaterialIndex (int faceID) const
 Returns the material index of the face. This method goes through material counts of all materials to find the material index of the face. Returns a negative number if the face as no material.
 
int GetMaterialFaceCount (int mtlID) const
 Returns the number of faces associated with the given material ID.
 
int GetMaterialFirstFace (int mtlID) const
 Returns the first face index associated with the given material ID. Other faces associated with the same material are placed are placed consecutively.
 
Compute Methods
void ComputeBoundingBox ()
 Computes the bounding box.
 
void ComputeNormals (bool clockwise=false)
 Computes and stores vertex normals.
 

Protected Attributes

Vec3fv
 vertices
 
TriFacef
 faces
 
Vec3fvn
 vertex normal
 
TriFacefn
 normal faces
 
Vec3fvt
 texture vertices
 
TriFaceft
 texture faces
 
Mtlm
 materials
 
int * mcfc
 material cumulative face count
 
unsigned int nv
 number of vertices
 
unsigned int nf
 number of faces
 
unsigned int nvn
 number of vertex normals
 
unsigned int nvt
 number of texture vertices
 
unsigned int nm
 number of materials
 
Vec3f boundMin
 Bounding box minimum bound.
 
Vec3f boundMax
 Bounding box maximum bound.
 

Load and Save methods

bool LoadFromFileObj (char const *filename, bool loadMtl=true, std::ostream *outStream=&std::cout)
 Loads the mesh from an OBJ file. Automatically converts all faces to triangles.
 
bool SaveToFileObj (char const *filename, std::ostream *outStream)
 Saves the mesh to an OBJ file with the given name.