00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_UTIL_MESH_COMPUTE_MESH_MEAN_H 00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_UTIL_MESH_COMPUTE_MESH_MEAN_H 00003 // 00004 // OpenTissue Template Library 00005 // - A generic toolbox for physics-based modeling and simulation. 00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen. 00007 // 00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php 00009 // 00010 #include <OpenTissue/configuration.h> 00011 00012 namespace OpenTissue 00013 { 00014 namespace mesh 00015 { 00016 00017 template<typename mesh_type, typename vector3_type> 00018 void compute_mesh_mean(mesh_type const & mesh, vector3_type & mean) 00019 { 00020 typedef typename mesh_type::math_types math_types; 00021 typedef typename math_types::value_traits value_traits; 00022 typedef typename math_types::real_type real_type; 00023 00024 assert(mesh.size_vertices()>0 || !"mesh did not have any vertices"); 00025 00026 typename mesh_type::const_vertex_iterator end = mesh.vertex_end(); 00027 typename mesh_type::const_vertex_iterator v = mesh.vertex_begin(); 00028 mean.clear(); 00029 for(;v!=end;++v) 00030 mean += v->m_coord; 00031 00032 mean /= static_cast<real_type>(mesh.size_vertices()); 00033 } 00034 00035 } // namespace mesh 00036 } // namespace OpenTissue 00037 00038 //OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_UTIL_MESH_COMPUTE_MESH_MEAN_H 00039 #endif