33 template <
class T,
typename KnotIterator,
typename Derived>
37 gsEigen::MatrixBase<Derived>
const & result )
39 STACK_ARRAY(T, left, deg + 1);
40 STACK_ARRAY(T, right, deg + 1);
41 evalBasis( u, knot, deg, left, right, result);
44 template <
class T,
typename KnotIterator,
typename Derived>
49 gsEigen::MatrixBase<Derived>
const & result )
51 gsEigen::MatrixBase<Derived>& res =
const_cast<gsEigen::MatrixBase<Derived>&
>(result);
55 for(
int j=1; j<= deg; j++)
57 left[j] = u - *(knot+1-j);
58 right[j] = *(knot+j) - u;
60 for(
int r=0; r<j ; r++)
62 const T temp = res(r,0) / ( right[r+1] + left[j-r] );
63 res(r,0) = saved + right[r+1] * temp ;
64 saved = left[j-r] * temp ;
71 template <
class T,
typename KnotIterator,
typename Derived>
73 const KnotIterator knot,
74 gsEigen::MatrixBase<Derived>
const & result )
76 result(0,0) = u - (*knot+1);
77 result(1,0) = (*knot) - u ;
78 const T dn = (*knot) - (*knot+1) ;
84 template <
class T,
typename KnotIterator,
typename Derived>
86 const KnotIterator knot,
87 gsEigen::MatrixBase<Derived>
const & result )
93 template <
class T,
typename KnotIterator,
typename MatrixType>
95 const KnotIterator knot,
106 template <
class T,
typename KnotIterator>
112 const int table_size = deg+1;
115 for(
int j = 0; j <= deg; j++ )
116 if( u >= *(knot+j) && u < *(knot+j+1) )
117 N[ j*table_size ] = 1;
119 N[ j*table_size ] = 0;
120 for(
int k = 1; k <= deg; k++ )
125 saved = ( (u-*(knot) )*N[ k-1 ])/( *(knot+k)- *(knot));
126 for(
int j = 0; j < deg-k+1; j++)
128 if( N[ (j+1)*table_size + (k-1) ] == 0 )
130 N[ j*table_size + k ] = saved;
135 const T Uleft = *(knot+j+1);
136 const T Uright = *(knot+j+k+1);
137 const T temp = N[ (j+1)*table_size + (k-1) ]/(Uright-Uleft);
138 N[ j*table_size + k ] = saved + (Uright-u)*temp;
139 saved = (u-Uleft)*temp;
151 template <
class T,
typename KnotIterator,
typename MatrixType>
153 const KnotIterator & knot,
156 MatrixType & result )
158 result.resize(deg+1, 1 ) ;
161 for (
int r=0; r!= deg; r++ )
163 for (
int i=deg; i>r; i-- )
165 tmp= ( u - *(knot+i) ) / ( *(knot+i+deg-r) - *(knot+i) );
166 coefs.row(i) = (T(1)-tmp)*coefs.row(i-1) + tmp* coefs.row(i) ;
168 result.noalias() = coefs.row(deg);
175 template <
class T,
typename KnotIterator,
typename MatrixType>
177 const KnotIterator & knot,
179 MatrixType & result )
181 MatrixType pseudo_coefs;
182 pseudo_coefs.setIdentity(deg+1,deg+1);
183 evalGeoAlg(u, knot, deg, pseudo_coefs, result);
189 template <
class T,
typename KnotIterator,
typename MatrixType>
198 template <
class T,
typename KnotIterator,
typename MatrixType>
204 template <
class T,
typename KnotIterator,
typename MatrixType>
210 template <
class T,
typename KnotIterator,
typename MatrixType>
216 template <
class T,
typename KnotIterator,
typename MatrixType>
223 template<
class Basis_t>
228 typedef typename Basis_t::Scalar_t T;
230 GISMO_ASSERT(m >= 0 && m<512,
"Can only elevate degree by a positive (not enormous) amount.");
231 GISMO_ASSERT(basis.size() == coefs.rows(),
"Invalid coefficients");
235 const short_t p = basis.degree();
236 const index_t ncoefs = coefs.rows();
237 const index_t n = coefs.cols();
245 std::vector<gsMatrix<T> > P(p+1);
248 P[i].setZero(ncoefs - i, n);
254 for(
index_t i=0; i<ncoefs-j; i++)
256 if(knots[i+p+1]>knots[i+j])
257 P[j].row(i).noalias() =
258 ( P[j-1].row(i+1) - P[j-1].row(i) ) / ( knots[i+p+1] - knots[i+j] );
262 const typename gsKnotVector<T>::multContainer &
266 basis.degreeElevate(m);
267 const index_t ncoefs_new = basis.size();
268 const short_t p_new = basis.degree();
274 std::vector<gsMatrix<T> > Q(p_new+1);
276 for(
short_t i=0; i<p_new+1; i++)
277 Q[i].setZero(ncoefs_new - i, n);
287 factor[j] *= static_cast<T>(p+1-l) /
static_cast<T
>(p_new+1-l);
294 for(
size_t k=0; k<mult.
size()-1; k++)
297 for(
short_t j=p+1-mult[k]; j<=p; ++j)
298 Q[j].row(betak+k*m) = factor[j] * P[j].row(betak);
300 for(
short_t j=p_new-1; j>=0;j--)
303 for(
short_t i=1; i<=p_new-j; i++)
305 const int ik= i+betak+k*m;
306 if(knots[ik+p_new]>knots[ik+j])
307 Q[j].row(ik).noalias() =
308 Q[j].row(ik-1) + Q[j+1].row(ik-1) * (knots[ik-1+p_new+1]-knots[ik-1+j+1]);
void evalBasis2(const T &u, const KnotIterator &knot, int deg, MatrixType &result)
Definition: gsBSplineAlgorithms.h:176
void allDersSingle()
Definition: gsBSplineAlgorithms.h:217
multContainer multiplicities() const
Returns vector of multiplicities of the knots.
Definition: gsKnotVector.hpp:714
#define short_t
Definition: gsConfig.h:35
void evalDeg3Basis(const T &u, const KnotIterator knot, MatrixType &result)
Evaluation for degree 3 B-spline basis.
Definition: gsBSplineAlgorithms.h:94
void evalDeg2Basis(const T &u, const KnotIterator knot, gsEigen::MatrixBase< Derived > const &result)
Evaluation for degree 2 B-spline basis.
Definition: gsBSplineAlgorithms.h:85
size_t size() const
Number of knots (including repetitions).
Definition: gsKnotVector.h:242
#define index_t
Definition: gsConfig.h:32
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition: gsMatrix.h:38
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
void degreeElevateBSpline(Basis_t &basis, gsMatrix< typename Basis_t::Scalar_t > &coefs, short_t m)
Increase the degree of a 1D B-spline from degree p to degree p + m.
Definition: gsBSplineAlgorithms.h:224
void allDersBasis()
Definition: gsBSplineAlgorithms.h:211
void evalGeo(const T &u, const KnotIterator &knot, int deg, MatrixType coefs, MatrixType &result)
Definition: gsBSplineAlgorithms.h:152
void evalBasis(T u, KnotIterator knot, int deg, gsEigen::MatrixBase< Derived > const &result)
Definition: gsBSplineAlgorithms.h:34
void deBoorTriangle(T u, KnotIterator knot, int deg, T N[])
Definition: gsBSplineAlgorithms.h:107
void evalBasisSingle()
Definition: gsBSplineAlgorithms.h:190
Class for representing a knot vector.
Definition: gsKnotVector.h:79
void derivBasis()
Definition: gsBSplineAlgorithms.h:199
void derivBasisSingle()
Definition: gsBSplineAlgorithms.h:205
void evalDeg1Basis(const T &u, const KnotIterator knot, gsEigen::MatrixBase< Derived > const &result)
Evaluation for degree 1 B-spline basis.
Definition: gsBSplineAlgorithms.h:72