Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_SPLINE_COMPUTE_CORD_LENGTH_POLICY_H
00002 #define OPENTISSUE_CORE_SPLINE_COMPUTE_CORD_LENGTH_POLICY_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_value_traits.h>
00013
00014 namespace OpenTissue
00015 {
00016 namespace spline
00017 {
00018
00025 template<typename knot_container, typename point_container>
00026 inline void compute_chord_length_knot_vector(int const & k, point_container const & X, knot_container & U)
00027 {
00028 using std::sqrt;
00029 using std::fabs;
00030
00031 typedef typename point_container::value_type V;
00032 typedef typename knot_container::value_type T;
00033 typedef OpenTissue::math::ValueTraits<T> value_traits;
00034
00035 int i;
00036 int const n = X.size()+1;
00037
00038 U.resize( n+k+1 );
00039
00040
00041 for(i=0; i<k; ++i)
00042 {
00043 U[i] = value_traits::zero();
00044 }
00045
00046 V diff( X[0].size() );
00047
00048 T accumulated = value_traits::zero();
00049
00050 for(i=0; i<=n-3; ++i)
00051 {
00052 diff = X[i+1];
00053 diff -= X[i];
00054
00055
00056 T length = sqrt( inner_prod(diff,diff) );
00057 if( fabs(length)> value_traits::zero() )
00058 {
00059 accumulated += length;
00060 }
00061 else
00062 {
00063 accumulated += value_traits::half();
00064 }
00065 U[i+4] = accumulated;
00066 }
00067
00068 for(i=n+2; i<n+k+1; ++i)
00069 {
00070 U[i]=accumulated;
00071 }
00072
00073 T const maxU = (n - value_traits::two() );
00074 T const scale = maxU/accumulated;
00075
00076 for(i=0; i<=n+k; ++i)
00077 {
00078 U[i] *= scale;
00079 }
00080 }
00081
00082 }
00083 }
00084
00085
00086 #endif