The TriMesh class

1. Introduction

The TriMesh class represents a triangular mesh, together with:

The library also contains code for

The primary design considerations were ease of coding and space and time efficiency.

2. Quick Introduction

#include "trimesh.h"

	// Read a mesh
	TriMesh *mymesh = TriMesh::ReadPly("somefile.ply");
	if (!mymesh) {
		printf("Couldn't read mesh!\n");

	// If the mesh had triangle strips, unpack them into individual triangles
	if (mymesh->tstrips) {

	// Print out some facts about vertices and faces
	printf("The mesh has %d vertices and %d triangles\n",
		mymesh->numvertices, mymesh->numfaces);
	printf("The coordinates of the 17th vertex are %f %f %f\n",
		mymesh->vertices[17][0], mymesh->vertices[17][1], mymesh->vertices[17][2]);
	printf("The 23rd face consists of vertices %d, %d, and %d\n",
		mymesh->faces[23][0], mymesh->faces[23][1], mymesh->faces[23][2]);
	if (mymesh->colors) {
		printf("The color of the 31st face is %d, %d, %d\n",
			mymesh->colors[31][0], mymesh->colors[31][1], mymesh->colors[31][2]);
	} else {
		printf("The mesh does not have per-vertex color\n");

	// Print out some stats
	printf("The mesh has X ranging from %f to %f, Y from %f to %f, and Z from %f to %f\n",
		mymesh->bbox->xmin, mymesh->bbox->xmax,
		mymesh->bbox->ymin, mymesh->bbox->ymax,
		mymesh->bbox->zmin, mymesh->bbox->zmax);
	printf("The average edge length of the mesh is %f\n", mymesh->meanedgelength());

	// Write out the file

3. Members

The TriMesh class contains the following member data:

The class contains the following member functions:

4. File input and output

5. triutil.h

triutil.h> contains a random collection of occasionally-useful utility functions. Most of the functions are templatized, so they can accept arguments of any type (OK, at least float and double...). The functions are:

6. Sample source

Source code to the following demo programs is provided:

Last update: Mon Nov 16 23:23:28 CET 1998