Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ModQuadricT.hh

Go to the documentation of this file.
00001 //=============================================================================
00002 //
00003 //                               OpenMesh
00004 //      Copyright (C) 2001-2005 by Computer Graphics Group, RWTH Aachen
00005 //                           www.openmesh.org
00006 //
00007 //-----------------------------------------------------------------------------
00008 //
00009 //                                License
00010 //
00011 //   This library is free software; you can redistribute it and/or modify it
00012 //   under the terms of the GNU Library General Public License as published
00013 //   by the Free Software Foundation, version 2.
00014 //
00015 //   This library is distributed in the hope that it will be useful, but
00016 //   WITHOUT ANY WARRANTY; without even the implied warranty of
00017 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 //   Library General Public License for more details.
00019 //
00020 //   You should have received a copy of the GNU Library General Public
00021 //   License along with this library; if not, write to the Free Software
00022 //   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00023 //
00024 //-----------------------------------------------------------------------------
00025 //
00026 //   $Revision: 1.2 $
00027 //   $Date: 2005/04/18 09:07:11 $
00028 //
00029 //=============================================================================
00030 
00031 
00032 //=============================================================================
00033 //
00034 //  CLASS ModQuadricT
00035 //
00036 //=============================================================================
00037 
00038 #ifndef OSG_MODQUADRIC_HH
00039 #define OSG_MODQUADRIC_HH
00040 
00041 
00042 //== INCLUDES =================================================================
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 //== NAMESPACE ================================================================
00052 
00053 namespace OpenMesh  {
00054 namespace Decimater {
00055 
00056 
00057 //== CLASS DEFINITION =========================================================
00058 
00059 
00064 template <class DecimaterType>
00065 class ModQuadricT : public ModBaseT<DecimaterType>
00066 {
00067 public:
00068 
00069   // Defines the types Self, Handle, Base, Mesh, and CollapseInfo
00070   // and the memberfunction name()
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: // inherited
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     //min_ = std::min(err, min_);
00115     //max_ = std::max(err, max_);
00116 
00117     //double err = q( p );
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: // specific methods
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   // maximum quadric error
00163   double max_err_;
00164 
00165   // this vertex property stores a quadric for each vertex
00166   VPropHandleT< Geometry::QuadricT<double> >  quadrics_;
00167 };
00168 
00169 //=============================================================================
00170 } // END_NS_DECIMATER
00171 } // END_NS_OPENMESH
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 

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .