Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MCMesh Class Reference

The complete mesh. More...

#include <MarchingCubesData.h>

Collaboration diagram for MCMesh:

Collaboration graph
[legend]
List of all members.

Public Types

typedef unsigned int index_t
 Type of the index in _vertices.

Public Member Functions

 MCMesh (MCGlobalData *gd, MCBProgressCallback *cb=0)
 Default constructor.
virtual ~MCMesh ()
 Destructor.
index_t AddVertex (int x, int y, int z, int edge, int triangle, vuVector &v)
 Add a vertex at the specified position.
index_t AddVertex (int idx, int triangle)
 Adds a already existing vertex to the triangle given by triangle.
index_t GetVertex (int x, int y, int z, int edge)
 Determines if the vertex already exists in _vertices.
int AddTriangle (int type)
 Adds a new triangle to _triangles and returns the index in the array.
void DebugPrint (void)
 Prints the actual triangle buffer.
void prepare (void)
 Does last preparations on the data before the rendering can start.
void render ()
 Renders the triangles.
void drawNormals (bool mode)
 Turn on and off the normals rendering.
bool drawNormals ()
 Returns the actual value of the rendering mode for the normals lines (see drawNormals(bool mode) for more information).
void drawNormalsSize (float size)
 Sets the size of the line drawn for each normal (see drawNormals(bool mode) for more information).
float drawNormalsSize ()
 Returns the size of the line drawn for each normal (see drawNormals(bool mode) for more information).
index_t numTriangles ()
 Returns the actual number of triangles in the data structure.
index_t numVertices ()
 Returns the number of vertices in the data structure.
index_t numIndices ()
 Returns the number of elements in the indices array.

Private Member Functions

index_t _getIndex (int x, int y, int z, int edge)
 Calculates the index of a vertex in _vertices.
void _compileData ()
 Takes the data from the mesh (MCTriangle and MCVertex) and compiles an array which is passed to the graphics card.
void _compileNormalsArray ()
 Generates a vertex array and an index array which holds data for drawing the normals.

Private Attributes

MCData_data
 This array holds the data passed to the graphics card.
index_t _dataSize
 The size of the data array.
index_t_indices [256]
 This indexes will be passed to glDrawElements.
index_t _indexSize [256]
 The size of the index array.
float_normalsArray
index_t _normalsArraySize
std::map< index_t, MCVertex * > _vertices
 Each vertex in the mesh is referenced here four times.
std::list< MCVertex * > _vertexList
 For easyer access to all real vertices in _vertices this list also holds the vertices (see also Marching Cubes Data).
std::vector< MCTriangle * > _triangles
 Holds all triangles in the mesh.
bool _normalsPrepared
 Indicates that the normals are calcualted.
index_t _vertexSize
 The number of bytes occupied by a MCVertex object in memory.
index_t _triangleSize
 The number of bytes occupied by a MCTriangle object in memory.
MCGlobalData_gd
 Data structure holding data used by several classes.
MCBProgressCallback_progCB
 A callback to update a progress bar in the GUI.

Static Private Attributes

const int _edgeMapping [12][3][4]
 A spezial edge mapping table for this data structure.

Detailed Description

The complete mesh.

This class represents the entry point to the geometry data. For more informations see MCData.

Destroying objects

Many of the objects are not only refereces in the base class but also in many classes in the hierarchy. Such objects must not be destroyed in this classes but in the base class.

Bug:
When drawing the normals is enabled during cube browsing and the user than switches over to object drawing, the nromals are only if drawing the normals is turned of and on again.

Todo:
Do vertex buffer objects.

Definition at line 179 of file MarchingCubesData.h.


Member Typedef Documentation

typedef unsigned int MCMesh::index_t
 

Type of the index in _vertices.

If you want to use the results of AddVertex or GetVertex you should use this type.

Definition at line 188 of file MarchingCubesData.h.

Referenced by _compileData(), _compileNormalsArray(), _getIndex(), AddVertex(), GetVertex(), MCMesh::MCTriangle::GetVertexIdx(), MCMesh::MCVertex::Idx(), numIndices(), numTriangles(), and numVertices().


Constructor & Destructor Documentation

MCMesh::MCMesh MCGlobalData gd,
MCBProgressCallback cb = 0
 

Default constructor.

The constructor also disables OpenGL array data.

Parameters:
ves Vertices extend size (see MCData::_extendSize).
ies Indices extend size (see MCData::_extendSize).

Definition at line 246 of file MarchingCubesData.cpp.

References _data, _dataSize, _gd, _indexSize, _indices, _normalsArray, _normalsArraySize, _normalsPrepared, _progCB, _triangleSize, _vertexSize, assert, MCGlobalData::compileNormals, DEBUGC, GL_COLOR_ARRAY, GL_NORMAL_ARRAY, GL_VERTEX_ARRAY, glDisableClientState(), MCGlobalData::meshSize, and NULL.

Here is the call graph for this function:

MCMesh::~MCMesh  )  [virtual]
 

Destructor.

Definition at line 270 of file MarchingCubesData.cpp.

References _indices, _triangles, _vertexList, and DEBUGD.


Member Function Documentation

void MCMesh::_compileData  )  [private]
 

Takes the data from the mesh (MCTriangle and MCVertex) and compiles an array which is passed to the graphics card.

Bug:
Some normals are wrong, but which. Maybe we should use more asserts.

Definition at line 290 of file MarchingCubesData.cpp.

References _data, _dataSize, _gd, _indexSize, _indices, _progCB, _triangles, _vertexList, assert, MCGlobalData::compileData, MCMesh::MCData::copyNormalFrom(), MCGlobalData::cubeSize, DEBUG0, DEBUG4, DEBUG5, MCGlobalData::doMeshStatistics, MCBProgressCallback::End(), vuVector::getData(), MCMesh::MCVertex::Idx(), index_t, MCMesh::MCVertex::Indexed(), vuVector::makeUnit(), MC_FAIL_EXIT, MCGlobalData::meshSize, numTriangles(), numVertices(), MCBProgressCallback::SetText(), MCBProgressCallback::Start(), MCGlobalData::termProgress, MCBProgressCallback::Update(), MCMesh::MCVertex::Vertex(), and MCMesh::MCData::vertex.

Referenced by prepare().

Here is the call graph for this function:

void MCMesh::_compileNormalsArray  )  [private]
 

Generates a vertex array and an index array which holds data for drawing the normals.

Definition at line 422 of file MarchingCubesData.cpp.

References _data, _dataSize, _gd, _normalsArray, _normalsArraySize, assert, MCGlobalData::compileNormals, DEBUG0, DEBUG1, DEBUG3, index_t, MC_FAIL_EXIT, MCGlobalData::normalsLength, and MCMesh::MCData::vertex.

Referenced by prepare().

MCMesh::index_t MCMesh::_getIndex int  x,
int  y,
int  z,
int  edge
[inline, private]
 

Calculates the index of a vertex in _vertices.

For informations on the composition of the index see _vertices.

Parameters:
x x-position of the cube in the volume.
y y-position of the cube in the volume.
z z-position of the cube in the volume.
edge Number of the edge, at which the vertex lies.
Returns:
The index of the vertex in _vertices.

Definition at line 283 of file MarchingCubesData.cpp.

References DEBUG0, and index_t.

Referenced by AddVertex(), and GetVertex().

int MCMesh::AddTriangle int  type  ) 
 

Adds a new triangle to _triangles and returns the index in the array.

Returns:
The index of the new triangle in _triangles.

Definition at line 512 of file MarchingCubesData.cpp.

References _gd, _normalsPrepared, _triangles, DEBUG0, MCGlobalData::doMeshStatistics, and MCGlobalData::meshSize.

Referenced by MarchingCubesBase::drawTriangles(), main(), and MarchingCubesBase::marchCubes().

MCMesh::index_t MCMesh::AddVertex int  idx,
int  triangle
 

Adds a already existing vertex to the triangle given by triangle.

In contrast to AddVertex(int, int, int, int, int, vuVector &) this function only adds a already existing vertex to a triangle. If the vertex does not exist, the function fails and returns MCD_ERROR.

Parameters:
idx The index of the vertex in _vertices.
triangle The triangle index in _triangles.
Returns:
The index of the vertex or MCD_ERROR if the vertex does not exist.

Definition at line 491 of file MarchingCubesData.cpp.

References _normalsPrepared, _triangles, _vertices, assert, DEBUG0, and index_t.

MCMesh::index_t MCMesh::AddVertex int  x,
int  y,
int  z,
int  edge,
int  triangle,
vuVector v
 

Add a vertex at the specified position.

With x, y, z and edge the position of a vertex in the grid is completly defined. With these parameters a uniqe index in the map _vertices is calculated. This function also adds the newly created MCVertex to the three corresonding positions in the map (see also Edge mapping table).

Mode of Operation

The function first looks, if the vertex is already added to _vertices by looking it up at the index, given by the parameters. If it exists a neighbouring cube of the given edge has added the vertex. In this case the vertex is only added to the triangle given by triangle. Otherwise the vertex is added to all four positions in _vertices according to Edge mapping table and after this added to the triangle.

Parameters:
x x-position of the cube in the volume.
y y-position of the cube in the volume.
z z-position of the cube in the volume.
edge Number of the edge, at which the vertex lies.
triangle Adds the vertex to the triangle with this index.
type The type of the cube, in which the vertex lies.
v Holds the coordinates of the vertex. These will be added to MCData.
Returns:
The index of the added vertex or MCD_ERROR otherwise.

Definition at line 455 of file MarchingCubesData.cpp.

References _edgeMapping, _gd, _getIndex(), _vertexList, _vertices, assert, DEBUG0, DEBUG1, MCGlobalData::doMeshStatistics, index_t, MCGlobalData::meshSize, and MCMesh::MCVertex::Vertex().

Referenced by MarchingCubesBase::drawTriangles(), main(), and MarchingCubesBase::marchCubes().

Here is the call graph for this function:

void MCMesh::DebugPrint void   ) 
 

Prints the actual triangle buffer.

This function is for debug use only. If debugging is turned off, this function does print nothing.

Definition at line 521 of file MarchingCubesData.cpp.

References DEBUG0.

Referenced by main().

bool MCMesh::drawNormals  ) 
 

Returns the actual value of the rendering mode for the normals lines (see drawNormals(bool mode) for more information).

void MCMesh::drawNormals bool  mode  ) 
 

Turn on and off the normals rendering.

If mode is set to true, there will be drawn a line for each normal using _drawNormalsSize as their size. The start point of such a line is the position of the corresponding vertex, and the end point is normal*_drawNormalsSize away from this point.

float MCMesh::drawNormalsSize  ) 
 

Returns the size of the line drawn for each normal (see drawNormals(bool mode) for more information).

void MCMesh::drawNormalsSize float  size  ) 
 

Sets the size of the line drawn for each normal (see drawNormals(bool mode) for more information).

MCMesh::index_t MCMesh::GetVertex int  x,
int  y,
int  z,
int  edge
 

Determines if the vertex already exists in _vertices.

Parameters:
x x-position of the cube in the volume.
y y-position of the cube in the volume.
z z-position of the cube in the volume.
edge Number of the edge, at which the vertex lies.
Returns:
If the vertex is found, the index of the vertex in _vertices is returned. Otherwise the function returns MCD_ERROR.

Definition at line 502 of file MarchingCubesData.cpp.

References _getIndex(), _vertices, DEBUG0, and index_t.

Referenced by MarchingCubesBase::drawTriangles(), main(), and MarchingCubesBase::marchCubes().

Here is the call graph for this function:

MCMesh::index_t MCMesh::numIndices  ) 
 

Returns the number of elements in the indices array.

Definition at line 626 of file MarchingCubesData.cpp.

References _indexSize, DEBUG0, and index_t.

Referenced by MarchingCubesBase::numIndices().

MCMesh::index_t MCMesh::numTriangles  ) 
 

Returns the actual number of triangles in the data structure.

Definition at line 613 of file MarchingCubesData.cpp.

References _triangles, DEBUG0, and index_t.

Referenced by _compileData(), and MarchingCubesBase::numTriangles().

MCMesh::index_t MCMesh::numVertices  ) 
 

Returns the number of vertices in the data structure.

Definition at line 619 of file MarchingCubesData.cpp.

References _vertexList, DEBUG0, and index_t.

Referenced by _compileData(), and MarchingCubesBase::numVertices().

void MCMesh::prepare void   ) 
 

Does last preparations on the data before the rendering can start.

These preparations are:

  • compiling the vertex-, normals- and color-array and
  • compiling the array for drawing the normals.
This function may be called after the data in MCMesh is complete. If it is not called, graphics output may not be what you want because normals will not be calcualted.

Definition at line 538 of file MarchingCubesData.cpp.

References _compileData(), _compileNormalsArray(), _data, _gd, MCGlobalData::compileData, MCGlobalData::compileNormals, DEBUG0, DEBUG3, and MCGlobalData::drawNormals.

Referenced by main(), MarchingCubesBase::marchCubes(), and render().

Here is the call graph for this function:

void MCMesh::render  ) 
 

Renders the triangles.

This function actually calls glDrawElements. Unfortunatly this is another drawing function (the fourth) on the stack but as far as this class holds the data it is teh best way to do the rendering.

Definition at line 546 of file MarchingCubesData.cpp.

References _data, _gd, _indexSize, _indices, _normalsArray, _normalsArraySize, DEBUG0, DEBUG3, MCGlobalData::drawNormals, vuVector::getData(), GL_AMBIENT, GL_BACK, GL_CULL_FACE, GL_CULL_FACE_MODE, GL_FILL, GL_FLOAT, GL_FRONT, GL_FRONT_AND_BACK, GL_LINE, GL_LINES, GL_N3F_V3F, GL_NORMAL_ARRAY, GL_TRIANGLES, GL_UNSIGNED_INT, GL_VERTEX_ARRAY, GLboolean, glCullFace(), glDisable(), glDisableClientState(), glDrawArrays(), glDrawElements(), glEnable(), glEnableClientState(), glGetBooleanv(), glGetIntegerv(), GLint, glInterleavedArrays(), glMaterialfv(), glPolygonMode(), glVertexPointer(), MCGlobalData::lineColor, MCGlobalData::linesMode, MCGlobalData::objectColor, and prepare().

Referenced by MarchingCubesBase::drawTriangles(), and MarchingCubesBase::glRender().

Here is the call graph for this function:


Member Data Documentation

MCData* MCMesh::_data [private]
 

This array holds the data passed to the graphics card.

Definition at line 377 of file MarchingCubesData.h.

Referenced by _compileData(), _compileNormalsArray(), MCMesh(), prepare(), and render().

index_t MCMesh::_dataSize [private]
 

The size of the data array.

Definition at line 379 of file MarchingCubesData.h.

Referenced by _compileData(), _compileNormalsArray(), and MCMesh().

const int MCMesh::_edgeMapping [static, private]
 

A spezial edge mapping table for this data structure.

Because this class only needs to traverse through all possible neighbour cubes this is a simple 12/3/4 list. The data for each edge is ordered counter clockwise if you look in the positive direction of the coordiante axis.

Definition at line 183 of file MarchingCubesData.cpp.

Referenced by AddVertex().

MCGlobalData* MCMesh::_gd [private]
 

Data structure holding data used by several classes.

Definition at line 418 of file MarchingCubesData.h.

Referenced by _compileData(), _compileNormalsArray(), AddTriangle(), AddVertex(), MCMesh(), prepare(), and render().

index_t MCMesh::_indexSize[256] [private]
 

The size of the index array.

Definition at line 385 of file MarchingCubesData.h.

Referenced by _compileData(), MCMesh(), numIndices(), and render().

index_t* MCMesh::_indices[256] [private]
 

This indexes will be passed to glDrawElements.

Definition at line 383 of file MarchingCubesData.h.

Referenced by _compileData(), MCMesh(), render(), and ~MCMesh().

float* MCMesh::_normalsArray [private]
 

Definition at line 387 of file MarchingCubesData.h.

Referenced by _compileNormalsArray(), MCMesh(), and render().

index_t MCMesh::_normalsArraySize [private]
 

Definition at line 388 of file MarchingCubesData.h.

Referenced by _compileNormalsArray(), MCMesh(), and render().

bool MCMesh::_normalsPrepared [private]
 

Indicates that the normals are calcualted.

Definition at line 412 of file MarchingCubesData.h.

Referenced by AddTriangle(), AddVertex(), and MCMesh().

MCBProgressCallback* MCMesh::_progCB [private]
 

A callback to update a progress bar in the GUI.

Definition at line 420 of file MarchingCubesData.h.

Referenced by _compileData(), and MCMesh().

std::vector<MCTriangle *> MCMesh::_triangles [private]
 

Holds all triangles in the mesh.

Definition at line 410 of file MarchingCubesData.h.

Referenced by _compileData(), AddTriangle(), AddVertex(), numTriangles(), and ~MCMesh().

index_t MCMesh::_triangleSize [private]
 

The number of bytes occupied by a MCTriangle object in memory.

Definition at line 416 of file MarchingCubesData.h.

Referenced by MCMesh().

std::list<MCVertex *> MCMesh::_vertexList [private]
 

For easyer access to all real vertices in _vertices this list also holds the vertices (see also Marching Cubes Data).

Definition at line 408 of file MarchingCubesData.h.

Referenced by _compileData(), AddVertex(), numVertices(), and ~MCMesh().

index_t MCMesh::_vertexSize [private]
 

The number of bytes occupied by a MCVertex object in memory.

Definition at line 414 of file MarchingCubesData.h.

Referenced by MCMesh().

std::map<index_t, MCVertex *> MCMesh::_vertices [private]
 

Each vertex in the mesh is referenced here four times.

One for each neighbour cube of the edge. The hash for this map corresponds with the index of the edge in the volume. The index is composed of a 4 bit number for the edge and a number of 9 bits for each direction. This leads to a 31 bit number. The ordering of the numbers in the index is as follows (bit display):

        0zzzzzzz zzyyyyyy yyyxxxxx xxxxeeee B

Where z stands for the z-direction, y for the y-direction, x for the x-direction and e for the edge.

Definition at line 403 of file MarchingCubesData.h.

Referenced by AddVertex(), and GetVertex().


The documentation for this class was generated from the following files:
Generated on Wed Dec 15 21:20:58 2004 for vuVolume by  doxygen 1.3.9.1