00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_COMPUTE_MIN_MAX_EDGE_LENGTH_H 00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_COMPUTE_MIN_MAX_EDGE_LENGTH_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 #include <OpenTissue/core/math/math_value_traits.h> 00013 #include <OpenTissue/core/containers/mesh/polymesh/util/polymesh_compute_edge_direction.h> 00014 #include <boost/cast.hpp> //--- Needed for boost::numeric_cast 00015 00016 00017 namespace OpenTissue 00018 { 00019 namespace polymesh 00020 { 00021 00031 template<typename mesh_type, typename real_type> 00032 inline void compute_minmax_edge_length( 00033 mesh_type const & mesh 00034 , real_type & min_length 00035 , real_type & max_length 00036 , real_type & avg_length 00037 ) 00038 { 00039 using std::sqrt; 00040 00041 typedef typename mesh_type::math_types::vector3_type vector3_type; 00042 typedef typename OpenTissue::math::ValueTraits<real_type> value_traits; 00043 00044 min_length = value_traits::infinity(); 00045 max_length = value_traits::zero(); 00046 avg_length = value_traits::zero(); 00047 00048 typename mesh_type::const_edge_iterator e = mesh.edge_begin(); 00049 typename mesh_type::const_edge_iterator end = mesh.edge_end(); 00050 for(;e!=end;++e) 00051 { 00052 vector3_type u; 00053 00054 OpenTissue::polymesh::compute_edge_direction( *(e->get_halfedge0_iterator()), u); 00055 00056 real_type edge_length = boost::numeric_cast<real_type>( sqrt( inner_prod( u,u) ) ); 00057 avg_length += edge_length; 00058 min_length = (edge_length < min_length)?edge_length: min_length; 00059 max_length = (edge_length > max_length)?edge_length: max_length; 00060 } 00061 avg_length /= mesh.size_edges(); 00062 } 00063 00064 } // namespace polymesh 00065 } // namespace OpenTissue 00066 00067 // OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_COMPUTE_MIN_MAX_EDGE_LENGTH_H 00068 #endif