39 #include <visp3/tt_mi/vpTemplateTrackerMIBSpline.h>
41 #ifndef DOXYGEN_SHOULD_SKIP_THIS
43 void vpTemplateTrackerMIBSpline::PutPVBsplineD(
double *Prt,
int cr,
double er,
int ct,
double et,
int Nc,
double val,
const int °re)
48 PutPVBsplineD4(Prt, cr, er, ct, et, Nc, val);
break;
50 PutPVBsplineD3(Prt, cr, er, ct, et, Nc, val);
54 void vpTemplateTrackerMIBSpline::PutPVBsplineD3(
double *Prt,
int cr,
double er,
int ct,
double et,
int Nc,
double val)
58 if(er>0.5){sr=1;er=er-1;}
59 if(et>0.5){st=1;et=et-1;}
60 double *pt=&Prt[((cr+sr)*Nc+(ct+st))*9];
61 for(
int ir=-1;ir<=1;ir++)
62 for(
int it=-1;it<=1;it++)
64 *pt++ +=Bspline3(ir-er)*Bspline3(it-et)*val;
69 void vpTemplateTrackerMIBSpline::PutPVBsplineD4(
double *Prt,
int cr,
double er,
int ct,
double et,
int Nc,
double val)
73 double *ptBti=&Bti[0];
74 for(
int it=-1;it<=2;it++)
76 *ptBti++ =Bspline4i(it-et,it);
79 double *pt=&Prt[(cr*Nc+ct)*16];
80 for(
int ir=-1;ir<=2;ir++)
82 double Br=Bspline4i(ir-er,ir);
84 for(
int it=-1;it<=2;it++)
86 *pt++ +=Br* *ptBti++ *val;
91 double vpTemplateTrackerMIBSpline::Bspline3(
double diff)
94 double aDiff=std::fabs(diff);
103 return (-(aDiff * aDiff) + 0.75);
104 return (0.5*(1.5-aDiff)*(1.5-aDiff));
110 double vpTemplateTrackerMIBSpline::Bspline4i(
double diff,
int &interv)
115 return ((2.+diff)*(2.+diff)*(2.+diff)/6.);
117 return (-diff*diff*diff/2.-diff*diff+4./6.);
119 return (diff*diff*diff/2.-diff*diff+4./6.);
121 return ((2.-diff)*(2.-diff)*(2.-diff)/6.);
127 double vpTemplateTrackerMIBSpline::dBspline3(
double diff)
129 if((diff>-1.5)&&(diff<=-0.5))
131 else if((diff>-0.5)&&(diff<=0.5))
133 else if((diff>0.5)&&(diff<=1.5))
146 double vpTemplateTrackerMIBSpline::dBspline4(
double diff)
148 if((diff>-2.)&&(diff<=-1.))
149 return (diff+2.)*(diff+2.)/2.;
150 else if((diff>-1.)&&(diff<=0.))
151 return -3.*diff*diff/2.-2.*diff;
152 else if((diff>0.)&&(diff<=1.))
153 return 3.*diff*diff/2.-2.*diff;
154 else if((diff>1.)&&(diff<=2.))
155 return -(diff-2.)*(diff-2.)/2.;
160 double vpTemplateTrackerMIBSpline::d2Bspline3(
double diff)
162 if((diff>-1.5)&&(diff<=-0.5))
164 else if((diff>-0.5)&&(diff<=0.5))
166 else if((diff>0.5)&&(diff<=1.5))
172 double vpTemplateTrackerMIBSpline::d2Bspline4(
double diff)
174 if((diff>-2.)&&(diff<=-1.))
176 else if((diff>-1.)&&(diff<=0.))
178 else if((diff>0.)&&(diff<=1.))
180 else if((diff>1.)&&(diff<=2.))
187 void vpTemplateTrackerMIBSpline::PutTotPVBspline(
double *Prt,
int cr,
double &er,
int ct,
double &et,
int Nc,
double *val,
unsigned int &NbParam,
int °ree)
192 PutTotPVBspline4(Prt, cr, er, ct, et, Nc, val, NbParam);
break;
194 PutTotPVBspline3(Prt, cr, er, ct, et, Nc, val, NbParam);
198 void vpTemplateTrackerMIBSpline::PutTotPVBspline(
double *Prt,
double *dPrt,
double *d2Prt,
int cr,
double &er,
int ct,
double &et,
int Ncb,
double *val,
unsigned int &NbParam,
int °ree)
203 PutTotPVBspline4(Prt, dPrt, d2Prt, cr, er, ct, et, Ncb, val, NbParam);
break;
205 PutTotPVBspline3(Prt, dPrt, d2Prt, cr, er, ct, et, Ncb, val, NbParam);
209 void vpTemplateTrackerMIBSpline::PutTotPVBspline3(
double *Prt,
int cr,
double &er,
int ct,
double &et,
int Nc,
double *val,
unsigned int &NbParam)
213 if(er>0.5){sr=1;er=er-1;}
214 if(et>0.5){st=1;et=et-1;}
220 double *ptBti=&Bti[0];
221 double *ptdBti=&dBti[0];
222 double *ptd2Bti=&d2Bti[0];
224 for(
short int it=1;it>=-1;it--)
226 *ptBti++ =Bspline3(it+et);
227 *ptdBti++ =dBspline3(it+et);
228 *ptd2Bti++ =d2Bspline3(it+et);
231 double *pt=&Prt[((cr+sr)*Nc+(ct+st))*9*(1+(
int)(NbParam+NbParam*NbParam))];
232 for(
short int ir=-1;ir<=1;++ir)
234 double Br=Bspline3(-ir+er);
236 for(
short unsigned int it=0;it<=2;++it)
238 *pt++ += Br * (Bti[it]);
240 double v1 = Br * (dBti[it]);
241 for(
short unsigned int ip=0;ip<NbParam;++ip)
244 double v2 = Br * (d2Bti[it]) * val[ip];
245 for(
short unsigned int ip2=0;ip2<NbParam;++ip2)
246 *pt++ += v2*val[ip2];
252 void vpTemplateTrackerMIBSpline::PutTotPVBspline3(
double *Prt,
double *dPrt,
double *d2Prt,
int cr,
double &er,
int ct,
double &et,
int Ncb,
double *val,
unsigned int &NbParam)
256 if(er>0.5){sr=1;er=er-1;}
257 if(et>0.5){st=1;et=et-1;}
263 double *ptBti=&Bti[0];
264 double *ptdBti=&dBti[0];
265 double *ptd2Bti=&d2Bti[0];
267 for(
short int it=1;it>=-1;it--)
269 *ptBti++ =Bspline3(it+et);
270 *ptdBti++ =dBspline3(it+et);
271 *ptd2Bti++ =d2Bspline3(it+et);
274 int NbParam_ = (int)NbParam;
275 for(
short int ir=-1;ir<=1;++ir)
277 double Br=Bspline3(-ir+er);
278 short int irInd = ir + 1;
279 short int ind = (cr+sr+irInd)*Ncb;
280 for(
short int it=0;it<=2;++it)
282 Prt[ind+(ct+st+it)] += Br * (Bti[it]);
284 double v1 = Br * (dBti[it]);
285 int ind1 = ((cr+sr+irInd)*Ncb+(ct+st+it))*NbParam_;
286 for (
int ip=0;ip<NbParam_;++ip)
288 dPrt[ind1+ip]-= v1*val[ip];
289 double v2 = Br * (d2Bti[it]) * val[ip];
290 int ind2 = ((cr+sr+irInd)*Ncb+(ct+st+it))*NbParam_*NbParam_+ip*NbParam_;
291 for(
short int ip2=0;ip2<NbParam_;++ip2)
292 d2Prt[ind2+ip2] += v2*val[ip2];
298 void vpTemplateTrackerMIBSpline::PutTotPVBspline3(
double *Prt,
double &er,
double *bt,
unsigned int size)
310 double *bt0 = &bt[0];
311 if(er>0.5){er=er-1.0;}
313 for(
int ir=-1;ir<=1;++ir)
315 double Br=Bspline3(-ir+er);
316 const double *btend = bt0 + size;
321 for (; bt < btend; bt += LSIZE){
322 *Prt++ += Br * bt[0];
323 *Prt++ += Br * bt[1];
324 *Prt++ += Br * bt[2];
325 *Prt++ += Br * bt[3];
326 *Prt++ += Br * bt[4];
327 *Prt++ += Br * bt[5];
328 *Prt++ += Br * bt[6];
329 *Prt++ += Br * bt[7];
330 *Prt++ += Br * bt[8];
331 *Prt++ += Br * bt[9];
332 *Prt++ += Br * bt[10];
333 *Prt++ += Br * bt[11];
337 for (; bt < btend; *Prt++ += Br * *bt++) {};
343 void vpTemplateTrackerMIBSpline::PutTotPVBspline4(
double *Prt,
int cr,
double er,
int ct,
double et,
int Nc,
double *val,
unsigned int &NbParam)
349 double *ptBti=&Bti[0];
350 double *ptdBti=&dBti[0];
351 double *ptd2Bti=&d2Bti[0];
352 for(
char it=-1;it<=2;it++)
354 *ptBti++ =vpTemplateTrackerBSpline::Bspline4(-it+et);
355 *ptdBti++ =dBspline4(-it+et);
356 *ptd2Bti++ =d2Bspline4(-it+et);
359 int NbParam_ = (int)NbParam;
361 double *pt=&Prt[(cr*Nc+ct)*16*(1+NbParam_+NbParam_*NbParam_)];
362 for(
char ir=-1;ir<=2;ir++)
364 double Br=vpTemplateTrackerBSpline::Bspline4(-ir+er);
368 for(
char it=-1;it<=2;it++)
371 for(
short int ip=0;ip<NbParam_;ip++)
373 *pt++ -=Br**ptdBti*val[ip];
374 for(
short int ip2=0;ip2<NbParam_;ip2++)
375 *pt++ +=Br**ptd2Bti*val[ip]*val[ip2];
384 void vpTemplateTrackerMIBSpline::PutTotPVBspline4(
double *Prt,
double *dPrt,
double *d2Prt,
int cr,
double er,
int ct,
double et,
int Ncb,
double *val,
unsigned int &NbParam)
390 double *ptBti=&Bti[0];
391 double *ptdBti=&dBti[0];
392 double *ptd2Bti=&d2Bti[0];
393 for(
char it=-1;it<=2;it++)
395 *ptBti++ =vpTemplateTrackerBSpline::Bspline4(-it+et);
396 *ptdBti++ =dBspline4(-it+et);
397 *ptd2Bti++ =d2Bspline4(-it+et);
400 int NbParam_ = (int)NbParam;
402 for(
int ir=-1;ir<=2;ir++)
404 double Br=vpTemplateTrackerBSpline::Bspline4(-ir+er);
406 int ind = (cr+irInd)*Ncb+ct;
412 for(
int it=-1;it<=2;it++)
414 Prt[ind+it] += Br * *ptBti;
415 int ind1 = ((cr+irInd)*Ncb+(ct+it))*NbParam_;
416 for(
int ip=0;ip<NbParam_;ip++)
418 dPrt[ind1+ip]-= Br**ptdBti*val[ip];
419 int ind2 = ((cr+irInd)*Ncb+(ct+it))*NbParam_*NbParam_+ip*NbParam_;
420 for(
int ip2=0;ip2<NbParam_;ip2++)
421 d2Prt[ind2+ip2] += Br**ptd2Bti*val[ip]*val[ip2];
430 void vpTemplateTrackerMIBSpline::PutTotPVBspline4(
double *Prt,
double &er,
double *bt,
unsigned int size)
433 double *bt0 = &bt[0];
435 for(
int ir=-1;ir<=2;++ir)
437 double Br=vpTemplateTrackerBSpline::Bspline4(-ir+er);
438 const double *btend = bt0 + size;
443 for (; bt < btend; bt += LSIZE){
444 *Prt++ += Br * bt[0];
445 *Prt++ += Br * bt[1];
446 *Prt++ += Br * bt[2];
447 *Prt++ += Br * bt[3];
448 *Prt++ += Br * bt[4];
449 *Prt++ += Br * bt[5];
450 *Prt++ += Br * bt[6];
451 *Prt++ += Br * bt[7];
452 *Prt++ += Br * bt[8];
453 *Prt++ += Br * bt[9];
454 *Prt++ += Br * bt[10];
455 *Prt++ += Br * bt[11];
459 for (; bt < btend; *Prt++ += Br * *bt++) {};
465 void vpTemplateTrackerMIBSpline::PutTotPVBsplineNoSecond(
double *Prt,
int &cr,
double &er,
int &ct,
double &et,
int &Nc,
double *val,
unsigned int &NbParam,
int °ree)
470 PutTotPVBspline4NoSecond(Prt, cr, er, ct, et, Nc, val, NbParam);
break;
472 PutTotPVBspline3NoSecond(Prt, cr, er, ct, et, Nc, val, NbParam);
476 void vpTemplateTrackerMIBSpline::PutTotPVBsplineNoSecond(
double *Prt,
double *dPrt,
int &cr,
double &er,
int &ct,
double &et,
int &Ncb,
double *val,
unsigned int &NbParam,
int °ree)
481 PutTotPVBspline4NoSecond(Prt, dPrt, cr, er, ct, et, Ncb, val, NbParam);
break;
483 PutTotPVBspline3NoSecond(Prt, dPrt, cr, er, ct, et, Ncb, val, NbParam);
487 void vpTemplateTrackerMIBSpline::PutTotPVBspline3NoSecond(
double *Prt,
int &cr,
double &er,
int &ct,
double &et,
int &Nc,
double *val,
unsigned int &NbParam)
491 if(er>0.5){sr=1;er=er-1;}
492 if(et>0.5){st=1;et=et-1;}
497 double *ptBti=&Bti[0];
498 double *ptdBti=&dBti[0];
499 for(
char it=-1;it<=1;it++)
501 *ptBti++ =Bspline3(-it+et);
502 *ptdBti++ =dBspline3(-it+et);
505 int NbParam_ = (int)NbParam;
507 double *pt=&Prt[((cr+sr)*Nc+(ct+st))*9*(1+NbParam_+NbParam_*NbParam_)];
508 for(
char ir=-1;ir<=1;ir++)
510 double Br=Bspline3(-ir+er);
513 for(
char it=-1;it<=1;it++)
516 for(
unsigned int ip=0;ip<NbParam;ip++)
518 *pt++ -=Br**ptdBti*val[ip];
528 void vpTemplateTrackerMIBSpline::PutTotPVBspline3NoSecond(
double *Prt,
double *dPrt,
int &cr,
double &er,
int &ct,
double &et,
int &Ncb,
double *val,
unsigned int &NbParam)
532 if(er>0.5){sr=1;er=er-1;}
533 if(et>0.5){st=1;et=et-1;}
538 double *ptBti=&Bti[0];
539 double *ptdBti=&dBti[0];
540 for(
char it=-1;it<=1;it++)
542 *ptBti++ =Bspline3(-it+et);
543 *ptdBti++ =dBspline3(-it+et);
546 int NbParam_ = (int)NbParam;
548 for(
char ir=-1;ir<=1;ir++)
550 double Br=Bspline3(-ir+er);
553 int ind = (cr+sr+irInd)*Ncb;
557 for(
char it=-1;it<=1;it++)
559 Prt[ind+(ct+st+it)] += Br**ptBti;
560 int ind1 = ((cr+sr+irInd)*Ncb+(ct+st+it))*NbParam_;
561 for(
short int ip=0;ip<NbParam_;ip++)
563 dPrt[ind1+ip]-= Br**ptdBti*val[ip];
572 void vpTemplateTrackerMIBSpline::PutTotPVBspline4NoSecond(
double *Prt,
int &cr,
double &er,
int &ct,
double &et,
int &Nc,
double *val,
unsigned int &NbParam)
574 double Bti[4] = {0, 0, 0, 0};
575 double dBti[4] = {0, 0, 0, 0};
577 for(
char it=-1;it<=2;it++)
579 Bti[it+1] =vpTemplateTrackerBSpline::Bspline4(-it+et);
580 dBti[it+1] = dBspline4(-it+et);
583 int NbParam_ = (int)NbParam;
585 double *pt=&Prt[(cr*Nc+ct)*16*(1+NbParam_+NbParam_*NbParam_)];
586 for(
int ir=-1;ir<=2;ir++)
588 double Br=vpTemplateTrackerBSpline::Bspline4(-ir+er);
589 for(
int it=0;it<=3;it++)
591 (*pt++) +=Br*Bti[it];
593 for(
int ip=0;ip<NbParam_;ip++)
595 (*pt++) -=Br*dBti[it]*val[ip];
603 void vpTemplateTrackerMIBSpline::PutTotPVBspline4NoSecond(
double *Prt,
double *dPrt,
int &cr,
double &er,
int &ct,
double &et,
int &Ncb,
double *val,
unsigned int &NbParam)
605 double Bti[4] = {0, 0, 0, 0};
606 double dBti[4] = {0, 0, 0, 0};
608 for(
char it=-1;it<=2;it++)
610 Bti[it+1] =vpTemplateTrackerBSpline::Bspline4(-it+et);
611 dBti[it+1] = dBspline4(-it+et);
614 int NbParam_ = (int)NbParam;
616 for(
int ir=-1;ir<=2;ir++)
618 double Br=vpTemplateTrackerBSpline::Bspline4(-ir+er);
620 int ind = (cr+irInd)*Ncb+ct;
622 for(
int it=0;it<=3;it++)
624 Prt[ind+it] += Br*Bti[it];
625 int ind1 = ((cr+irInd)*Ncb+(ct+it))*NbParam_;
627 for(
int ip=0;ip<NbParam_;ip++)
629 dPrt[ind1+ip]-= Br*dBti[it]*val[ip];
635 void vpTemplateTrackerMIBSpline::PutTotPVBsplinePrtTout(
double *PrtTout,
int &cr,
double &er,
int &ct,
double &et,
int &Nc,
unsigned int &NbParam,
int °ree)
640 PutTotPVBspline4PrtTout(PrtTout, cr, er, ct, et, Nc, NbParam);
break;
642 PutTotPVBspline3PrtTout(PrtTout, cr, er, ct, et, Nc, NbParam);
646 void vpTemplateTrackerMIBSpline::PutTotPVBspline3PrtTout(
double *PrtTout,
int &cr,
double &er,
int &ct,
double &et,
int &Nc,
unsigned int &NbParam)
650 if(er>0.5){sr=1;er=er-1;}
651 if(et>0.5){st=1;et=et-1;}
653 double Bti[3] = {0, 0, 0};
655 for(
char it=-1;it<=1;it++)
657 Bti[it+1] = Bspline3(-it+et);
660 int NbParam_ = (int)NbParam;
661 int NbParam_val = NbParam_+NbParam_*NbParam_;
663 double *pt=&PrtTout[(
unsigned int)(((cr+sr)*Nc+(ct+st))*9*(1+NbParam_val))];
664 for(
int ir=-1;ir<=1;ir++)
666 double Br= Bspline3(-ir+er);
667 for(
int it=0;it<=2;it++)
669 (*pt++) +=Br*Bti[it];
674 void vpTemplateTrackerMIBSpline::PutTotPVBspline4PrtTout(
double *PrtTout,
int &cr,
double &er,
int &ct,
double &et,
int &Nc,
unsigned int &NbParam)
676 double Bti[4] = {0, 0, 0, 0};
678 for(
char it=-1;it<=2;it++)
680 Bti[it+1] =vpTemplateTrackerBSpline::Bspline4(-it+et);
683 int NbParam_ = (int)NbParam;
684 int NbParam_val = NbParam_+NbParam_*NbParam_;
685 double *pt=&PrtTout[(
unsigned int)((cr*Nc+ct)*16*(1+NbParam_val))];
686 for(
int ir=-1;ir<=2;ir++)
688 double Br=vpTemplateTrackerBSpline::Bspline4(-ir+er);
689 for(
int it=0;it<=3;it++)
691 (*pt++) +=Br*Bti[it];
697 void vpTemplateTrackerMIBSpline::PutTotPVBsplinePrt(
double *Prt,
int &cr,
double &er,
int &ct,
double &et,
int &Ncb,
unsigned int &NbParam,
int °ree)
702 PutTotPVBspline4PrtTout(Prt, cr, er, ct, et, Ncb, NbParam);
break;
704 PutTotPVBspline3PrtTout(Prt, cr, er, ct, et, Ncb, NbParam);
708 void vpTemplateTrackerMIBSpline::PutTotPVBspline3Prt(
double *Prt,
int &cr,
double &er,
int &ct,
double &et,
int &Ncb)
713 if(er>0.5){sr=1;er=er-1;}
714 if(et>0.5){st=1;et=et-1;}
716 double Bti[3] = {0, 0, 0};
718 for(
char it=-1;it<=1;it++)
720 Bti[it+1] = Bspline3(-it+et);
723 for(
int ir=-1;ir<=1;ir++)
725 double Br= Bspline3(-ir+er);
728 int ind = (cr+sr+irInd)*Ncb;
729 for(
int it=0;it<=2;it++)
731 Prt[ind+(ct+st+it)] += Br*Bti[it];
737 void vpTemplateTrackerMIBSpline::PutTotPVBspline4Prt(
double *Prt,
int &cr,
double &er,
int &ct,
double &et,
int &Ncb)
739 double Bti[4] = {0, 0, 0, 0};
741 for(
char it=-1;it<=2;it++)
743 Bti[it+1] =vpTemplateTrackerBSpline::Bspline4(-it+et);
746 for(
int ir=-1;ir<=2;ir++)
748 double Br=vpTemplateTrackerBSpline::Bspline4(-ir+er);
750 int ind = (cr+irInd)*Ncb+ct;
752 for(
int it=0;it<=3;it++)
754 Prt[ind+it] += Br*Bti[it];