Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_MESH_TAUBIN_SMOOTH_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_MESH_TAUBIN_SMOOTH_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 namespace OpenTissue
00013 {
00014 namespace polymesh
00015 {
00016
00023 template<typename mesh_type>
00024 void taubin_smooth(
00025 mesh_type & mesh
00026 , unsigned int N
00027 )
00028 {
00029
00030 typedef typename mesh_type::math_types math_types;
00031 typedef typename math_types::value_traits value_traits;
00032 typedef typename math_types::vector3_type vector3_type;
00033 typedef typename math_types::real_type real_type;
00034
00035 typedef typename mesh_type::vertex_iterator vertex_iterator;
00036 typedef typename mesh_type::vertex_vertex_circulator vertex_vertex_circulator;
00037 typedef typename mesh_type::index_type index_type;
00038
00039 std::vector<vector3_type> laplacian(mesh.size_vertices());
00040
00041 real_type zero = static_cast<real_type>(0.0);
00042
00043 N*=2;
00044 for(unsigned int iteration=0;iteration<N;++iteration)
00045 {
00046 vertex_iterator vend = mesh.vertex_end();
00047 vertex_iterator v = mesh.vertex_begin();
00048 for(int i=0;v!=vend;++v,++i)
00049 {
00050 laplacian[i].clear();
00051
00052 if(is_boundary(*v))
00053 continue;
00054 vector3_type avg(zero,zero,zero);
00055 int n = 0;
00056 vertex_vertex_circulator V(*v),Vend;
00057 for(;V!=Vend;++V,++n)
00058 avg += V->m_coord;
00059 avg *= (1.0/n);
00060 laplacian[i] = avg - v->m_coord;
00061 }
00062 if((iteration%2)==1)
00063 {
00064 vend = mesh.vertex_end();
00065 v = mesh.vertex_begin();
00066 for(int i=0;v!=vend;++v,++i)
00067 v->m_coord -= .6731*laplacian[i];
00068 }
00069 else
00070 {
00071 vend = mesh.vertex_end();
00072 v = mesh.vertex_begin();
00073 for(int i=0;v!=vend;++v,++i)
00074 v->m_coord += 0.6307*laplacian[i];
00075 }
00076
00077 }
00078 }
00079
00080 }
00081 }
00082
00083
00084 #endif