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

ModRoundnessT.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 
00035 //=============================================================================
00036 //
00037 //  CLASS ModRoundnessT
00038 //
00039 //=============================================================================
00040 
00041 #ifndef OPENMESH_TOOLS_MODROUNDNESST_HH
00042 #define OPENMESH_TOOLS_MODROUNDNESST_HH
00043 
00044 
00045 //== INCLUDES =================================================================
00046 
00047 #include <OpenMesh/Tools/Decimater/ModBaseT.hh>
00048 #include <math.h>
00049 
00050 
00051 
00052 //== NAMESPACE ================================================================
00053 
00054 namespace OpenMesh { // BEGIN_NS_OPENMESH
00055 namespace Decimater { // BEGIN_NS_DECIMATER
00056 
00057 
00058 //== CLASS DEFINITION =========================================================
00059 
00060 
00063 template <class DecimaterType>
00064 class ModRoundnessT : public ModBaseT<DecimaterType>
00065 {
00066 public:
00067 
00068   DECIMATING_MODULE( ModRoundnessT, DecimaterType, Roundness );
00069 
00070   typedef typename Mesh::Point   Point;
00071   typedef typename Mesh::Scalar  Scalar;
00072 
00073 
00075   ModRoundnessT( DecimaterType &_dec ) 
00076     : Base(_dec, true), mesh_(Self::mesh()), min_roundness_(0.2f) 
00077   {}
00078  
00079 
00080 
00081 public:
00082    
00083 
00084   float collapse_priority(const CollapseInfo& _ci)  
00085   {    
00086     typename Mesh::VertexHandle  v2, v3;
00087     typename Mesh::Scalar        r, rmin(1.0);
00088     typename Mesh::CVVIter       vv_it(mesh_, _ci.v0);
00089     
00090 
00091     v3 = vv_it.handle();
00092     while (vv_it) 
00093     {
00094       v2 = v3;
00095       v3 = (++vv_it).handle(); 
00096       
00097       // if not boundary
00098       if (mesh_.face_handle(vv_it.current_halfedge_handle()).is_valid())
00099       {
00100         if (v2 != _ci.v1 && v3 != _ci.v1)
00101         {
00102           r = roundness(_ci.p1, mesh_.point(v2), mesh_.point(v3));
00103           if (r < rmin) rmin = r;
00104         }
00105       }
00106     }
00107 
00108 
00109     if (Base::is_binary())
00110     {
00111       return (rmin > min_roundness_) ? 0.0f : -1.0f;
00112     }
00113     else
00114     {
00115       return (rmin > min_roundness_) ? 1.0f - rmin : -1.0f;
00116     }
00117   }
00118   
00119    
00120 
00124   void set_min_roundness( Scalar _min_roundness )
00125   {
00126     assert( 0.0 <= _min_roundness && _min_roundness <= 1.0 );
00127     min_roundness_  = _min_roundness;
00128   }
00129 
00130 
00131 
00132   // compute roundness as 1.16 / aspect_ratio
00133   Scalar roundness(const Point& _v0, const Point& _v1, const Point& _v2) const
00134   {
00135     const double FOUR_ROOT3 = 6.928203230275509;
00136     const double area = 0.5*((_v1-_v0)%(_v2-_v0)).norm();
00137     return (Scalar) (FOUR_ROOT3 * area / ((_v0-_v1).sqrnorm() +
00138                                           (_v1-_v2).sqrnorm() +
00139                                           (_v2-_v0).sqrnorm() ));
00140   }
00141 
00142 
00143 
00144 private:
00145   
00146   Mesh&   mesh_;
00147   Scalar  min_roundness_;
00148 };
00149 
00150 
00151 //=============================================================================
00152 } // END_NS_DECIMATER
00153 } // END_NS_OPENMESH
00154 //=============================================================================
00155 #endif // OPENMESH_TOOLS_PROGMESHT_HH defined
00156 //=============================================================================
00157 

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