|
Avogadro
1.1.0
|
Class that can generate Mesh objects from Cube objects. More...
#include <avogadro/meshgenerator.h>

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 Cube * | cube () const |
| Mesh * | mesh () 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 Cube * | m_cube |
| Mesh * | m_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] |
Class that can generate Mesh objects from Cube objects.
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.
| 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.
| cube | The source Cube with the volumetric data. |
| mesh | The Mesh that will hold the isosurface. |
| iso | The iso value of the surface. |
References initialize().
Destructor.
| void Avogadro::MeshGenerator::clear | ( | ) |
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] |
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.
| cube | The source Cube with the volumetric data. |
| mesh | The Mesh that will hold the isosurface. |
| iso | The 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] |
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.
| pos | The position of the vertex whose normal is needed. |
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.
| val1 | The position of the vertex whose normal is needed. |
Referenced by marchingCube().
| int Avogadro::MeshGenerator::progressMaximum | ( | ) | [inline] |
| int Avogadro::MeshGenerator::progressMinimum | ( | ) | [inline] |
| void Avogadro::MeshGenerator::progressValueChanged | ( | int | ) | [signal] |
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().
const float Avogadro::MeshGenerator::a2fEdgeDirection [static, protected] |
{
{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] |
{
{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] |
{
{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] |
{
{0, 1}, {1, 2}, {2, 0}, {0, 3}, {1, 3}, {2, 3}
}
const int Avogadro::MeshGenerator::a2iTetrahedronsInACube [static, protected] |
{
{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] |
{
{-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] |
{
{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] |
{
0x00, 0x0d, 0x13, 0x1e, 0x26, 0x2b, 0x35, 0x38,
0x38, 0x35, 0x2b, 0x26, 0x1e, 0x13, 0x0d, 0x00,
}
const Cube* Avogadro::MeshGenerator::m_cube [protected] |
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().
Mesh* Avogadro::MeshGenerator::m_mesh [protected] |
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().
bool Avogadro::MeshGenerator::m_reverseWinding [protected] |
The value of the isosurface.
Referenced by initialize(), and marchingCube().
float Avogadro::MeshGenerator::m_stepSize [protected] |
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().
1.8.0