42 #include <visp/vpBSpline.h>
43 #include <visp/vpDebug.h>
52 : controlPoints(), knots(), p(3),
62 : controlPoints(), knots(), p(3),
65 controlPoints = bspline.controlPoints;
66 knots = bspline.knots;
68 crossingPoints = bspline.crossingPoints;
94 unsigned int m = (
unsigned int)l_knots.size()-1;
96 if(l_u > l_knots.back())
99 return((
unsigned int)(m-l_p-1));
103 if (std::fabs(l_u - l_knots.back()) <= std::fabs(
vpMath::maximum(l_u, l_knots.back())) * std::numeric_limits<double>::epsilon())
104 return((
unsigned int)(m-l_p-1));
108 double middle = (low+high)/2.0;
112 if(l_u < l_knots[(
unsigned int)
vpMath::round(middle)]) high = middle;
114 middle = (low+high)/2.0;
117 return (
unsigned int)middle;
154 vpBasisFunction* N =
new vpBasisFunction[l_p+1];
158 double *left =
new double[l_p+1];
159 double *right =
new double[l_p+1];
163 for(
unsigned int j = 1; j <= l_p; j++)
165 left[j] = l_u - l_knots[l_i+1-j];
166 right[j] = l_knots[l_i+j] - l_u;
169 for (
unsigned int r = 0; r < j; r++)
171 temp = N[r].value / (right[r+1]+left[j-r]);
172 N[r].value = saved +right[r+1]*temp;
173 saved = left[j-r]*temp;
177 for(
unsigned int j = 0; j < l_p+1; j++)
236 N =
new vpBasisFunction*[l_der+1];
237 for(
unsigned int j = 0; j <= l_der; j++)
238 N[j] =
new vpBasisFunction[l_p+1];
244 double *left =
new double[l_p+1];
245 double *right =
new double[l_p+1];
249 for(
unsigned int j = 1; j <= l_p; j++)
251 left[j] = l_u - l_knots[l_i+1-j];
252 right[j] = l_knots[l_i+j] - l_u;
255 for (
unsigned int r = 0; r < j; r++)
257 ndu[j][r] = right[r+1]+left[j-r];
258 temp = ndu[r][j-1]/ndu[j][r];
259 ndu[r][j] = saved + right[r+1]*temp;
260 saved = left[j-r]*temp;
265 for(
unsigned int j = 0; j <= l_p; j++)
267 N[0][j].value = ndu[j][l_p];
268 N[0][j].i = l_i-l_p+j;
276 vpTRACE(
"l_der must be under or equal to l_p");
286 for (
unsigned int r = 0; r <= l_p; r++)
291 for(
unsigned int k = 1; k <= l_der; k++)
298 a[s2][0] = a[s1][0]/ndu[pk+1][rk];
299 d = a[s2][0]*ndu[(
unsigned int)rk][pk];
305 j1 = (
unsigned int)(-rk);
312 for(
unsigned int j =j1; j<= j2; j++)
314 a[s2][j] = (a[s1][j]-a[s1][j-1])/ndu[pk+1][(
unsigned int)rk+j];
315 d += a[s2][j]*ndu[(
unsigned int)rk+j][pk];
320 a[s2][k] = -a[s1][k-1]/ndu[pk+1][r];
321 d += a[s2][k]*ndu[r][pk];
324 N[k][r].i = l_i-l_p+r;
335 for (
unsigned int k = 1; k <= l_der; k++ )
337 for (
unsigned int j = 0; j <= l_p; j++)
394 for(
unsigned int j = 0; j <= l_p; j++)
396 ic = ic + N[j].value * (l_controlPoints[l_i-l_p+j]).get_i();
397 jc = jc + N[j].value * (l_controlPoints[l_i-l_p+j]).get_j();
423 for(
unsigned int j = 0; j <= p; j++)
425 ic = ic + N[j].value * (controlPoints[N[0].i+j]).get_i();
426 jc = jc + N[j].value * (controlPoints[N[0].i+j]).get_j();
465 vpTRACE(
"l_der must be under or equal to l_p");
470 for(
unsigned int k = 0; k <= du; k++)
472 derivate[k].
set_ij(0.0,0.0);
473 for(
unsigned int j = 0; j<= l_p; j++)
475 derivate[k].
set_i( derivate[k].get_i() + N[k][j].value*(l_controlPoints[l_i-l_p+j]).get_i());
476 derivate[k].
set_j( derivate[k].get_j() + N[k][j].value*(l_controlPoints[l_i-l_p+j]).get_j());
481 for(
unsigned int j = 0; j <= l_der; j++)
513 vpTRACE(
"der must be under or equal to p");
518 for(
unsigned int k = 0; k <= du; k++)
520 derivate[k].
set_ij(0.0,0.0);
521 for(
unsigned int j = 0; j<= p; j++)
523 derivate[k].
set_i( derivate[k].get_i() + N[k][j].value*(controlPoints[N[0][0].i-p+j]).get_i());
524 derivate[k].
set_j( derivate[k].get_j() + N[k][j].value*(controlPoints[N[0][0].i-p+j]).get_j());
528 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)
Definition of the vpMatrix class.
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)