Added docs to the spline module.

This commit is contained in:
Hauke Heibel 2011-12-04 18:44:01 +01:00
parent 9bd902ed9c
commit a8a2bf3b5a
4 changed files with 198 additions and 66 deletions

View File

@ -29,100 +29,184 @@
namespace Eigen namespace Eigen
{ {
/** /**
* \class Spline class * \ingroup Splines_Module
* \brief A class representing N-D spline curves. * \class Spline class
* \tparam _Scalar The underlying data type (typically float or double) * \brief A class representing multi-dimensional spline curves.
* \tparam _Dim The curve dimension (e.g. 2 or 3) *
* \tparam _Degree Per default set to Dynamic; could be set to the actual desired * The class represents B-splines with non-uniform knot vectors. Each control
* degree for optimization purposes (would result in stack allocation * point of the B-spline is associated with a basis function
* of several temporary variables). * \f{align*}
**/ * C(u) & = \sum_{i=0}^{n}N_{i,p}(u)P_i
* \f}
*
* \tparam _Scalar The underlying data type (typically float or double)
* \tparam _Dim The curve dimension (e.g. 2 or 3)
* \tparam _Degree Per default set to Dynamic; could be set to the actual desired
* degree for optimization purposes (would result in stack allocation
* of several temporary variables).
**/
template <typename _Scalar, int _Dim, int _Degree> template <typename _Scalar, int _Dim, int _Degree>
class Spline class Spline
{ {
public: public:
typedef _Scalar Scalar; typedef _Scalar Scalar; /*!< The spline curve's scalar type. */
enum { Dimension = _Dim }; enum { Dimension = _Dim /*!< The spline curve's dimension. */ };
enum { Degree = _Degree }; enum { Degree = _Degree /*!< The spline curve's degree. */ };
/** \brief The point type the spline is representing. */
typedef typename SplineTraits<Spline>::PointType PointType; typedef typename SplineTraits<Spline>::PointType PointType;
/** \brief The data type used to store knot vectors. */
typedef typename SplineTraits<Spline>::KnotVectorType KnotVectorType; typedef typename SplineTraits<Spline>::KnotVectorType KnotVectorType;
/** \brief The data type used to store non-zero basis functions. */
typedef typename SplineTraits<Spline>::BasisVectorType BasisVectorType; typedef typename SplineTraits<Spline>::BasisVectorType BasisVectorType;
/** \brief The data type representing the spline's control points. */
typedef typename SplineTraits<Spline>::ControlPointVectorType ControlPointVectorType; typedef typename SplineTraits<Spline>::ControlPointVectorType ControlPointVectorType;
/** /**
* \brief Creates a spline from a knot vector and control points. * \brief Creates a spline from a knot vector and control points.
* \param knots The spline's knot vector.
* \param ctrls The spline's control point vector.
**/ **/
template <typename OtherVectorType, typename OtherArrayType> template <typename OtherVectorType, typename OtherArrayType>
Spline(const OtherVectorType& knots, const OtherArrayType& ctrls) : m_knots(knots), m_ctrls(ctrls) {} Spline(const OtherVectorType& knots, const OtherArrayType& ctrls) : m_knots(knots), m_ctrls(ctrls) {}
/**
* \brief Copy constructor for splines.
* \param spline The input spline.
**/
template <int OtherDegree> template <int OtherDegree>
Spline(const Spline<Scalar, Dimension, OtherDegree>& spline) : Spline(const Spline<Scalar, Dimension, OtherDegree>& spline) :
m_knots(spline.knots()), m_ctrls(spline.ctrls()) {} m_knots(spline.knots()), m_ctrls(spline.ctrls()) {}
/* Const access methods for knots and control points. */ /**
* \brief Returns the knots of the underlying spline.
**/
const KnotVectorType& knots() const { return m_knots; } const KnotVectorType& knots() const { return m_knots; }
/**
* \brief Returns the knots of the underlying spline.
**/
const ControlPointVectorType& ctrls() const { return m_ctrls; } const ControlPointVectorType& ctrls() const { return m_ctrls; }
/* Spline evaluation. */ /**
* \brief Returns the spline value at a given site \f$u\f$.
*
* The function returns
* \f{align*}
* C(u) & = \sum_{i=0}^{n}N_{i,p}P_i
* \f}
*
* \param u Parameter \f$u \in [0;1]\f$ at which the spline is evaluated.
* \return The spline value at the given location \f$u\f$.
**/
PointType operator()(Scalar u) const; PointType operator()(Scalar u) const;
/* Evaluation of spline derivatives of up-to given order. /**
* The returned matrix has dimensions Dim-by-(Order+1) containing * \brief Evaluation of spline derivatives of up-to given order.
* the 0-th order up-to Order-th order derivatives. *
*/ * The function returns
* \f{align*}
* \frac{d^i}{du^i}C(u) & = \sum_{i=0}^{n} \frac{d^i}{du^i} N_{i,p}(u)P_i
* \f}
* for i ranging between 0 and order.
*
* \param u Parameter \f$u \in [0;1]\f$ at which the spline derivative is evaluated.
* \param order The order up to which the derivatives are computed.
**/
typename SplineTraits<Spline>::DerivativeType typename SplineTraits<Spline>::DerivativeType
derivatives(Scalar u, DenseIndex order) const; derivatives(Scalar u, DenseIndex order) const;
/** /**
* Evaluation of spline derivatives of up-to given order. * \copydoc Spline::derivatives
* The function performs identically to derivatives(Scalar, int) but * Using the template version of this function is more efficieent since
* does not require any heap allocations. * temporary objects are allocated on the stack whenever this is possible.
* \sa derivatives(Scalar, int) **/
**/
template <int DerivativeOrder> template <int DerivativeOrder>
typename SplineTraits<Spline,DerivativeOrder>::DerivativeType typename SplineTraits<Spline,DerivativeOrder>::DerivativeType
derivatives(Scalar u, DenseIndex order = DerivativeOrder) const; derivatives(Scalar u, DenseIndex order = DerivativeOrder) const;
/* Non-zero spline basis functions. */ /**
* \brief Computes the non-zero basis functions at the given site.
*
* Splines have local support and a point from their image is defined
* by exactly \f$p+1\f$ control points \f$P_i\f$ where \f$p\f$ is the
* spline degree.
*
* This function computes the \f$p+1\f$ non-zero basis function values
* for a given parameter value \f$u\f$. It returns
* \f{align*}{
* N_{i,p}(u), \hdots, N_{i+p+1,p}(u)
* \f}
*
* \param u Parameter \f$u \in [0;1]\f$ at which the non-zero basis functions
* are computed.
**/
typename SplineTraits<Spline>::BasisVectorType typename SplineTraits<Spline>::BasisVectorType
basisFunctions(Scalar u) const; basisFunctions(Scalar u) const;
/* Non-zero spline basis function derivatives up to given order. /**
* The order is different from the spline order - it is the order * \brief Computes the non-zero spline basis function derivatives up to given order.
* up to which derivatives will be computed. *
* \sa basisFunctions(Scalar) * The function computes
*/ * \f{align*}{
* \frac{d^i}{du^i} N_{i,p}(u), \hdots, \frac{d^i}{du^i} N_{i+p+1,p}(u)
* \f}
* with i ranging from 0 up to the specified order.
*
* \param u Parameter \f$u \in [0;1]\f$ at which the non-zero basis function
* derivatives are computed.
* \param order The order up to which the basis function derivatives are computes.
**/
typename SplineTraits<Spline>::BasisDerivativeType typename SplineTraits<Spline>::BasisDerivativeType
basisFunctionDerivatives(Scalar u, DenseIndex order) const; basisFunctionDerivatives(Scalar u, DenseIndex order) const;
/** /**
* Computes non-zero basis function derivatives up to the given derivative order. * \copydoc Spline::basisFunctionDerivatives
* As opposed to basisFunctionDerivatives(Scalar, int) this function does not perform * Using the template version of this function is more efficieent since
* any heap allocations. * temporary objects are allocated on the stack whenever this is possible.
* \sa basisFunctionDerivatives(Scalar, int) **/
**/
template <int DerivativeOrder> template <int DerivativeOrder>
typename SplineTraits<Spline,DerivativeOrder>::BasisDerivativeType typename SplineTraits<Spline,DerivativeOrder>::BasisDerivativeType
basisFunctionDerivatives(Scalar u, DenseIndex order = DerivativeOrder) const; basisFunctionDerivatives(Scalar u, DenseIndex order = DerivativeOrder) const;
/** /**
* \brief The current spline degree. It's a function of knot size and number * \brief Returns the spline degree.
* of controls and thus does not require a dedicated member. **/
*/
DenseIndex degree() const; DenseIndex degree() const;
/** Computes the span within the knot vector in which u falls. */ /**
* \brief Returns the span within the knot vector in which u is falling.
* \param u The site for which the span is determined.
**/
DenseIndex span(Scalar u) const; DenseIndex span(Scalar u) const;
/**
* \brief Computes the spang within the provided knot vector in which u is falling.
**/
static DenseIndex Span(typename SplineTraits<Spline>::Scalar u, DenseIndex degree, const typename SplineTraits<Spline>::KnotVectorType& knots); static DenseIndex Span(typename SplineTraits<Spline>::Scalar u, DenseIndex degree, const typename SplineTraits<Spline>::KnotVectorType& knots);
/**
* \brief Returns the spline's non-zero basis functions.
*
* The function computes and returns
* \f{align*}{
* N_{i,p}(u), \hdots, N_{i+p+1,p}(u)
* \f}
*
* \param u The site at which the basis functions are computed.
* \param degree The degree of the underlying spline.
* \param knots The underlying spline's knot vector.
**/
static BasisVectorType BasisFunctions(Scalar u, DenseIndex degree, const KnotVectorType& knots); static BasisVectorType BasisFunctions(Scalar u, DenseIndex degree, const KnotVectorType& knots);
private: private:
KnotVectorType m_knots; /* Knot vector. */ KnotVectorType m_knots; /*!< Knot vector. */
ControlPointVectorType m_ctrls; /* Control points. */ ControlPointVectorType m_ctrls; /*!< Control points. */
}; };
template <typename _Scalar, int _Dim, int _Degree> template <typename _Scalar, int _Dim, int _Degree>
@ -188,10 +272,6 @@ namespace Eigen
return Spline::Span(u, degree(), knots()); return Spline::Span(u, degree(), knots());
} }
/**
* \brief A functor for the computation of a spline point.
* \sa Piegl & Tiller, "The NURBS Book", A4.1 (p. 124)
**/
template <typename _Scalar, int _Dim, int _Degree> template <typename _Scalar, int _Dim, int _Degree>
typename Spline<_Scalar, _Dim, _Degree>::PointType Spline<_Scalar, _Dim, _Degree>::operator()(Scalar u) const typename Spline<_Scalar, _Dim, _Degree>::PointType Spline<_Scalar, _Dim, _Degree>::operator()(Scalar u) const
{ {
@ -242,10 +322,6 @@ namespace Eigen
} }
} }
/**
* \brief A functor for the computation of a spline point.
* \sa Piegl & Tiller, "The NURBS Book", A4.1 (p. 124)
**/
template <typename _Scalar, int _Dim, int _Degree> template <typename _Scalar, int _Dim, int _Degree>
typename SplineTraits< Spline<_Scalar, _Dim, _Degree> >::DerivativeType typename SplineTraits< Spline<_Scalar, _Dim, _Degree> >::DerivativeType
Spline<_Scalar, _Dim, _Degree>::derivatives(Scalar u, DenseIndex order) const Spline<_Scalar, _Dim, _Degree>::derivatives(Scalar u, DenseIndex order) const
@ -265,10 +341,6 @@ namespace Eigen
return res; return res;
} }
/**
* \brief A functor for the computation of a spline's non-zero basis functions.
* \sa Piegl & Tiller, "The NURBS Book", A2.2 (p. 70)
**/
template <typename _Scalar, int _Dim, int _Degree> template <typename _Scalar, int _Dim, int _Degree>
typename SplineTraits< Spline<_Scalar, _Dim, _Degree> >::BasisVectorType typename SplineTraits< Spline<_Scalar, _Dim, _Degree> >::BasisVectorType
Spline<_Scalar, _Dim, _Degree>::basisFunctions(Scalar u) const Spline<_Scalar, _Dim, _Degree>::basisFunctions(Scalar u) const

View File

@ -33,6 +33,25 @@
namespace Eigen namespace Eigen
{ {
/**
* \brief Computes knot averages.
* \ingroup Splines_Module
*
* The knots are computes 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> template <typename KnotVectorType>
void KnotAveraging(const KnotVectorType& parameters, DenseIndex degree, KnotVectorType& knots) void KnotAveraging(const KnotVectorType& parameters, DenseIndex degree, KnotVectorType& knots)
{ {
@ -47,6 +66,15 @@ namespace Eigen
knots.segment(knots.size()-degree-1,degree+1) = KnotVectorType::Ones(degree+1); knots.segment(knots.size()-degree-1,degree+1) = KnotVectorType::Ones(degree+1);
} }
/**
* \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 lenggth 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> template <typename PointArrayType, typename KnotVectorType>
void ChordLengths(const PointArrayType& pts, KnotVectorType& chord_lengths) void ChordLengths(const PointArrayType& pts, KnotVectorType& chord_lengths)
{ {
@ -67,9 +95,16 @@ namespace Eigen
chord_lengths(n-1) = Scalar(1); chord_lengths(n-1) = Scalar(1);
} }
/**
* \brief Spline fitting methods.
* \ingroup Splines_Module
**/
template <typename SplineType> template <typename SplineType>
struct SplineFitting struct SplineFitting
{ {
/**
* \brief Fits an interpolating Spline to the given data points.
**/
template <typename PointArrayType> template <typename PointArrayType>
static SplineType Interpolate(const PointArrayType& pts, DenseIndex degree); static SplineType Interpolate(const PointArrayType& pts, DenseIndex degree);
}; };

View File

@ -31,47 +31,70 @@ namespace Eigen
{ {
template <typename Scalar, int Dim, int Degree = Dynamic> class Spline; template <typename Scalar, int Dim, int Degree = Dynamic> class Spline;
template < typename SplineType, int _DerivativeOrder = Dynamic > struct SplineTraits {}; template < typename SplineType, int DerivativeOrder = Dynamic > struct SplineTraits {};
// hide specializations from doxygen
#ifndef DOXYGEN_SHOULD_SKIP_THIS
/**
* \ingroup Splines_Module
* \brief Compile-time attributes of the Spline class for Dynamic degree.
**/
template <typename _Scalar, int _Dim, int _Degree> template <typename _Scalar, int _Dim, int _Degree>
struct SplineTraits< Spline<_Scalar, _Dim, _Degree>, Dynamic > struct SplineTraits< Spline<_Scalar, _Dim, _Degree>, Dynamic >
{ {
typedef _Scalar Scalar; /* The underlying scalar value. */ typedef _Scalar Scalar; /*!< The spline curve's scalar type. */
enum { Dimension = _Dim }; /* The spline curve's dimension. */ enum { Dimension = _Dim /*!< The spline curve's dimension. */ };
enum { Degree = _Degree }; /* The spline curve's degree. */ enum { Degree = _Degree /*!< The spline curve's degree. */ };
enum { OrderAtCompileTime = _Degree==Dynamic ? Dynamic : _Degree+1 }; enum { OrderAtCompileTime = _Degree==Dynamic ? Dynamic : _Degree+1 /*!< The spline curve's order at compile-time. */ };
enum { NumOfDerivativesAtCompileTime = OrderAtCompileTime }; enum { NumOfDerivativesAtCompileTime = OrderAtCompileTime /*!< The number of derivatives defined for the current spline. */ };
/** \brief The data type used to store non-zero basis functions. */
typedef Array<Scalar,1,OrderAtCompileTime> BasisVectorType; typedef Array<Scalar,1,OrderAtCompileTime> BasisVectorType;
/** \brief The data type used to store the values of the basis function derivatives. */
typedef Array<Scalar,Dynamic,Dynamic,RowMajor,NumOfDerivativesAtCompileTime,OrderAtCompileTime> BasisDerivativeType; typedef Array<Scalar,Dynamic,Dynamic,RowMajor,NumOfDerivativesAtCompileTime,OrderAtCompileTime> BasisDerivativeType;
/** \brief The data type used to store the spline's derivative values. */
typedef Array<Scalar,Dimension,Dynamic,ColMajor,Dimension,NumOfDerivativesAtCompileTime> DerivativeType; typedef Array<Scalar,Dimension,Dynamic,ColMajor,Dimension,NumOfDerivativesAtCompileTime> DerivativeType;
/** \brief The point type the spline is representing. */
typedef Array<Scalar,Dimension,1> PointType; typedef Array<Scalar,Dimension,1> PointType;
/** \brief The data type used to store knot vectors. */
typedef Array<Scalar,1,Dynamic> KnotVectorType; typedef Array<Scalar,1,Dynamic> KnotVectorType;
/** \brief The data type representing the spline's control points. */
typedef Array<Scalar,Dimension,Dynamic> ControlPointVectorType; typedef Array<Scalar,Dimension,Dynamic> ControlPointVectorType;
}; };
/**
* \ingroup Splines_Module
* \brief Compile-time attributes of the Spline class for fixed degree.
*
* The traits class inherits all attributes from the SplineTraits of Dynamic degree.
**/
template < typename _Scalar, int _Dim, int _Degree, int _DerivativeOrder > template < typename _Scalar, int _Dim, int _Degree, int _DerivativeOrder >
struct SplineTraits< Spline<_Scalar, _Dim, _Degree>, _DerivativeOrder > : public SplineTraits< Spline<_Scalar, _Dim, _Degree> > struct SplineTraits< Spline<_Scalar, _Dim, _Degree>, _DerivativeOrder > : public SplineTraits< Spline<_Scalar, _Dim, _Degree> >
{ {
enum { OrderAtCompileTime = _Degree==Dynamic ? Dynamic : _Degree+1 }; enum { OrderAtCompileTime = _Degree==Dynamic ? Dynamic : _Degree+1 /*!< The spline curve's order at compile-time. */ };
enum { NumOfDerivativesAtCompileTime = _DerivativeOrder==Dynamic ? Dynamic : _DerivativeOrder+1 }; enum { NumOfDerivativesAtCompileTime = _DerivativeOrder==Dynamic ? Dynamic : _DerivativeOrder+1 /*!< The number of derivatives defined for the current spline. */ };
/** \brief The data type used to store the values of the basis function derivatives. */
typedef Array<_Scalar,Dynamic,Dynamic,RowMajor,NumOfDerivativesAtCompileTime,OrderAtCompileTime> BasisDerivativeType; typedef Array<_Scalar,Dynamic,Dynamic,RowMajor,NumOfDerivativesAtCompileTime,OrderAtCompileTime> BasisDerivativeType;
/** \brief The data type used to store the spline's derivative values. */
typedef Array<_Scalar,_Dim,Dynamic,ColMajor,_Dim,NumOfDerivativesAtCompileTime> DerivativeType; typedef Array<_Scalar,_Dim,Dynamic,ColMajor,_Dim,NumOfDerivativesAtCompileTime> DerivativeType;
}; };
#endif /** \brief 2D float B-spline with dynamic degree. */
typedef Spline<float,2> Spline2f; typedef Spline<float,2> Spline2f;
/** \brief 3D float B-spline with dynamic degree. */
typedef Spline<float,3> Spline3f; typedef Spline<float,3> Spline3f;
/** \brief 2D double B-spline with dynamic degree. */
typedef Spline<double,2> Spline2d; typedef Spline<double,2> Spline2d;
/** \brief 3D double B-spline with dynamic degree. */
typedef Spline<double,3> Spline3d; typedef Spline<double,3> Spline3d;
} }

View File

@ -553,6 +553,7 @@ WARN_LOGFILE =
# with spaces. # with spaces.
INPUT = "${Eigen_SOURCE_DIR}/unsupported/Eigen" \ INPUT = "${Eigen_SOURCE_DIR}/unsupported/Eigen" \
"${Eigen_SOURCE_DIR}/unsupported/Eigen/src/Splines" \
"${Eigen_SOURCE_DIR}/unsupported/doc" "${Eigen_SOURCE_DIR}/unsupported/doc"
# This tag can be used to specify the character encoding of the source files # This tag can be used to specify the character encoding of the source files
@ -958,7 +959,8 @@ PAPER_TYPE = a4wide
# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX # The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX
# packages that should be included in the LaTeX output. # packages that should be included in the LaTeX output.
EXTRA_PACKAGES = amssymb EXTRA_PACKAGES = amssymb \
amsmath
# The LATEX_HEADER tag can be used to specify a personal LaTeX header for # The LATEX_HEADER tag can be used to specify a personal LaTeX header for
# the generated latex document. The header should contain everything until # the generated latex document. The header should contain everything until