class Mesh

Trivial class to represent a simple triangular mesh

Public Fields

[more]bool has_color
true if the loaded mesh has color

Public Methods

[more] Mesh()
standard constructor
[more]void Draw()
Simply Draw all the Triangles stored in T
[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 Smooth()
Calculate smooth per vertex normal
[more]void Normalize(float size=1)
Resize a mesh so that it can fit in the unitary box

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 vector<Triangle> T
All the triangles are stored in a STL vector.

ovoid 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 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 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.


This class has no child classes.

Alphabetic index HTML hierarchy of classes or Java



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