Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_SPLINE_SPLINE_COMPUTE_KNOT_SPAN_H
00002 #define OPENTISSUE_CORE_SPLINE_SPLINE_COMPUTE_KNOT_SPAN_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <stdexcept>
00013
00014 namespace OpenTissue
00015 {
00016 namespace spline
00017 {
00018 namespace detail
00019 {
00041 template <typename knot_container>
00042 inline int compute_knot_span(
00043 typename knot_container::value_type const & u
00044 , int const & k
00045 , knot_container const & U
00046 )
00047 {
00048 if(k < 1)
00049 throw std::invalid_argument("order must be greater than zero");
00050
00051 if(U.size() < 2u*k)
00052 throw std::invalid_argument("knot vector was too small or order was too high");
00053
00054 int const m = U.size() - 1;
00055 int const n = m-k;
00056
00057 if (u >= U[n+1])
00058 {
00059 return n;
00060 }
00061
00062 if (u <= U[k-1])
00063 {
00064 return k-1;
00065 }
00066
00067 int low = k-1;
00068 int high = n+1;
00069 int mid = (low+high)/2;
00070
00071 while(u < U[mid] || u >= U[mid+1])
00072 {
00073 if (u < U[mid])
00074 {
00075 high = mid;
00076 }
00077 else
00078 {
00079 low = mid;
00080 }
00081 mid = (low+high)/2;
00082 }
00083 return mid;
00084
00085 }
00086
00087 }
00088 }
00089 }
00090
00091
00092 #endif