MarchingCubes.h

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @class  MarchingCubes
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @author Matthew Jacobs (jacobs.mh@gmail.com)
00005    @date   Spring 2008
00006    
00007    @brief
00008       Marching Cubes is a well-known algorithm for generating a polygonal 
00009    approximation to an isosurface defined over a scalar field. This 
00010    class is a fairly standard implementation of Marching Cubes in 3D that 
00011    generates triangular meshes as output.
00012    
00013    References:
00014       http://www.ia.hiof.no/~borres/cgraph/explain/marching/p-march.html
00015    <!-------------------------------------------------------------------->**/
00016 
00017 #ifndef MARCHING_CUBES_H_
00018 #define MARCHING_CUBES_H_
00019 
00020 #include "shapes/ScalarField.h"
00021 #include "shapes/MeshTriangle.h"
00022 
00023 class  Mesh;
00024 struct MCData;
00025 
00026 class MarchingCubes : public SSEAligned {
00027    public:
00028       ///@name Constructors
00029       //@{-----------------------------------------------------------------
00030       
00031       inline MarchingCubes()
00032          : m_resolution(256, 256, 256)
00033       { }
00034       
00035       inline MarchingCubes(const Vector3 &resolution)
00036          : m_resolution(resolution)
00037       { }
00038       
00039       virtual ~MarchingCubes()
00040       { }
00041       
00042       
00043       //@}-----------------------------------------------------------------
00044       ///@name Core functionality
00045       //@{-----------------------------------------------------------------
00046       
00047       /**
00048        * @brief
00049        *    Generates a triangular mesh approximating a specific isocontour
00050        * defined over the given ScalarField at the threshold value specified
00051        * 
00052        * @note
00053        *    the generated mesh is not guaranteed to be closed
00054        * 
00055        * @returns the generated Mesh or NULL upon error
00056        */
00057       virtual Mesh *polygonize(const ScalarField &field, real_t threshold);
00058       
00059       
00060       //@}-----------------------------------------------------------------
00061       ///@name Accessors / Mutators
00062       //@{-----------------------------------------------------------------
00063       
00064       /**
00065        * @returns the resolution of the grid used for marching squares
00066        */
00067       inline const Vector3 &getResolution() const {
00068          return m_resolution;
00069       }
00070       
00071       /**
00072        * @brief
00073        *    sets the resolution of the grid used for marching squares
00074        */
00075       inline void setResolution(const Vector3 &resolution) {
00076          m_resolution = resolution;
00077       }
00078       
00079       
00080       //@}-----------------------------------------------------------------
00081       
00082    protected:
00083       Vertex _calculateIntersection(const MCData &data, unsigned edge) const;
00084       
00085       inline unsigned _getVertexID(const MCData &data, unsigned edge) const;
00086       inline unsigned _getVertexID(const MCData &data) const;
00087       inline unsigned _getVertexID(unsigned i, unsigned j, unsigned k, 
00088                                    unsigned width, unsigned height) const;
00089       
00090       inline Vertex _interpolate(const Vertex &v1, const Vertex &v2, 
00091                                  real_t coeff1, real_t coeff2, 
00092                                  real_t threshold) const;
00093       
00094       void _addVertex(const Vertex &vertex, unsigned id, MCData &data) const;
00095       
00096       void _cleanup(MCData &data) const;
00097       
00098    protected:
00099       Vector3 m_resolution;
00100 };
00101 
00102 #endif // MARCHING_CUBES_H_
00103 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6