Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members

# LevelSetSurfaceT.hh

    00001 //=============================================================================
    00002 //
    00003 //  CLASS LevelSetSurfaceT
    00004 //
    00005 //=============================================================================
    00006
    00007
    00008 #ifndef ISOEX_LEVELSETSURFACET_HH
    00009 #define ISOEX_LEVELSETSURFACET_HH
    00010
    00011
    00012 //== INCLUDES =================================================================
    00013
    00014 #include <IsoEx/Grids/ScalarGridT.hh>
    00015
    00016 //== NAMESPACES ===============================================================
    00017
    00018 namespace IsoEx {
    00019
    00020 //== CLASS DEFINITION =========================================================
    00021
    00022
    00030 template <typename Scalar>
    00031 class LevelSetSurfaceT : public ScalarGridT<Scalar>
    00032 {
    00033 public:
    00034
    00035   typedef Scalar _Scalar;
    00036   enum    EvolutionMode { NORMAL, JUST_SHRINK, JUST_GROW };
    00037
    00038
    00039   LevelSetSurfaceT(const OpenMesh::Vec3f&  _origin = OpenMesh::Vec3f(0,0,0),
    00040                    const OpenMesh::Vec3f&  _x_axis = OpenMesh::Vec3f(1,0,0),
    00041                    const OpenMesh::Vec3f&  _y_axis = OpenMesh::Vec3f(0,1,0),
    00042                    const OpenMesh::Vec3f&  _z_axis = OpenMesh::Vec3f(0,0,1),
    00043                    unsigned int            _x_res  = 10,
    00044                    unsigned int            _y_res  = 10,
    00045                    unsigned int            _z_res  = 10);
    00046   virtual ~LevelSetSurfaceT() {}
    00047
    00048
    00049   // read from stream
    00050   virtual bool read(const char* _filename);
    00051   virtual bool read(FILE* _in);
    00052
    00053
    00054   // set evolution mode
    00055   void set_evolution_mode(EvolutionMode _mode) { emode_=_mode; }
    00056
    00057   // update surface
    00058   template <class Force>
    00059   void evolve(const Force& _force, Scalar _timestep);
    00060
    00061   // isotropic diffusion
    00062   void filter(unsigned int _iters);
    00063
    00064
    00065   Scalar dx() const { return dx_; }
    00066   Scalar dy() const { return dy_; }
    00067   Scalar dz() const { return dz_; }
    00068
    00069
    00070   Scalar& speed(unsigned int x, unsigned int y, unsigned int z) {
    00071     return speed_[x + y*x_resolution() + z*x_resolution()*y_resolution()];
    00072   }
    00073   Scalar speed(unsigned int x, unsigned int y, unsigned int z) const {
    00074     return speed_[x + y*x_resolution() + z*x_resolution()*y_resolution()];
    00075   }
    00076
    00077
    00078   Scalar Dx_fwd(unsigned int x, unsigned int y, unsigned int z) const {
    00079     return (value(x+1,y,z) - value(x,y,z)) / dx_;
    00080   }
    00081   Scalar Dy_fwd(unsigned int x, unsigned int y, unsigned int z) const {
    00082     return (value(x,y+1,z) - value(x,y,z)) / dy_;
    00083   }
    00084   Scalar Dz_fwd(unsigned int x, unsigned int y, unsigned int z) const {
    00085     return (value(x,y,z+1) - value(x,y,z)) / dz_;
    00086   }
    00087
    00088
    00089   Scalar Dx_bwd(unsigned int x, unsigned int y, unsigned int z) const {
    00090     return (value(x,y,z) - value(x-1,y,z)) / dx_;
    00091   }
    00092   Scalar Dy_bwd(unsigned int x, unsigned int y, unsigned int z) const {
    00093     return (value(x,y,z) - value(x,y-1,z)) / dy_;
    00094   }
    00095   Scalar Dz_bwd(unsigned int x, unsigned int y, unsigned int z) const {
    00096     return (value(x,y,z) - value(x,y,z-1)) / dz_;
    00097   }
    00098
    00099
    00100   Scalar Dx(unsigned int x, unsigned int y, unsigned int z) const {
    00101     return (value(x+1,y,z) - value(x-1,y,z)) / (2.0*dx_);
    00102   }
    00103   Scalar Dy(unsigned int x, unsigned int y, unsigned int z) const {
    00104     return (value(x,y+1,z) - value(x,y-1,z)) / (2.0*dy_);
    00105   }
    00106   Scalar Dz(unsigned int x, unsigned int y, unsigned int z) const {
    00107     return (value(x,y,z+1) - value(x,y,z-1)) / (2.0*dz_);
    00108   }
    00109
    00110
    00111   Scalar Dxx(unsigned int x, unsigned int y, unsigned int z) const {
    00112     return (value(x-1,y,z) - 2.0*value(x,y,z) + value(x+1,y,z)) / (dx_*dx_);
    00113   }
    00114   Scalar Dyy(unsigned int x, unsigned int y, unsigned int z) const {
    00115     return (value(x,y-1,z) - 2.0*value(x,y,z) + value(x,y+1,z)) / (dy_*dy_);
    00116   }
    00117   Scalar Dzz(unsigned int x, unsigned int y, unsigned int z) const {
    00118     return (value(x,y,z-1) - 2.0*value(x,y,z) + value(x,y,z+1)) / (dz_*dz_);
    00119   }
    00120
    00121
    00122   Scalar Dxy(unsigned int x, unsigned int y, unsigned int z) const {
    00123     return (value(x+1,y+1,z) + value(x-1,y-1,z) -
    00124             value(x+1,y-1,z) - value(x-1,y+1,z)) / (4.0*dx_*dy_);
    00125   }
    00126   Scalar Dxz(unsigned int x, unsigned int y, unsigned int z) const {
    00127     return (value(x+1,y,z+1) + value(x-1,y,z-1) -
    00128             value(x+1,y,z-1) - value(x-1,y,z+1)) / (4.0*dx_*dz_);
    00129   }
    00130   Scalar Dyz(unsigned int x, unsigned int y, unsigned int z) const {
    00131     return (value(x,y+1,z+1) + value(x,y-1,z-1) -
    00132             value(x,y+1,z-1) - value(x,y-1,z+1)) / (4.0*dy_*dz_);
    00133   }
    00134
    00135
    00136   void init();  // changed
    00137
    00138
    00139 private:
    00140
    00141   Scalar sqr(Scalar _f) const { return _f*_f; }
    00142
    00143
    00144 private:
    00145
    00146   typename ScalarGridT<Scalar>::Values  speed_;
    00147   Scalar  dx_, dy_, dz_;
    00148   EvolutionMode  emode_;
    00149 };
    00150
    00151
    00152 //=============================================================================
    00153 } // namespace IsoEx
    00154 //=============================================================================
    00155 #if defined(INCLUDE_TEMPLATES) && !defined(ISOEX_LEVELSETSURFACET_C)
    00156 #define ISOEX_LEVELSETSURFACET_TEMPLATES
    00157 #include "LevelSetSurfaceT.cc"
    00158 #endif
    00159 //=============================================================================
    00160 #endif // ISOEX_LEVELSETSURFACET_HH defined
    00161 //=============================================================================
    00162