// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 20010-2011 Hauke Heibel <hauke.heibel@gmail.com> // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
namespace Eigen
{ /** * \brief Computes knot averages. * \ingroup Splines_Module * * The knots are computed as * \f{align*} * u_0 & = \hdots = u_p = 0 \\ * u_{m-p} & = \hdots = u_{m} = 1 \\ * u_{j+p} & = \frac{1}{p}\sum_{i=j}^{j+p-1}\bar{u}_i \quad\quad j=1,\hdots,n-p * \f} * where \f$p\f$ is the degree and \f$m+1\f$ the number knots * of the desired interpolating spline. * * \param[in] parameters The input parameters. During interpolation one for each data point. * \param[in] degree The spline degree which is used during the interpolation. * \param[out] knots The output knot vector. * * \sa Les Piegl and Wayne Tiller, The NURBS book (2nd ed.), 1997, 9.2.1 Global Curve Interpolation to Point Data
**/ template <typename KnotVectorType> void KnotAveraging(const KnotVectorType& parameters, DenseIndex degree, KnotVectorType& knots)
{
knots.resize(parameters.size()+degree+1);
for (DenseIndex j=1; j<parameters.size()-degree; ++j)
knots(j+degree) = parameters.segment(j,degree).mean();
/** * \brief Computes knot averages when derivative constraints are present. * Note that this is a technical interpretation of the referenced article * since the algorithm contained therein is incorrect as written. * \ingroup Splines_Module * * \param[in] parameters The parameters at which the interpolation B-Spline * will intersect the given interpolation points. The parameters * are assumed to be a non-decreasing sequence. * \param[in] degree The degree of the interpolating B-Spline. This must be * greater than zero. * \param[in] derivativeIndices The indices corresponding to parameters at * which there are derivative constraints. The indices are assumed * to be a non-decreasing sequence. * \param[out] knots The calculated knot vector. These will be returned as a * non-decreasing sequence * * \sa Les A. Piegl, Khairan Rajab, Volha Smarodzinana. 2008. * Curve interpolation with directional constraints for engineering design. * Engineering with Computers
**/ template <typename KnotVectorType, typename ParameterVectorType, typename IndexArray> void KnotAveragingWithDerivatives(const ParameterVectorType& parameters, constunsignedint degree, const IndexArray& derivativeIndices,
KnotVectorType& knots)
{ typedeftypename ParameterVectorType::Scalar Scalar;
// There are (endIndex - startIndex + 1) knots obtained from the averaging // and 2 for the first and last parameters.
DenseIndex numAverageKnots = endIndex - startIndex + 3;
KnotVectorType averageKnots(numAverageKnots);
averageKnots[0] = parameters[0];
int newKnotIndex = 0; for (DenseIndex i = startIndex; i <= endIndex; ++i)
averageKnots[++newKnotIndex] = parameters.segment(i, degree).mean();
averageKnots[++newKnotIndex] = parameters[numParameters - 1];
// Number of knots (one for each point and derivative) plus spline order.
DenseIndex numKnots = numParameters + numDerivatives + degree + 1;
knots.resize(numKnots);
/** * \brief Computes chord length parameters which are required for spline interpolation. * \ingroup Splines_Module * * \param[in] pts The data points to which a spline should be fit. * \param[out] chord_lengths The resulting chord length vector. * * \sa Les Piegl and Wayne Tiller, The NURBS book (2nd ed.), 1997, 9.2.1 Global Curve Interpolation to Point Data
**/ template <typename PointArrayType, typename KnotVectorType> void ChordLengths(const PointArrayType& pts, KnotVectorType& chord_lengths)
{ typedeftypename KnotVectorType::Scalar Scalar;
/** * \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 <typename PointArrayType> 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 <typename PointArrayType> static SplineType Interpolate(const PointArrayType& pts, DenseIndex degree, const KnotVectorType& knot_parameters);
/** * \brief Fits an interpolating spline to the given data points and * derivatives. * * \param points The points for which an interpolating spline will be computed. * \param derivatives The desired derivatives of the interpolating spline at interpolation * points. * \param derivativeIndices An array indicating which point each derivative belongs to. This * must be the same size as @a derivatives. * \param degree The degree of the interpolating spline. * * \returns A spline interpolating @a points with @a derivatives at those points. * * \sa Les A. Piegl, Khairan Rajab, Volha Smarodzinana. 2008. * Curve interpolation with directional constraints for engineering design. * Engineering with Computers
**/ template <typename PointArrayType, typename IndexArray> static SplineType InterpolateWithDerivatives(const PointArrayType& points, const PointArrayType& derivatives, const IndexArray& derivativeIndices, constunsignedint degree);
/** * \brief Fits an interpolating spline to the given data points and derivatives. * * \param points The points for which an interpolating spline will be computed. * \param derivatives The desired derivatives of the interpolating spline at interpolation points. * \param derivativeIndices An array indicating which point each derivative belongs to. This * must be the same size as @a derivatives. * \param degree The degree of the interpolating spline. * \param parameters The parameters corresponding to the interpolation points. * * \returns A spline interpolating @a points with @a derivatives at those points. * * \sa Les A. Piegl, Khairan Rajab, Volha Smarodzinana. 2008. * Curve interpolation with directional constraints for engineering design. * Engineering with Computers
*/ template <typename PointArrayType, typename IndexArray> static SplineType InterpolateWithDerivatives(const PointArrayType& points, const PointArrayType& derivatives, const IndexArray& derivativeIndices, constunsignedint degree, const ParameterVectorType& parameters);
};
DenseIndex n = pts.cols();
MatrixType A = MatrixType::Zero(n,n); for (DenseIndex i=1; i<n-1; ++i)
{ const DenseIndex span = SplineType::Span(knot_parameters[i], degree, knots);
// The segment call should somehow be told the spline order at compile time.
A.row(i).segment(span-degree, degree+1) = SplineType::BasisFunctions(knot_parameters[i], degree, knots);
}
A(0,0) = 1.0;
A(n-1,n-1) = 1.0;
HouseholderQR<MatrixType> qr(A);
// Here, we are creating a temporary due to an Eigen issue.
ControlPointVectorType ctrls = qr.solve(MatrixType(pts.transpose())).transpose();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.