OpenMesh
OpenMesh/Tools/Smoother/SmootherT.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 SmootherT
00049 //
00050 //=============================================================================
00051 
00052 #ifndef OPENMESH_SMOOTHER_SMOOTHERT_HH
00053 #define OPENMESH_SMOOTHER_SMOOTHERT_HH
00054 
00055 
00056 //== INCLUDES =================================================================
00057 
00058 #include <OpenMesh/Core/System/config.hh>
00059 #include <OpenMesh/Core/Utils/Property.hh>
00060 #include <OpenMesh/Core/Utils/Noncopyable.hh>
00061 
00062 //== FORWARDDECLARATIONS ======================================================
00063 
00064 //== NAMESPACES ===============================================================
00065 
00066 namespace OpenMesh {
00067 namespace Smoother {
00068 
00069 //== CLASS DEFINITION =========================================================
00070 
00073 template <class Mesh>
00074 class SmootherT : private Utils::Noncopyable
00075 {
00076 public:
00077 
00078   typedef typename Mesh::Scalar        Scalar;
00079   typedef typename Mesh::Point         Point;
00080   typedef typename Mesh::Normal        NormalType;
00081   typedef typename Mesh::VertexHandle  VertexHandle;
00082   typedef typename Mesh::EdgeHandle    EdgeHandle;
00083 
00084   // initialize smoother
00085   enum Component {
00086     Tangential,           
00087     Normal,               
00088     Tangential_and_Normal 
00089   };
00090 
00091   enum Continuity {
00092     C0,
00093     C1,
00094     C2
00095   };
00096 
00097 public:
00098 
00103   SmootherT( Mesh& _mesh );
00104   virtual ~SmootherT();
00105 
00106 
00107 public:
00108 
00113   void initialize(Component _comp, Continuity _cont);
00114 
00115 
00117 
00118   void set_relative_local_error(Scalar _err);
00119   void set_absolute_local_error(Scalar _err);
00120   void disable_local_error_check();
00122 
00128   void skip_features( bool _state ){ skip_features_ = _state; };
00129 
00131   virtual void smooth(unsigned int _n);
00132 
00133 
00134 
00136   void set_active_vertices();
00137 
00138 
00139 private:
00140 
00141   // single steps of smoothing
00142   void compute_new_positions();
00143   void project_to_tangent_plane();
00144   void local_error_check();
00145   void move_points();
00146 
00147 
00148 
00149 protected:
00150 
00151   // override these
00152   virtual void compute_new_positions_C0() = 0;
00153   virtual void compute_new_positions_C1() = 0;
00154 
00155 
00156 
00157 protected:
00158 
00159   // misc helpers
00160 
00161   const Point& orig_position(VertexHandle _vh) const
00162   { return mesh_.property(original_positions_, _vh); }
00163 
00164   const NormalType& orig_normal(VertexHandle _vh) const
00165   { return mesh_.property(original_normals_, _vh); }
00166 
00167   const Point& new_position(VertexHandle _vh) const
00168   { return mesh_.property(new_positions_, _vh); }
00169 
00170   void set_new_position(VertexHandle _vh, const Point& _p)
00171   { mesh_.property(new_positions_, _vh) = _p; }
00172 
00173   bool is_active(VertexHandle _vh) const
00174   { return mesh_.property(is_active_, _vh); }
00175 
00176   Component  component()  const { return component_;  }
00177   Continuity continuity() const { return continuity_; }
00178 
00179 protected:
00180 
00181   Mesh&  mesh_;
00182   bool   skip_features_;
00183 
00184 
00185 private:
00186 
00187   Scalar      tolerance_;
00188   Scalar      normal_deviation_;
00189   Component   component_;
00190   Continuity  continuity_;
00191 
00192   OpenMesh::VPropHandleT<Point>      original_positions_;
00193   OpenMesh::VPropHandleT<NormalType> original_normals_;
00194   OpenMesh::VPropHandleT<Point>      new_positions_;
00195   OpenMesh::VPropHandleT<bool>       is_active_;
00196 };
00197 
00198 
00199 //=============================================================================
00200 } // namespace Smoother
00201 } // namespace OpenMesh
00202 //=============================================================================
00203 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_SMOOTHERT_C)
00204 #define OPENMESH_SMOOTHERT_TEMPLATES
00205 #include "SmootherT.cc"
00206 #endif
00207 //=============================================================================
00208 #endif // OPENMESH_SMOOTHER_SMOOTHERT_HH defined
00209 //=============================================================================
00210 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines