Eulerian Smoke Simulation on the GPU
include/VolumeMesher.h
Go to the documentation of this file.
00001 #ifndef __VOLUME_MESHER_H__
00002 #define __VOLUME_MESHER_H__
00003 
00004 //---------------------------------------------------------------------
00007 //---------------------------------------------------------------------
00008 
00009 #include <ngl/Colour.h>
00010 #include <ngl/TransformStack.h>
00011 #include <ngl/Matrix.h>
00012 #include "GLUtil.h"
00013 #include "ImageUnitStack.h"
00014 #include "Texture1D.h"
00015 #include "Texture2D.h"
00016 #include "Texture3D.h"
00017 #include "VertexArrayObject.h"
00018 
00027 class VolumeMesher
00028 {
00029 public:
00030 
00032   enum MeshingMethod{ MARCHING_CUBES, DIVIDING_CUBES };
00033 
00038   VolumeMesher(
00039                 int             _resX,
00040                 int             _resY,
00041                 int             _resZ,
00042                 ImageUnitStack* _imageUnitStack
00043               );
00044 
00046   ~VolumeMesher();
00047 
00049   void init();
00050 
00052   inline int getResX() const {return m_resX;}
00054   inline int getResY() const {return m_resY;}
00056   inline int getResZ() const {return m_resZ;}
00057 
00062   inline void setResolution(
00063                             int _resX,
00064                             int _resY,
00065                             int _resZ
00066                            )
00067                            {
00068                             m_resX = _resX;
00069                             m_resY = _resY;
00070                             m_resZ = _resZ;
00071 
00072                             m_samplingStepX = 2.0f/m_resX;
00073                             m_samplingStepY = 2.0f/m_resY;
00074                             m_samplingStepZ = 2.0f/m_resZ;
00075                            }
00076 
00078   inline float getSamplingStepX() const {return m_samplingStepX;}
00080   inline float getSamplingStepY() const {return m_samplingStepY;}
00082   inline float getSamplingStepZ() const {return m_samplingStepZ;}
00083 
00091   void drawMesh(
00092                 Texture3D*   _texture3D,
00093                 float        _isoLevel,
00094                 int          _samplingChannel,
00095                 ngl::Colour* _colour,
00096                 ngl::Matrix  _modelMatrix,
00097                 bool         _inverseNormals = false
00098                );
00099 
00104   void resetResolution(
00105                         int _resX,
00106                         int _resY,
00107                         int _resZ
00108                       );
00109 
00112   void setMeshingMethod(
00113                         MeshingMethod _meshingMethod
00114                        );
00115 
00119   void passViewProjectionMatrix(
00120                                 ngl::Matrix _modelViewMatrix,
00121                                 ngl::Matrix _projectionMatrix
00122                                );
00123 
00124 private:
00126   static int s_edgeTable[256];
00128   static int s_triTable[256][16];
00129 
00131   float* m_grid;
00132 
00134   int m_resX;
00136   int m_resY;
00138   int m_resZ;
00139 
00141   float m_samplingStepX;
00143   float m_samplingStepY;
00145   float m_samplingStepZ;
00146 
00148   ImageUnitStack* m_imageUnitStack;
00149 
00151   MeshingMethod m_meshingMethod;
00152 
00154   Texture1D* m_edgeTableTex;
00156   Texture2D* m_triTableTex;
00157 
00159   VertexArrayObject* m_marchGridVAO;
00160 
00161 private:
00163   void createMarchingGrid();
00164 };
00165 
00166 #endif // __VOLUME_MESHER_H__
 All Classes Files Functions Variables