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

ModNormalFlippingT.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.14 $
00027 //   $Date: 2004/01/12 17:36:30 $
00028 //                                                                            
00029 //=============================================================================
00030 
00035 //=============================================================================
00036 //
00037 //  CLASS ModNormalFlipping
00038 //
00039 //=============================================================================
00040 
00041 
00042 #ifndef OPENMESH_DECIMATER_MODNORMALFLIPPING_HH
00043 #define OPENMESH_DECIMATER_MODNORMALFLIPPING_HH
00044 
00045 
00046 //== INCLUDES =================================================================
00047 
00048 #include <OpenMesh/Tools/Decimater/ModBaseT.hh>
00049 
00050 //== NAMESPACES ===============================================================
00051 
00052 namespace OpenMesh { // BEGIN_NS_OPENMESH
00053 namespace Decimater { // BEGIN_NS_DECIMATER
00054 
00055 
00056 //== CLASS DEFINITION =========================================================
00057 
00066 template <typename DecimaterT>
00067 class ModNormalFlippingT : public ModBaseT< DecimaterT >
00068 {
00069 public:
00070 
00071   DECIMATING_MODULE( ModNormalFlippingT, DecimaterT, NormalFlipping );
00072 
00073 public:
00074   
00076   ModNormalFlippingT( DecimaterT &_dec) : Base(_dec, true)
00077   {
00078     set_max_normal_deviation( 90.0f );
00079   }
00080   
00081 
00082   ~ModNormalFlippingT() 
00083   { }
00084   
00085 
00086 public:
00087   
00102   float collapse_priority(const CollapseInfo& _ci)
00103   {
00104     // simulate collapse
00105     mesh().set_point(_ci.v0, _ci.p1);
00106     
00107     // check for flipping normals
00108     typename Mesh::ConstVertexFaceIter vf_it(mesh(), _ci.v0);
00109     typename Mesh::FaceHandle          fh;
00110     typename Mesh::Scalar              c(1.0);
00111     
00112     for (; vf_it; ++vf_it) 
00113     {
00114       fh = vf_it.handle();
00115       if (fh != _ci.fl && fh != _ci.fr)
00116       {
00117         typename Mesh::Normal n1 = mesh().normal(fh);
00118         typename Mesh::Normal n2 = mesh().calc_face_normal(fh);
00119 
00120         c = dot(n1, n2);
00121         
00122         if (c < min_cos_)
00123           break;
00124       }
00125     }
00126       
00127     // undo simulation changes
00128     mesh().set_point(_ci.v0, _ci.p0);
00129 
00130     return float( (c < min_cos_) ? ILLEGAL_COLLAPSE : LEGAL_COLLAPSE );
00131   }
00132 
00133 
00134 
00135 public:
00136    
00138   float max_normal_deviation() const { return max_deviation_ / M_PI * 180.0; }
00139   
00141   float normal_deviation() const { return max_normal_deviation(); }
00142   
00148   void set_max_normal_deviation(float _f) { 
00149     max_deviation_ = _f / 180.0 * M_PI; 
00150     min_cos_       = cos(max_deviation_);
00151   }
00152 
00154   void set_normal_deviation(float _f) 
00155   { set_max_normal_deviation(_f); }
00156   
00157 private:
00158 
00159   // hide this method
00160   void set_binary(bool _b) {}
00161    
00162 private:
00163 
00164   // maximum normal deviation
00165   double max_deviation_, min_cos_;
00166 };
00167 
00168 
00169 //=============================================================================
00170 } // END_NS_DECIMATER
00171 } // END_NS_OPENMESH
00172 //=============================================================================
00173 #endif // OPENACG_MODNORMALFLIPPING_HH defined
00174 //=============================================================================
00175 

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