Avogadro  1.1.0
/home/kitware/dashboards/avogadro/libavogadro/src/meshgenerator.h
00001 /**********************************************************************
00002   MeshGenerator - Class to generate meshes from volumetric data
00003 
00004   Copyright (C) 2008-2009 by Marcus D. Hanwell
00005 
00006   This file is part of the Avogadro molecular editor project.
00007   For more information, see <http://avogadro.openmolecules.net/>
00008 
00009   Avogadro is free software; you can redistribute it and/or modify
00010   it under the terms of the GNU Lesser General Public License as published by
00011   the Free Software Foundation; either version 2.1 of the License, or
00012   (at your option) any later version.
00013 
00014   Avogadro is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017   GNU General Public License for more details.
00018 
00019   You should have received a copy of the GNU General Public License
00020   along with this program; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00022   02110-1301, USA.
00023  **********************************************************************/
00024 
00025  #ifndef MESHGENERATOR_H
00026  #define MESHGENERATOR_H
00027 
00028 #include <avogadro/global.h>
00029 
00030 #include <Eigen/Core>
00031 
00032 #include <QThread>
00033 
00034 #include <vector>
00035 
00036  namespace Avogadro {
00037 
00038   class Cube;
00039   class Mesh;
00040 
00058   class A_EXPORT MeshGenerator : public QThread
00059   {
00060     Q_OBJECT
00061   public:
00065     explicit MeshGenerator(QObject *parent = 0);
00066 
00074     MeshGenerator(const Cube *cube, Mesh *mesh, float iso,
00075                   bool reverse = false, QObject *parent = 0);
00076 
00080     ~MeshGenerator();
00081 
00089     bool initialize(const Cube *cube, Mesh *mesh, float iso,
00090                     bool reverse = false);
00091 
00096     void run();
00097 
00101     const Cube * cube() const { return m_cube; }
00102 
00106     Mesh * mesh() const { return m_mesh; }
00107 
00111     void clear();
00112 
00116     int progressMinimum() {return m_progmin;};
00117 
00121     int progressMaximum() {return m_progmax;};
00122 
00123   signals:
00127     void progressValueChanged(int);
00128 
00129   protected:
00136     Eigen::Vector3f normal(const Eigen::Vector3f &pos);
00137 
00144     float offset(float val1, float val2);
00145 
00146     unsigned long duplicate(const Eigen::Vector3i &c,
00147                             const Eigen::Vector3f &pos);
00148 
00152     bool marchingCube(const Eigen::Vector3i &pos);
00153 
00154     float m_iso;           
00155     bool m_reverseWinding; 
00156     const Cube *m_cube;    
00157     Mesh *m_mesh;          
00158     float m_stepSize;      
00159     Eigen::Vector3f m_min; 
00160     Eigen::Vector3i m_dim; 
00161     std::vector<Eigen::Vector3f> m_vertices, m_normals;
00162     std::vector<unsigned int> m_indices;
00163     int m_progmin;
00164     int m_progmax;
00165 
00171     static const float a2fVertexOffset[8][3];
00172     static const int   a2iVertexOffset[8][3];
00173     static const int   a2iEdgeConnection[12][2];
00174     static const float a2fEdgeDirection[12][3];
00175     static const int   a2iTetrahedronEdgeConnection[6][2];
00176     static const int   a2iTetrahedronsInACube[6][4];
00177     static const long  aiTetrahedronEdgeFlags[16];
00178     static const int   a2iTetrahedronTriangles[16][7];
00179     static const long  aiCubeEdgeFlags[256];
00180     static const int   a2iTriangleConnectionTable[256][16];
00181   };
00182 
00183  } // End namespace Avogadro
00184 
00185  #endif
00186