- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# Tools/Smoother/smooth_mesh.hh

    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-12-21 13:58:54 $
    00028 //
    00029 //=============================================================================
    00030
    00031 #ifndef SMOOTH_MESH_HH
    00032 #define SMOOTH_MESH_HH
    00033
    00034 //== INCLUDES =================================================================
    00035
    00036 #include <OpenMesh/Core/Utils/Property.hh>
    00037
    00038 //== NAMESPACE ================================================================
    00039
    00040 namespace OpenMesh { //BEGIN_NS_OPENMESH
    00041
    00042 template <class _Mesh, class _PropertyHandle>
    00043 void smooth_mesh_property(unsigned int _n_iters, _Mesh& _m, _PropertyHandle _pph)
    00044 {
    00045   typedef typename _PropertyHandle::Value   Value;
    00046
    00047   std::vector<Value> temp_values(_m.n_vertices());
    00048
    00049   for (unsigned int i=0; i < _n_iters; ++i)
    00050   {
    00051     for ( typename _Mesh::ConstVertexIter cv_it = _m.vertices_begin();
    00052           cv_it != _m.vertices_end(); ++cv_it)
    00053     {
    00054       unsigned int valence = 0;
    00055
    00056       Value& temp_value = temp_values[cv_it.handle().idx()];
    00057
    00058       temp_value.vectorize(0);
    00059
    00060       for ( typename _Mesh::ConstVertexVertexIter cvv_it = _m.cvv_iter(cv_it);
    00061             cvv_it; ++cvv_it)
    00062       {
    00063         temp_value += _m.property(_pph,cvv_it);
    00064         ++valence;
    00065       }
    00066       if (valence > 0)
    00067       {//guard against isolated vertices
    00068         temp_value *= (1.0 / valence);
    00069       }
    00070       else
    00071       {
    00072         temp_value = _m.property(_pph, cv_it);
    00073       }
    00074     }
    00075
    00076     for ( typename _Mesh::ConstVertexIter cv_it = _m.vertices_begin();
    00077           cv_it != _m.vertices_end(); ++cv_it)
    00078     {
    00079       _m.property(_pph,cv_it) = temp_values[cv_it.handle().idx()];
    00080     }
    00081   }
    00082 }
    00083
    00084 template <class _Mesh>
    00085 void smooth_mesh(_Mesh& _m, uint _n_iters)
    00086 {
    00087   smooth_mesh_property(_n_iters, _m, _m.points_pph());
    00088 }
    00089
    00090 };//namespace OpenMesh
    00091
    00092 #endif//SMOOTH_MESH_HH