OpenMesh
smooth_mesh.hh
1 /*===========================================================================*\
2  * *
3  * OpenMesh *
4  * Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen *
5  * www.openmesh.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenMesh. *
9  * *
10  * OpenMesh is free software: you can redistribute it and/or modify *
11  * it under the terms of the GNU Lesser General Public License as *
12  * published by the Free Software Foundation, either version 3 of *
13  * the License, or (at your option) any later version with the *
14  * following exceptions: *
15  * *
16  * If other files instantiate templates or use macros *
17  * or inline functions from this file, or you compile this file and *
18  * link it with other files to produce an executable, this file does *
19  * not by itself cause the resulting executable to be covered by the *
20  * GNU Lesser General Public License. This exception does not however *
21  * invalidate any other reasons why the executable file might be *
22  * covered by the GNU Lesser General Public License. *
23  * *
24  * OpenMesh is distributed in the hope that it will be useful, *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27  * GNU Lesser General Public License for more details. *
28  * *
29  * You should have received a copy of the GNU LesserGeneral Public *
30  * License along with OpenMesh. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision: 990 $ *
38  * $Date: 2014-02-05 10:01:07 +0100 (Mi, 05 Feb 2014) $ *
39  * *
40 \*===========================================================================*/
41 
42 #ifndef SMOOTH_MESH_HH
43 #define SMOOTH_MESH_HH
44 
45 //== INCLUDES =================================================================
46 
47 #include <OpenMesh/Core/Utils/Property.hh>
48 
49 //== NAMESPACE ================================================================
50 
51 namespace OpenMesh { //BEGIN_NS_OPENMESH
52 
53 template <class _Mesh, class _PropertyHandle>
54 void smooth_mesh_property(unsigned int _n_iters, _Mesh& _m, _PropertyHandle _pph)
55 {
56  typedef typename _PropertyHandle::Value Value;
57 
58  std::vector<Value> temp_values(_m.n_vertices());
59 
60  for (unsigned int i=0; i < _n_iters; ++i)
61  {
62  for ( typename _Mesh::ConstVertexIter cv_it = _m.vertices_begin();
63  cv_it != _m.vertices_end(); ++cv_it)
64  {
65  unsigned int valence = 0;
66 
67  Value& temp_value = temp_values[cv_it->idx()];
68 
69  temp_value.vectorize(0);
70 
71  for ( typename _Mesh::ConstVertexVertexIter cvv_it = _m.cvv_iter(cv_it);
72  cvv_it; ++cvv_it)
73  {
74  temp_value += _m.property(_pph,cvv_it);
75  ++valence;
76  }
77  if (valence > 0)
78  {//guard against isolated vertices
79  temp_value *= (typename Value::value_type)(1.0 / valence);
80  }
81  else
82  {
83  temp_value = _m.property(_pph, cv_it);
84  }
85  }
86 
87  for ( typename _Mesh::ConstVertexIter cv_it = _m.vertices_begin();
88  cv_it != _m.vertices_end(); ++cv_it)
89  {
90  _m.property(_pph,cv_it) = temp_values[cv_it->idx()];
91  }
92  }
93 }
94 
95 template <class _Mesh>
96 void smooth_mesh(_Mesh& _m, uint _n_iters)
97 {
98  smooth_mesh_property(_n_iters, _m, _m.points_pph());
99 }
100 
101 };//namespace OpenMesh
102 
103 #endif//SMOOTH_MESH_HH
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:56

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