Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_UTIL_MESH_COMPUTE_SURFACE_COVARIANCE_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_UTIL_MESH_COMPUTE_SURFACE_COVARIANCE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 namespace OpenTissue
00013 {
00014 namespace mesh
00015 {
00016
00025 template<typename mesh_type, typename vector3_type, typename matrix3x3_type>
00026 void compute_surface_covariance(
00027 mesh_type const & mesh
00028 , vector3_type & mu
00029 , matrix3x3_type & cov
00030 )
00031 {
00032 typedef typename mesh_type::const_face_iterator const_face_iterator;
00033 typedef typename mesh_type::const_face_vertex_circulator const_face_vertex_circulator;
00034 typedef typename vector3_type::value_type real_type;
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 mu.clear();
00052 unsigned int n=0;
00053 const_face_iterator end = mesh.face_end();
00054 const_face_iterator f = mesh.face_begin();
00055 for(;f!=end;++f)
00056 {
00057 const_face_vertex_circulator a(*f);--a;
00058 const_face_vertex_circulator b(*f);
00059 const_face_vertex_circulator c(*f);++c;
00060 for(;c->get_handle()!= a->get_handle(); ++b,++c )
00061 {
00062 mu += a->m_coord + b->m_coord + c->m_coord;
00063 ++n;
00064 }
00065 }
00066 real_type factor = static_cast<real_type>(1.0/(3.0*n));
00067 mu *= factor;
00068 cov.clear();
00069 for(f = mesh.face_begin();f!=end;++f)
00070 {
00071 const_face_vertex_circulator a(*f);--a;
00072 const_face_vertex_circulator b(*f);
00073 const_face_vertex_circulator c(*f);++c;
00074 for(;c->get_handle()!= a->get_handle(); ++b,++c)
00075 {
00076 vector3_type A = a->m_coord - mu;
00077 vector3_type B = b->m_coord - mu;
00078 vector3_type C = c->m_coord - mu;
00079 for(unsigned int j=0;j<3;++j)
00080 for(unsigned int k=0;k<3;++k)
00081 cov(j,k) += A(j)*A(k) + B(j)*B(k) + C(j)*C(k);
00082 }
00083 }
00084 for(unsigned int j=0;j<3;++j)
00085 for(unsigned int k=0;k<3;++k)
00086 cov(j,k) *= factor;
00087 }
00088
00089 }
00090 }
00091
00092
00093 #endif