An Implementation of the Marching Cubes Algorithm
1.0
|
This class represents a 3D cubic grid in which all cubes have faces parallel to the Cartesian axes, and have the same size, i.e., the grid is a uniform, cubic decomposition of the 3D space. More...
#include <grid.hpp>
Public Member Functions | |
Grid (unsigned sx, unsigned sy, unsigned sz, const t3DVector &og, const t3DVector &sp) | |
Creates an instance of this class. | |
Grid (const Grid &g) | |
Creates an instance of this class. | |
~Grid () | |
Destroys an instance of this class. | |
unsigned | get_size_x () const |
Returns the number of grid vertices in the X direction. | |
unsigned | get_size_y () const |
Returns the number of grid vertices in the Y direction. | |
unsigned | get_size_z () const |
Returns the number of grid vertices in the Z direction. | |
double | get_spacing_x () const |
Returns the length of the cube edges in the X direction. | |
double | get_spacing_y () const |
Returns the length of the cube edges in the Y direction. | |
double | get_spacing_z () const |
Returns the length of the cube edges in the Z direction. | |
t3DVector | get_origin () const |
Returns the origin of this 3D grid. | |
double | get_value (unsigned i, unsigned j, unsigned k) const throw (ExceptionObject) |
Returns the value of an unknown implicit function at the grid vertex represented by a given triple of indices, (i,j,k). | |
void | set_value (unsigned i, unsigned j, unsigned k, double f) throw (ExceptionObject) |
Assigns a value of an unknown implicit function to the grid vertex represented by a given triple of indices, (i,j,k). | |
Private Attributes | |
unsigned | _sizex |
The number of grid vertices in the X direction. | |
unsigned | _sizey |
The number of grid vertices in the Y direction. | |
unsigned | _sizez |
The number of grid vertices in the Z direction. | |
t3DVector | _orig |
The origin of the 3D grid. | |
t3DVector | _spac |
The length of the cube edges in each direction. | |
double *** | _f |
The values of an unknown implicit function at the vertices of the 3D grid. |
This class represents a 3D cubic grid in which all cubes have faces parallel to the Cartesian axes, and have the same size, i.e., the grid is a uniform, cubic decomposition of the 3D space.
mc::Grid::Grid | ( | unsigned | sx, |
unsigned | sy, | ||
unsigned | sz, | ||
const t3DVector & | og, | ||
const t3DVector & | sp | ||
) |
Creates an instance of this class.
sx | The number of grid vertices in the X direction. |
sy | The number of grid vertices in the Y direction. |
sz | The number of grid vertices in the Z direction. |
og | The origin point of the grid. |
sp | The length of cube edges in each direction. |
Definition at line 72 of file grid.cpp.
References _f, _sizex, _sizey, and _sizez.
: _sizex( sx ) , _sizey( sy ) , _sizez( sz ) , _orig( og ) , _spac( sp ) { /* * Allocate memory for the function values associated with the * grid vertices. */ _f = ( double*** ) new double**[ _sizex ] ; for ( unsigned i = 0 ; i < _sizex ; i++ ) { _f[ i ] = ( double** ) new double*[ _sizey ] ; for ( unsigned j = 0 ; j < _sizey ; j++ ) { _f[ i ][ j ] = ( double* ) new double[ _sizez ] ; } } }
mc::Grid::Grid | ( | const Grid & | g | ) |
Creates an instance of this class.
g | A 3D grid to be cloned. |
Definition at line 107 of file grid.cpp.
References _f, _sizex, _sizey, and _sizez.
: _sizex( g._sizex ) , _sizey( g._sizey ) , _sizez( g._sizez ) , _orig( g._orig ) , _spac( g._spac ) { /* * Allocate memory for the function values associated with the * grid vertices. */ _f = ( double*** ) new double**[ _sizex ] ; _f = ( double*** ) new double**[ _sizex ] ; for ( unsigned i = 0 ; i < _sizex ; i++ ) { _f[ i ] = ( double** ) new double*[ _sizey ] ; for ( unsigned j = 0 ; j < _sizey ; j++ ) { _f[ i ][ j ] = ( double* ) new double[ _sizez ] ; } } for ( unsigned i = 0 ; i < _sizex ; i++ ) { for ( unsigned j = 0 ; j < _sizey ; j++ ) { for ( unsigned k = 0 ; k < _sizez ; k++ ) { _f[ i ][ j ][ k ] = g._f[ i ][ j ][ k ] ; } } } }
t3DVector mc::Grid::get_origin | ( | ) | const [inline] |
unsigned mc::Grid::get_size_x | ( | ) | const [inline] |
Returns the number of grid vertices in the X direction.
Definition at line 110 of file grid.hpp.
References _sizex.
Referenced by check_grid(), mc::SurfBuilder::from_index_to_id(), main(), and mc::SurfBuilder::run().
{ return _sizex ; }
unsigned mc::Grid::get_size_y | ( | ) | const [inline] |
Returns the number of grid vertices in the Y direction.
Definition at line 123 of file grid.hpp.
References _sizey.
Referenced by check_grid(), mc::SurfBuilder::from_index_to_id(), main(), and mc::SurfBuilder::run().
{ return _sizey ; }
unsigned mc::Grid::get_size_z | ( | ) | const [inline] |
Returns the number of grid vertices in the Z direction.
Definition at line 136 of file grid.hpp.
References _sizez.
Referenced by check_grid(), main(), and mc::SurfBuilder::run().
{ return _sizez ; }
double mc::Grid::get_spacing_x | ( | ) | const [inline] |
double mc::Grid::get_spacing_y | ( | ) | const [inline] |
double mc::Grid::get_spacing_z | ( | ) | const [inline] |
double mc::Grid::get_value | ( | unsigned | i, |
unsigned | j, | ||
unsigned | k | ||
) | const throw (ExceptionObject) |
Returns the value of an unknown implicit function at the grid vertex represented by a given triple of indices, (i,j,k).
Definition at line 172 of file grid.cpp.
Referenced by check_grid(), and mc::SurfBuilder::run().
void mc::Grid::set_value | ( | unsigned | i, |
unsigned | j, | ||
unsigned | k, | ||
double | f | ||
) | throw (ExceptionObject) |
Assigns a value of an unknown implicit function to the grid vertex represented by a given triple of indices, (i,j,k).
i | The first index of the triple representing the vertex. |
j | The second index of the triple representing the vertex. |
k | The third index of the triple representing the vertex. |
f | The value (at the vertex) of an unknown implicit function. |
Definition at line 205 of file grid.cpp.
Referenced by main().
{ if ( ( i > _sizex ) || ( j > _sizey ) || ( k > _sizez ) ) { std::stringstream ss ( std::stringstream::in | std::stringstream::out ) ; ss << "Vertex index is out of range" ; throw ExceptionObject( __FILE__ , __LINE__ , ss.str() ) ; } if ( common::is_zero( f ) ) { std::stringstream ss ( std::stringstream::in | std::stringstream::out ) ; ss << "Vertex grid cannot be assigned the value 0" ; throw ExceptionObject( __FILE__ , __LINE__ , ss.str() ) ; } _f[ i ][ j ][ k ] = f ; }