Avogadro  1.1.0
Signals | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
Avogadro::MeshGenerator Class Reference

Class that can generate Mesh objects from Cube objects. More...

#include <avogadro/meshgenerator.h>

Inheritance diagram for Avogadro::MeshGenerator:
Inheritance graph
[legend]

List of all members.

Signals

void progressValueChanged (int)

Public Member Functions

 MeshGenerator (QObject *parent=0)
 MeshGenerator (const Cube *cube, Mesh *mesh, float iso, bool reverse=false, QObject *parent=0)
 ~MeshGenerator ()
bool initialize (const Cube *cube, Mesh *mesh, float iso, bool reverse=false)
void run ()
const Cubecube () const
Meshmesh () const
void clear ()
int progressMinimum ()
int progressMaximum ()

Protected Member Functions

Eigen::Vector3f normal (const Eigen::Vector3f &pos)
float offset (float val1, float val2)
unsigned long duplicate (const Eigen::Vector3i &c, const Eigen::Vector3f &pos)
bool marchingCube (const Eigen::Vector3i &pos)

Protected Attributes

float m_iso
bool m_reverseWinding
const Cubem_cube
Meshm_mesh
float m_stepSize
Eigen::Vector3f m_min
Eigen::Vector3i m_dim
std::vector< Eigen::Vector3f > m_vertices
std::vector< Eigen::Vector3f > m_normals
std::vector< unsigned int > m_indices
int m_progmin
int m_progmax

Static Protected Attributes

static const float a2fVertexOffset [8][3]
static const int a2iVertexOffset [8][3]
static const int a2iEdgeConnection [12][2]
static const float a2fEdgeDirection [12][3]
static const int a2iTetrahedronEdgeConnection [6][2]
static const int a2iTetrahedronsInACube [6][4]
static const long aiTetrahedronEdgeFlags [16]
static const int a2iTetrahedronTriangles [16][7]
static const long aiCubeEdgeFlags [256]
static const int a2iTriangleConnectionTable [256][16]

Detailed Description

Class that can generate Mesh objects from Cube objects.

Author:
Marcus D. Hanwell

This class implements a method of generating an isosurface Mesh from volumetric data using the marching cubes algorithm. In the case of the MeshGenerator class it expects a Cube as an input and an isosurface value. The tables and the basic code is taken from the public domain code written by Cory Bloyd (marchingsource.cpp) and available at, http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise/

You must first initialize the class and then call run() to actually polygonize the isosurface. Connect to the classes finished() signal to do something once the polygonization is complete.


Constructor & Destructor Documentation

Avogadro::MeshGenerator::MeshGenerator ( QObject parent = 0) [explicit]

Constructor.

Avogadro::MeshGenerator::MeshGenerator ( const Cube cube,
Mesh mesh,
float  iso,
bool  reverse = false,
QObject parent = 0 
)

Constructor. Can be used to initialize the MeshGenerator.

Parameters:
cubeThe source Cube with the volumetric data.
meshThe Mesh that will hold the isosurface.
isoThe iso value of the surface.
Returns:
True if the MeshGenerator was successfully initialized.

References initialize().

Destructor.


Member Function Documentation

Clears the contents of the MeshGenerator.

References m_cube, m_dim, m_mesh, m_min, and m_stepSize.

const Cube* Avogadro::MeshGenerator::cube ( ) const [inline]
Returns:
The Cube being used by the class.

Referenced by initialize().

bool Avogadro::MeshGenerator::initialize ( const Cube cube,
Mesh mesh,
float  iso,
bool  reverse = false 
)

Initialization function, set up the MeshGenerator ready to find an isosurface of the supplied Cube.

Parameters:
cubeThe source Cube with the volumetric data.
meshThe Mesh that will hold the isosurface.
isoThe iso value of the surface.

References cube(), Avogadro::Cube::dimensions(), Avogadro::Cube::lock(), m_cube, m_dim, m_mesh, m_min, m_reverseWinding, m_stepSize, mesh(), Avogadro::Cube::min(), Avogadro::Cube::spacing(), QReadWriteLock::tryLockForRead(), and QReadWriteLock::unlock().

Referenced by MeshGenerator().

bool Avogadro::MeshGenerator::marchingCube ( const Eigen::Vector3i &  pos) [protected]

Perform a marching cubes step on a single cube.

FIXME Optimize this to only calculate normals when required

References a2fVertexOffset, m_cube, m_min, m_reverseWinding, m_stepSize, m_vertices, normal(), offset(), and Avogadro::Cube::value().

Referenced by run().

Mesh* Avogadro::MeshGenerator::mesh ( ) const [inline]
Returns:
The Mesh being generated by the class.

Referenced by initialize().

Vector3f Avogadro::MeshGenerator::normal ( const Eigen::Vector3f &  pos) [protected]

Get the normal to the supplied point. This operation is quite expensive and so should be avoided wherever possible.

Parameters:
posThe position of the vertex whose normal is needed.
Returns:
The normal vector for the supplied point.

References m_cube, and Avogadro::Cube::valuef().

Referenced by marchingCube().

float Avogadro::MeshGenerator::offset ( float  val1,
float  val2 
) [inline, protected]

Get the offset, i.e. the approximate point of intersection of the surface between two points.

Parameters:
val1The position of the vertex whose normal is needed.
Returns:
The normal vector for the supplied point.

Referenced by marchingCube().

Returns:
The maximum value of the progress value.
Returns:
The minimum value of the progress value.

The current value of the calculation's progress.

Referenced by run().

void Avogadro::MeshGenerator::run ( ) [virtual]

Use this function to begin Mesh generation. Uses an asynchronous thread, and so avoids locking the user interface while the isosurface is found.

Reimplemented from QThread.

References Avogadro::Mesh::clear(), Avogadro::Cube::lock(), m_cube, m_dim, m_mesh, m_vertices, marchingCube(), progressValueChanged(), Avogadro::Mesh::setNormals(), Avogadro::Mesh::setStable(), Avogadro::Mesh::setVertices(), QReadWriteLock::tryLockForRead(), and QReadWriteLock::unlock().


Member Data Documentation

const float Avogadro::MeshGenerator::a2fEdgeDirection [static, protected]
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}
  }
const float Avogadro::MeshGenerator::a2fVertexOffset [static, protected]
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}
  }

These are the tables of constants for the marching cubes and tetrahedra algorithms. They are taken from the public domain source at http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise/

Referenced by marchingCube().

const int Avogadro::MeshGenerator::a2iEdgeConnection [static, protected]
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}
  }
const int Avogadro::MeshGenerator::a2iTetrahedronEdgeConnection [static, protected]
Initial value:
  {
    {0, 1}, {1, 2}, {2, 0}, {0, 3}, {1, 3}, {2, 3}
  }
const int Avogadro::MeshGenerator::a2iTetrahedronsInACube [static, protected]
Initial value:
  {
    {0, 5, 1, 6},
    {0, 1, 2, 6},
    {0, 2, 3, 6},
    {0, 3, 7, 6},
    {0, 7, 4, 6},
    {0, 4, 5, 6},
  }
const int Avogadro::MeshGenerator::a2iTetrahedronTriangles [static, protected]
Initial value:
  {
    {-1, -1, -1, -1, -1, -1, -1},
    { 0,  3,  2, -1, -1, -1, -1},
    { 0,  1,  4, -1, -1, -1, -1},
    { 1,  4,  2,  2,  4,  3, -1},

    { 1,  2,  5, -1, -1, -1, -1},
    { 0,  3,  5,  0,  5,  1, -1},
    { 0,  2,  5,  0,  5,  4, -1},
    { 5,  4,  3, -1, -1, -1, -1},

    { 3,  4,  5, -1, -1, -1, -1},
    { 4,  5,  0,  5,  2,  0, -1},
    { 1,  5,  0,  5,  3,  0, -1},
    { 5,  2,  1, -1, -1, -1, -1},

    { 3,  4,  2,  2,  4,  1, -1},
    { 4,  1,  0, -1, -1, -1, -1},
    { 2,  3,  0, -1, -1, -1, -1},
    {-1, -1, -1, -1, -1, -1, -1},
  }
const int Avogadro::MeshGenerator::a2iVertexOffset [static, protected]
Initial value:
  {
    {0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0},
    {0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1}
  }
const long Avogadro::MeshGenerator::aiTetrahedronEdgeFlags [static, protected]
Initial value:
  {
    0x00, 0x0d, 0x13, 0x1e, 0x26, 0x2b, 0x35, 0x38,
    0x38, 0x35, 0x2b, 0x26, 0x1e, 0x13, 0x0d, 0x00,
  }

Whether the winding and normals are reversed

Referenced by clear(), initialize(), marchingCube(), normal(), and run().

Eigen::Vector3i Avogadro::MeshGenerator::m_dim [protected]

The minimum point in the cube.

Referenced by clear(), initialize(), and run().

The cube that we are generating a Mesh from.

Referenced by clear(), initialize(), and run().

Eigen::Vector3f Avogadro::MeshGenerator::m_min [protected]

The step size of the cube.

Referenced by clear(), initialize(), and marchingCube().

The value of the isosurface.

Referenced by initialize(), and marchingCube().

The mesh that is being generated.

Referenced by clear(), initialize(), and marchingCube().

std::vector<Eigen::Vector3f> Avogadro::MeshGenerator::m_vertices [protected]

The dimensions of the cube.

Referenced by marchingCube(), and run().


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