00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef SMOOTH_MESH_HH
00032 #define SMOOTH_MESH_HH
00033
00034
00035
00036 #include <OpenMesh/Core/Utils/Property.hh>
00037
00038
00039
00040 namespace 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 {
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 };
00091
00092 #endif//SMOOTH_MESH_HH