00001 00063 #ifndef COB_DECIMATION_MODULES_H 00064 #define COB_DECIMATION_MODULES_H 00065 00066 #include <OpenMesh/Tools/Decimater/ModBaseT.hh> 00067 00068 namespace OpenMesh 00069 { 00070 namespace Decimater 00071 { 00072 template<typename MeshT> 00073 class ModNormalQuadricT : public OpenMesh::Decimater::ModBaseT<MeshT> 00074 { 00075 public: 00076 // Defines the types Self, Handle, Base, Mesh, and CollapseInfo 00077 // and the memberfunction name() 00078 DECIMATING_MODULE( ModNormalQuadricT, MeshT, NormalQuadric ); 00079 00080 public: 00081 ModNormalQuadricT( MeshT &_mesh ) 00082 : Base(_mesh, false) 00083 { 00084 unset_max_err(); 00085 Base::mesh().add_property( quadrics_ ); 00086 } 00087 00088 virtual ~ModNormalQuadricT() 00089 { 00090 Base::mesh().remove_property(quadrics_); 00091 } 00092 00093 public: // inherited 00094 00095 virtual void initialize(void); 00096 00097 virtual float collapse_priority(const CollapseInfo& _ci) 00098 { 00099 typedef Geometry::QuadricT<double> Q; 00100 00101 Q q = Base::mesh().property(quadrics_, _ci.v0); 00102 q += Base::mesh().property(quadrics_, _ci.v1); 00103 /*Vec3f v = (_ci.p1 + _ci.p0); 00104 v = v * 0.5; 00105 double err = q(v);*/ 00106 double err = q(_ci.p1); 00107 //std::cout << v << " Err: " << err << std::endl; 00108 00109 return float( (err < max_err_) ? err : Base::ILLEGAL_COLLAPSE ); 00110 } 00111 00112 virtual void postprocess_collapse(const CollapseInfo& _ci) 00113 { 00114 Base::mesh().property(quadrics_, _ci.v1) += 00115 Base::mesh().property(quadrics_, _ci.v0); 00116 00117 //Base::mesh().point(_ci.v1) += Base::mesh().point(_ci.v0); 00118 //Base::mesh().point(_ci.v1) *= 0.5; 00119 } 00120 00121 void set_error_tolerance_factor(double _factor); 00122 00123 public: // specific methods 00124 00125 void set_max_err(double _err, bool _binary=true) 00126 { 00127 max_err_ = _err; 00128 Base::set_binary(_binary); 00129 } 00130 00131 void set_normal_property(const VPropHandleT<Vec4f>& normals) 00132 { 00133 normals_ = normals; 00134 } 00135 00136 void set_label_property(const VPropHandleT<int>& labels) 00137 { 00138 labels_ = labels; 00139 } 00140 00141 void unset_max_err(void) { max_err_ = DBL_MAX; Base::set_binary(false); } 00142 double max_err() const { return max_err_; } 00143 00144 private: 00145 double max_err_; 00146 00147 VPropHandleT< Geometry::QuadricT<double> > quadrics_; 00148 VPropHandleT< Vec4f > normals_; 00149 VPropHandleT< int > labels_; 00150 }; 00151 00152 00153 //============================================================================= 00154 } // END_NS_DECIMATER 00155 } // END_NS_OPENMESH 00156 //============================================================================= 00157 00158 #endif