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

ModNormalFlippingT.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:10 $
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   typedef typename Mesh::Scalar  Scalar;
00074   
00075 
00076   ModNormalFlippingT( DecimaterT &_dec) 
00077     : Base(_dec, true), mesh_(Self::mesh())
00078   {
00079     set_max_normal_deviation( 90.0f );
00080   }
00081   
00082 
00083   
00098   float collapse_priority(const CollapseInfo& _ci)
00099   {
00100     // simulate collapse
00101     mesh_.set_point(_ci.v0, _ci.p1);
00102     
00103     // check for flipping normals
00104     typename Mesh::ConstVertexFaceIter vf_it(mesh_, _ci.v0);
00105     typename Mesh::FaceHandle          fh;
00106     typename Mesh::Scalar              c(1.0);
00107     
00108     for (; vf_it; ++vf_it) 
00109     {
00110       fh = vf_it.handle();
00111       if (fh != _ci.fl && fh != _ci.fr)
00112       {
00113         typename Mesh::Normal n1 = mesh_.normal(fh);
00114         typename Mesh::Normal n2 = mesh_.calc_face_normal(fh);
00115 
00116         c = dot(n1, n2);
00117         
00118         if (c < min_cos_)
00119           break;
00120       }
00121     }
00122       
00123     // undo simulation changes
00124     mesh_.set_point(_ci.v0, _ci.p0);
00125 
00126     return float( (c < min_cos_) ? 
00127                   Self::ILLEGAL_COLLAPSE : 
00128                   Self::LEGAL_COLLAPSE );
00129   }
00130 
00131 
00132 
00134   Scalar max_normal_deviation() const { return max_deviation_ / M_PI * 180.0; }
00135   
00136   
00142   void set_max_normal_deviation(Scalar _f) { 
00143     max_deviation_ = (Scalar)(_f / 180.0 * M_PI); 
00144     min_cos_       = cos(max_deviation_);
00145   }
00146 
00147   
00148   
00149   // only binary mode possible
00150   void set_binary(bool _b) 
00151   {
00152     if (!_b)
00153     {
00154       std::cerr << "ModNormalFlippingT can only be used binary\n";
00155       exit(1);
00156     }
00157   }
00158    
00159 
00160 private:
00161 
00162   Mesh&   mesh_;
00163   Scalar  max_deviation_, min_cos_;
00164 };
00165 
00166 
00167 //=============================================================================
00168 } // END_NS_DECIMATER
00169 } // END_NS_OPENMESH
00170 //=============================================================================
00171 #endif // OPENACG_MODNORMALFLIPPING_HH defined
00172 //=============================================================================
00173 

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