class Mesh

Trivial class to represent a simple triangular mesh

Public Fields

[more]int dl
the Index of the Display List of the Mesh
[more]bool has_color
true if the loaded mesh has color

Public Methods

[more] Mesh()
standard constructor
[more] ~Mesh()
destructor should only de-allocate opengl display lists
[more]int Draw()
Simply Draw all the Triangles stored in T
[more]void GenerateDL()
Create the display list for this Mesh
[more]int DrawDL()
Draw the mesh using Display lists
[more]int DrawA()
Draw the mesh using Vertex arrays
[more]void Open(char *filename)
Load a mesh from a file
[more]void OpenColor(char *filename)
Load a mesh with color (rawc) from file
[more]void OpenNormal(char *filename)
Load a mesh with normal (rawn) from file
[more]void Smooth()
Calculate smooth per vertex normal
[more]void Normalize(float size=1)
Resize a mesh so that it can fit in the unitary box
[more]void Flip()
Flip orientaion of all the triangles

Public

[more] vector<Triangle> T
All the triangles are stored in a STL vector

Documentation

Trivial class to represent a simple triangular mesh.

Version History

o Mesh()
standard constructor. By default the mesh has no color.

o ~Mesh()
destructor should only de-allocate opengl display lists.

o vector<Triangle> T
All the triangles are stored in a STL vector.

oint dl
the Index of the Display List of the Mesh

oint Draw()
Simply Draw all the Triangles stored in T. If the mesh has_color then the defined per-vertex colors are used, else the current color is used.

ovoid GenerateDL()
Create the display list for this Mesh.

oint DrawDL()
Draw the mesh using Display lists. If the list was never generated it is generated on the fly

oint DrawA()
Draw the mesh using Vertex arrays.

ovoid Open(char *filename)
Load a mesh from a file. The format is the so-called RAW ascii format, for each triangle just the ascii print of xyz coordinates of its vertexes. E.g. a tetrahedron is stored as:
	 1  1  1    -1 -1  1     1 -1 -1
	-1 -1  1     1  1  1    -1  1 -1
	 1 -1 -1    -1 -1  1    -1  1 -1
	-1  1 -1     1 -1 -1     1  1  1
	

The Open function understand the type of the file from the extension. It manages the standard ".raw" and the new "*.rawc" (mesh with per vertex color). The loading of a "rawc" is done by the OpenColor function

obool has_color
true if the loaded mesh has color

ovoid OpenColor(char *filename)
Load a mesh with color (rawc) from file. In the extended raw (*.rawc) format for each face we also have three colors. The three colors (in the 0-1 range) are written after the three coords. E.g. a Red-Blue tetrahedron can be specified as follows:

	 1  1  1    -1 -1  1     1 -1 -1    1 0 0  1 0 0  0 0 1
	-1 -1  1     1  1  1    -1  1 -1    1 0 0  1 0 0  0 0 1
	 1 -1 -1    -1 -1  1    -1  1 -1    0 0 1  1 0 0  0 0 1
	-1  1 -1     1 -1 -1     1  1  1    0 0 1  0 0 1  1 0 0
	

ovoid OpenNormal(char *filename)
Load a mesh with normal (rawn) from file. In the extended raw (*.rawc) format for each face we also have three normals. The three normals(in the 0-1 range) are written immediately after the each vertex coords (warning different from color format!).

ovoid Smooth()
Calculate smooth per vertex normal. The normals are calculated by averaging the normals of all the faces incident on a same vertex. Obviously we should be sure that all the face has the same vertex ordering (otherwise we could average opposite normals). This can be efficiently done by exploiting the map associative container of STL. A map<key,data> is a Associative Container that associates objects of type Key with objects of type Data. The easiest way to think a map is a vector indexed by object of type key instead of integers. In our case we use a map<point,normal>. We do all in three steps:
  • In the first step we clear all the entry,
  • then we accumalte all the vertex normals and
  • in the third pass we normalize the accumulated normals, and assign them to their vertexes.

ovoid Normalize(float size=1)
Resize a mesh so that it can fit in the unitary box. It is useful when loading a mesh of unknown size. An object can also be scaled to a user-defined size by using the size param.

ovoid Flip()
Flip orientaion of all the triangles.


This class has no child classes.

Alphabetic index HTML hierarchy of classes or Java



This page was generated with the help of DOC++.