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

MarchingCubesBase Class Reference

Base class of the Marching Cubes Model (see vuMarchingCubes). More...

#include <MarchingCubesBase.h>

Inheritance diagram for MarchingCubesBase:

Inheritance graph
[legend]
Collaboration diagram for MarchingCubesBase:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 MarchingCubesBase ()
 Default constructor.
virtual ~MarchingCubesBase ()
 Destructor.
void setGlobalData (MCGlobalData *gd)
 This has to be done first!
void glRenderFrame ()
 Renders the frame that borders the volume.
void glRender ()
 This function executes the code to render the marching cubes volume.
void Size (int sz1, int sz2, int sz3)
 Size setter.
int Size1 ()
 Size 1 getter.
int Size2 ()
 Size 2 getter.
int Size3 ()
 Size 3 getter.
int maxSize ()
 Returns the bigges size.
void Origin (float or1, float or2, float or3)
 Origin setter.
float Origin1 ()
float Origin2 ()
float Origin3 ()
void marchCubes ()
 This function calculates the triangle mesh by marching trough the cubes.
long long numVertices ()
long long numTriangles ()
long long numIndices ()
int getCubeType (int x, int y, int z)
 The function determines the type of the cube.
float valueAt (float px, float py, float pz)
 Takes a point inside the mesh and returns the value at that point.
void SetProgressCallback (MCBProgressCallback *cb)
void SetHistoCallback (MCBHistoCallback *cb)

Protected Member Functions

void SetProgressText (const char *txt)
void StartProgress ()
void UpdateProgress (int v)
void EndProgress ()

Protected Attributes

int * _data
 Hold's the volume data.

Private Member Functions

void drawHorCylinder (int pos, float angle, float r, float l)
 Draws a horizontal cylinder.
void drawVertCylinder (int pos, float r, float l)
 Draw a vertical cylinder.
void drawCorner (int pos, float r)
 Draws a ball at the coordinate p.
void drawSpot (int pos)
void drawTriangles ()
vuVector calcVertex (int x, int y, int z, int edge)
 Calculates the vertex position from the cube position (x, y, z), the edge number (edge) and the threshold (_thres).

Private Attributes

int _size [3]
 Data size.
float _origin1
 Origin in first direction.
float _origin2
 Origin in second direction.
float _origin3
 Origin in third direction.
MCGlobalData_gd
 A reference to the global data structure.
bool _valueRangeAdjusted
 Range calculation state machine.
MCBProgressCallback_progCB
MCBHistoCallback_histoCB
MCMesh_mesh
int _theCube
MCMesh_cube

Static Private Attributes

const GLfloat _vertOffset [8][3]
 As described in the class documentation, this table defines the cube geometry.
const int _marchingCubesTable [256][16]
 This is the marching cubes table.
const int _edgeConnect [12][2]
 Describes the connection between the edges and it's end points in the cube.
const int _edgeSizeConnect [12]
 Defines which MCGlobalData::cubeSize value is relevant for each edge.
const int _edgeMapping [12][3][3][3]
 This mapping table connectes edges of neighbouring cubes (see The Marching Cubes Engine and Edge mapping table).
const GLfloat _edgeDir [12][3]
const int _edgeFlags [256]

Detailed Description

Base class of the Marching Cubes Model (see vuMarchingCubes).

This class does the actual scanning of the data.

Geometry

The variable _vertOffset defines the cube geometry which (according to the actual values in _vertOffset) is:

        (3)-----2-----(2)
        /|            /|
      11 |          10 |
      /  |          /  |
    (7)-----6-----(6)  1
     |   3         |   |
     |   |         |   |
     |   |         |   |
     7  (0)-----0--|--(1)    y
     |  /          5  /      |
     | 8           | 9       o-- x
     |/            |/       /
    (4)-----4-----(5)      z

The above picture also shows the edge numbering. All code in this class referes to this geometry.

Cube Type

The type of a cube is calculated by testing every edge vertex of the cube against the threshold saved in _thres. A value that is higher means the vertex is inside. Each edge is associated with a bit in the type integer where the position of the bit corresponds with the nomber of the edge in the above given geometry.

Definition at line 75 of file MarchingCubesBase.h.


Constructor & Destructor Documentation

MarchingCubesBase::MarchingCubesBase  ) 
 

Default constructor.

Definition at line 591 of file MarchingCubesBase.cpp.

References DEBUG0, and NULL.

MarchingCubesBase::~MarchingCubesBase  )  [virtual]
 

Destructor.

Definition at line 606 of file MarchingCubesBase.cpp.

References DEBUGD.


Member Function Documentation

vuVector MarchingCubesBase::calcVertex int  x,
int  y,
int  z,
int  edge
[inline, private]
 

Calculates the vertex position from the cube position (x, y, z), the edge number (edge) and the threshold (_thres).

Definition at line 903 of file MarchingCubesBase.cpp.

References _data, _edgeConnect, _gd, _vertOffset, assert, DEBUG0, DEBUG5, vuVector::makeUnit(), MCB_IDX, vuVector::norm(), and MCGlobalData::thres.

Referenced by marchCubes().

Here is the call graph for this function:

void MarchingCubesBase::drawCorner int  pos,
float  r
[private]
 

Draws a ball at the coordinate p.

Definition at line 789 of file MarchingCubesBase.cpp.

References _gd, _size, _vertOffset, MCGlobalData::cubeSize, glPopMatrix(), glPushMatrix(), and glTranslated().

Referenced by glRenderFrame().

Here is the call graph for this function:

void MarchingCubesBase::drawHorCylinder int  pos,
float  angle,
float  r,
float  l
[private]
 

Draws a horizontal cylinder.

Definition at line 761 of file MarchingCubesBase.cpp.

References _gd, _size, _vertOffset, assert, MCGlobalData::cubeSize, DEBUG0, glPopMatrix(), glPushMatrix(), glRotated(), and glTranslated().

Referenced by glRenderFrame().

Here is the call graph for this function:

void MarchingCubesBase::drawSpot int  pos  )  [private]
 

Definition at line 800 of file MarchingCubesBase.cpp.

References _gd, _size, _vertOffset, MCGlobalData::cubeSize, glPopMatrix(), glPushMatrix(), glTranslatef(), and maxSize().

Referenced by glRender().

Here is the call graph for this function:

void MarchingCubesBase::drawTriangles  )  [private]
 

Definition at line 812 of file MarchingCubesBase.cpp.

References _cube, _edgeConnect, _edgeDir, _edgeSizeConnect, _gd, _marchingCubesTable, _size, _theCube, _vertOffset, MCMesh::AddTriangle(), MCMesh::AddVertex(), MCGlobalData::cube, DEBUG7, MCMesh::GetVertex(), and MCMesh::render().

Referenced by glRender().

Here is the call graph for this function:

void MarchingCubesBase::drawVertCylinder int  pos,
float  r,
float  l
[private]
 

Draw a vertical cylinder.

Definition at line 776 of file MarchingCubesBase.cpp.

References _gd, _size, _vertOffset, MCGlobalData::cubeSize, glPopMatrix(), glPushMatrix(), glRotated(), and glTranslated().

Referenced by glRenderFrame().

Here is the call graph for this function:

void MarchingCubesBase::EndProgress  )  [protected]
 

Definition at line 1064 of file MarchingCubesBase.cpp.

References _progCB, DEBUG0, and MCBProgressCallback::End().

Referenced by marchCubes(), and vu1112211::read().

Here is the call graph for this function:

int MarchingCubesBase::getCubeType int  x,
int  y,
int  z
 

The function determines the type of the cube.

According to the values in _vertOffset each vertex in the cube gets the value of true if it is inside the volume defined by the threshold. Otherwise it is false. Each vertex is associated with a bit in the returned integer and this integer represents the cube type.

Definition at line 856 of file MarchingCubesBase.cpp.

References _data, _gd, _size, _vertOffset, assert, DEBUG0, DEBUG4, MCB_IDX, MCGlobalData::thres, MCGlobalData::valueMax, and MCGlobalData::valueMin.

Referenced by marchCubes(), and vuMarchingCubes::onDblClick().

void MarchingCubesBase::glRender  ) 
 

This function executes the code to render the marching cubes volume.

Todo:
Handling the origin correct and in a unique way!

Definition at line 643 of file MarchingCubesBase.cpp.

References _gd, _mesh, _origin1, _origin2, _origin3, _size, MCGlobalData::cube, MCGlobalData::cubeBrowser, MCGlobalData::cullMode, DEBUG0, MCGlobalData::drawObject, drawSpot(), drawTriangles(), GL_BACK, GL_CULL_FACE, glCullFace(), glDisable(), glEnable(), glPopMatrix(), glPushMatrix(), glRotatef(), glTranslatef(), MCMesh::render(), and MCGlobalData::termProgress.

Referenced by vuMarchingCubes::glRender(), and vu1112211::render().

Here is the call graph for this function:

void MarchingCubesBase::glRenderFrame  ) 
 

Renders the frame that borders the volume.

Parameters:
width line width of the frame.

Definition at line 617 of file MarchingCubesBase.cpp.

References _gd, _origin1, _origin2, _origin3, _size, assert, MCGlobalData::cubeSize, DEBUG0, drawCorner(), drawHorCylinder(), drawVertCylinder(), MCGlobalData::frameRadius, glPopMatrix(), glPushMatrix(), glTranslatef(), and NULL.

Referenced by vuMarchingCubes::glRender().

Here is the call graph for this function:

void MarchingCubesBase::marchCubes  ) 
 

This function calculates the triangle mesh by marching trough the cubes.

As described in the class documentation the function visits every cube, calculates it's type and then determines the part of the mesh introduced by this cube. For more information see The Marching Cubes Engine.

Definition at line 954 of file MarchingCubesBase.cpp.

References _gd, _histoCB, _marchingCubesTable, _mesh, _progCB, _size, _valueRangeAdjusted, MCMesh::AddTriangle(), MCMesh::AddVertex(), assert, calcVertex(), MCBHistoCallback::Clear(), DEBUG0, DEBUG5, DEBUG6, EndProgress(), MCBHistoCallback::Flush(), getCubeType(), MCMesh::GetVertex(), MCBHistoCallback::Inc(), MC_FAIL_EXIT, MCGlobalData::meshSize, NULL, MCMesh::prepare(), SetProgressText(), StartProgress(), MCGlobalData::termProgress, UpdateProgress(), MCGlobalData::valueMax, and MCGlobalData::valueMin.

Referenced by vuMarchingCubes::init(), and vuMarchingCubes::OnThresChange().

Here is the call graph for this function:

int MarchingCubesBase::maxSize  ) 
 

Returns the bigges size.

Definition at line 720 of file MarchingCubesBase.cpp.

References _size, DEBUG0, and max.

Referenced by drawSpot(), vuMarchingCubes::glResize(), vuMarchingCubes::init(), vuMarchingCubes::onDblClick(), vuMarchingCubes::onMouseLeftMoving(), vuMarchingCubes::onMouseRightMoving(), and Size().

long long MarchingCubesBase::numIndices  ) 
 

Definition at line 744 of file MarchingCubesBase.cpp.

References _mesh, DEBUG0, and MCMesh::numIndices().

Referenced by vuMarchingCubes::doThresChange().

Here is the call graph for this function:

long long MarchingCubesBase::numTriangles  ) 
 

Definition at line 736 of file MarchingCubesBase.cpp.

References _mesh, DEBUG0, and MCMesh::numTriangles().

Referenced by vuMarchingCubes::doThresChange().

Here is the call graph for this function:

long long MarchingCubesBase::numVertices  ) 
 

Definition at line 728 of file MarchingCubesBase.cpp.

References _mesh, DEBUG0, and MCMesh::numVertices().

Referenced by vuMarchingCubes::doThresChange().

Here is the call graph for this function:

void MarchingCubesBase::Origin float  or1,
float  or2,
float  or3
 

Origin setter.

Definition at line 752 of file MarchingCubesBase.cpp.

References _origin1, _origin2, _origin3, and DEBUG0.

Referenced by vuMarchingCubes::OnCubeSizeChange(), and Size().

float MarchingCubesBase::Origin1  )  [inline]
 

Definition at line 171 of file MarchingCubesBase.h.

float MarchingCubesBase::Origin2  )  [inline]
 

Definition at line 172 of file MarchingCubesBase.h.

float MarchingCubesBase::Origin3  )  [inline]
 

Definition at line 173 of file MarchingCubesBase.h.

void MarchingCubesBase::setGlobalData MCGlobalData gd  )  [inline]
 

This has to be done first!

Definition at line 144 of file MarchingCubesBase.h.

Referenced by vuMarchingCubes::init().

void MarchingCubesBase::SetHistoCallback MCBHistoCallback cb  ) 
 

Definition at line 1036 of file MarchingCubesBase.cpp.

References _histoCB, and DEBUG0.

Referenced by vuMarchingCubes::init().

void MarchingCubesBase::SetProgressCallback MCBProgressCallback cb  ) 
 

Definition at line 1029 of file MarchingCubesBase.cpp.

References _progCB, and DEBUG0.

Referenced by vuMarchingCubes::init().

void MarchingCubesBase::SetProgressText const char *  txt  )  [protected]
 

Definition at line 1043 of file MarchingCubesBase.cpp.

References _progCB, DEBUG0, and MCBProgressCallback::SetText().

Referenced by marchCubes(), and vu1112211::read().

Here is the call graph for this function:

void MarchingCubesBase::Size int  sz1,
int  sz2,
int  sz3
 

Size setter.

This is the point where the _data array is created. This function also does some other settings. In other words, when this function has not been called, the class will not work correctly.

Definition at line 703 of file MarchingCubesBase.cpp.

References _data, _gd, _size, assert, DEBUG0, maxSize(), MCGlobalData::normalsLength, Origin(), and MCGlobalData::termProgress.

Referenced by vu1112211::read().

Here is the call graph for this function:

int MarchingCubesBase::Size1  )  [inline]
 

Size 1 getter.

Definition at line 162 of file MarchingCubesBase.h.

Referenced by vuMarchingCubes::init(), vuMarchingCubes::OnCubeSizeChange(), and vuMarchingCubes::onDblClick().

int MarchingCubesBase::Size2  )  [inline]
 

Size 2 getter.

Definition at line 164 of file MarchingCubesBase.h.

Referenced by vuMarchingCubes::init(), vuMarchingCubes::OnCubeSizeChange(), and vuMarchingCubes::onDblClick().

int MarchingCubesBase::Size3  )  [inline]
 

Size 3 getter.

Definition at line 166 of file MarchingCubesBase.h.

Referenced by vuMarchingCubes::init(), vuMarchingCubes::OnCubeSizeChange(), and vuMarchingCubes::onDblClick().

void MarchingCubesBase::StartProgress  )  [protected]
 

Definition at line 1050 of file MarchingCubesBase.cpp.

References _progCB, DEBUG0, and MCBProgressCallback::Start().

Referenced by marchCubes(), and vu1112211::read().

Here is the call graph for this function:

void MarchingCubesBase::UpdateProgress int  v  )  [protected]
 

Definition at line 1057 of file MarchingCubesBase.cpp.

References _progCB, DEBUG0, and MCBProgressCallback::Update().

Referenced by marchCubes(), and vu1112211::read().

Here is the call graph for this function:

float MarchingCubesBase::valueAt float  px,
float  py,
float  pz
 

Takes a point inside the mesh and returns the value at that point.

The calculation of the value is done using trilinear interpolation.

Definition at line 880 of file MarchingCubesBase.cpp.

References _data, DEBUG0, DEBUG8, and MCB_IDX.

Referenced by vuMarchingCubes::onDblClick().


Member Data Documentation

MCMesh* MarchingCubesBase::_cube [private]
 

Definition at line 134 of file MarchingCubesBase.h.

Referenced by drawTriangles().

int* MarchingCubesBase::_data [protected]
 

Hold's the volume data.

This member is protected, because it should be accessable from derived classes.

Definition at line 89 of file MarchingCubesBase.h.

Referenced by calcVertex(), getCubeType(), Size(), and valueAt().

const int MarchingCubesBase::_edgeConnect [static, private]
 

Initial value:

 { 
        {0,1}, {1,2}, {2,3}, {3,0},
        {4,5}, {5,6}, {6,7}, {7,4},
        {0,4}, {1,5}, {2,6}, {3,7}
}
Describes the connection between the edges and it's end points in the cube.

Definition at line 290 of file MarchingCubesBase.cpp.

Referenced by calcVertex(), and drawTriangles().

const GLfloat MarchingCubesBase::_edgeDir [static, private]
 

Initial value:

 { 
        {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {-1.0, 0.0, 0.0}, {0.0, -1.0, 0.0},
        {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {-1.0, 0.0, 0.0}, {0.0, -1.0, 0.0},
        {0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, { 0.0, 0.0, 1.0}, {0.0,  0.0, 1.0}
}

Definition at line 548 of file MarchingCubesBase.cpp.

Referenced by drawTriangles().

const int MarchingCubesBase::_edgeFlags [static, private]
 

Definition at line 555 of file MarchingCubesBase.cpp.

const int MarchingCubesBase::_edgeMapping [static, private]
 

This mapping table connectes edges of neighbouring cubes (see The Marching Cubes Engine and Edge mapping table).

Definition at line 304 of file MarchingCubesBase.cpp.

const int MarchingCubesBase::_edgeSizeConnect [static, private]
 

Initial value:

 { 
        0, 1, 0, 1,
        0, 1, 0, 1,
        2, 2, 2, 2
}
Defines which MCGlobalData::cubeSize value is relevant for each edge.

Definition at line 297 of file MarchingCubesBase.cpp.

Referenced by drawTriangles().

MCGlobalData* MarchingCubesBase::_gd [private]
 

A reference to the global data structure.

This need not be destroyed.

Definition at line 97 of file MarchingCubesBase.h.

Referenced by calcVertex(), drawCorner(), drawHorCylinder(), drawSpot(), drawTriangles(), drawVertCylinder(), getCubeType(), glRender(), glRenderFrame(), marchCubes(), and Size().

MCBHistoCallback* MarchingCubesBase::_histoCB [private]
 

Definition at line 129 of file MarchingCubesBase.h.

Referenced by marchCubes(), and SetHistoCallback().

const int MarchingCubesBase::_marchingCubesTable [static, private]
 

This is the marching cubes table.

It connects the cube type with a number of edges. Each edge on it's part represents a vertex of a triangle. Also this table assumes, that a set bit in the type means, that the corrseponding edge is outside the volume.

Definition at line 30 of file MarchingCubesBase.cpp.

Referenced by drawTriangles(), and marchCubes().

MCMesh* MarchingCubesBase::_mesh [private]
 

Definition at line 131 of file MarchingCubesBase.h.

Referenced by glRender(), marchCubes(), numIndices(), numTriangles(), and numVertices().

float MarchingCubesBase::_origin1 [private]
 

Origin in first direction.

Definition at line 81 of file MarchingCubesBase.h.

Referenced by glRender(), glRenderFrame(), and Origin().

float MarchingCubesBase::_origin2 [private]
 

Origin in second direction.

Definition at line 82 of file MarchingCubesBase.h.

Referenced by glRender(), glRenderFrame(), and Origin().

float MarchingCubesBase::_origin3 [private]
 

Origin in third direction.

Definition at line 83 of file MarchingCubesBase.h.

Referenced by glRender(), glRenderFrame(), and Origin().

MCBProgressCallback* MarchingCubesBase::_progCB [private]
 

Definition at line 128 of file MarchingCubesBase.h.

Referenced by EndProgress(), marchCubes(), SetProgressCallback(), SetProgressText(), StartProgress(), and UpdateProgress().

int MarchingCubesBase::_size[3] [private]
 

Data size.

Definition at line 80 of file MarchingCubesBase.h.

Referenced by drawCorner(), drawHorCylinder(), drawSpot(), drawTriangles(), drawVertCylinder(), getCubeType(), glRender(), glRenderFrame(), marchCubes(), maxSize(), and Size().

int MarchingCubesBase::_theCube [private]
 

Definition at line 133 of file MarchingCubesBase.h.

Referenced by drawTriangles().

bool MarchingCubesBase::_valueRangeAdjusted [private]
 

Range calculation state machine.

False in the beginning and true after calculation.

Definition at line 102 of file MarchingCubesBase.h.

Referenced by marchCubes().

const GLfloat MarchingCubesBase::_vertOffset [static, private]
 

Initial value:

 { 
        {0.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 1.0, 0.0}, {0.0, 1.0, 0.0},
        {0.0, 0.0, 1.0}, {1.0, 0.0, 1.0}, {1.0, 1.0, 1.0}, {0.0, 1.0, 1.0}
}
As described in the class documentation, this table defines the cube geometry.

Definition at line 24 of file MarchingCubesBase.cpp.

Referenced by calcVertex(), drawCorner(), drawHorCylinder(), drawSpot(), drawTriangles(), drawVertCylinder(), and getCubeType().


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