36 #include <visp3/core/vpBSpline.h>
37 #include <visp3/core/vpDebug.h>
46 : controlPoints(), knots(), p(3),
55 : controlPoints(bspline.controlPoints), knots(bspline.knots), p(bspline.p),
56 crossingPoints(bspline.crossingPoints)
81 unsigned int m = (
unsigned int)l_knots.size() - 1;
83 if (l_u > l_knots.back()) {
86 return ((
unsigned int)(m - l_p - 1));
90 if (std::fabs(l_u - l_knots.back()) <=
91 std::fabs(
vpMath::maximum(l_u, l_knots.back())) * std::numeric_limits<double>::epsilon())
92 return ((
unsigned int)(m - l_p - 1));
95 double high = m - l_p;
96 double middle = (low + high) / 2.0;
98 while (l_u < l_knots[(
unsigned int)middle] || l_u >= l_knots[(
unsigned int)middle + 1]) {
103 middle = (low + high) / 2.0;
106 return (
unsigned int)middle;
143 std::vector<double> &l_knots)
145 vpBasisFunction *N =
new vpBasisFunction[l_p + 1];
149 double *left =
new double[l_p + 1];
150 double *right =
new double[l_p + 1];
153 for (
unsigned int j = 1; j <= l_p; j++) {
154 left[j] = l_u - l_knots[l_i + 1 - j];
155 right[j] = l_knots[l_i + j] - l_u;
158 for (
unsigned int r = 0; r < j; r++) {
159 temp = N[r].value / (right[r + 1] + left[j - r]);
160 N[r].value = saved + right[r + 1] * temp;
161 saved = left[j - r] * temp;
165 for (
unsigned int j = 0; j < l_p + 1; j++) {
166 N[j].i = l_i - l_p + j;
229 std::vector<double> &l_knots)
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];
244 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++) {
250 ndu[j][r] = right[r + 1] + left[j - r];
251 temp = ndu[r][j - 1] / ndu[j][r];
252 ndu[r][j] = saved + right[r + 1] * temp;
253 saved = left[j - r] * temp;
258 for (
unsigned int j = 0; j <= l_p; j++) {
259 N[0][j].value = ndu[j][l_p];
260 N[0][j].i = l_i - l_p + j;
267 vpTRACE(
"l_der must be under or equal to l_p");
276 for (
unsigned int r = 0; r <= l_p; r++) {
280 for (
unsigned int k = 1; k <= l_der; k++) {
285 a[s2][0] = a[s1][0] / ndu[pk + 1][rk];
286 d = a[s2][0] * ndu[(
unsigned int)rk][pk];
292 j1 = (
unsigned int)(-rk);
299 for (
unsigned int j = j1; j <= j2; j++) {
300 a[s2][j] = (a[s1][j] - a[s1][j - 1]) / ndu[pk + 1][(
unsigned int)rk + j];
301 d += a[s2][j] * ndu[(
unsigned int)rk + j][pk];
305 a[s2][k] = -a[s1][k - 1] / ndu[pk + 1][r];
306 d += a[s2][k] * ndu[r][pk];
309 N[k][r].i = l_i - l_p + r;
320 for (
unsigned int k = 1; k <= l_der; k++) {
321 for (
unsigned int j = 0; j <= l_p; j++)
376 std::vector<vpImagePoint> &l_controlPoints)
383 for (
unsigned int j = 0; j <= l_p; j++) {
384 ic = ic + N[j].value * (l_controlPoints[l_i - l_p + j]).get_i();
385 jc = jc + N[j].value * (l_controlPoints[l_i - l_p + j]).get_j();
411 for (
unsigned int j = 0; j <= p; j++) {
412 ic = ic + N[j].value * (controlPoints[N[0].i + j]).get_i();
413 jc = jc + N[j].value * (controlPoints[N[0].i + j]).get_j();
446 std::vector<double> &l_knots, std::vector<vpImagePoint> &l_controlPoints)
454 vpTRACE(
"l_der must be under or equal to l_p");
460 for (
unsigned int k = 0; k <= du; k++) {
461 derivate[k].
set_ij(0.0, 0.0);
462 for (
unsigned int j = 0; j <= l_p; j++) {
463 derivate[k].
set_i(derivate[k].get_i() + N[k][j].value * (l_controlPoints[l_i - l_p + j]).get_i());
464 derivate[k].
set_j(derivate[k].get_j() + N[k][j].value * (l_controlPoints[l_i - l_p + j]).get_j());
468 for (
unsigned int j = 0; j <= l_der; j++)
500 vpTRACE(
"der must be under or equal to p");
506 for (
unsigned int k = 0; k <= du; k++) {
507 derivate[k].
set_ij(0.0, 0.0);
508 for (
unsigned int j = 0; j <= p; j++) {
509 derivate[k].
set_i(derivate[k].get_i() + N[k][j].value * (controlPoints[N[0][0].i - p + j]).get_i());
510 derivate[k].
set_j(derivate[k].get_j() + N[k][j].value * (controlPoints[N[0][0].i - p + j]).get_j());
514 for (
unsigned int j = 0; j <= der; j++)
Class that provides tools to compute and manipulate a B-Spline curve.
static vpBasisFunction ** computeDersBasisFuns(double l_u, unsigned int l_i, unsigned int l_p, unsigned int l_der, std::vector< double > &l_knots)
static vpBasisFunction * computeBasisFuns(double l_u, unsigned int l_i, unsigned int l_p, std::vector< double > &l_knots)
static vpImagePoint computeCurvePoint(double l_u, unsigned int l_i, unsigned int l_p, std::vector< double > &l_knots, std::vector< vpImagePoint > &l_controlPoints)
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)
static unsigned int findSpan(double l_u, unsigned int l_p, std::vector< double > &l_knots)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void set_ij(double ii, double jj)
static Type maximum(const Type &a, const Type &b)
static int round(double x)
Implementation of a matrix and operations on matrices.