36 #include <visp3/core/vpBSpline.h>
37 #include <visp3/core/vpDebug.h>
47 : controlPoints(), knots(), p(3),
56 : controlPoints(bspline.controlPoints), knots(bspline.knots), p(bspline.p),
57 crossingPoints(bspline.crossingPoints)
82 unsigned int m = (
unsigned int)l_knots.size() - 1;
84 if (l_u > l_knots.back()) {
87 return ((
unsigned int)(m - l_p - 1));
91 if (std::fabs(l_u - l_knots.back()) <=
92 std::fabs(
vpMath::maximum(l_u, l_knots.back())) * std::numeric_limits<double>::epsilon())
93 return ((
unsigned int)(m - l_p - 1));
96 double high = m - l_p;
97 double middle = (low + high) / 2.0;
99 while (l_u < l_knots[(
unsigned int)middle] || l_u >= l_knots[(
unsigned int)middle + 1]) {
104 middle = (low + high) / 2.0;
107 return (
unsigned int)middle;
144 const std::vector<double> &l_knots)
146 vpBasisFunction *N =
new vpBasisFunction[l_p + 1];
150 double *left =
new double[l_p + 1];
151 double *right =
new double[l_p + 1];
154 for (
unsigned int j = 1; j <= l_p; j++) {
155 left[j] = l_u - l_knots[l_i + 1 - j];
156 right[j] = l_knots[l_i + j] - l_u;
159 for (
unsigned int r = 0; r < j; r++) {
160 temp = N[r].value / (right[r + 1] + left[j - r]);
161 N[r].value = saved + right[r + 1] * temp;
162 saved = left[j - r] * temp;
166 for (
unsigned int j = 0; j < l_p + 1; j++) {
167 N[j].i = l_i - l_p + j;
230 const std::vector<double> &l_knots)
233 N =
new vpBasisFunction *[l_der + 1];
234 for (
unsigned int j = 0; j <= l_der; j++)
235 N[j] =
new vpBasisFunction[l_p + 1];
241 double *left =
new double[l_p + 1];
242 double *right =
new double[l_p + 1];
245 for (
unsigned int j = 1; j <= l_p; j++) {
246 left[j] = l_u - l_knots[l_i + 1 - j];
247 right[j] = l_knots[l_i + j] - l_u;
250 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++) {
260 N[0][j].value = ndu[j][l_p];
261 N[0][j].i = l_i - l_p + j;
268 vpTRACE(
"l_der must be under or equal to l_p");
277 for (
unsigned int r = 0; r <= l_p; r++) {
281 for (
unsigned int k = 1; k <= l_der; k++) {
286 a[s2][0] = a[s1][0] / ndu[pk + 1][rk];
287 d = a[s2][0] * ndu[(
unsigned int)rk][pk];
293 j1 = (
unsigned int)(-rk);
300 for (
unsigned int j = j1; j <= j2; j++) {
301 a[s2][j] = (a[s1][j] - a[s1][j - 1]) / ndu[pk + 1][(
unsigned int)rk + j];
302 d += a[s2][j] * ndu[(
unsigned int)rk + j][pk];
306 a[s2][k] = -a[s1][k - 1] / ndu[pk + 1][r];
307 d += a[s2][k] * ndu[r][pk];
310 N[k][r].i = l_i - l_p + r;
321 for (
unsigned int k = 1; k <= l_der; k++) {
322 for (
unsigned int j = 0; j <= l_p; j++)
377 const std::vector<vpImagePoint> &l_controlPoints)
384 for (
unsigned int j = 0; j <= l_p; j++) {
385 ic = ic + N[j].value * (l_controlPoints[l_i - l_p + j]).get_i();
386 jc = jc + N[j].value * (l_controlPoints[l_i - l_p + j]).get_j();
412 for (
unsigned int j = 0; j <= p; j++) {
413 ic = ic + N[j].value * (controlPoints[N[0].i + j]).get_i();
414 jc = jc + N[j].value * (controlPoints[N[0].i + j]).get_j();
447 const std::vector<double> &l_knots,
const std::vector<vpImagePoint> &l_controlPoints)
455 vpTRACE(
"l_der must be under or equal to l_p");
461 for (
unsigned int k = 0; k <= du; k++) {
462 derivate[k].
set_ij(0.0, 0.0);
463 for (
unsigned int j = 0; j <= l_p; j++) {
464 derivate[k].
set_i(derivate[k].get_i() + N[k][j].value * (l_controlPoints[l_i - l_p + j]).get_i());
465 derivate[k].
set_j(derivate[k].get_j() + N[k][j].value * (l_controlPoints[l_i - l_p + j]).get_j());
469 for (
unsigned int j = 0; j <= l_der; j++)
501 vpTRACE(
"der must be under or equal to p");
507 for (
unsigned int k = 0; k <= du; k++) {
508 derivate[k].
set_ij(0.0, 0.0);
509 for (
unsigned int j = 0; j <= p; j++) {
510 derivate[k].
set_i(derivate[k].get_i() + N[k][j].value * (controlPoints[N[0][0].i - p + j]).get_i());
511 derivate[k].
set_j(derivate[k].get_j() + N[k][j].value * (controlPoints[N[0][0].i - p + j]).get_j());
515 for (
unsigned int j = 0; j <= der; j++)
Class that provides tools to compute and manipulate a B-Spline curve.
static vpImagePoint computeCurvePoint(double l_u, unsigned int l_i, unsigned int l_p, const std::vector< double > &l_knots, const std::vector< vpImagePoint > &l_controlPoints)
static unsigned int findSpan(double l_u, unsigned int l_p, const std::vector< double > &l_knots)
static vpBasisFunction ** computeDersBasisFuns(double l_u, unsigned int l_i, unsigned int l_p, unsigned int l_der, const std::vector< double > &l_knots)
static vpImagePoint * computeCurveDers(double l_u, unsigned int l_i, unsigned int l_p, unsigned int l_der, const std::vector< double > &l_knots, const std::vector< vpImagePoint > &l_controlPoints)
static vpBasisFunction * computeBasisFuns(double l_u, unsigned int l_i, unsigned int l_p, const 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.