40 #include <visp3/tt_mi/vpTemplateTrackerMIBSpline.h> 42 #ifndef DOXYGEN_SHOULD_SKIP_THIS 44 void vpTemplateTrackerMIBSpline::PutPVBsplineD(
double *Prt,
int cr,
double er,
int ct,
double et,
int Nc,
double val,
49 PutPVBsplineD4(Prt, cr, er, ct, et, Nc, val);
52 PutPVBsplineD3(Prt, cr, er, ct, et, Nc,
57 void vpTemplateTrackerMIBSpline::PutPVBsplineD3(
double *Prt,
int cr,
double er,
int ct,
double et,
int Nc,
double val)
69 double *pt = &Prt[((cr + sr) * Nc + (ct + st)) * 9];
70 for (
int ir = -1; ir <= 1; ir++)
71 for (
int it = -1; it <= 1; it++) {
72 *pt++ += Bspline3(ir - er) * Bspline3(it - et) * val;
77 void vpTemplateTrackerMIBSpline::PutPVBsplineD4(
double *Prt,
int cr,
double er,
int ct,
double et,
int Nc,
double val)
81 double *ptBti = &Bti[0];
82 for (
int it = -1; it <= 2; it++) {
83 *ptBti++ = Bspline4i(it - et, it);
86 double *pt = &Prt[(cr * Nc + ct) * 16];
87 for (
int ir = -1; ir <= 2; ir++) {
88 double Br = Bspline4i(ir - er, ir);
90 for (
int it = -1; it <= 2; it++) {
91 *pt++ += Br * *ptBti++ * val;
96 double vpTemplateTrackerMIBSpline::Bspline3(
double diff)
99 double aDiff = std::fabs(diff);
108 return (-(aDiff * aDiff) + 0.75);
109 return (0.5 * (1.5 - aDiff) * (1.5 - aDiff));
115 double vpTemplateTrackerMIBSpline::Bspline4i(
double diff,
int &interv)
119 return ((2. + diff) * (2. + diff) * (2. + diff) / 6.);
121 return (-diff * diff * diff / 2. - diff * diff + 4. / 6.);
123 return (diff * diff * diff / 2. - diff * diff + 4. / 6.);
125 return ((2. - diff) * (2. - diff) * (2. - diff) / 6.);
131 double vpTemplateTrackerMIBSpline::dBspline3(
double diff)
133 if ((diff > -1.5) && (diff <= -0.5))
135 else if ((diff > -0.5) && (diff <= 0.5))
137 else if ((diff > 0.5) && (diff <= 1.5))
150 double vpTemplateTrackerMIBSpline::dBspline4(
double diff)
152 if ((diff > -2.) && (diff <= -1.))
153 return (diff + 2.) * (diff + 2.) / 2.;
154 else if ((diff > -1.) && (diff <= 0.))
155 return -3. * diff * diff / 2. - 2. * diff;
156 else if ((diff > 0.) && (diff <= 1.))
157 return 3. * diff * diff / 2. - 2. * diff;
158 else if ((diff > 1.) && (diff <= 2.))
159 return -(diff - 2.) * (diff - 2.) / 2.;
164 double vpTemplateTrackerMIBSpline::d2Bspline3(
double diff)
166 if ((diff > -1.5) && (diff <= -0.5))
168 else if ((diff > -0.5) && (diff <= 0.5))
170 else if ((diff > 0.5) && (diff <= 1.5))
176 double vpTemplateTrackerMIBSpline::d2Bspline4(
double diff)
178 if ((diff > -2.) && (diff <= -1.))
180 else if ((diff > -1.) && (diff <= 0.))
181 return -3. * diff - 2.;
182 else if ((diff > 0.) && (diff <= 1.))
183 return 3. * diff - 2.;
184 else if ((diff > 1.) && (diff <= 2.))
190 void vpTemplateTrackerMIBSpline::PutTotPVBspline(
double *Prt,
int cr,
double &er,
int ct,
double &et,
int Nc,
191 double *val,
unsigned int &NbParam,
int °ree)
195 PutTotPVBspline4(Prt, cr, er, ct, et, Nc, val, NbParam);
198 PutTotPVBspline3(Prt, cr, er, ct, et, Nc, val, NbParam);
202 void vpTemplateTrackerMIBSpline::PutTotPVBspline(
double *Prt,
double *dPrt,
double *d2Prt,
int cr,
double &er,
int ct,
203 double &et,
int Ncb,
double *val,
unsigned int &NbParam,
int °ree)
207 PutTotPVBspline4(Prt, dPrt, d2Prt, cr, er, ct, et, Ncb, val, NbParam);
210 PutTotPVBspline3(Prt, dPrt, d2Prt, cr, er, ct, et, Ncb, val, NbParam);
214 void vpTemplateTrackerMIBSpline::PutTotPVBspline3(
double *Prt,
int cr,
double &er,
int ct,
double &et,
int Nc,
215 double *val,
unsigned int &NbParam)
232 double *ptBti = &Bti[0];
233 double *ptdBti = &dBti[0];
234 double *ptd2Bti = &d2Bti[0];
236 for (
short int it = 1; it >= -1; it--) {
237 *ptBti++ = Bspline3(it + et);
238 *ptdBti++ = dBspline3(it + et);
239 *ptd2Bti++ = d2Bspline3(it + et);
242 double *pt = &Prt[((cr + sr) * Nc + (ct + st)) * 9 * (1 + (
int)(NbParam + NbParam * NbParam))];
243 for (
short int ir = -1; ir <= 1; ++ir) {
244 double Br = Bspline3(-ir + er);
246 for (
short unsigned int it = 0; it <= 2; ++it) {
247 *pt++ += Br * (Bti[it]);
249 double v1 = Br * (dBti[it]);
250 for (
short unsigned int ip = 0; ip < NbParam; ++ip) {
251 *pt++ -= v1 * val[ip];
252 double v2 = Br * (d2Bti[it]) * val[ip];
253 for (
short unsigned int ip2 = 0; ip2 < NbParam; ++ip2)
254 *pt++ += v2 * val[ip2];
260 void vpTemplateTrackerMIBSpline::PutTotPVBspline3(
double *Prt,
double *dPrt,
double *d2Prt,
int cr,
double &er,
int ct,
261 double &et,
int Ncb,
double *val,
unsigned int &NbParam)
278 double *ptBti = &Bti[0];
279 double *ptdBti = &dBti[0];
280 double *ptd2Bti = &d2Bti[0];
282 for (
short int it = 1; it >= -1; it--) {
283 *ptBti++ = Bspline3(it + et);
284 *ptdBti++ = dBspline3(it + et);
285 *ptd2Bti++ = d2Bspline3(it + et);
288 int NbParam_ = (int)NbParam;
289 for (
short int ir = -1; ir <= 1; ++ir) {
290 double Br = Bspline3(-ir + er);
291 short int irInd = ir + 1;
292 short int ind = (cr + sr + irInd) * Ncb;
293 for (
short int it = 0; it <= 2; ++it) {
294 Prt[ind + (ct + st + it)] += Br * (Bti[it]);
296 double v1 = Br * (dBti[it]);
297 int ind1 = ((cr + sr + irInd) * Ncb + (ct + st + it)) * NbParam_;
298 for (
int ip = 0; ip < NbParam_; ++ip) {
299 dPrt[ind1 + ip] -= v1 * val[ip];
300 double v2 = Br * (d2Bti[it]) * val[ip];
301 int ind2 = ((cr + sr + irInd) * Ncb + (ct + st + it)) * NbParam_ * NbParam_ + ip * NbParam_;
302 for (
short int ip2 = 0; ip2 < NbParam_; ++ip2)
303 d2Prt[ind2 + ip2] += v2 * val[ip2];
309 void vpTemplateTrackerMIBSpline::PutTotPVBspline3(
double *Prt,
double &er,
double *bt,
unsigned int size)
321 double *bt0 = &bt[0];
326 for (
int ir = -1; ir <= 1; ++ir) {
327 double Br = Bspline3(-ir + er);
328 const double *btend = bt0 + size;
333 for (; bt < btend; bt += LSIZE) {
334 *Prt++ += Br * bt[0];
335 *Prt++ += Br * bt[1];
336 *Prt++ += Br * bt[2];
337 *Prt++ += Br * bt[3];
338 *Prt++ += Br * bt[4];
339 *Prt++ += Br * bt[5];
340 *Prt++ += Br * bt[6];
341 *Prt++ += Br * bt[7];
342 *Prt++ += Br * bt[8];
343 *Prt++ += Br * bt[9];
344 *Prt++ += Br * bt[10];
345 *Prt++ += Br * bt[11];
349 for (; bt < btend; *Prt++ += Br * *bt++) {
355 void vpTemplateTrackerMIBSpline::PutTotPVBspline4(
double *Prt,
int cr,
double er,
int ct,
double et,
int Nc,
356 double *val,
unsigned int &NbParam)
362 double *ptBti = &Bti[0];
363 double *ptdBti = &dBti[0];
364 double *ptd2Bti = &d2Bti[0];
365 for (
char it = -1; it <= 2; it++) {
366 *ptBti++ = vpTemplateTrackerBSpline::Bspline4(-it + et);
367 *ptdBti++ = dBspline4(-it + et);
368 *ptd2Bti++ = d2Bspline4(-it + et);
371 int NbParam_ = (int)NbParam;
373 double *pt = &Prt[(cr * Nc + ct) * 16 * (1 + NbParam_ + NbParam_ * NbParam_)];
374 for (
char ir = -1; ir <= 2; ir++) {
375 double Br = vpTemplateTrackerBSpline::Bspline4(-ir + er);
379 for (
char it = -1; it <= 2; it++) {
380 *pt++ += Br * *ptBti;
381 for (
short int ip = 0; ip < NbParam_; ip++) {
382 *pt++ -= Br * *ptdBti * val[ip];
383 for (
short int ip2 = 0; ip2 < NbParam_; ip2++)
384 *pt++ += Br * *ptd2Bti * val[ip] * val[ip2];
393 void vpTemplateTrackerMIBSpline::PutTotPVBspline4(
double *Prt,
double *dPrt,
double *d2Prt,
int cr,
double er,
int ct,
394 double et,
int Ncb,
double *val,
unsigned int &NbParam)
400 double *ptBti = &Bti[0];
401 double *ptdBti = &dBti[0];
402 double *ptd2Bti = &d2Bti[0];
403 for (
char it = -1; it <= 2; it++) {
404 *ptBti++ = vpTemplateTrackerBSpline::Bspline4(-it + et);
405 *ptdBti++ = dBspline4(-it + et);
406 *ptd2Bti++ = d2Bspline4(-it + et);
409 int NbParam_ = (int)NbParam;
411 for (
int ir = -1; ir <= 2; ir++) {
412 double Br = vpTemplateTrackerBSpline::Bspline4(-ir + er);
414 int ind = (cr + irInd) * Ncb + ct;
420 for (
int it = -1; it <= 2; it++) {
421 Prt[ind + it] += Br * *ptBti;
422 int ind1 = ((cr + irInd) * Ncb + (ct + it)) * NbParam_;
423 for (
int ip = 0; ip < NbParam_; ip++) {
424 dPrt[ind1 + ip] -= Br * *ptdBti * val[ip];
425 int ind2 = ((cr + irInd) * Ncb + (ct + it)) * NbParam_ * NbParam_ + ip * NbParam_;
426 for (
int ip2 = 0; ip2 < NbParam_; ip2++)
427 d2Prt[ind2 + ip2] += Br * *ptd2Bti * val[ip] * val[ip2];
436 void vpTemplateTrackerMIBSpline::PutTotPVBspline4(
double *Prt,
double &er,
double *bt,
unsigned int size)
439 double *bt0 = &bt[0];
441 for (
int ir = -1; ir <= 2; ++ir) {
442 double Br = vpTemplateTrackerBSpline::Bspline4(-ir + er);
443 const double *btend = bt0 + size;
448 for (; bt < btend; bt += LSIZE) {
449 *Prt++ += Br * bt[0];
450 *Prt++ += Br * bt[1];
451 *Prt++ += Br * bt[2];
452 *Prt++ += Br * bt[3];
453 *Prt++ += Br * bt[4];
454 *Prt++ += Br * bt[5];
455 *Prt++ += Br * bt[6];
456 *Prt++ += Br * bt[7];
457 *Prt++ += Br * bt[8];
458 *Prt++ += Br * bt[9];
459 *Prt++ += Br * bt[10];
460 *Prt++ += Br * bt[11];
464 for (; bt < btend; *Prt++ += Br * *bt++) {
470 void vpTemplateTrackerMIBSpline::PutTotPVBsplineNoSecond(
double *Prt,
int &cr,
double &er,
int &ct,
double &et,
int &Nc,
471 double *val,
unsigned int &NbParam,
int °ree)
475 PutTotPVBspline4NoSecond(Prt, cr, er, ct, et, Nc, val, NbParam);
478 PutTotPVBspline3NoSecond(Prt, cr, er, ct, et, Nc, val, NbParam);
482 void vpTemplateTrackerMIBSpline::PutTotPVBsplineNoSecond(
double *Prt,
double *dPrt,
int &cr,
double &er,
int &ct,
483 double &et,
int &Ncb,
double *val,
unsigned int &NbParam,
488 PutTotPVBspline4NoSecond(Prt, dPrt, cr, er, ct, et, Ncb, val, NbParam);
491 PutTotPVBspline3NoSecond(Prt, dPrt, cr, er, ct, et, Ncb, val, NbParam);
495 void vpTemplateTrackerMIBSpline::PutTotPVBspline3NoSecond(
double *Prt,
int &cr,
double &er,
int &ct,
double &et,
496 int &Nc,
double *val,
unsigned int &NbParam)
512 double *ptBti = &Bti[0];
513 double *ptdBti = &dBti[0];
514 for (
char it = -1; it <= 1; it++) {
515 *ptBti++ = Bspline3(-it + et);
516 *ptdBti++ = dBspline3(-it + et);
519 int NbParam_ = (int)NbParam;
521 double *pt = &Prt[((cr + sr) * Nc + (ct + st)) * 9 * (1 + NbParam_ + NbParam_ * NbParam_)];
522 for (
char ir = -1; ir <= 1; ir++) {
523 double Br = Bspline3(-ir + er);
526 for (
char it = -1; it <= 1; it++) {
527 *pt++ += Br * *ptBti;
528 for (
unsigned int ip = 0; ip < NbParam; ip++) {
529 *pt++ -= Br * *ptdBti * val[ip];
539 void vpTemplateTrackerMIBSpline::PutTotPVBspline3NoSecond(
double *Prt,
double *dPrt,
int &cr,
double &er,
int &ct,
540 double &et,
int &Ncb,
double *val,
unsigned int &NbParam)
556 double *ptBti = &Bti[0];
557 double *ptdBti = &dBti[0];
558 for (
char it = -1; it <= 1; it++) {
559 *ptBti++ = Bspline3(-it + et);
560 *ptdBti++ = dBspline3(-it + et);
563 int NbParam_ = (int)NbParam;
565 for (
char ir = -1; ir <= 1; ir++) {
566 double Br = Bspline3(-ir + er);
569 int ind = (cr + sr + irInd) * Ncb;
573 for (
char it = -1; it <= 1; it++) {
574 Prt[ind + (ct + st + it)] += Br * *ptBti;
575 int ind1 = ((cr + sr + irInd) * Ncb + (ct + st + it)) * NbParam_;
576 for (
short int ip = 0; ip < NbParam_; ip++) {
577 dPrt[ind1 + ip] -= Br * *ptdBti * val[ip];
585 void vpTemplateTrackerMIBSpline::PutTotPVBspline4NoSecond(
double *Prt,
int &cr,
double &er,
int &ct,
double &et,
586 int &Nc,
double *val,
unsigned int &NbParam)
588 double Bti[4] = {0, 0, 0, 0};
589 double dBti[4] = {0, 0, 0, 0};
591 for (
char it = -1; it <= 2; it++) {
592 Bti[it + 1] = vpTemplateTrackerBSpline::Bspline4(-it + et);
593 dBti[it + 1] = dBspline4(-it + et);
596 int NbParam_ = (int)NbParam;
598 double *pt = &Prt[(cr * Nc + ct) * 16 * (1 + NbParam_ + NbParam_ * NbParam_)];
599 for (
int ir = -1; ir <= 2; ir++) {
600 double Br = vpTemplateTrackerBSpline::Bspline4(-ir + er);
601 for (
int it = 0; it <= 3; it++) {
602 (*pt++) += Br * Bti[it];
604 for (
int ip = 0; ip < NbParam_; ip++) {
605 (*pt++) -= Br * dBti[it] * val[ip];
613 void vpTemplateTrackerMIBSpline::PutTotPVBspline4NoSecond(
double *Prt,
double *dPrt,
int &cr,
double &er,
int &ct,
614 double &et,
int &Ncb,
double *val,
unsigned int &NbParam)
616 double Bti[4] = {0, 0, 0, 0};
617 double dBti[4] = {0, 0, 0, 0};
619 for (
char it = -1; it <= 2; it++) {
620 Bti[it + 1] = vpTemplateTrackerBSpline::Bspline4(-it + et);
621 dBti[it + 1] = dBspline4(-it + et);
624 int NbParam_ = (int)NbParam;
626 for (
int ir = -1; ir <= 2; ir++) {
627 double Br = vpTemplateTrackerBSpline::Bspline4(-ir + er);
629 int ind = (cr + irInd) * Ncb + ct;
631 for (
int it = 0; it <= 3; it++) {
632 Prt[ind + it] += Br * Bti[it];
633 int ind1 = ((cr + irInd) * Ncb + (ct + it)) * NbParam_;
635 for (
int ip = 0; ip < NbParam_; ip++) {
636 dPrt[ind1 + ip] -= Br * dBti[it] * val[ip];
642 void vpTemplateTrackerMIBSpline::PutTotPVBsplinePrtTout(
double *PrtTout,
int &cr,
double &er,
int &ct,
double &et,
643 int &Nc,
unsigned int &NbParam,
int °ree)
647 PutTotPVBspline4PrtTout(PrtTout, cr, er, ct, et, Nc, NbParam);
650 PutTotPVBspline3PrtTout(PrtTout, cr, er, ct, et, Nc, NbParam);
654 void vpTemplateTrackerMIBSpline::PutTotPVBspline3PrtTout(
double *PrtTout,
int &cr,
double &er,
int &ct,
double &et,
655 int &Nc,
unsigned int &NbParam)
668 double Bti[3] = {0, 0, 0};
670 for (
char it = -1; it <= 1; it++) {
671 Bti[it + 1] = Bspline3(-it + et);
674 int NbParam_ = (int)NbParam;
675 int NbParam_val = NbParam_ + NbParam_ * NbParam_;
677 double *pt = &PrtTout[(
unsigned int)(((cr + sr) * Nc + (ct + st)) * 9 * (1 + NbParam_val))];
678 for (
int ir = -1; ir <= 1; ir++) {
679 double Br = Bspline3(-ir + er);
680 for (
int it = 0; it <= 2; it++) {
681 (*pt++) += Br * Bti[it];
682 pt = pt + NbParam_val;
686 void vpTemplateTrackerMIBSpline::PutTotPVBspline4PrtTout(
double *PrtTout,
int &cr,
double &er,
int &ct,
double &et,
687 int &Nc,
unsigned int &NbParam)
689 double Bti[4] = {0, 0, 0, 0};
691 for (
char it = -1; it <= 2; it++) {
692 Bti[it + 1] = vpTemplateTrackerBSpline::Bspline4(-it + et);
695 int NbParam_ = (int)NbParam;
696 int NbParam_val = NbParam_ + NbParam_ * NbParam_;
697 double *pt = &PrtTout[(
unsigned int)((cr * Nc + ct) * 16 * (1 + NbParam_val))];
698 for (
int ir = -1; ir <= 2; ir++) {
699 double Br = vpTemplateTrackerBSpline::Bspline4(-ir + er);
700 for (
int it = 0; it <= 3; it++) {
701 (*pt++) += Br * Bti[it];
702 pt = pt + NbParam_val;
707 void vpTemplateTrackerMIBSpline::PutTotPVBsplinePrt(
double *Prt,
int &cr,
double &er,
int &ct,
double &et,
int &Ncb,
708 unsigned int &NbParam,
int °ree)
712 PutTotPVBspline4PrtTout(Prt, cr, er, ct, et, Ncb, NbParam);
715 PutTotPVBspline3PrtTout(Prt, cr, er, ct, et, Ncb, NbParam);
719 void vpTemplateTrackerMIBSpline::PutTotPVBspline3Prt(
double *Prt,
int &cr,
double &er,
int &ct,
double &et,
int &Ncb)
733 double Bti[3] = {0, 0, 0};
735 for (
char it = -1; it <= 1; it++) {
736 Bti[it + 1] = Bspline3(-it + et);
739 for (
int ir = -1; ir <= 1; ir++) {
740 double Br = Bspline3(-ir + er);
743 int ind = (cr + sr + irInd) * Ncb;
744 for (
int it = 0; it <= 2; it++) {
745 Prt[ind + (ct + st + it)] += Br * Bti[it];
750 void vpTemplateTrackerMIBSpline::PutTotPVBspline4Prt(
double *Prt,
int &cr,
double &er,
int &ct,
double &et,
int &Ncb)
752 double Bti[4] = {0, 0, 0, 0};
754 for (
char it = -1; it <= 2; it++) {
755 Bti[it + 1] = vpTemplateTrackerBSpline::Bspline4(-it + et);
758 for (
int ir = -1; ir <= 2; ir++) {
759 double Br = vpTemplateTrackerBSpline::Bspline4(-ir + er);
761 int ind = (cr + irInd) * Ncb + ct;
763 for (
int it = 0; it <= 3; it++) {
764 Prt[ind + it] += Br * Bti[it];