roboptim::trajectory::CubicBSpline Class Reference

Cubic B-Spline trajectory. More...

#include <roboptim/trajectory/cubic-b-spline.hh>

Inheritance diagram for roboptim::trajectory::CubicBSpline:
roboptim::trajectory::Trajectory< 3 > NTimesDerivableFunction

List of all members.

Public Types

typedef std::vector
< Polynomial3,
Eigen::aligned_allocator
< Polynomial3 > > 
polynomials3vector_t
typedef std::vector
< polynomials3vector_t
polynomials3vectors_t
typedef std::vector< value_type > knots_t

Public Member Functions

 CubicBSpline (interval_t timeRange, size_type dimension, const vector_t &parameters, const std::string name="cubic B-Spline", bool clamped=false)
 Instantiate a uniform cubic B-Spline from its definition.
 CubicBSpline (size_type dimension, const knots_t &knots, const vector_t &parameters, const std::string name="cubic B-Spline")
 Instantiate a cubic B-Spline from its definition.
 CubicBSpline (const CubicBSpline &spline)
 Copy constructor.
virtual ~CubicBSpline ()
virtual void setParameters (const vector_t &)
 Modify spline parameters.
virtual jacobian_t variationConfigWrtParam (double t) const
 Get the variation of a configuration with respect to parameter vector.
virtual jacobian_t variationDerivWrtParam (double t, size_type order) const
 Get the variation of a derivative with respect to parameter vector.
virtual value_type singularPointAtRank (size_type rank) const
 Get singular point at given rank.
virtual vector_t derivBeforeSingularPoint (size_type rank, size_type order) const
 Get left limit value of derivative at given singular point.
virtual vector_t derivAfterSingularPoint (size_type rank, size_type order) const
 Get right limit value of derivative at given singular point.
virtual Trajectory
< derivabilityOrder > * 
resize (interval_t timeRange) const
 Clone and resize a trajectory.
virtual std::ostream & print (std::ostream &o) const
 Display the function on the specified output stream.
jacobian_t variationConfigWrtParam (StableTimePoint tp) const
jacobian_t variationDerivWrtParam (StableTimePoint tp, size_type order) const
template<typename P >
void freezeCurveStart (P &problem, size_type offset=0) const
 Add a constraint to a problem in order to freeze the B-spline at its start.
template<typename P >
void freezeCurveEnd (P &problem, size_type offset=0) const
 Add a constraint to a problem in order to freeze the B-spline at its end.
value_type Dt () const ROBOPTIM_TRAJECTORY_DEPRECATED
 Regular spacing between B-spline knots.
void translateBasisPolynomials (double t1)
 Translate the basis polynomials to a given time t1.
void toPolynomials (polynomials3vector_t &res) const
 Return the polynomial expression of the cubic B-spline on each time interval.
const polynomials3vectors_tbasisPolynomials () const
 Constant getter for the basis polynomials of the cubic B-spline.
size_type interval (value_type t) const
 Find the index of the interval in which t is.
size_type getNumberControlPoints () const
 Get the number of control points of the spline.
const knots_tknotVector () const
 Return the knot vector of the spline.
CubicBSpline operator+ (const CubicBSpline &s) const
 Add two cubic B-splines, supposing they have the same dimensions.
void operator+= (const CubicBSpline &s)
 Add a second B-spline to this B-spline.

Protected Member Functions

void impl_compute (result_ref, double) const
void impl_derivative (derivative_ref g, double x, size_type order) const
void impl_derivative (derivative_ref g, StableTimePoint, size_type order) const
void computeBasisPolynomials ()
 Compute the basis polynomials for the cubic B-spline.
vector_t basisFunctions (value_type t, size_type order) const ROBOPTIM_TRAJECTORY_DEPRECATED
 Compute the basis functions for a given instant t.

Detailed Description

Cubic B-Spline trajectory.

Implement a B-Spline as a trajectory as described in doc/cubic-b-spline.tex

Examples:
spline-optimization.cc, and spline-time-optimization.cc.

Member Typedef Documentation

typedef std::vector<value_type> roboptim::trajectory::CubicBSpline::knots_t
typedef std::vector< Polynomial3, Eigen::aligned_allocator<Polynomial3> > roboptim::trajectory::CubicBSpline::polynomials3vector_t

Constructor & Destructor Documentation

roboptim::trajectory::CubicBSpline::CubicBSpline ( interval_t  timeRange,
size_type  dimension,
const vector_t &  parameters,
const std::string  name = "cubic B-Spline",
bool  clamped = false 
)

Instantiate a uniform cubic B-Spline from its definition.

Parameters:
timeRangespline time range: $ $[t_3,t_n]$
dimensionspline dimension: $n$
parametersvector of parameters defining control points
namefunction title
clampedwhether the spline should be clamped

The number of control points is inferred from the dimension of the parameter vector.

References computeBasisPolynomials(), roboptim::trajectory::Trajectory< 3 >::parameters_, and setParameters().

Referenced by resize().

roboptim::trajectory::CubicBSpline::CubicBSpline ( size_type  dimension,
const knots_t knots,
const vector_t &  parameters,
const std::string  name = "cubic B-Spline" 
)

Instantiate a cubic B-Spline from its definition.

Parameters:
dimensionspline dimension: $n$
knotsvector of knots,
parametersvector of parameters defining control points
namefunction title

The number of control points is inferred from the dimension of the parameter vector.

References computeBasisPolynomials(), roboptim::trajectory::Trajectory< 3 >::parameters_, and setParameters().


Member Function Documentation

CubicBSpline::vector_t roboptim::trajectory::CubicBSpline::basisFunctions ( value_type  t,
size_type  order 
) const [protected]

Compute the basis functions for a given instant t.

Parameters:
tinstant considered.
orderorder of the basis functions.
Returns:
basis functions evaluated at t.

References Dt(), roboptim::trajectory::detail::fixTime(), interval(), roboptim::trajectory::Trajectory< 3 >::length(), roboptim::trajectory::Trajectory< 3 >::timeRange(), and roboptim::trajectory::Trajectory< 3 >::tolerance().

Constant getter for the basis polynomials of the cubic B-spline.

Returns:
constant reference to the basis polynomials.

Note: computeBasisPolynomials() needs to be called beforehand (which is done in the CubicBSpline constructor).

Compute the basis polynomials for the cubic B-spline.

Referenced by CubicBSpline().

CubicBSpline::vector_t roboptim::trajectory::CubicBSpline::derivAfterSingularPoint ( size_type  rank,
size_type  order 
) const [virtual]

Get right limit value of derivative at given singular point.

Parameters:
rankrank of the singular points.
orderorder of derivation.
Return values:
derivativeLimit of the derivative at singular point for decreasing parameter values.

Implements roboptim::trajectory::Trajectory< 3 >.

References roboptim::trajectory::Trajectory< 3 >::derivative(), and singularPointAtRank().

CubicBSpline::vector_t roboptim::trajectory::CubicBSpline::derivBeforeSingularPoint ( size_type  rank,
size_type  order 
) const [virtual]

Get left limit value of derivative at given singular point.

Parameters:
rankrank of the singular points.
orderorder of derivation.
Returns:
Limit of the derivative at singular point for increasing parameter values.

Implements roboptim::trajectory::Trajectory< 3 >.

References roboptim::trajectory::Trajectory< 3 >::derivative(), and singularPointAtRank().

CubicBSpline::value_type roboptim::trajectory::CubicBSpline::Dt ( ) const

Regular spacing between B-spline knots.

This is only valid for uniform B-splines.

Returns:
regular spacing between B-spline knots.

References roboptim::trajectory::Trajectory< 3 >::length().

Referenced by basisFunctions().

template<typename P >
void roboptim::trajectory::CubicBSpline::freezeCurveEnd ( P &  problem,
size_type  offset = 0 
) const

Add a constraint to a problem in order to freeze the B-spline at its end.

Parameters:
problemproblem to which the constraint will be added.
offsetoffset of the B-spline parameters in the problem's parameter list.
Examples:
spline-optimization.cc.

References interval(), and roboptim::trajectory::Trajectory< 3 >::parameters().

template<typename P >
void roboptim::trajectory::CubicBSpline::freezeCurveStart ( P &  problem,
size_type  offset = 0 
) const

Add a constraint to a problem in order to freeze the B-spline at its start.

Parameters:
problemproblem to which the constraint will be added.
offsetoffset of the B-spline parameters in the problem's parameter list.
Examples:
spline-optimization.cc.

References interval(), and roboptim::trajectory::Trajectory< 3 >::parameters().

Get the number of control points of the spline.

Returns:
Number of control points of the spline.

Referenced by roboptim::trajectory::visualization::matplotlib::plot_spline().

void roboptim::trajectory::CubicBSpline::impl_derivative ( derivative_ref  g,
double  x,
size_type  order 
) const [protected]
void roboptim::trajectory::CubicBSpline::impl_derivative ( derivative_ref  g,
StableTimePoint  stp,
size_type  order 
) const [protected, virtual]
CubicBSpline::size_type roboptim::trajectory::CubicBSpline::interval ( value_type  t) const

Find the index of the interval in which t is.

Parameters:
tinstant considered.
Returns:
index of the interval in which t is.

References roboptim::trajectory::detail::fixTime(), and roboptim::trajectory::Trajectory< 3 >::timeRange().

Referenced by basisFunctions(), freezeCurveEnd(), freezeCurveStart(), impl_derivative(), and variationDerivWrtParam().

Return the knot vector of the spline.

Returns:
knot vector of the spline (const).

Referenced by roboptim::trajectory::visualization::matplotlib::plot_spline().

CubicBSpline roboptim::trajectory::CubicBSpline::operator+ ( const CubicBSpline s) const

Add two cubic B-splines, supposing they have the same dimensions.

Parameters:
sother B-spline with the same dimensions.
Returns:
S2 = S0 + S1
Exceptions:
std::runtime_errorif splines do not have the same dimensions.

References roboptim::trajectory::Trajectory< 3 >::parameters(), roboptim::trajectory::Trajectory< DerivabilityOrder >::parameters(), roboptim::trajectory::Trajectory< 3 >::timeRange(), and roboptim::trajectory::Trajectory< DerivabilityOrder >::timeRange().

void roboptim::trajectory::CubicBSpline::operator+= ( const CubicBSpline s)

Add a second B-spline to this B-spline.

Parameters:
sother B-spline with the same dimensions.
Exceptions:
std::runtime_errorif splines do not have the same dimensions.

References roboptim::trajectory::Trajectory< 3 >::parameters(), roboptim::trajectory::Trajectory< DerivabilityOrder >::parameters(), setParameters(), roboptim::trajectory::Trajectory< 3 >::timeRange(), and roboptim::trajectory::Trajectory< DerivabilityOrder >::timeRange().

std::ostream & roboptim::trajectory::CubicBSpline::print ( std::ostream &  o) const [virtual]

Display the function on the specified output stream.

Parameters:
ooutput stream used for display
Returns:
output stream

Reimplemented from roboptim::trajectory::Trajectory< 3 >.

References roboptim::trajectory::Trajectory< 3 >::length(), and roboptim::trajectory::Trajectory< 3 >::parameters().

virtual Trajectory<derivabilityOrder>* roboptim::trajectory::CubicBSpline::resize ( interval_t  timeRange) const [inline, virtual]
CubicBSpline::value_type roboptim::trajectory::CubicBSpline::singularPointAtRank ( size_type  rank) const [virtual]

Return the polynomial expression of the cubic B-spline on each time interval.

ROBOPTIM_DO_NOT_CHECK_ALLOCATION

ROBOPTIM_DO_NOT_CHECK_ALLOCATION

References roboptim::trajectory::Trajectory< 3 >::parameters().

Referenced by roboptim::trajectory::visualization::matplotlib::plot_spline().

Translate the basis polynomials to a given time t1.

Parameters:
t1new center time, i.e. P = sum(a_i*(t-t1)^i, i={0,3})

This method can be useful when one needs to have all the polynomials expressed in the same basis (e.g. t1 = 0).

CubicBSpline::jacobian_t roboptim::trajectory::CubicBSpline::variationConfigWrtParam ( double  t) const [virtual]

Get the variation of a configuration with respect to parameter vector.

Parameters:
tvalue $t$ in the definition interval.
Returns:
Jacobian:

\[\frac{\partial\Gamma_{\textbf{p}}(t)}{\partial\textbf{p}}\]

Implements roboptim::trajectory::Trajectory< 3 >.

Examples:
spline-optimization.cc.

References variationDerivWrtParam().

Referenced by variationConfigWrtParam().

CubicBSpline::jacobian_t roboptim::trajectory::CubicBSpline::variationDerivWrtParam ( double  t,
size_type  order 
) const [virtual]

Get the variation of a derivative with respect to parameter vector.

Parameters:
tvalue $t$ in the definition interval.
orderorder $r$ of the derivative.
Returns:
jacobian

\[ \frac{\partial}{\partial\textbf{p}} \left(\frac{d^r\Gamma_{\textbf{p}}}{dt^r}(t)\right) \]

Implements roboptim::trajectory::Trajectory< 3 >.

References roboptim::trajectory::Polynomial< N >::derivative(), roboptim::trajectory::detail::fixTime(), and interval().

Referenced by variationConfigWrtParam(), and variationDerivWrtParam().

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines