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 #include <float.h>
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), mesh_(Self::mesh())
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 double err = q(_ci.p1);
00113
00114
00115
00116
00117
00118
00119 return float( (err < max_err_) ? err : Self::ILLEGAL_COLLAPSE );
00120 }
00121
00122
00124 virtual void postprocess_collapse(const CollapseInfo& _ci)
00125 {
00126 mesh_.property(quadrics_, _ci.v1) +=
00127 mesh_.property(quadrics_, _ci.v0);
00128 }
00129
00130
00131
00132 public:
00133
00140 void set_max_err(double _err, bool _binary=true)
00141 {
00142 max_err_ = _err;
00143 Self::set_binary(_binary);
00144 }
00145
00148 void unset_max_err(void)
00149 {
00150 max_err_ = DBL_MAX;
00151 Self::set_binary(false);
00152 }
00153
00155 double max_err() const { return max_err_; }
00156
00157
00158 private:
00159
00160 Mesh& mesh_;
00161
00162
00163 double max_err_;
00164
00165
00166 VPropHandleT< Geometry::QuadricT<double> > quadrics_;
00167 };
00168
00169
00170 }
00171 }
00172
00173 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_DECIMATER_MODQUADRIC_CC)
00174 #define OSG_MODQUADRIC_TEMPLATES
00175 #include "ModQuadricT.cc"
00176 #endif
00177
00178 #endif // OSG_MODQUADRIC_HH defined
00179
00180