Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_GEOMETRY_GEOMETRY_COMPUTE_INSCRIBED_RADIUS_LENGTH_QUALITY_MEASURE_H
00002 #define OPENTISSUE_CORE_GEOMETRY_GEOMETRY_COMPUTE_INSCRIBED_RADIUS_LENGTH_QUALITY_MEASURE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_is_number.h>
00013 #include <OpenTissue/core/math/math_basic_types.h>
00014 #include <OpenTissue/core/geometry/geometry_compute_inscribed_sphere.h>
00015
00016 #include <boost/cast.hpp>
00017
00018 #include <cmath>
00019 #include <cassert>
00020
00021 namespace OpenTissue
00022 {
00023 namespace geometry
00024 {
00025
00047 template<typename vector3_type>
00048 inline typename vector3_type::value_type
00049 compute_inscribed_radius_length_quality_measure (
00050 vector3_type const & p0
00051 , vector3_type const & p1
00052 , vector3_type const & p2
00053 , vector3_type const & p3
00054 )
00055 {
00056 using std::max;
00057
00058 typedef typename vector3_type::value_type real_type;
00059 typedef OpenTissue::math::BasicMathTypes<real_type, size_t> math_types;
00060 typedef typename math_types::value_traits value_traits;
00061
00062 real_type l0 = length(p0-p1);
00063 real_type l1 = length(p1-p2);
00064 real_type l2 = length(p2-p0);
00065 real_type l3 = length(p0-p3);
00066 real_type l4 = length(p1-p3);
00067 real_type l5 = length(p2-p3);
00068 real_type l_max = max( l0, max( l1, max( l2, max( l3, max( l4, l5 ) ) ) ) );
00069
00070 real_type r_in;
00071 vector3_type center;
00072
00073 compute_tetrahedron_inscribed_sphere( p0, p1, p2, p3, center, r_in);
00074
00075 r_in = (r_in<0) ? 0 : r_in;
00076
00077 real_type const fraction = boost::numeric_cast<real_type>( 2.0 * sqrt ( 6.0 ) );
00078 real_type quality = fraction * r_in / l_max;
00079 assert( is_number( l_max ) || !"maximum edge length was not a number" );
00080 assert( l_max >= value_traits::zero() || !"maximum edge length must be non-negative" );
00081 assert( is_number( r_in ) || !"circumscribed radius was not a number" );
00082 assert( r_in >= value_traits::zero() || !"inscribed radius must be non-negative" );
00083 assert( is_number( quality ) || !"quality was not a number" );
00084 assert( quality>= value_traits::zero() || !"invalid qualtiy value" );
00085 assert( quality<= value_traits::one() || !"invalid qualtiy value" );
00086 return quality;
00087 };
00088
00089
00090
00091 }
00092
00093 }
00094
00095
00096 #endif