@ -15,15 +15,16 @@
namespace tinynurbs
namespace tinynurbs
{
{
/**
/**
* Find the span of the given parameter in the knot vector .
* Find the span of the given parameter in the knot vector .
* @ param [ in ] degree Degree of the curve .
* @ param [ in ] degree Degree of the curve .
* @ param [ in ] knots Knot vector of the curve .
* @ param [ in ] knots Knot vector of the curve .
* @ param [ in ] u Parameter value .
* @ param [ in ] u Parameter value .
* @ return Span index into the knot vector such that ( span - 1 ) < u < = span
* @ return Span index into the knot vector such that ( span - 1 ) < u < = span
*/
*/
template < typename T > int findSpan ( unsigned int degree , const std : : vector < T > & knots , T u )
template < typename T >
{
int findSpan ( unsigned int degree , const std : : vector < T > & knots , T u )
{
// index of last control point
// index of last control point
int n = static_cast < int > ( knots . size ( ) ) - degree - 2 ;
int n = static_cast < int > ( knots . size ( ) ) - degree - 2 ;
assert ( n > = 0 ) ;
assert ( n > = 0 ) ;
@ -61,9 +62,9 @@ template <typename T> int findSpan(unsigned int degree, const std::vector<T> &kn
mid = ( int ) std : : floor ( ( low + high ) / 2.0 ) ;
mid = ( int ) std : : floor ( ( low + high ) / 2.0 ) ;
}
}
return mid ;
return mid ;
}
}
/**
/**
* Compute a single B - spline basis function
* Compute a single B - spline basis function
* @ param [ in ] i The ith basis function to compute .
* @ param [ in ] i The ith basis function to compute .
* @ param [ in ] deg Degree of the basis function .
* @ param [ in ] deg Degree of the basis function .
@ -71,8 +72,9 @@ template <typename T> int findSpan(unsigned int degree, const std::vector<T> &kn
* @ param [ in ] u Parameter to evaluate the basis functions at .
* @ param [ in ] u Parameter to evaluate the basis functions at .
* @ return The value of the ith basis function at u .
* @ return The value of the ith basis function at u .
*/
*/
template < typename T > T bsplineOneBasis ( int i , unsigned int deg , const std : : vector < T > & U , T u )
template < typename T >
{
T bsplineOneBasis ( int i , unsigned int deg , const std : : vector < T > & U , T u )
{
int m = static_cast < int > ( U . size ( ) ) - 1 ;
int m = static_cast < int > ( U . size ( ) ) - 1 ;
// Special case
// Special case
if ( ( i = = 0 & & close ( u , U [ 0 ] ) ) | | ( i = = m - deg - 1 & & close ( u , U [ m ] ) ) )
if ( ( i = = 0 & & close ( u , U [ 0 ] ) ) | | ( i = = m - deg - 1 & & close ( u , U [ m ] ) ) )
@ -113,9 +115,9 @@ template <typename T> T bsplineOneBasis(int i, unsigned int deg, const std::vect
}
}
}
}
return N [ 0 ] ;
return N [ 0 ] ;
}
}
/**
/**
* Compute all non - zero B - spline basis functions
* Compute all non - zero B - spline basis functions
* @ param [ in ] deg Degree of the basis function .
* @ param [ in ] deg Degree of the basis function .
* @ param [ in ] span Index obtained from findSpan ( ) corresponding the u and knots .
* @ param [ in ] span Index obtained from findSpan ( ) corresponding the u and knots .
@ -123,9 +125,9 @@ template <typename T> T bsplineOneBasis(int i, unsigned int deg, const std::vect
* @ param [ in ] u Parameter to evaluate the basis functions at .
* @ param [ in ] u Parameter to evaluate the basis functions at .
* @ return N Values of ( deg + 1 ) non - zero basis functions .
* @ return N Values of ( deg + 1 ) non - zero basis functions .
*/
*/
template < typename T >
template < typename T >
std : : vector < T > bsplineBasis ( unsigned int deg , int span , const std : : vector < T > & knots , T u )
std : : vector < T > bsplineBasis ( unsigned int deg , int span , const std : : vector < T > & knots , T u )
{
{
std : : vector < T > N ;
std : : vector < T > N ;
N . resize ( deg + 1 , T ( 0 ) ) ;
N . resize ( deg + 1 , T ( 0 ) ) ;
std : : vector < T > left , right ;
std : : vector < T > left , right ;
@ -149,9 +151,9 @@ std::vector<T> bsplineBasis(unsigned int deg, int span, const std::vector<T> &kn
N [ j ] = saved ;
N [ j ] = saved ;
}
}
return N ;
return N ;
}
}
/**
/**
* Compute all non - zero derivatives of B - spline basis functions
* Compute all non - zero derivatives of B - spline basis functions
* @ param [ in ] deg Degree of the basis function .
* @ param [ in ] deg Degree of the basis function .
* @ param [ in ] span Index obtained from findSpan ( ) corresponding the u and knots .
* @ param [ in ] span Index obtained from findSpan ( ) corresponding the u and knots .
@ -160,10 +162,10 @@ std::vector<T> bsplineBasis(unsigned int deg, int span, const std::vector<T> &kn
* @ param [ in ] num_ders Number of derivatives to compute ( num_ders < = deg )
* @ param [ in ] num_ders Number of derivatives to compute ( num_ders < = deg )
* @ return ders Values of non - zero derivatives of basis functions .
* @ return ders Values of non - zero derivatives of basis functions .
*/
*/
template < typename T >
template < typename T >
array2 < T > bsplineDerBasis ( unsigned int deg , int span , const std : : vector < T > & knots , T u ,
array2 < T > bsplineDerBasis ( unsigned int deg , int span , const std : : vector < T > & knots , T u ,
int num_ders )
int num_ders )
{
{
std : : vector < T > left , right ;
std : : vector < T > left , right ;
left . resize ( deg + 1 , 0.0 ) ;
left . resize ( deg + 1 , 0.0 ) ;
right . resize ( deg + 1 , 0.0 ) ;
right . resize ( deg + 1 , 0.0 ) ;
@ -269,7 +271,7 @@ array2<T> bsplineDerBasis(unsigned int deg, int span, const std::vector<T> &knot
}
}
return ders ;
return ders ;
}
}
} // namespace tinynurbs
} // namespace tinynurbs