OpenMesh
OpenMesh/Tools/Decimater/ModBaseT.hh
Go to the documentation of this file.
00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                               OpenMesh                                    *
00004  *      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openmesh.org                                *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------* 
00008  *  This file is part of OpenMesh.                                           *
00009  *                                                                           *
00010  *  OpenMesh is free software: you can redistribute it and/or modify         * 
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenMesh is distributed in the hope that it will be useful,              *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenMesh.  If not,                                    *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/ 
00034 
00035 /*===========================================================================*\
00036  *                                                                           *             
00037  *   $Revision: 448 $                                                         *
00038  *   $Date: 2011-11-04 13:59:37 +0100 (Fr, 04 Nov 2011) $                   *
00039  *                                                                           *
00040 \*===========================================================================*/
00041 
00046 //=============================================================================
00047 //
00048 //  CLASS ModBaseT
00049 //
00050 //=============================================================================
00051 
00052 #ifndef OPENMESH_DECIMATER_MODBASET_HH
00053 #define OPENMESH_DECIMATER_MODBASET_HH
00054 
00055 
00056 //== INCLUDES =================================================================
00057 
00058 #include <OpenMesh/Core/Utils/Noncopyable.hh>
00059 #include <OpenMesh/Tools/Decimater/CollapseInfoT.hh>
00060 #include <string>
00061 
00062 
00063 //== NAMESPACE ================================================================
00064 
00065 namespace OpenMesh  {
00066 namespace Decimater {
00067 
00068 
00069 //== FORWARD DECLARATIONS =====================================================
00070 
00071 template <typename Mesh> class DecimaterT;
00072 
00073 
00074 //== CLASS DEFINITION =========================================================
00075 
00079 template <typename Module>
00080 class ModHandleT : private Utils::Noncopyable
00081 {
00082 public:
00083 
00084   typedef ModHandleT<Module> Self;
00085   typedef Module module_type;
00086 
00087 public:
00088 
00090   ModHandleT() : mod_(NULL) {} 
00091 
00093   ~ModHandleT() { /* don't delete mod_, since handle is not owner! */ }
00094   
00097   bool is_valid() const { return mod_ != NULL; }
00098 
00099 private:
00100 
00101 #if defined(OM_CC_MSVC)
00102   friend class DecimaterT;
00103 #else
00104   template <typename Mesh> friend class DecimaterT;
00105 #endif
00106 
00107   void     clear()           { mod_ = NULL; }
00108   void     init(Module* _m)  { mod_ = _m;   }
00109   Module*  module()          { return mod_; }
00110 
00111 
00112 private:
00113 
00114   Module* mod_;
00115 
00116 };
00117 
00118 
00119 
00120 
00121 //== CLASS DEFINITION =========================================================
00122 
00123 
00124 
00127 #define DECIMATER_MODNAME(_mod_name) \
00128  virtual const std::string& name() const { \
00129   static std::string _s_modname_(#_mod_name); return _s_modname_; \
00130 }
00131 
00132 
00146 #define DECIMATING_MODULE(Classname, DecimaterT, Name)  \
00147   typedef Classname < DecimaterT >    Self;             \
00148   typedef OpenMesh::Decimater::ModHandleT< Self >     Handle; \
00149   typedef OpenMesh::Decimater::ModBaseT< DecimaterT > Base;   \
00150   typedef typename Base::Mesh         Mesh;             \
00151   typedef typename Base::CollapseInfo CollapseInfo;     \
00152   DECIMATER_MODNAME( Name )
00153 
00154 
00155 
00156 //== CLASS DEFINITION =========================================================
00157 
00158 
00187 template <typename DecimaterType> 
00188 class ModBaseT
00189 {
00190 public:
00191    
00192   typedef typename DecimaterType::Mesh        Mesh;
00193   typedef CollapseInfoT<Mesh>                 CollapseInfo;
00194 
00195   enum {
00196     ILLEGAL_COLLAPSE = -1, 
00197     LEGAL_COLLAPSE   = 0   
00198   };
00199 
00200 protected:
00201    
00204   ModBaseT(DecimaterType& _dec, bool _is_binary) 
00205     : dec_(_dec), is_binary_(_is_binary) {}
00206 
00207 public:
00208 
00210   virtual ~ModBaseT() { } 
00211 
00213   DECIMATER_MODNAME(ModBase);
00214   
00215 
00217   bool is_binary(void) const { return is_binary_; }
00218 
00220   void set_binary(bool _b)   { is_binary_ = _b; }
00221 
00222 
00223 public: // common interface
00224    
00226    virtual void initialize() { }
00227 
00242    virtual float collapse_priority(const CollapseInfoT<Mesh>& /* _ci */)
00243    { return LEGAL_COLLAPSE; }
00244 
00248    virtual void preprocess_collapse(const CollapseInfoT<Mesh>& /* _ci */)
00249    {}
00250 
00254    virtual void postprocess_collapse(const CollapseInfoT<Mesh>& /* _ci */)
00255    {}
00256 
00257 
00258 
00259 protected:
00260 
00262   Mesh& mesh() { return dec_.mesh(); }
00263 
00264 private:
00265 
00266   // hide copy constructor & assignemnt
00267   ModBaseT(const ModBaseT& _cpy);
00268   ModBaseT& operator=(const ModBaseT& );
00269 
00270   // reference to decimater
00271   DecimaterType &dec_;  
00272 
00273   bool is_binary_;
00274 };
00275 
00276 
00277 //=============================================================================
00278 } // namespace Decimater
00279 } // namespace OpenMesh
00280 //=============================================================================
00281 #endif // OPENMESH_DECIMATER_MODBASE_HH defined
00282 //=============================================================================
00283 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines