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

ModQuadricT.hh

Go to the documentation of this file.
00001 //=============================================================================
00002 //                                                                            
00003 //                               OpenMesh                                     
00004 //        Copyright (C) 2003 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.19 $
00027 //   $Date: 2004/01/12 17:36:30 $
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 
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)
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     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: // specific methods
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   // maximum quadric error
00159   double max_err_;
00160 
00161   // this vertex property stores a quadric for each vertex
00162   VPropHandleT< Geometry::QuadricT<double> >  quadrics_;
00163 };
00164 
00165 //=============================================================================
00166 } // END_NS_DECIMATER
00167 } // END_NS_OPENMESH
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 

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