39 #include <visp3/core/vpBSpline.h> 40 #include <visp3/core/vpDebug.h> 49 : controlPoints(), knots(), p(3),
59 : controlPoints(bspline.controlPoints), knots(bspline.knots), p(bspline.p),
60 crossingPoints(bspline.crossingPoints)
86 unsigned int m = (
unsigned int)l_knots.size() - 1;
88 if (l_u > l_knots.back()) {
91 return ((
unsigned int)(m - l_p - 1));
95 if (std::fabs(l_u - l_knots.back()) <=
96 std::fabs(
vpMath::maximum(l_u, l_knots.back())) * std::numeric_limits<double>::epsilon())
97 return ((
unsigned int)(m - l_p - 1));
100 double high = m - l_p;
101 double middle = (low + high) / 2.0;
109 middle = (low + high) / 2.0;
112 return (
unsigned int)middle;
149 std::vector<double> &l_knots)
151 vpBasisFunction *N =
new vpBasisFunction[l_p + 1];
155 double *left =
new double[l_p + 1];
156 double *right =
new double[l_p + 1];
159 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++) {
165 temp = N[r].value / (right[r + 1] + left[j - r]);
166 N[r].value = saved + right[r + 1] * temp;
167 saved = left[j - r] * temp;
171 for (
unsigned int j = 0; j < l_p + 1; j++) {
172 N[j].i = l_i - l_p + j;
235 std::vector<double> &l_knots)
238 N =
new vpBasisFunction *[l_der + 1];
239 for (
unsigned int j = 0; j <= l_der; j++)
240 N[j] =
new vpBasisFunction[l_p + 1];
246 double *left =
new double[l_p + 1];
247 double *right =
new double[l_p + 1];
250 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++) {
256 ndu[j][r] = right[r + 1] + left[j - r];
257 temp = ndu[r][j - 1] / ndu[j][r];
258 ndu[r][j] = saved + right[r + 1] * temp;
259 saved = left[j - r] * temp;
264 for (
unsigned int j = 0; j <= l_p; j++) {
265 N[0][j].value = ndu[j][l_p];
266 N[0][j].i = l_i - l_p + j;
273 vpTRACE(
"l_der must be under or equal to l_p");
282 for (
unsigned int r = 0; r <= l_p; r++) {
286 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++) {
306 a[s2][j] = (a[s1][j] - a[s1][j - 1]) / ndu[pk + 1][(
unsigned int)rk + j];
307 d += a[s2][j] * ndu[(
unsigned int)rk + j][pk];
311 a[s2][k] = -a[s1][k - 1] / ndu[pk + 1][r];
312 d += a[s2][k] * ndu[r][pk];
315 N[k][r].i = l_i - l_p + r;
326 for (
unsigned int k = 1; k <= l_der; k++) {
327 for (
unsigned int j = 0; j <= l_p; j++)
382 std::vector<vpImagePoint> &l_controlPoints)
389 for (
unsigned int j = 0; j <= l_p; j++) {
390 ic = ic + N[j].value * (l_controlPoints[l_i - l_p + j]).get_i();
391 jc = jc + N[j].value * (l_controlPoints[l_i - l_p + j]).get_j();
417 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();
452 std::vector<double> &l_knots, std::vector<vpImagePoint> &l_controlPoints)
460 vpTRACE(
"l_der must be under or equal to l_p");
465 for (
unsigned int k = 0; k <= du; k++) {
466 derivate[k].
set_ij(0.0, 0.0);
467 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());
473 for (
unsigned int j = 0; j <= l_der; j++)
505 vpTRACE(
"der must be under or equal to p");
510 for (
unsigned int k = 0; k <= du; k++) {
511 derivate[k].
set_ij(0.0, 0.0);
512 for (
unsigned int j = 0; j <= p; j++) {
513 derivate[k].
set_i(derivate[k].get_i() + N[k][j].value * (controlPoints[N[0][0].i - p + j]).get_i());
514 derivate[k].
set_j(derivate[k].get_j() + N[k][j].value * (controlPoints[N[0][0].i - p + j]).get_j());
518 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)