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

ImplicitGrid.hh

00001 //=============================================================================
00002 //
00003 //  CLASS ImplicitGrid
00004 //
00005 //=============================================================================
00006 
00007 
00008 #ifndef ISOEX_IMPLICITGRID_HH
00009 #define ISOEX_IMPLICITGRID_HH
00010 
00011 
00012 //== INCLUDES =================================================================
00013 
00014 #include <IsoEx/Grids/RegularGrid.hh>
00015 #include <IsoEx/Implicits/Implicit.hh>
00016 #include <OpenMesh/Core/Math/VectorT.hh>
00017 #include <vector>
00018 
00019 //== NAMESPACES ===============================================================
00020 
00021 namespace IsoEx {
00022 
00023 //== CLASS DEFINITION =========================================================
00024 
00025               
00038 class ImplicitGrid : public RegularGrid
00039 {
00040 public:
00041    
00042   //------------------------------------------------------------ public methods
00043 
00044 
00046   ImplicitGrid(const Implicit& _implicit,
00047                const OpenMesh::Vec3f&  _origin,
00048                const OpenMesh::Vec3f&  _x_axis,
00049                const OpenMesh::Vec3f&  _y_axis,
00050                const OpenMesh::Vec3f&  _z_axis,
00051                unsigned int            _x_res,
00052                unsigned int            _y_res,
00053                unsigned int            _z_res) 
00054     : RegularGrid(_origin, _x_axis, _y_axis, _z_axis, _x_res, _y_res, _z_res),
00055       implicit_(_implicit) 
00056   {}
00057 
00059   virtual ~ImplicitGrid() {}
00060 
00061 
00062 
00064 
00065 
00067   virtual bool is_inside(PointIdx _pidx) const {
00068     return (is_inside_cache_.empty() ? 
00069             implicit_.is_inside(point(_pidx)) :
00070             is_inside_cache_[_pidx]);
00071   }
00072 
00074   virtual float scalar_distance(PointIdx _pidx) const {
00075     return (scalar_distance_cache_.empty() ? 
00076             implicit_.scalar_distance(point(_pidx)) :
00077             scalar_distance_cache_[_pidx]);
00078   }
00079 
00081   virtual bool directed_distance(const OpenMesh::Vec3f&  _p0,
00082                                  const OpenMesh::Vec3f&  _p1,
00083                                  OpenMesh::Vec3f&        _point,
00084                                  OpenMesh::Vec3f&        _normal,
00085                                  float&                  _distance) const {
00086     return implicit_.directed_distance(_p0, _p1, _point, _normal, _distance);
00087   }
00088   
00090 
00091 
00092 
00094 
00095 
00097   void build_is_inside_cache() const
00098   {
00099     int i, np(n_points());
00100     
00101     is_inside_cache_.clear();
00102     is_inside_cache_.resize(n_points());
00103 
00104     for (i=0; i<np; ++i)
00105       is_inside_cache_[i] = implicit_.is_inside(point(i));
00106   }
00107 
00109   void build_scalar_distance_cache() const
00110   {
00111     int i, np(n_points());
00112 
00113     scalar_distance_cache_.clear();
00114     scalar_distance_cache_.resize(np);
00115 
00116     for (i=0; i<np; ++i)
00117       scalar_distance_cache_[i] = implicit_.scalar_distance(point(i));
00118   }
00119 
00121 
00122 
00123  
00124 protected:
00125 
00126   const Implicit&     implicit_;
00127 
00128   mutable std::vector<bool>   is_inside_cache_;
00129   mutable std::vector<float>  scalar_distance_cache_;
00130 };
00131 
00132 
00133 //=============================================================================
00134 } // namespace IsoEx
00135 //=============================================================================
00136 #endif // ISOEX_IMPLICITGRID_HH defined
00137 //=============================================================================

Generated on Mon Jul 5 18:07:08 2004 for IsoEx by doxygen 1.3.6-20040222