ViSP  2.8.0
vpBSpline Class Reference

#include <vpBSpline.h>

+ Inheritance diagram for vpBSpline:

Public Member Functions

 vpBSpline ()
 
 vpBSpline (const vpBSpline &bspline)
 
virtual ~vpBSpline ()
 
unsigned int get_p () const
 
void get_controlPoints (std::list< vpImagePoint > &list) const
 
void get_knots (std::list< double > &list) const
 
void get_crossingPoints (std::list< vpImagePoint > &list) const
 
void set_p (unsigned int p)
 
void set_controlPoints (const std::list< vpImagePoint > &list)
 
void set_knots (const std::list< double > &list)
 
void set_crossingPoints (const std::list< vpImagePoint > &list)
 
unsigned int findSpan (double u)
 
vpBasisFunction * computeBasisFuns (double u)
 
vpBasisFunction ** computeDersBasisFuns (double u, unsigned int der)
 
vpImagePoint computeCurvePoint (double u)
 
vpImagePointcomputeCurveDers (double u, unsigned int der)
 
Deprecated functions
vp_deprecated vpList< vpImagePointget_controlPoints () const
 
vp_deprecated vpList< double > get_knots () const
 
vp_deprecated vpList< vpImagePointget_crossingPoints () const
 
vp_deprecated void set_controlPoints (vpList< vpImagePoint > &list)
 
vp_deprecated void set_knots (vpList< double > &list)
 
vp_deprecated void set_crossingPoints (vpList< vpImagePoint > &list)
 

Static Public Member Functions

static unsigned int findSpan (double l_u, unsigned int l_p, std::vector< double > &l_knots)
 
static vpBasisFunction * computeBasisFuns (double l_u, unsigned int l_i, unsigned int l_p, std::vector< double > &l_knots)
 
static vpBasisFunction ** computeDersBasisFuns (double l_u, unsigned int l_i, unsigned int l_p, unsigned int l_der, std::vector< double > &l_knots)
 
static vpImagePoint computeCurvePoint (double l_u, unsigned int l_i, unsigned int l_p, std::vector< double > &l_knots, std::vector< vpImagePoint > &l_controlPoints)
 
static vpImagePointcomputeCurveDers (double l_u, unsigned int l_i, unsigned int l_p, unsigned int l_der, std::vector< double > &l_knots, std::vector< vpImagePoint > &l_controlPoints)
 

Detailed Description

Class that provides tools to compute and manipulate a B-Spline curve.

The different parameters are :

  • The knot vector $ U = {u_0, ... , u_m} $ where the knots $ u_i, i = 0, ...,m $ are real number such as $ u_i < u_{i+1}, i = 0, ...,m $. To define a curve, the knot vector is such as : $ U = {a , ... , a, u_{p+1} , ... , u_{m-p-1} , b , ... , b} $ where $ a $ and $ b $ are real numbers and p is the degree of the B-Spline basis functions.
  • The B-Spline basis functions $ N_{i,p} $ defined as :

    \[ N_{i,0}(u) = \left\{\begin{array}{cc} 1 & \mbox{if } u_i \leq u \leq u_{i+1} \\ 0 & else \end{array}\right.\]

    \[ N_{i,p}(u) = \frac{u-u_i}{u_{i+p}-u_i}N_{i,p-1}(u)+\frac{u_{i+p+1}-u}{u_{i+p+1}-u_{i+1}}N_{i+1,p-1}(u)\]

where $ i = 0 , ... , m-1 $ and p is the degree of the B-Spline basis functions.

  • The control points $ {P_i} $ which are defined by the coordinates $ (i,j) $ of a point in an image.

It is possible to compute the coordinates of a point corresponding to the knots $ u $ ( $ u \in [u_0,u_m]$) thanks to the formula :

\[ C(u) = \sum_{i=0}^n (N_{i,p}(u)P_i)\]

You can find much more information about the B-Splines and the implementation of all the methods in the Nurbs Book.

Examples:
BSpline.cpp.

Definition at line 109 of file vpBSpline.h.

Constructor & Destructor Documentation

vpBSpline::vpBSpline ( )

Basic constructor.

The degree $ p $ of the B-Spline basis functions is set to 3 to compute cubic B-Spline.

Definition at line 51 of file vpBSpline.cpp.

vpBSpline::vpBSpline ( const vpBSpline bspline)

Copy constructor.

Definition at line 60 of file vpBSpline.cpp.

vpBSpline::~vpBSpline ( )
virtual

Basic destructor.

Definition at line 70 of file vpBSpline.cpp.

Member Function Documentation

vpBasisFunction * vpBSpline::computeBasisFuns ( double  l_u,
unsigned int  l_i,
unsigned int  l_p,
std::vector< double > &  l_knots 
)
static

Compute the nonvanishing basis functions at $ l_u $ which is in the $ l_i $ th knot interval. All the basis functions are stored in an array such as :

N = $ N_{l_i,0}(l_u) $, $ N_{l_i-1,1}(l_u) $, $ N_{l_i,1}(l_u) $, ... , $ N_{l_i-k,k}(l_u) $, ..., $ N_{l_i,k}(l_u) $, ... , $ N_{l_i-p,p}(l_u) $, ... , $ N_{l_i,p}(l_u) $

Parameters
l_u: A real number which is between the extrimities of the knot vector
l_i: the number of the knot interval in which $ l_u $ lies
l_p: Degree of the B-Spline basis functions.
l_knots: The knot vector
Returns
An array containing the nonvanishing basis functions at $ l_u $. The size of the array is $ l_p +1 $.
Examples:
BSpline.cpp, and Nurbs.cpp.

Definition at line 149 of file vpBSpline.cpp.

Referenced by computeBasisFuns(), vpNurbs::computeCurvePoint(), computeCurvePoint(), vpNurbs::globalCurveApprox(), and vpNurbs::globalCurveInterp().

vpBasisFunction * vpBSpline::computeBasisFuns ( double  u)

Compute the nonvanishing basis functions at $ u $. All the basis functions are stored in an array such as :

N = $ N_{i,0}(u) $, $ N_{i-1,1}(u) $, $ N_{i,1}(u) $, ... , $ N_{i-k,k}(u) $, ..., $ N_{i,k}(u) $, ... , $ N_{i-p,p}(u) $, ... , $ N_{i,p}(u) $

where i the number of the knot interval in which $ u $ lies.

Parameters
u: A real number which is between the extrimities of the knot vector
Returns
An array containing the nonvanishing basis functions at $ u $. The size of the array is $ p +1 $.

Definition at line 200 of file vpBSpline.cpp.

References computeBasisFuns(), and findSpan().

vpImagePoint * vpBSpline::computeCurveDers ( double  l_u,
unsigned int  l_i,
unsigned int  l_p,
unsigned int  l_der,
std::vector< double > &  l_knots,
std::vector< vpImagePoint > &  l_controlPoints 
)
static

Compute the kth derivatives of $ C(u) $ for $ k = 0, ... , l_{der} $.

The formula used is the following :

\[ C^{(k)}(u) = \sum_{i=0}^n (N_{i,p}^{(k)}(u)P_i) \]

where $ i $ is the knot interval number in which $ u $ lies and $ p $ is the degree of the B-Spline basis function.

Parameters
l_u: A real number which is between the extrimities of the knot vector
l_i: the number of the knot interval in which $ l_u $ lies
l_p: Degree of the B-Spline basis functions.
l_der: The last derivative to be computed.
l_knots: The knot vector
l_controlPoints: the list of control points.
Returns
an array of size l_der+1 containing the coordinates $ C^{(k)}(u) $ for $ k = 0, ... , l_der $. The kth derivative is in the kth cell of the array.

Definition at line 453 of file vpBSpline.cpp.

References computeDersBasisFuns(), vpImagePoint::set_i(), vpImagePoint::set_ij(), vpImagePoint::set_j(), and vpTRACE.

vpImagePoint * vpBSpline::computeCurveDers ( double  u,
unsigned int  der 
)

Compute the kth derivatives of $ C(u) $ for $ k = 0, ... , der $.

The formula used is the following :

\[ C^{(k)}(u) = \sum_{i=0}^n (N_{i,p}^{(k)}(u)P_i) \]

where $ i $ is the knot interval number in which $ u $ lies and $ p $ is the degree of the B-Spline basis function.

Parameters
u: A real number which is between the extrimities of the knot vector
der: The last derivative to be computed.
Returns
an array of size der+1 containing the coordinates $ C^{(k)}(u) $ for $ k = 0, ... , der $. The kth derivative is in the kth cell of the array.

Definition at line 501 of file vpBSpline.cpp.

References computeDersBasisFuns(), vpImagePoint::set_i(), vpImagePoint::set_ij(), vpImagePoint::set_j(), and vpTRACE.

vpImagePoint vpBSpline::computeCurvePoint ( double  l_u,
unsigned int  l_i,
unsigned int  l_p,
std::vector< double > &  l_knots,
std::vector< vpImagePoint > &  l_controlPoints 
)
static

Compute the coordinates of a point $ C(u) = \sum_{i=0}^n (N_{i,p}(u)P_i) $ corresponding to the knot $ u $.

Parameters
l_u: A real number which is between the extrimities of the knot vector
l_i: the number of the knot interval in which $ l_u $ lies
l_p: Degree of the B-Spline basis functions.
l_knots: The knot vector
l_controlPoints: the list of control points.

return the coordinates of a point corresponding to the knot $ u $.

Examples:
BSpline.cpp.

Definition at line 384 of file vpBSpline.cpp.

References computeBasisFuns(), vpImagePoint::set_i(), and vpImagePoint::set_j().

vpImagePoint vpBSpline::computeCurvePoint ( double  u)

Compute the coordinates of a point $ C(u) = \sum_{i=0}^n (N_{i,p}(u)P_i) $ corresponding to the knot $ u $.

Parameters
u: A real number which is between the extrimities of the knot vector

return the coordinates of a point corresponding to the knot $ u $.

Definition at line 413 of file vpBSpline.cpp.

References computeBasisFuns(), vpImagePoint::set_i(), and vpImagePoint::set_j().

vpBasisFunction ** vpBSpline::computeDersBasisFuns ( double  l_u,
unsigned int  l_i,
unsigned int  l_p,
unsigned int  l_der,
std::vector< double > &  l_knots 
)
static

Compute the nonzero basis functions and their derivatives until the $ l_der $ th derivative. All the functions are computed at l_u.

Warning
$ l_der $ must be under or equal $ l_p $.

The result is given as an array of size l_der+1 x l_p+1. The kth line corresponds to the kth basis functions derivatives.

The formula to compute the kth derivative at $ u $ is :

\[ N_{i,p}^{(k)}(u) =p \left( \frac{N_{i,p-1}^{(k-1)}}{u_{i+p}-u_i} - \frac{N_{i+1,p-1}^{(k-1)}}{u_{i+p+1}-u_{i+1}} \right) \]

where $ i $ is the knot interval number in which $ u $ lies and $ p $ is the degree of the B-Spline basis function.

Parameters
l_u: A real number which is between the extrimities of the knot vector
l_i: the number of the knot interval in which $ l_u $ lies
l_p: Degree of the B-Spline basis functions.
l_der: The last derivative to be computed.
l_knots: The knot vector
Returns
the basis functions and their derivatives as an array of size l_der+1 x l_p+1. The kth line corresponds to the kth basis functions derivatives.

Example : return[0] is the list of the 0th derivatives ie the basis functions. return[k] is the list of the kth derivatives.

Examples:
BSpline.cpp, and Nurbs.cpp.

Definition at line 230 of file vpBSpline.cpp.

References vpTRACE.

Referenced by vpNurbs::computeCurveDers(), computeCurveDers(), and computeDersBasisFuns().

vpBasisFunction ** vpBSpline::computeDersBasisFuns ( double  u,
unsigned int  der 
)

Compute the nonzero basis functions and their derivatives until the $ der $ th derivative. All the functions are computed at u.

Warning
$ der $ must be under or equal $ p $.

The result is given as an array of size der+1 x p+1. The kth line corresponds to the kth basis functions derivatives.

The formula to compute the kth derivative at $ u $ is :

\[ N_{i,p}^{(k)}(u) =p \left( \frac{N_{i,p-1}^{(k-1)}}{u_{i+p}-u_i} - \frac{N_{i+1,p-1}^{(k-1)}}{u_{i+p+1}-u_{i+1}} \right) \]

where $ i $ is the knot interval number in which $ u $ lies and $ p $ is the degree of the B-Spline basis function.

Parameters
u: A real number which is between the extrimities of the knot vector
der: The last derivative to be computed.
Returns
the basis functions and their derivatives as an array of size der+1 x p+1. The kth line corresponds to the kth basis functions derivatives.

Example : return[0] is the list of the 0th derivatives ie the basis functions. return[k] is the list of the kth derivatives.

Definition at line 366 of file vpBSpline.cpp.

References computeDersBasisFuns(), and findSpan().

unsigned int vpBSpline::findSpan ( double  l_u,
unsigned int  l_p,
std::vector< double > &  l_knots 
)
static

Find the knot interval in which the parameter $ l_u $ lies. Indeed $ l_u \in [u_i, u_{i+1}[ $

Example : The knot vector is the following $ U = \{0, 0 , 1 , 2 ,3 , 3\} $ with $ p $ is equal to 1.

  • For $ l_u $ equal to 0.5 the method will retun 1.
  • For $ l_u $ equal to 2.5 the method will retun 3.
  • For $ l_u $ equal to 3 the method will retun 3.
Parameters
l_u: The knot whose knot interval is seeked.
l_p: Degree of the B-Spline basis functions.
l_knots: The knot vector
Returns
the number of the knot interval in which $ l_u $ lies.
Examples:
BSpline.cpp, and Nurbs.cpp.

Definition at line 89 of file vpBSpline.cpp.

References vpMath::maximum(), and vpMath::round().

Referenced by computeBasisFuns(), vpNurbs::computeCurveDersPoint(), computeDersBasisFuns(), vpNurbs::curveKnotIns(), findSpan(), vpNurbs::globalCurveApprox(), vpNurbs::globalCurveInterp(), and vpNurbs::refineKnotVectCurve().

unsigned int vpBSpline::findSpan ( double  u)

Find the knot interval in which the parameter $ u $ lies. Indeed $ u \in [u_i, u_{i+1}[ $

Example : The knot vector is the following $ U = \{0, 0 , 1 , 2 ,3 , 3\} $ with $ p $ is equal to 1.

  • For $ u $ equal to 0.5 the method will retun 1.
  • For $ u $ equal to 2.5 the method will retun 3.
  • For $ u $ equal to 3 the method will retun 3.
Parameters
u: The knot whose knot interval is seeked.
Returns
the number of the knot interval in which $ u $ lies.

Definition at line 131 of file vpBSpline.cpp.

References findSpan().

void vpBSpline::get_controlPoints ( std::list< vpImagePoint > &  list) const
inline

Gets all the control points.

Parameters
list: A std::list containing the coordinates of the control points.
Examples:
BSpline.cpp, and Nurbs.cpp.

Definition at line 139 of file vpBSpline.h.

vp_deprecated vpList<vpImagePoint> vpBSpline::get_controlPoints ( ) const
inline
Deprecated:
This method is deprecated. You should use get_controlPoints(std::list<vpImagePoint> &) const instead.

Gets all the control points.
Returns
list : A vpList containing the coordinates of the control points

Definition at line 237 of file vpBSpline.h.

References vpList< type >::addRight().

void vpBSpline::get_crossingPoints ( std::list< vpImagePoint > &  list) const
inline

Gets all the crossing points (used in the interpolation method)

Parameters
list: A std::list containing the coordinates of the crossing points.

Definition at line 161 of file vpBSpline.h.

vp_deprecated vpList<vpImagePoint> vpBSpline::get_crossingPoints ( ) const
inline
Deprecated:
This method is deprecated. You should use get_crossingPoints(std::list<vpImagePoint> &) const instead.

Gets all the crossing points (used in the interpolation method)
Returns
list : A vpList containing the coordinates of the crossing points

Definition at line 259 of file vpBSpline.h.

References vpList< type >::addRight().

void vpBSpline::get_knots ( std::list< double > &  list) const
inline

Gets all the knots.

Parameters
list: A std::list containing the value of the knots.
Examples:
BSpline.cpp, and Nurbs.cpp.

Definition at line 150 of file vpBSpline.h.

vp_deprecated vpList<double> vpBSpline::get_knots ( ) const
inline
Deprecated:
This method is deprecated. You should use get_knots(std::list<double> &) const instead.

Gets all the knots.
Returns
list : A vpList containing the value of the knots.

Definition at line 248 of file vpBSpline.h.

References vpList< type >::addRight().

unsigned int vpBSpline::get_p ( ) const
inline

Gets the degree of the B-Spline.

Returns
the degree of the B-Spline.
Examples:
BSpline.cpp, and Nurbs.cpp.

Definition at line 132 of file vpBSpline.h.

void vpBSpline::set_controlPoints ( const std::list< vpImagePoint > &  list)
inline

Sets all the control points.

Parameters
list: A std::list containing the coordinates of the control points
Examples:
BSpline.cpp, and Nurbs.cpp.

Definition at line 181 of file vpBSpline.h.

vp_deprecated void vpBSpline::set_controlPoints ( vpList< vpImagePoint > &  list)
inline
Deprecated:
This method is deprecated. You should use set_controlPoints(const std::list<vpImagePoint> &) instead.

Sets all the control points.
Parameters
list: A vpList containing the coordinates of the control points

Definition at line 270 of file vpBSpline.h.

References vpList< type >::front(), vpList< type >::nbElements(), vpList< type >::next(), and vpList< type >::value().

void vpBSpline::set_crossingPoints ( const std::list< vpImagePoint > &  list)
inline

Sets all the crossing points (used in the interpolation method)

Parameters
list: A std::list containing the coordinates of the crossing points

Definition at line 205 of file vpBSpline.h.

vp_deprecated void vpBSpline::set_crossingPoints ( vpList< vpImagePoint > &  list)
inline
Deprecated:
This method is deprecated. You should use set_crossingPoints(const std::list<vpImagePoint> &) instead.

Sets all the crossing points (used in the interpolation method)
Parameters
list: A vpList containing the coordinates of the crossing points

Definition at line 302 of file vpBSpline.h.

References vpList< type >::front(), vpList< type >::nbElements(), vpList< type >::next(), and vpList< type >::value().

void vpBSpline::set_knots ( const std::list< double > &  list)
inline

Sets all the knots.

Parameters
list: A std::list containing the value of the knots.
Examples:
BSpline.cpp, and Nurbs.cpp.

Definition at line 193 of file vpBSpline.h.

vp_deprecated void vpBSpline::set_knots ( vpList< double > &  list)
inline
Deprecated:
This method is deprecated. You should use set_knots(const std::list<double> &) instead.

Sets all the knots.
Parameters
list: A vpList containing the value of the knots.

Definition at line 286 of file vpBSpline.h.

References vpList< type >::front(), vpList< type >::nbElements(), vpList< type >::next(), and vpList< type >::value().

void vpBSpline::set_p ( unsigned int  p)
inline

Sets the degree of the B-Spline.

Parameters
p: the degree of the B-Spline.
Examples:
BSpline.cpp, and Nurbs.cpp.

Definition at line 173 of file vpBSpline.h.