00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00035
00036
00037
00038
00039
00040
00041 #ifndef OPENMESH_DECIMATER_MODBASET_HH
00042 #define OPENMESH_DECIMATER_MODBASET_HH
00043
00044
00045
00046
00047 #include <OpenMesh/Core/Utils/Noncopyable.hh>
00048 #include <OpenMesh/Tools/Decimater/CollapseInfoT.hh>
00049 #include <string>
00050
00051
00052
00053
00054 namespace OpenMesh {
00055 namespace Decimater {
00056
00057
00058
00059
00060 template <typename Mesh> class DecimaterT;
00061
00062
00063
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() { }
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
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
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:
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
00257 ModBaseT(const ModBaseT& _cpy);
00258 ModBaseT& operator=(const ModBaseT& );
00259
00260
00261 DecimaterType &dec_;
00262
00263 bool is_binary_;
00264 };
00265
00266
00267
00268 }
00269 }
00270
00271 #endif // OPENMESH_DECIMATER_MODBASE_HH defined
00272
00273