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

ModBaseT.hh

Go to the documentation of this file.
00001 //=============================================================================
00002 //                                                                            
00003 //                               OpenMesh                                     
00004 //      Copyright (C) 2001-2005 by Computer Graphics Group, RWTH Aachen       
00005 //                           www.openmesh.org                                 
00006 //                                                                            
00007 //-----------------------------------------------------------------------------
00008 //                                                                            
00009 //                                License                                     
00010 //                                                                            
00011 //   This library is free software; you can redistribute it and/or modify it 
00012 //   under the terms of the GNU Library General Public License as published  
00013 //   by the Free Software Foundation, version 2.                             
00014 //                                                                             
00015 //   This library is distributed in the hope that it will be useful, but       
00016 //   WITHOUT ANY WARRANTY; without even the implied warranty of                
00017 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         
00018 //   Library General Public License for more details.                          
00019 //                                                                            
00020 //   You should have received a copy of the GNU Library General Public         
00021 //   License along with this library; if not, write to the Free Software       
00022 //   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 
00023 //                                                                            
00024 //-----------------------------------------------------------------------------
00025 //                                                                            
00026 //   $Revision: 1.3 $
00027 //   $Date: 2005/04/19 08:01:10 $
00028 //                                                                            
00029 //=============================================================================
00030 
00035 //=============================================================================
00036 //
00037 //  CLASS ModBaseT
00038 //
00039 //=============================================================================
00040 
00041 #ifndef OPENMESH_DECIMATER_MODBASET_HH
00042 #define OPENMESH_DECIMATER_MODBASET_HH
00043 
00044 
00045 //== INCLUDES =================================================================
00046 
00047 #include <OpenMesh/Core/Utils/Noncopyable.hh>
00048 #include <OpenMesh/Tools/Decimater/CollapseInfoT.hh>
00049 #include <string>
00050 
00051 
00052 //== NAMESPACE ================================================================
00053 
00054 namespace OpenMesh  {
00055 namespace Decimater {
00056 
00057 
00058 //== FORWARD DECLARATIONS =====================================================
00059 
00060 template <typename Mesh> class DecimaterT;
00061 
00062 
00063 //== CLASS DEFINITION =========================================================
00064 
00068 template <typename Module>
00069 class ModHandleT : private Utils::Noncopyable
00070 {
00071 public:
00072 
00073   typedef ModHandleT<Module> Self;
00074   typedef Module module_type;
00075 
00076 public:
00077 
00079   ModHandleT() : mod_(NULL) {} 
00080 
00082   ~ModHandleT() { /* don't delete mod_, since handle is not owner! */ }
00083   
00086   bool is_valid() const { return mod_ != NULL; }
00087 
00088 private:
00089 
00090 #if defined(OM_CC_MSVC)
00091   friend class DecimaterT;
00092 #else
00093   template <typename Mesh> friend class DecimaterT;
00094 #endif
00095 
00096   void     clear()           { mod_ = NULL; }
00097   void     init(Module* _m)  { mod_ = _m;   }
00098   Module*  module()          { return mod_; }
00099 
00100 
00101 private:
00102 
00103   Module* mod_;
00104 
00105 };
00106 
00107 
00108 
00109 
00110 //== CLASS DEFINITION =========================================================
00111 
00112 
00113 
00116 #define DECIMATER_MODNAME(_mod_name) \
00117  virtual const std::string& name() const { \
00118   static std::string _s_modname_(#_mod_name); return _s_modname_; \
00119 }
00120 
00121 
00135 #define DECIMATING_MODULE(Classname, DecimaterT, Name)  \
00136   typedef Classname < DecimaterT >    Self;             \
00137   typedef OpenMesh::Decimater::ModHandleT< Self >     Handle; \
00138   typedef OpenMesh::Decimater::ModBaseT< DecimaterT > Base;   \
00139   typedef typename Base::Mesh         Mesh;             \
00140   typedef typename Base::CollapseInfo CollapseInfo;     \
00141   DECIMATER_MODNAME( Name )
00142 
00143 
00144 
00145 //== CLASS DEFINITION =========================================================
00146 
00147 
00176 template <typename DecimaterType> 
00177 class ModBaseT
00178 {
00179 public:
00180    
00181   typedef typename DecimaterType::Mesh        Mesh;
00182   typedef CollapseInfoT<Mesh>                 CollapseInfo;
00183 
00184   enum {
00185     ILLEGAL_COLLAPSE = -1, 
00186     LEGAL_COLLAPSE   = 0   
00187   };
00188 
00189 protected:
00190    
00193   ModBaseT(DecimaterType& _dec, bool _is_binary) 
00194     : dec_(_dec), is_binary_(_is_binary) {}
00195 
00196 public:
00197 
00199   virtual ~ModBaseT() { } 
00200 
00202   DECIMATER_MODNAME(ModBase);
00203   
00204 
00206   bool is_binary(void) const { return is_binary_; }
00207 
00209   void set_binary(bool _b)   { is_binary_ = _b; }
00210 
00211 
00212 public: // common interface
00213    
00215    virtual void initialize() { }
00216 
00231    virtual float collapse_priority(const CollapseInfoT<Mesh>& _ci)
00232    { return LEGAL_COLLAPSE; }
00233 
00234 
00238    virtual void preprocess_collapse(const CollapseInfoT<Mesh>& _ci)
00239    {}
00240 
00244    virtual void postprocess_collapse(const CollapseInfoT<Mesh>& _ci)
00245    {}
00246 
00247 
00248 
00249 protected:
00250 
00252   Mesh& mesh() { return dec_.mesh(); }
00253 
00254 private:
00255 
00256   // hide copy constructor & assignemnt
00257   ModBaseT(const ModBaseT& _cpy);
00258   ModBaseT& operator=(const ModBaseT& );
00259 
00260   // reference to decimater
00261   DecimaterType &dec_;  
00262 
00263   bool is_binary_;
00264 };
00265 
00266 
00267 //=============================================================================
00268 } // namespace Decimater
00269 } // namespace OpenMesh
00270 //=============================================================================
00271 #endif // OPENMESH_DECIMATER_MODBASE_HH defined
00272 //=============================================================================
00273 

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .