Eigen::SplineFitting< SplineType > Struct Template Reference

Spline fitting methods. More...

Public Types

typedef SplineType::KnotVectorType KnotVectorType
 
typedef SplineType::ParameterVectorType ParameterVectorType
 

Static Public Member Functions

template<typename PointArrayType >
static SplineType Interpolate (const PointArrayType &pts, DenseIndex degree)
 Fits an interpolating Spline to the given data points. More...
 
template<typename PointArrayType >
static SplineType Interpolate (const PointArrayType &pts, DenseIndex degree, const KnotVectorType &knot_parameters)
 Fits an interpolating Spline to the given data points. More...
 
template<typename PointArrayType , typename IndexArray >
static SplineType InterpolateWithDerivatives (const PointArrayType &points, const PointArrayType &derivatives, const IndexArray &derivativeIndices, const unsigned int degree)
 Fits an interpolating spline to the given data points and derivatives. More...
 
template<typename PointArrayType , typename IndexArray >
static SplineType InterpolateWithDerivatives (const PointArrayType &points, const PointArrayType &derivatives, const IndexArray &derivativeIndices, const unsigned int degree, const ParameterVectorType &parameters)
 Fits an interpolating spline to the given data points and derivatives. More...
 

Detailed Description

template<typename SplineType>
struct Eigen::SplineFitting< SplineType >

Spline fitting methods.

Definition at line 216 of file SplineFitting.h.

Member Typedef Documentation

◆ KnotVectorType

template<typename SplineType >
typedef SplineType::KnotVectorType Eigen::SplineFitting< SplineType >::KnotVectorType

Definition at line 218 of file SplineFitting.h.

◆ ParameterVectorType

template<typename SplineType >
typedef SplineType::ParameterVectorType Eigen::SplineFitting< SplineType >::ParameterVectorType

Definition at line 219 of file SplineFitting.h.

Member Function Documentation

◆ Interpolate() [1/2]

template<typename SplineType >
template<typename PointArrayType >
SplineType Eigen::SplineFitting< SplineType >::Interpolate ( const PointArrayType &  pts,
DenseIndex  degree 
)
static

Fits an interpolating Spline to the given data points.

Parameters
ptsThe points for which an interpolating spline will be computed.
degreeThe degree of the interpolating spline.
Returns
A spline interpolating the initially provided points.

Definition at line 325 of file SplineFitting.h.

326  {
327  KnotVectorType chord_lengths; // knot parameters
328  ChordLengths(pts, chord_lengths);
329  return Interpolate(pts, degree, chord_lengths);
330  }
void ChordLengths(const PointArrayType &pts, KnotVectorType &chord_lengths)
Computes chord length parameters which are required for spline interpolation.
SplineType::KnotVectorType KnotVectorType
static SplineType Interpolate(const PointArrayType &pts, DenseIndex degree)
Fits an interpolating Spline to the given data points.

◆ Interpolate() [2/2]

template<typename SplineType >
template<typename PointArrayType >
SplineType Eigen::SplineFitting< SplineType >::Interpolate ( const PointArrayType &  pts,
DenseIndex  degree,
const KnotVectorType knot_parameters 
)
static

Fits an interpolating Spline to the given data points.

Parameters
ptsThe points for which an interpolating spline will be computed.
degreeThe degree of the interpolating spline.
knot_parametersThe knot parameters for the interpolation.
Returns
A spline interpolating the initially provided points.

Definition at line 293 of file SplineFitting.h.

294  {
295  typedef typename SplineType::KnotVectorType::Scalar Scalar;
296  typedef typename SplineType::ControlPointVectorType ControlPointVectorType;
297 
298  typedef Matrix<Scalar,Dynamic,Dynamic> MatrixType;
299 
300  KnotVectorType knots;
301  KnotAveraging(knot_parameters, degree, knots);
302 
303  DenseIndex n = pts.cols();
304  MatrixType A = MatrixType::Zero(n,n);
305  for (DenseIndex i=1; i<n-1; ++i)
306  {
307  const DenseIndex span = SplineType::Span(knot_parameters[i], degree, knots);
308 
309  // The segment call should somehow be told the spline order at compile time.
310  A.row(i).segment(span-degree, degree+1) = SplineType::BasisFunctions(knot_parameters[i], degree, knots);
311  }
312  A(0,0) = 1.0;
313  A(n-1,n-1) = 1.0;
314 
315  HouseholderQR<MatrixType> qr(A);
316 
317  // Here, we are creating a temporary due to an Eigen issue.
318  ControlPointVectorType ctrls = qr.solve(MatrixType(pts.transpose())).transpose();
319 
320  return SplineType(knots, ctrls);
321  }
int n
SparseMatrix< double > A(n, n)
int i
HouseholderQR< MatrixXf > qr(A)
Matrix< float, 1, Dynamic > MatrixType
void KnotAveraging(const KnotVectorType &parameters, DenseIndex degree, KnotVectorType &knots)
Computes knot averages.
Definition: SplineFitting.h:48
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex

◆ InterpolateWithDerivatives() [1/2]

template<typename SplineType >
template<typename PointArrayType , typename IndexArray >
SplineType Eigen::SplineFitting< SplineType >::InterpolateWithDerivatives ( const PointArrayType &  points,
const PointArrayType &  derivatives,
const IndexArray &  derivativeIndices,
const unsigned int  degree 
)
static

Fits an interpolating spline to the given data points and derivatives.

Parameters
pointsThe points for which an interpolating spline will be computed.
derivativesThe desired derivatives of the interpolating spline at interpolation points.
derivativeIndicesAn array indicating which point each derivative belongs to. This must be the same size as derivatives.
degreeThe degree of the interpolating spline.
Returns
A spline interpolating points with derivatives at those points.
See also
Les A. Piegl, Khairan Rajab, Volha Smarodzinana. 2008. Curve interpolation with directional constraints for engineering design. Engineering with Computers

Definition at line 423 of file SplineFitting.h.

427  {
428  ParameterVectorType parameters;
429  ChordLengths(points, parameters);
430  return InterpolateWithDerivatives(points, derivatives, derivativeIndices, degree, parameters);
431  }
static SplineType InterpolateWithDerivatives(const PointArrayType &points, const PointArrayType &derivatives, const IndexArray &derivativeIndices, const unsigned int degree)
Fits an interpolating spline to the given data points and derivatives.
SplineType::ParameterVectorType ParameterVectorType

◆ InterpolateWithDerivatives() [2/2]

template<typename SplineType >
template<typename PointArrayType , typename IndexArray >
SplineType Eigen::SplineFitting< SplineType >::InterpolateWithDerivatives ( const PointArrayType &  points,
const PointArrayType &  derivatives,
const IndexArray &  derivativeIndices,
const unsigned int  degree,
const ParameterVectorType parameters 
)
static

Fits an interpolating spline to the given data points and derivatives.

Parameters
pointsThe points for which an interpolating spline will be computed.
derivativesThe desired derivatives of the interpolating spline at interpolation points.
derivativeIndicesAn array indicating which point each derivative belongs to. This must be the same size as derivatives.
degreeThe degree of the interpolating spline.
parametersThe parameters corresponding to the interpolation points.
Returns
A spline interpolating points with derivatives at those points.
See also
Les A. Piegl, Khairan Rajab, Volha Smarodzinana. 2008. Curve interpolation with directional constraints for engineering design. Engineering with Computers

Definition at line 335 of file SplineFitting.h.

340  {
341  typedef typename SplineType::KnotVectorType::Scalar Scalar;
342  typedef typename SplineType::ControlPointVectorType ControlPointVectorType;
343 
344  typedef Matrix<Scalar, Dynamic, Dynamic> MatrixType;
345 
346  const DenseIndex n = points.cols() + derivatives.cols();
347 
348  KnotVectorType knots;
349 
350  KnotAveragingWithDerivatives(parameters, degree, derivativeIndices, knots);
351 
352  // fill matrix
353  MatrixType A = MatrixType::Zero(n, n);
354 
355  // Use these dimensions for quicker populating, then transpose for solving.
356  MatrixType b(points.rows(), n);
357 
358  DenseIndex startRow;
359  DenseIndex derivativeStart;
360 
361  // End derivatives.
362  if (derivativeIndices[0] == 0)
363  {
364  A.template block<1, 2>(1, 0) << -1, 1;
365 
366  Scalar y = (knots(degree + 1) - knots(0)) / degree;
367  b.col(1) = y*derivatives.col(0);
368 
369  startRow = 2;
370  derivativeStart = 1;
371  }
372  else
373  {
374  startRow = 1;
375  derivativeStart = 0;
376  }
377  if (derivativeIndices[derivatives.cols() - 1] == points.cols() - 1)
378  {
379  A.template block<1, 2>(n - 2, n - 2) << -1, 1;
380 
381  Scalar y = (knots(knots.size() - 1) - knots(knots.size() - (degree + 2))) / degree;
382  b.col(b.cols() - 2) = y*derivatives.col(derivatives.cols() - 1);
383  }
384 
385  DenseIndex row = startRow;
386  DenseIndex derivativeIndex = derivativeStart;
387  for (DenseIndex i = 1; i < parameters.size() - 1; ++i)
388  {
389  const DenseIndex span = SplineType::Span(parameters[i], degree, knots);
390 
391  if (derivativeIndex < derivativeIndices.size() && derivativeIndices[derivativeIndex] == i)
392  {
393  A.block(row, span - degree, 2, degree + 1)
394  = SplineType::BasisFunctionDerivatives(parameters[i], 1, degree, knots);
395 
396  b.col(row++) = points.col(i);
397  b.col(row++) = derivatives.col(derivativeIndex++);
398  }
399  else
400  {
401  A.row(row).segment(span - degree, degree + 1)
402  = SplineType::BasisFunctions(parameters[i], degree, knots);
403  b.col(row++) = points.col(i);
404  }
405  }
406  b.col(0) = points.col(0);
407  b.col(b.cols() - 1) = points.col(points.cols() - 1);
408  A(0,0) = 1;
409  A(n - 1, n - 1) = 1;
410 
411  // Solve
412  FullPivLU<MatrixType> lu(A);
413  ControlPointVectorType controlPoints = lu.solve(MatrixType(b.transpose())).transpose();
414 
415  SplineType spline(knots, controlPoints);
416 
417  return spline;
418  }
RowXpr row(Index i) const
Matrix3f y
cout<< "Here is the matrix m:"<< endl<< m<< endl;Eigen::FullPivLU< Matrix5x3 > lu(m)
void KnotAveragingWithDerivatives(const ParameterVectorType &parameters, const unsigned int degree, const IndexArray &derivativeIndices, KnotVectorType &knots)
Computes knot averages when derivative constraints are present. Note that this is a technical interpr...
Definition: SplineFitting.h:81

The documentation for this struct was generated from the following file: