10 #ifndef EIGEN_SPLINE_H 11 #define EIGEN_SPLINE_H 13 #include "SplineFwd.h" 34 template <
typename _Scalar,
int _Dim,
int _Degree>
43 typedef typename SplineTraits<Spline>::PointType
PointType;
80 template <
typename OtherVectorType,
typename OtherArrayType>
81 Spline(
const OtherVectorType&
knots,
const OtherArrayType&
ctrls) : m_knots(knots), m_ctrls(ctrls) {}
87 template <
int OtherDegree>
89 m_knots(spline.
knots()), m_ctrls(spline.
ctrls()) {}
94 const KnotVectorType&
knots()
const {
return m_knots; }
99 const ControlPointVectorType&
ctrls()
const {
return m_ctrls; }
126 typename SplineTraits<Spline>::DerivativeType
134 template <
int DerivativeOrder>
135 typename SplineTraits<Spline,DerivativeOrder>::DerivativeType
136 derivatives(Scalar u, DenseIndex order = DerivativeOrder)
const;
154 typename SplineTraits<Spline>::BasisVectorType
170 typename SplineTraits<Spline>::BasisDerivativeType
178 template <
int DerivativeOrder>
179 typename SplineTraits<Spline,DerivativeOrder>::BasisDerivativeType
185 DenseIndex
degree()
const;
191 DenseIndex
span(Scalar u)
const;
196 static DenseIndex
Span(
typename SplineTraits<Spline>::Scalar u, DenseIndex degree,
const typename SplineTraits<Spline>::KnotVectorType&
knots);
210 static BasisVectorType
BasisFunctions(Scalar u, DenseIndex degree,
const KnotVectorType& knots);
218 const Scalar u,
const DenseIndex order,
const DenseIndex degree,
const KnotVectorType& knots);
221 KnotVectorType m_knots;
222 ControlPointVectorType m_ctrls;
224 template <
typename DerivativeType>
225 static void BasisFunctionDerivativesImpl(
227 const DenseIndex order,
233 template <
typename _Scalar,
int _Dim,
int _Degree>
241 const Scalar* pos = std::upper_bound(knots.data()+degree-1, knots.data()+knots.size()-degree-1, u);
242 return static_cast<DenseIndex
>( std::distance(knots.data(), pos) - 1 );
245 template <
typename _Scalar,
int _Dim,
int _Degree>
252 const DenseIndex p =
degree;
265 for (DenseIndex j=1; j<=p; ++j)
268 for (DenseIndex r=0; r<j; r++)
270 const Scalar tmp = N(r)/(right(r+1)+left(j-r));
271 N[r] = saved + right(r+1)*tmp;
272 saved = left(j-r)*tmp;
279 template <
typename _Scalar,
int _Dim,
int _Degree>
283 return m_knots.size() - m_ctrls.cols() - 1;
288 template <
typename _Scalar,
int _Dim,
int _Degree>
294 template <
typename _Scalar,
int _Dim,
int _Degree>
297 enum { Order = SplineTraits<Spline>::OrderAtCompileTime };
299 const DenseIndex
span = this->
span(u);
300 const DenseIndex p =
degree();
305 return (ctrl_weights * ctrl_pts).rowwise().sum();
310 template <
typename SplineType,
typename DerivativeType>
311 void derivativesImpl(
const SplineType& spline,
typename SplineType::Scalar u, DenseIndex order, DerivativeType& der)
313 enum {
Dimension = SplineTraits<SplineType>::Dimension };
314 enum { Order = SplineTraits<SplineType>::OrderAtCompileTime };
315 enum { DerivativeOrder = DerivativeType::ColsAtCompileTime };
318 typedef typename SplineTraits<SplineType,DerivativeOrder>::BasisDerivativeType
BasisDerivativeType;
319 typedef typename BasisDerivativeType::ConstRowXpr BasisDerivativeRowXpr;
321 const DenseIndex p = spline.degree();
322 const DenseIndex
span = spline.span(u);
324 const DenseIndex n = (std::min)(p, order);
329 const BasisDerivativeType basis_func_ders = spline.template basisFunctionDerivatives<DerivativeOrder>(u, n+1);
332 for (DenseIndex der_order=0; der_order<n+1; ++der_order)
336 der.col(der_order) = (ctrl_weights * ctrl_pts).rowwise().sum();
340 template <
typename _Scalar,
int _Dim,
int _Degree>
341 typename SplineTraits< Spline<_Scalar, _Dim, _Degree> >::DerivativeType
344 typename SplineTraits< Spline >::DerivativeType res;
345 derivativesImpl(*
this, u, order, res);
349 template <
typename _Scalar,
int _Dim,
int _Degree>
350 template <
int DerivativeOrder>
351 typename SplineTraits< Spline<_Scalar, _Dim, _Degree>, DerivativeOrder >::DerivativeType
354 typename SplineTraits< Spline, DerivativeOrder >::DerivativeType res;
355 derivativesImpl(*
this, u, order, res);
359 template <
typename _Scalar,
int _Dim,
int _Degree>
369 template <
typename _Scalar,
int _Dim,
int _Degree>
370 template <
typename DerivativeType>
373 const DenseIndex order,
379 enum { Order = SplineTraits<SplineType>::OrderAtCompileTime };
381 const DenseIndex
span = SplineType::Span(u, p, U);
383 const DenseIndex n = (std::min)(p, order);
399 left[j] = u-U[span+1-j];
400 right[j] = U[span+j]-u;
403 for (DenseIndex r=0; r<j; ++r)
406 ndu(j,r) = right[r+1]+left[j-r];
407 temp = ndu(r,j-1)/ndu(j,r);
409 ndu(r,j) =
static_cast<Scalar>(saved+right[r+1] * temp);
410 saved = left[j-r] * temp;
413 ndu(j,j) =
static_cast<Scalar>(saved);
416 for (j = p; j>=0; --j)
420 DerivativeType a(n+1,p+1);
429 for (DenseIndex k=1; k<=static_cast<DenseIndex>(n); ++k)
432 DenseIndex rk,pk,j1,j2;
437 a(s2,0) = a(s1,0)/ndu(pk+1,rk);
438 d = a(s2,0)*ndu(rk,pk);
444 if (r-1 <= pk) j2 = k-1;
447 for (j=j1; j<=j2; ++j)
449 a(s2,j) = (a(s1,j)-a(s1,j-1))/ndu(pk+1,rk+j);
450 d += a(s2,j)*ndu(rk+j,pk);
455 a(s2,k) = -a(s1,k-1)/ndu(pk+1,r);
456 d += a(s2,k)*ndu(r,pk);
459 N_(k,r) =
static_cast<Scalar>(d);
460 j = s1; s1 = s2; s2 = j;
467 for (DenseIndex k=1; k<=static_cast<DenseIndex>(n); ++k)
469 for (j=p; j>=0; --j) N_(k,j) *= r;
474 template <
typename _Scalar,
int _Dim,
int _Degree>
479 BasisFunctionDerivativesImpl(u, order,
degree(),
knots(), der);
483 template <
typename _Scalar,
int _Dim,
int _Degree>
484 template <
int DerivativeOrder>
489 BasisFunctionDerivativesImpl(u, order,
degree(),
knots(), der);
493 template <
typename _Scalar,
int _Dim,
int _Degree>
497 const DenseIndex order,
501 typename SplineTraits<Spline>::BasisDerivativeType der;
502 BasisFunctionDerivativesImpl(u, order, degree, knots, der);
507 #endif // EIGEN_SPLINE_H A class representing multi-dimensional spline curves.
Definition: Spline.h:35
static BasisVectorType BasisFunctions(Scalar u, DenseIndex degree, const KnotVectorType &knots)
Returns the spline's non-zero basis functions.
Definition: Spline.h:247
SplineTraits< Spline >::PointType PointType
The point type the spline is representing.
Definition: Spline.h:43
SplineTraits< Spline >::DerivativeType derivatives(Scalar u, DenseIndex order) const
Evaluation of spline derivatives of up-to given order.
Definition: Spline.h:342
SplineTraits< Spline >::BasisDerivativeType BasisDerivativeType
The data type used to store the values of the basis function derivatives.
Definition: Spline.h:55
Namespace containing all symbols from the Eigen library.
SplineTraits< Spline >::BasisDerivativeType basisFunctionDerivatives(Scalar u, DenseIndex order) const
Computes the non-zero spline basis function derivatives up to given order.
Definition: Spline.h:476
const ControlPointVectorType & ctrls() const
Returns the ctrls of the underlying spline.
Definition: Spline.h:99
static BasisDerivativeType BasisFunctionDerivatives(const Scalar u, const DenseIndex order, const DenseIndex degree, const KnotVectorType &knots)
Computes the non-zero spline basis function derivatives up to given order.
Definition: Spline.h:495
PointType operator()(Scalar u) const
Returns the spline value at a given site .
Definition: Spline.h:295
DenseIndex span(Scalar u) const
Returns the span within the knot vector in which u is falling.
Definition: Spline.h:289
DenseIndex degree() const
Returns the spline degree.
Definition: Spline.h:280
Spline()
Creates a (constant) zero spline. For Splines with dynamic degree, the resulting degree will be 0...
Definition: Spline.h:64
SplineTraits< Spline >::ParameterVectorType ParameterVectorType
The data type used to store parameter vectors.
Definition: Spline.h:49
static DenseIndex Span(typename SplineTraits< Spline >::Scalar u, DenseIndex degree, const typename SplineTraits< Spline >::KnotVectorType &knots)
Computes the span within the provided knot vector in which u is falling.
Definition: Spline.h:234
const KnotVectorType & knots() const
Returns the knots of the underlying spline.
Definition: Spline.h:94
SplineTraits< Spline >::ControlPointVectorType ControlPointVectorType
The data type representing the spline's control points.
Definition: Spline.h:58
Spline(const Spline< Scalar, Dimension, OtherDegree > &spline)
Copy constructor for splines.
Definition: Spline.h:88
SplineTraits< Spline >::BasisVectorType basisFunctions(Scalar u) const
Computes the non-zero basis functions at the given site.
Definition: Spline.h:361
Spline(const OtherVectorType &knots, const OtherArrayType &ctrls)
Creates a spline from a knot vector and control points.
Definition: Spline.h:81
SplineTraits< Spline >::BasisVectorType BasisVectorType
The data type used to store non-zero basis functions.
Definition: Spline.h:52
SplineTraits< Spline >::KnotVectorType KnotVectorType
The data type used to store knot vectors.
Definition: Spline.h:46
_Scalar Scalar
Definition: Spline.h:38