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];
158 for(
unsigned int j = 1; j <= l_p; j++)
160 left[j] = l_u - l_knots[l_i+1-j];
161 right[j] = l_knots[l_i+j] - l_u;
164 for (
unsigned int r = 0; r < j; r++)
166 temp = N[r].value / (right[r+1]+left[j-r]);
167 N[r].value = saved +right[r+1]*temp;
168 saved = left[j-r]*temp;
172 for(
unsigned int j = 0; j < l_p+1; j++)
231 N =
new vpBasisFunction*[l_der+1];
232 for(
unsigned int j = 0; j <= l_der; j++)
233 N[j] =
new vpBasisFunction[l_p+1];
239 double *left =
new double[l_p+1];
240 double *right =
new double[l_p+1];
243 for(
unsigned int j = 1; j <= l_p; j++)
245 left[j] = l_u - l_knots[l_i+1-j];
246 right[j] = l_knots[l_i+j] - l_u;
249 for (
unsigned int r = 0; r < j; r++)
251 ndu[j][r] = right[r+1]+left[j-r];
252 temp = ndu[r][j-1]/ndu[j][r];
253 ndu[r][j] = saved + right[r+1]*temp;
254 saved = left[j-r]*temp;
259 for(
unsigned int j = 0; j <= l_p; j++)
261 N[0][j].value = ndu[j][l_p];
262 N[0][j].i = l_i-l_p+j;
270 vpTRACE(
"l_der must be under or equal to l_p");
279 for (
unsigned int r = 0; r <= l_p; r++)
284 for(
unsigned int k = 1; k <= l_der; k++)
291 a[s2][0] = a[s1][0]/ndu[pk+1][rk];
292 d = a[s2][0]*ndu[(
unsigned int)rk][pk];
298 j1 = (
unsigned int)(-rk);
305 for(
unsigned int j =j1; j<= j2; j++)
307 a[s2][j] = (a[s1][j]-a[s1][j-1])/ndu[pk+1][(
unsigned int)rk+j];
308 d += a[s2][j]*ndu[(
unsigned int)rk+j][pk];
313 a[s2][k] = -a[s1][k-1]/ndu[pk+1][r];
314 d += a[s2][k]*ndu[r][pk];
317 N[k][r].i = l_i-l_p+r;
328 for (
unsigned int k = 1; k <= l_der; k++ )
330 for (
unsigned int j = 0; j <= l_p; j++)
387 for(
unsigned int j = 0; j <= l_p; j++)
389 ic = ic + N[j].value * (l_controlPoints[l_i-l_p+j]).get_i();
390 jc = jc + N[j].value * (l_controlPoints[l_i-l_p+j]).get_j();
416 for(
unsigned int j = 0; j <= p; j++)
418 ic = ic + N[j].value * (controlPoints[N[0].i+j]).get_i();
419 jc = jc + N[j].value * (controlPoints[N[0].i+j]).get_j();
458 vpTRACE(
"l_der must be under or equal to l_p");
463 for(
unsigned int k = 0; k <= du; k++)
465 derivate[k].
set_ij(0.0,0.0);
466 for(
unsigned int j = 0; j<= l_p; j++)
468 derivate[k].
set_i( derivate[k].get_i() + N[k][j].value*(l_controlPoints[l_i-l_p+j]).get_i());
469 derivate[k].
set_j( derivate[k].get_j() + N[k][j].value*(l_controlPoints[l_i-l_p+j]).get_j());
474 for(
unsigned int j = 0; j <= l_der; j++)
506 vpTRACE(
"der must be under or equal to p");
511 for(
unsigned int k = 0; k <= du; k++)
513 derivate[k].
set_ij(0.0,0.0);
514 for(
unsigned int j = 0; j<= p; j++)
516 derivate[k].
set_i( derivate[k].get_i() + N[k][j].value*(controlPoints[N[0][0].i-p+j]).get_i());
517 derivate[k].
set_j( derivate[k].get_j() + N[k][j].value*(controlPoints[N[0][0].i-p+j]).get_j());
521 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)