38 #include <visp3/core/vpBSpline.h>
39 #include <visp3/core/vpDebug.h>
48 : controlPoints(), knots(), p(3),
58 : controlPoints(), knots(), p(3),
61 controlPoints = bspline.controlPoints;
62 knots = bspline.knots;
64 crossingPoints = bspline.crossingPoints;
90 unsigned int m = (
unsigned int)l_knots.size()-1;
92 if(l_u > l_knots.back())
95 return((
unsigned int)(m-l_p-1));
99 if (std::fabs(l_u - l_knots.back()) <= std::fabs(
vpMath::maximum(l_u, l_knots.back())) * std::numeric_limits<double>::epsilon())
100 return((
unsigned int)(m-l_p-1));
104 double middle = (low+high)/2.0;
108 if(l_u < l_knots[(
unsigned int)
vpMath::round(middle)]) high = middle;
110 middle = (low+high)/2.0;
113 return (
unsigned int)middle;
150 vpBasisFunction* N =
new vpBasisFunction[l_p+1];
154 double *left =
new double[l_p+1];
155 double *right =
new double[l_p+1];
159 for(
unsigned int j = 1; j <= l_p; j++)
161 left[j] = l_u - l_knots[l_i+1-j];
162 right[j] = l_knots[l_i+j] - l_u;
165 for (
unsigned int r = 0; r < j; r++)
167 temp = N[r].value / (right[r+1]+left[j-r]);
168 N[r].value = saved +right[r+1]*temp;
169 saved = left[j-r]*temp;
173 for(
unsigned int j = 0; j < l_p+1; j++)
232 N =
new vpBasisFunction*[l_der+1];
233 for(
unsigned int j = 0; j <= l_der; j++)
234 N[j] =
new vpBasisFunction[l_p+1];
240 double *left =
new double[l_p+1];
241 double *right =
new double[l_p+1];
245 for(
unsigned int j = 1; j <= l_p; j++)
247 left[j] = l_u - l_knots[l_i+1-j];
248 right[j] = l_knots[l_i+j] - l_u;
251 for (
unsigned int r = 0; r < j; r++)
253 ndu[j][r] = right[r+1]+left[j-r];
254 temp = ndu[r][j-1]/ndu[j][r];
255 ndu[r][j] = saved + right[r+1]*temp;
256 saved = left[j-r]*temp;
261 for(
unsigned int j = 0; j <= l_p; j++)
263 N[0][j].value = ndu[j][l_p];
264 N[0][j].i = l_i-l_p+j;
272 vpTRACE(
"l_der must be under or equal to l_p");
282 for (
unsigned int r = 0; r <= l_p; r++)
287 for(
unsigned int k = 1; k <= l_der; k++)
294 a[s2][0] = a[s1][0]/ndu[pk+1][rk];
295 d = a[s2][0]*ndu[(
unsigned int)rk][pk];
301 j1 = (
unsigned int)(-rk);
308 for(
unsigned int j =j1; j<= j2; j++)
310 a[s2][j] = (a[s1][j]-a[s1][j-1])/ndu[pk+1][(
unsigned int)rk+j];
311 d += a[s2][j]*ndu[(
unsigned int)rk+j][pk];
316 a[s2][k] = -a[s1][k-1]/ndu[pk+1][r];
317 d += a[s2][k]*ndu[r][pk];
320 N[k][r].i = l_i-l_p+r;
331 for (
unsigned int k = 1; k <= l_der; k++ )
333 for (
unsigned int j = 0; j <= l_p; j++)
390 for(
unsigned int j = 0; j <= l_p; j++)
392 ic = ic + N[j].value * (l_controlPoints[l_i-l_p+j]).get_i();
393 jc = jc + N[j].value * (l_controlPoints[l_i-l_p+j]).get_j();
419 for(
unsigned int j = 0; j <= p; j++)
421 ic = ic + N[j].value * (controlPoints[N[0].i+j]).get_i();
422 jc = jc + N[j].value * (controlPoints[N[0].i+j]).get_j();
461 vpTRACE(
"l_der must be under or equal to l_p");
466 for(
unsigned int k = 0; k <= du; k++)
468 derivate[k].
set_ij(0.0,0.0);
469 for(
unsigned int j = 0; j<= l_p; j++)
471 derivate[k].
set_i( derivate[k].get_i() + N[k][j].value*(l_controlPoints[l_i-l_p+j]).get_i());
472 derivate[k].
set_j( derivate[k].get_j() + N[k][j].value*(l_controlPoints[l_i-l_p+j]).get_j());
477 for(
unsigned int j = 0; j <= l_der; j++)
509 vpTRACE(
"der must be under or equal to p");
514 for(
unsigned int k = 0; k <= du; k++)
516 derivate[k].
set_ij(0.0,0.0);
517 for(
unsigned int j = 0; j<= p; j++)
519 derivate[k].
set_i( derivate[k].get_i() + N[k][j].value*(controlPoints[N[0][0].i-p+j]).get_i());
520 derivate[k].
set_j( derivate[k].get_j() + N[k][j].value*(controlPoints[N[0][0].i-p+j]).get_j());
524 for(
unsigned int j = 0; j <= der; 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)
Implementation of a matrix and operations on matrices.
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_i(const double ii)
static vpBasisFunction * computeBasisFuns(double l_u, unsigned int l_i, unsigned int l_p, std::vector< double > &l_knots)
void set_j(const double jj)
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 ...
void set_ij(const double ii, const double jj)
static vpImagePoint computeCurvePoint(double l_u, unsigned int l_i, unsigned int l_p, std::vector< double > &l_knots, std::vector< vpImagePoint > &l_controlPoints)