10 #ifndef EIGEN_SPLINE_FITTING_H
11 #define EIGEN_SPLINE_FITTING_H
15 #include "SplineFwd.h"
40 template <
typename KnotVectorType>
41 void KnotAveraging(
const KnotVectorType& parameters, DenseIndex degree, KnotVectorType& knots)
43 typedef typename KnotVectorType::Scalar Scalar;
45 knots.resize(parameters.size()+degree+1);
47 for (DenseIndex j=1; j<parameters.size()-degree; ++j)
48 knots(j+degree) = parameters.segment(j,degree).mean();
50 knots.segment(0,degree+1) = KnotVectorType::Zero(degree+1);
51 knots.segment(knots.size()-degree-1,degree+1) = KnotVectorType::Ones(degree+1);
63 template <
typename Po
intArrayType,
typename KnotVectorType>
64 void ChordLengths(
const PointArrayType& pts, KnotVectorType& chord_lengths)
66 typedef typename KnotVectorType::Scalar Scalar;
68 const DenseIndex n = pts.cols();
71 chord_lengths.resize(pts.cols());
73 chord_lengths.rightCols(n-1) = (pts.array().leftCols(n-1) - pts.array().rightCols(n-1)).matrix().colwise().norm();
76 std::partial_sum(chord_lengths.data(), chord_lengths.data()+n, chord_lengths.data());
79 chord_lengths /= chord_lengths(n-1);
80 chord_lengths(n-1) = Scalar(1);
87 template <
typename SplineType>
90 typedef typename SplineType::KnotVectorType KnotVectorType;
100 template <
typename Po
intArrayType>
101 static SplineType
Interpolate(
const PointArrayType& pts, DenseIndex degree);
112 template <
typename Po
intArrayType>
113 static SplineType
Interpolate(
const PointArrayType& pts, DenseIndex degree,
const KnotVectorType& knot_parameters);
116 template <
typename SplineType>
117 template <
typename Po
intArrayType>
120 typedef typename SplineType::KnotVectorType::Scalar Scalar;
121 typedef typename SplineType::BasisVectorType BasisVectorType;
122 typedef typename SplineType::ControlPointVectorType ControlPointVectorType;
126 KnotVectorType knots;
129 DenseIndex n = pts.cols();
130 MatrixType A = MatrixType::Zero(n,n);
131 for (DenseIndex i=1; i<n-1; ++i)
133 const DenseIndex span = SplineType::Span(knot_parameters[i], degree, knots);
136 A.row(i).segment(span-degree, degree+1) = SplineType::BasisFunctions(knot_parameters[i], degree, knots);
141 HouseholderQR<MatrixType> qr(A);
144 ControlPointVectorType ctrls = qr.solve(MatrixType(pts.transpose())).transpose();
146 return SplineType(knots, ctrls);
149 template <
typename SplineType>
150 template <
typename Po
intArrayType>
153 KnotVectorType chord_lengths;
155 return Interpolate(pts, degree, chord_lengths);
159 #endif // EIGEN_SPLINE_FITTING_H