vee_volume_grid.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 /* COPYRIGHT
00004  *
00005  * This file is part of the Visual Effects Engine - VEE
00006  *
00007  * Read the "VEE-LICENSE" file for the license.
00008  *
00009  * Authors & Copyright:   
00010  *
00011  * Tommi Ilmonen, Tuukka Heikura, Marko Myllymaa and 
00012  * Janne Kontkanen 2001-2004
00013  *
00014  * Additional copyrights: Tekes 2003-2004
00015  *
00016  * firstname.lastname@hut.fi
00017  *
00018  */
00019 
00020 #ifndef VEE_VOLUME_GRID_H
00021 #define VEE_VOLUME_GRID_H
00022 
00023 #include <vee_bounding_box.h>
00024 #include <vee_marching_cubes.h>
00025 #include <vee_meta_balls.h>
00026 #include <vee_volume.h>
00027 
00028 #include <mj_array3d.h>
00029 
00030 #include <map>
00031 
00032 class VEE_MetaBalls;
00033 
00037 class VEE_VolumeGrid : public VEE_Volume
00038 {
00039 public:
00040   VEE_VolumeGrid();
00041   virtual ~VEE_VolumeGrid();
00042 
00043   virtual float inside(const VEE_Vector3 &);
00044   virtual void getBoundingBox(VEE_BoundingBox *);
00045   virtual VEE_Vector3 newRandomPoint();
00046 
00047   virtual bool setValue(const char *, VEE_Value *);
00048   virtual VEE_Volume * clone() const;
00049 
00050   VEE_MetaBalls * metaBalls() { return m_metaBalls; }
00051 
00052   VEE_Vector3 createFromMetaBalls(VEE_MetaBalls *, uint density = 60);
00053 
00054   void updateMarchingCubes(float threshold) 
00055   { m_triangles.triangulateGrid(m_grid, threshold); }
00056 
00057   const VEE_Matrix3 & rotation() const { return m_rotation; }
00058   const VEE_Vector3 & scale()    const { return m_scale;}
00059   
00060   VEE_MarchingCubes & marchingCubes() { return m_triangles; }
00061 
00062   void clear(bool zeroSize = true)
00063   {
00064     if(zeroSize)
00065       m_grid.resize(0, 0, 0);
00066     else
00067       m_grid.setAll(0.0);
00068     m_triangles.clear();
00069   }
00070 
00071 protected:
00072 
00073   MJ_Array3D<float> m_grid;
00074   VEE_MarchingCubes m_triangles;
00075 
00076   VEE_Matrix3 m_rotation;
00077   VEE_Matrix3 m_rotationInv;
00078   VEE_Vector3 m_scale;
00079 
00080   VEE_MetaBalls * m_metaBalls;
00081 };
00082 
00085 
00089 class VEE_VolumeGrid2 : public VEE_Volume
00090 {
00091 public:
00092   class GridGrid
00093   {
00094   public:
00095     GridGrid() : m_touched(false), m_dirty(false) { m_bbox.clear(); }
00096 
00097     uint byteCount() const
00098     {
00099       return sizeof(*this) + sizeof(float) * m_grid.elements();
00100     }
00101 
00102     VEE_BoundingBox m_bbox;
00103     MJ_Array3D<float> m_grid;
00104     bool m_touched;
00105     bool m_dirty;
00106     int  m_ind[3];
00107 
00108     VEE_MarchingCubes m_triangles;
00109   };
00110 
00111   VEE_VolumeGrid2();
00112   VEE_VolumeGrid2(const VEE_VolumeGrid2 &);
00113   virtual ~VEE_VolumeGrid2();
00114 
00115   virtual float inside(const VEE_Vector3 &);
00116   virtual void getBoundingBox(VEE_BoundingBox *);
00117   virtual VEE_Vector3 newRandomPoint();
00118 
00119   virtual bool setValue(const char *, VEE_Value *);
00120   virtual VEE_Volume * clone() const;
00121 
00122   const VEE_Matrix3 & rotation() const { return m_rotation; }
00123   float scale()    const { return m_scale;}
00124   
00125   void addBall(const VEE_Vector3 &loc, float radius);
00126 
00127   void clear();
00128 
00129   void setVoxelSize(float s) { m_scale = 1.0 / s; m_voxelSize = s; }
00130   float voxelSize() const { return m_voxelSize; }
00131 
00132   float & getVoxel(int x, int y, int z, GridGrid ** gptr = 0);
00133   float getVoxel2(int x, int y, int z);
00134 
00135   void triangulate();
00136 
00137   uint triangleCount() const;
00138   uint byteCount() const;
00139   uint ballCount() const { return m_balls.nofBalls(); }
00140 
00141   VEE_MetaBalls * metaBalls() { return & m_balls; }
00142 
00143   GridGrid ** grids() { return & m_gridLinear[0];}
00144   const GridGrid * grid(uint i) const { return m_gridLinear[i];}
00145   uint gridCount() const { return m_gridLinear.size(); }
00146 
00147   VEE_VolumeGrid2 & operator = (const VEE_VolumeGrid2 & that);
00148 
00149 protected:
00150 
00151   typedef std::map<int, GridGrid>    grid_array;
00152   typedef std::map<int, grid_array>  grid_array2;
00153   typedef std::map<int, grid_array2> grid_array3;
00154 
00155   grid_array3 m_grids;
00157   std::vector<GridGrid * > m_gridLinear;
00158 
00159   float m_scale;
00160   float m_voxelSize;
00161   uint  m_firstLevelDivision;
00162 
00163   VEE_BoundingBox m_bbox;
00164 
00165   VEE_Matrix3 m_rotation;
00166   VEE_Matrix3 m_rotationInv;
00167 
00168   VEE_MetaBalls m_balls;
00169   bool m_absoluteCoords;
00170 };
00171 
00172 
00173 #endif

Generated on Mon Mar 12 21:09:01 2007 for VEE - The Visual Effects Engine by  doxygen 1.4.6