Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_UTIL_COMPUTE_MEAN_VERTEX_NORMALS_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_UTIL_COMPUTE_MEAN_VERTEX_NORMALS_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <cassert>
00013 #include <cmath>
00014 #include <vector>
00015
00016 namespace OpenTissue
00017 {
00018 namespace mesh
00019 {
00020
00021 template<typename mesh_type>
00022 void compute_mean_vertex_normals(mesh_type & mesh)
00023 {
00024 typedef typename mesh_type::math_types math_types;
00025 typedef typename math_types::value_traits value_traits;
00026 typedef typename math_types::vector3_type vector3_type;
00027 typedef typename math_types::real_type real_type;
00028
00029 typedef typename mesh_type::vertex_iterator vertex_iterator;
00030 typedef typename mesh_type::face_iterator face_iterator;
00031 typedef typename mesh_type::face_vertex_circulator face_vertex_circulator;
00032 {
00033 vertex_iterator end = mesh.vertex_end();
00034 vertex_iterator v = mesh.vertex_begin();
00035 for(;v!=end;++v)
00036 v->m_normal.clear();
00037 }
00038 {
00039 face_iterator end = mesh.face_end();
00040 face_iterator f = mesh.face_begin();
00041 for(;f!=end;++f)
00042 {
00043 face_vertex_circulator i ( *f ),vend;
00044 face_vertex_circulator j ( *f );
00045 face_vertex_circulator k ( *f );
00046 ++j; ++k;++k;
00047 for(;i!=vend;++i,++j,++k)
00048 {
00049 vector3_type u0 = normalize(j->m_coord - i->m_coord);
00050 vector3_type u1 = normalize(k->m_coord - j->m_coord);
00051 vector3_type n = normalize(u0 % u1);
00052 j->m_normal += n;
00053 }
00054 }
00055 }
00056 {
00057 vertex_iterator end = mesh.vertex_end();
00058 vertex_iterator v = mesh.vertex_begin();
00059 for(;v!=end;++v)
00060 v->m_normal = normalize(v->m_normal);
00061 }
00062 }
00063
00064 }
00065 }
00066
00067
00068 #endif