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
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef OSG_MODQUADRIC_HH
00039 #define OSG_MODQUADRIC_HH
00040
00041
00042
00043
00044
00045 #include <OpenMesh/Tools/Decimater/ModBaseT.hh>
00046 #include <OpenMesh/Core/Utils/Property.hh>
00047 #include <OpenMesh/Core/Utils/vector_cast.hh>
00048 #include <OpenMesh/Tools/Geometry/QuadricT.hh>
00049
00050
00051
00052
00053 namespace OpenMesh {
00054 namespace Decimater {
00055
00056
00057
00058
00059
00064 template <class DecimaterType>
00065 class ModQuadricT : public ModBaseT<DecimaterType>
00066 {
00067 public:
00068
00069
00070
00071 DECIMATING_MODULE( ModQuadricT, DecimaterType, Quadric );
00072
00073 public:
00074
00078 ModQuadricT( DecimaterType &_dec )
00079 : Base(_dec, false)
00080 {
00081 unset_max_err();
00082 mesh().add_property( quadrics_ );
00083 }
00084
00085
00087 virtual ~ModQuadricT()
00088 {
00089 mesh().remove_property(quadrics_);
00090 }
00091
00092
00093 public:
00094
00096 virtual void initialize(void);
00097
00103 virtual float collapse_priority(const CollapseInfo& _ci)
00104 {
00105 using namespace OpenMesh;
00106
00107 typedef Geometry::QuadricT<double> Q;
00108
00109 Q q = mesh().property(quadrics_, _ci.v0);
00110 q += mesh().property(quadrics_, _ci.v1);
00111
00112 typename Q::Vec3 p =
00113 vector_cast<typename Q::Vec3>(_ci.p1);
00114
00115 double err = q( p );
00116
00117 return float( (err < max_err_) ? err : ILLEGAL_COLLAPSE );
00118 }
00119
00120
00122 virtual void postprocess_collapse(const CollapseInfo& _ci)
00123 {
00124 mesh().property(quadrics_, _ci.v1) +=
00125 mesh().property(quadrics_, _ci.v0);
00126 }
00127
00128
00129
00130 public:
00131
00138 void set_max_err(double _err, bool _binary=true)
00139 {
00140 max_err_ = _err;
00141 set_binary(_binary);
00142 }
00143
00146 void unset_max_err(void)
00147 {
00148 max_err_ = DBL_MAX;
00149 set_binary(false);
00150 }
00151
00153 double max_err() const { return max_err_; }
00154
00155
00156 private:
00157
00158
00159 double max_err_;
00160
00161
00162 VPropHandleT< Geometry::QuadricT<double> > quadrics_;
00163 };
00164
00165
00166 }
00167 }
00168
00169 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_DECIMATER_MODQUADRIC_CC)
00170 #define OSG_MODQUADRIC_TEMPLATES
00171 #include "ModQuadricT.cc"
00172 #endif
00173
00174 #endif // OSG_MODQUADRIC_HH defined
00175
00176