OpenMesh
OpenMesh/Tools/Decimater/ModNormalFlippingT.hh
Go to the documentation of this file.
00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                               OpenMesh                                    *
00004  *      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openmesh.org                                *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------* 
00008  *  This file is part of OpenMesh.                                           *
00009  *                                                                           *
00010  *  OpenMesh is free software: you can redistribute it and/or modify         * 
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenMesh is distributed in the hope that it will be useful,              *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenMesh.  If not,                                    *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/ 
00034 
00035 /*===========================================================================*\
00036  *                                                                           *             
00037  *   $Revision: 362 $                                                         *
00038  *   $Date: 2011-01-26 10:21:12 +0100 (Mi, 26 Jan 2011) $                   *
00039  *                                                                           *
00040 \*===========================================================================*/
00041 
00046 //=============================================================================
00047 //
00048 //  CLASS ModNormalFlipping
00049 //
00050 //=============================================================================
00051 
00052 
00053 #ifndef OPENMESH_DECIMATER_MODNORMALFLIPPING_HH
00054 #define OPENMESH_DECIMATER_MODNORMALFLIPPING_HH
00055 
00056 
00057 //== INCLUDES =================================================================
00058 
00059 #include <OpenMesh/Tools/Decimater/ModBaseT.hh>
00060 
00061 //== NAMESPACES ===============================================================
00062 
00063 namespace OpenMesh { // BEGIN_NS_OPENMESH
00064 namespace Decimater { // BEGIN_NS_DECIMATER
00065 
00066 
00067 //== CLASS DEFINITION =========================================================
00068 
00077 template <typename DecimaterT>
00078 class ModNormalFlippingT : public ModBaseT< DecimaterT >
00079 { 
00080 public:
00081 
00082   DECIMATING_MODULE( ModNormalFlippingT, DecimaterT, NormalFlipping );
00083 
00084 public:
00085   
00087   ModNormalFlippingT( DecimaterT &_dec) : Base(_dec, true)
00088   {
00089     set_max_normal_deviation( 90.0f );
00090   }
00091   
00092 
00093   ~ModNormalFlippingT() 
00094   { }
00095   
00096 
00097 public:
00098   
00113   float collapse_priority(const CollapseInfo& _ci)
00114   {
00115     // simulate collapse
00116     Base::mesh().set_point(_ci.v0, _ci.p1);
00117     
00118     // check for flipping normals
00119     typename Mesh::ConstVertexFaceIter vf_it(Base::mesh(), _ci.v0);
00120     typename Mesh::FaceHandle          fh;
00121     typename Mesh::Scalar              c(1.0);
00122     
00123     for (; vf_it; ++vf_it) 
00124     {
00125       fh = vf_it.handle();
00126       if (fh != _ci.fl && fh != _ci.fr)
00127       {
00128         typename Mesh::Normal n1 = Base::mesh().normal(fh);
00129         typename Mesh::Normal n2 = Base::mesh().calc_face_normal(fh);
00130 
00131         c = dot(n1, n2);
00132         
00133         if (c < min_cos_)
00134           break;
00135       }
00136     }
00137       
00138     // undo simulation changes
00139     Base::mesh().set_point(_ci.v0, _ci.p0);
00140 
00141     return float( (c < min_cos_) ? Base::ILLEGAL_COLLAPSE : Base::LEGAL_COLLAPSE );
00142   }
00143 
00144 
00145 
00146 public:
00147    
00149   float max_normal_deviation() const { return max_deviation_ / M_PI * 180.0; }
00150   
00152   float normal_deviation() const { return max_normal_deviation(); }
00153   
00159   void set_max_normal_deviation(float _f) { 
00160     max_deviation_ = _f / 180.0 * M_PI; 
00161     min_cos_       = cos(max_deviation_);
00162   }
00163 
00165   void set_normal_deviation(float _f) 
00166   { set_max_normal_deviation(_f); }
00167   
00168 private:
00169 
00170   // hide this method
00171   void set_binary(bool _b) {}
00172    
00173 private:
00174 
00175   // maximum normal deviation
00176   double max_deviation_, min_cos_;
00177 };
00178 
00179 
00180 //=============================================================================
00181 } // END_NS_DECIMATER
00182 } // END_NS_OPENMESH
00183 //=============================================================================
00184 #endif // OPENACG_MODNORMALFLIPPING_HH defined
00185 //=============================================================================
00186