An Implementation of the Marching Cubes Algorithm  1.0
mc::Grid Class Reference

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>

Collaboration diagram for mc::Grid:

List of all members.

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.

Detailed Description

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.

Definition at line 63 of file grid.hpp.


Constructor & Destructor Documentation

mc::Grid::Grid ( unsigned  sx,
unsigned  sy,
unsigned  sz,
const t3DVector og,
const t3DVector sp 
)

Creates an instance of this class.

Parameters:
sxThe number of grid vertices in the X direction.
syThe number of grid vertices in the Y direction.
szThe number of grid vertices in the Z direction.
ogThe origin point of the grid.
spThe 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.

Parameters:
gA 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 ] ;
        }
      }
    }
  }

Member Function Documentation

t3DVector mc::Grid::get_origin ( ) const [inline]

Returns the origin of this 3D grid.

Returns:
The origin of this 3D grid.

Definition at line 188 of file grid.hpp.

References _orig.

Referenced by main().

    { 
      return _orig ;
    }
unsigned mc::Grid::get_size_x ( ) const [inline]

Returns the number of grid vertices in the X direction.

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.

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.

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]

Returns the length of the cube edges in the X direction.

Returns:
The length of the cube edges in the X direction.

Definition at line 149 of file grid.hpp.

References _spac, and common::t3DVector::_x.

Referenced by main().

    { 
      return _spac._x ;
    }
double mc::Grid::get_spacing_y ( ) const [inline]

Returns the length of the cube edges in the Y direction.

Returns:
The length of the cube edges in the Y direction.

Definition at line 162 of file grid.hpp.

References _spac, and common::t3DVector::_y.

Referenced by main().

    { 
      return _spac._y ;
    }
double mc::Grid::get_spacing_z ( ) const [inline]

Returns the length of the cube edges in the Z direction.

Returns:
The length of the cube edges in the Z direction.

Definition at line 175 of file grid.hpp.

References _spac, and common::t3DVector::_z.

Referenced by main().

    { 
      return _spac._z ;
    }
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).

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().

  {
    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() ) ;
    }
  
    return _f[ i ][ j ][ k ] ;
  }
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).

Parameters:
iThe first index of the triple representing the vertex.
jThe second index of the triple representing the vertex.
kThe third index of the triple representing the vertex.
fThe 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 ;
  }

The documentation for this class was generated from the following files: