42 #include <visp/vpBSpline.h>
43 #include <visp/vpDebug.h>
62 controlPoints = bspline.controlPoints;
63 knots = bspline.knots;
65 crossingPoints = bspline.crossingPoints;
91 unsigned int m = (
unsigned int)l_knots.size()-1;
93 if(l_u > l_knots.back())
96 return((
unsigned int)(m-l_p-1));
100 if (std::fabs(l_u - l_knots.back()) <= std::fabs(
vpMath::maximum(l_u, l_knots.back())) * std::numeric_limits<double>::epsilon())
101 return((
unsigned int)(m-l_p-1));
105 double middle = (low+high)/2.0;
109 if(l_u < l_knots[(
unsigned int)
vpMath::round(middle)]) high = middle;
111 middle = (low+high)/2.0;
114 return (
unsigned int)middle;
151 vpBasisFunction* N =
new vpBasisFunction[l_p+1];
155 double *left =
new double[l_p+1];
156 double *right =
new double[l_p+1];
160 for(
unsigned int j = 1; j <= l_p; j++)
162 left[j] = l_u - l_knots[l_i+1-j];
163 right[j] = l_knots[l_i+j] - l_u;
166 for (
unsigned int r = 0; r < j; r++)
168 temp = N[r].value / (right[r+1]+left[j-r]);
169 N[r].value = saved +right[r+1]*temp;
170 saved = left[j-r]*temp;
174 for(
unsigned int j = 0; j < l_p+1; j++)
233 N =
new vpBasisFunction*[l_der+1];
234 for(
unsigned int j = 0; j <= l_der; j++)
235 N[j] =
new vpBasisFunction[l_p+1];
241 double *left =
new double[l_p+1];
242 double *right =
new double[l_p+1];
246 for(
unsigned int j = 1; j <= l_p; j++)
248 left[j] = l_u - l_knots[l_i+1-j];
249 right[j] = l_knots[l_i+j] - l_u;
252 for (
unsigned int r = 0; r < j; r++)
254 ndu[j][r] = right[r+1]+left[j-r];
255 temp = ndu[r][j-1]/ndu[j][r];
256 ndu[r][j] = saved + right[r+1]*temp;
257 saved = left[j-r]*temp;
262 for(
unsigned int j = 0; j <= l_p; j++)
264 N[0][j].value = ndu[j][l_p];
265 N[0][j].i = l_i-l_p+j;
273 vpTRACE(
"l_der must be under or equal to l_p");
283 for (
unsigned int r = 0; r <= l_p; r++)
288 for(
unsigned int k = 1; k <= l_der; k++)
295 a[s2][0] = a[s1][0]/ndu[pk+1][rk];
296 d = a[s2][0]*ndu[(
unsigned int)rk][pk];
302 j1 = (
unsigned int)(-rk);
309 for(
unsigned int j =j1; j<= j2; j++)
311 a[s2][j] = (a[s1][j]-a[s1][j-1])/ndu[pk+1][(
unsigned int)rk+j];
312 d += a[s2][j]*ndu[(
unsigned int)rk+j][pk];
317 a[s2][k] = -a[s1][k-1]/ndu[pk+1][r];
318 d += a[s2][k]*ndu[r][pk];
321 N[k][r].i = l_i-l_p+r;
332 for (
unsigned int k = 1; k <= l_der; k++ )
334 for (
unsigned int j = 0; j <= l_p; j++)
391 for(
unsigned int j = 0; j <= l_p; j++)
393 ic = ic + N[j].value * (l_controlPoints[l_i-l_p+j]).get_i();
394 jc = jc + N[j].value * (l_controlPoints[l_i-l_p+j]).get_j();
420 for(
unsigned int j = 0; j <= p; j++)
422 ic = ic + N[j].value * (controlPoints[N[0].i+j]).get_i();
423 jc = jc + N[j].value * (controlPoints[N[0].i+j]).get_j();
462 vpTRACE(
"l_der must be under or equal to l_p");
467 for(
unsigned int k = 0; k <= du; k++)
469 derivate[k].
set_ij(0.0,0.0);
470 for(
unsigned int j = 0; j<= l_p; j++)
472 derivate[k].
set_i( derivate[k].get_i() + N[k][j].value*(l_controlPoints[l_i-l_p+j]).get_i());
473 derivate[k].
set_j( derivate[k].get_j() + N[k][j].value*(l_controlPoints[l_i-l_p+j]).get_j());
478 for(
unsigned int j = 0; j <= l_der; j++)
510 vpTRACE(
"der must be under or equal to p");
515 for(
unsigned int k = 0; k <= du; k++)
517 derivate[k].
set_ij(0.0,0.0);
518 for(
unsigned int j = 0; j<= p; j++)
520 derivate[k].
set_i( derivate[k].get_i() + N[k][j].value*(controlPoints[N[0][0].i-p+j]).get_i());
521 derivate[k].
set_j( derivate[k].get_j() + N[k][j].value*(controlPoints[N[0][0].i-p+j]).get_j());
525 for(
unsigned int j = 0; j <= der; j++)
void set_j(const double j)
static vpImagePoint * computeCurveDers(double l_u, unsigned int l_i, unsigned int l_p, unsigned int l_der, std::vector< double > &l_knots, std::vector< vpImagePoint > &l_controlPoints)
Definition of the vpMatrix class.
void set_i(const double i)
static int round(const double x)
static vpBasisFunction ** computeDersBasisFuns(double l_u, unsigned int l_i, unsigned int l_p, unsigned int l_der, std::vector< double > &l_knots)
static Type maximum(const Type &a, const Type &b)
static unsigned int findSpan(double l_u, unsigned int l_p, std::vector< double > &l_knots)
void set_ij(const double i, const double j)
static vpBasisFunction * computeBasisFuns(double l_u, unsigned int l_i, unsigned int l_p, std::vector< double > &l_knots)
Class that provides tools to compute and manipulate a B-Spline curve.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static vpImagePoint computeCurvePoint(double l_u, unsigned int l_i, unsigned int l_p, std::vector< double > &l_knots, std::vector< vpImagePoint > &l_controlPoints)