diff --git a/unsupported/Eigen/src/Splines/SplineFitting.h b/unsupported/Eigen/src/Splines/SplineFitting.h index 195f869b8..3e8abbbce 100644 --- a/unsupported/Eigen/src/Splines/SplineFitting.h +++ b/unsupported/Eigen/src/Splines/SplineFitting.h @@ -102,38 +102,53 @@ namespace Eigen template struct SplineFitting { + typedef typename SplineType::KnotVectorType KnotVectorType; + /** * \brief Fits an interpolating Spline to the given data points. + * + * \param pts The points for which an interpolating spline will be computed. + * \param degree The degree of the interpolating spline. + * + * \returns A spline interpolating the initially provided points. **/ template static SplineType Interpolate(const PointArrayType& pts, DenseIndex degree); + + /** + * \brief Fits an interpolating Spline to the given data points. + * + * \param pts The points for which an interpolating spline will be computed. + * \param degree The degree of the interpolating spline. + * \param knot_parameters The knot parameters for the interpolation. + * + * \returns A spline interpolating the initially provided points. + **/ + template + static SplineType Interpolate(const PointArrayType& pts, DenseIndex degree, const KnotVectorType& knot_parameters); }; template template - SplineType SplineFitting::Interpolate(const PointArrayType& pts, DenseIndex degree) + SplineType SplineFitting::Interpolate(const PointArrayType& pts, DenseIndex degree, const KnotVectorType& knot_parameters) { typedef typename SplineType::KnotVectorType::Scalar Scalar; - typedef typename SplineType::KnotVectorType KnotVectorType; typedef typename SplineType::BasisVectorType BasisVectorType; typedef typename SplineType::ControlPointVectorType ControlPointVectorType; typedef Matrix MatrixType; - KnotVectorType chord_lengths; // knot parameters - ChordLengths(pts, chord_lengths); - KnotVectorType knots; - KnotAveraging(chord_lengths, degree, knots); + KnotAveraging(knot_parameters, degree, knots); DenseIndex n = pts.cols(); MatrixType A = MatrixType::Zero(n,n); for (DenseIndex i=1; i + template + SplineType SplineFitting::Interpolate(const PointArrayType& pts, DenseIndex degree) + { + KnotVectorType chord_lengths; // knot parameters + ChordLengths(pts, chord_lengths); + return Interpolate(pts, degree, chord_lengths); + } } #endif // EIGEN_SPLINE_FITTING_H diff --git a/unsupported/test/splines.cpp b/unsupported/test/splines.cpp index 02e170c44..fe98bf183 100644 --- a/unsupported/test/splines.cpp +++ b/unsupported/test/splines.cpp @@ -216,16 +216,32 @@ void check_global_interpolation2d() typedef Spline2d::ControlPointVectorType ControlPointVectorType; ControlPointVectorType points = ControlPointVectorType::Random(2,100); - const Spline2d spline = SplineFitting::Interpolate(points,3); KnotVectorType chord_lengths; // knot parameters Eigen::ChordLengths(points, chord_lengths); - for (Eigen::DenseIndex i=0; i::Interpolate(points,3); + + for (Eigen::DenseIndex i=0; i::Interpolate(points,3,chord_lengths); + + for (Eigen::DenseIndex i=0; i