26 # define _USE_MATH_DEFINES
31 #include "Interpolator.hh"
32 #include "Base/Debug/Error.hh"
41 nmatrix_.newsize(4,4);
60 listPolynoms1_.clear();
61 listPolynoms2_.clear();
62 listPolynoms3_.clear();
69 startTangentX_=-10000;
70 startTangentY_=-10000;
71 startTangentZ_=-10000;
81 bezierInitialized_ =
false;
86 listTangDim1_.clear();
93 unsigned n = cPnt.size();
96 listPntDim1_.clear();listPntDim1_.resize(n);
97 listPntDim2_.clear();listPntDim2_.resize(n);
99 for (
unsigned int i=0;i<n;i++) {
100 temp=cPnt[i][0];listPntDim1_[i] = temp;
101 temp=cPnt[i][1];listPntDim2_[i] = temp;
109 unsigned n = cPnt.size();
111 listPntDim1_.clear();listPntDim1_.resize(n);
112 listPntDim2_.clear();listPntDim2_.resize(n);
113 listPntDim3_.clear();listPntDim3_.resize(n);
115 for (
unsigned int i=0;i<n;i++) {
116 temp=cPnt[i][0];listPntDim1_[i] = temp;
117 temp=cPnt[i][1];listPntDim2_[i] = temp;
118 temp=cPnt[i][2];listPntDim3_[i] = temp;
127 for (
unsigned int i=0;i<listPntDim1_.size();i++) {
128 temp[0]=listPntDim1_[i];
129 temp[1]=listPntDim2_[i];
130 cPnt.push_back(temp);
140 for (
unsigned int i=0;i<listPntDim1_.size();i++) {
141 temp[0]=listPntDim1_[i];
142 temp[1]=listPntDim2_[i];
143 temp[2]=listPntDim3_[i];
144 cPnt.push_back(temp);
150 BIASDOUT(D_INTERPOL_COMMON,
"validating t:"<<t);
151 if (listPntDim1_.size()>KPts_.size()) {
154 for (
unsigned int i=0;i<listPntDim1_.size();i++)
155 KPts_.push_back((
double)i/(
double)(listPntDim1_.size()-1));
158 unsigned int tSize=KPts_.size()-1;
159 if ( (tSize<=0) || (listPntDim1_.size()<=1) ) {
160 BIASERR(
"less than 2 control points");
163 if (t<=KPts_[0]) {t=KPts_[0]; actIndex_=0;
return true;}
167 while ((i<tSize) && (KPts_[i]<t))
171 if(debug && actIndex_ < 0){
173 cout<<
"ActIndex_ = "<<actIndex_<<endl;
184 if ((n=kPnt.size())==0)
return;
191 for (
unsigned int i=0;i<n;i++)
193 for (
unsigned int i=1;i<n;i++)
194 T_[i]=kPnt[i]-kPnt[i-1];
204 const std::vector<double>& listPnt,
205 const double startTangent,
const double endTangent)
207 int n=listPnt.size();
208 BIASDOUT(D_INTERPOL_SPLINE3,
"n="<<n);
210 InitSpline2(listP,listPnt,-10000);
220 for (
int j=0; j<n-1; j++) {
226 if (startTangent==-10000) {
233 if (endTangent==-10000) {
240 for (
int i=j-2; i<=j+3; i++) {
241 if (i>=Min && i<=Max) {
246 if (startTangent==-10000) {
248 Py[k] = listPnt[Min];
250 Px[k] = KPts_[Min] - (KPts_[Min+1]-KPts_[Min]) * (Min-i);
251 Py[k] = listPnt[Min] -
252 (KPts_[Min+1]-KPts_[Min]) * (Min-i) * startTangent;
255 if (endTangent==-10000) {
257 Py[k] = listPnt[Max];
259 Px[k] = KPts_[Max] + (KPts_[Max]-KPts_[Max-1]) * (i-Max);
260 Py[k] = listPnt[Max] +
261 (KPts_[Max]-KPts_[Max-1]) * (i-Max) * endTangent;
268 for (
int i=0; i<6; i++) {
271 fakima(a, Px, Py, from, to, 2);
280 int from,
int to,
int intervall)
289 for (
int i=0; i<from; i++) {
290 d1 = Py[from+1] - Py[from];
291 d2 = Px[from+1] - Px[from];
297 for (
int i=from; i<to; i++) {
298 d1 = Py[i+1] - Py[i];
299 d2 = Px[i+1] - Px[i];
305 for (
int i=to; i<6; i++) {
306 d1 = Py[to] - Py[to-1];
307 d2 = Px[to] - Px[to-1];
316 a1 = fabs(dq[intervall+1] - dq[intervall]);
317 a2 = fabs(dq[intervall-1] - dq[intervall-2]);
319 si[0] = (dq[intervall-1]+dq[intervall]) / 2;
321 si[0] = (a1 * dq[intervall-1] + a2 * dq[intervall]) / (a1+a2);
326 a1 = fabs(dq[intervall+1] - dq[intervall]);
327 a2 = fabs(dq[intervall-1] - dq[intervall-2]);
329 si[1] = (dq[intervall-1]+dq[intervall]) / 2;
331 si[1] = (a1 * dq[intervall-1] + a2 * dq[intervall]) / (a1+a2);
336 A[0][0] = ((double)(Px[intervall])) *
337 ((
double)(Px[intervall])) * ((double)(Px[intervall]));
338 A[0][1] = ((double)(Px[intervall])) * ((
double)(Px[intervall]));
339 A[0][2] = (double)(Px[intervall]);
342 A[1][0] = ((double)(Px[intervall+1])) *
343 ((
double)(Px[intervall+1])) * ((double)(Px[intervall+1]));
344 A[1][1] = ((double)(Px[intervall+1])) * ((
double)(Px[intervall+1]));
345 A[1][2] = (double)(Px[intervall+1]);
348 A[2][0] = 3.0 * ((double)(Px[intervall])) * ((
double)(Px[intervall]));
349 A[2][1] = 2.0 * ((double)(Px[intervall]));
353 A[3][0] = 3.0 * ((double)(Px[intervall+1])) * ((
double)(Px[intervall+1]));
354 A[3][1] = 2.0 * ((double)(Px[intervall+1]));
358 b[0] = (double)(Py[intervall]);
359 b[1] = (double)(Py[intervall+1]);
368 const std::vector<double> &listPnt,
369 const double startTangent,
const double endTangent)
371 unsigned int n=listPnt.size();
372 BIASDOUT(D_INTERPOL_SPLINE3,
"n="<<n);
376 if (startTangent == -10000) {
379 tangents[0] = startTangent;
381 if (endTangent == -10000) {
382 tangents[n-1] = 0.0f;
384 tangents[n-1] = endTangent;
387 for (
unsigned int i=1;i<n-1;i++) {
388 double s1 = (listPnt[i+1] - listPnt[i]) / (2* (KPts_[i+1] - KPts_[i]));
389 double s2 = (listPnt[i] - listPnt[i-1]) / (2* (KPts_[i] - KPts_[i-1]));
390 tangents[i] = (s1 + s2);
401 const std::vector<double> &listPnt,
402 const double startTangent,
const double endTangent)
406 unsigned int n=listPnt.size();
407 BIASDOUT(D_INTERPOL_SPLINE3,
"n="<<n);
409 InitSpline2(listP,listPnt,startTangent);
417 if (startTangent==-10000) {
421 if (endTangent==-10000) {
433 A[0][0]=2.0*(T_[1] + T_[2]);
435 b[0]= 3.0/(T_[1]*T_[2]) *
436 ( T_[1]*T_[1] * (listPnt[2] - listPnt[1]) +
437 T_[2]*T_[2] * (listPnt[1] - listPnt[0]) ) -
438 T_[2] * startTangent;
443 b[0]= 3.0 * (listPnt[1] - listPnt[0]);
445 for (i=1;i<n-3+stAdd+edAdd;i++) {
446 A[i][i-1]=T_[i+2-stAdd];
447 A[i][i] = 2.0 * (T_[i+1-stAdd] + T_[i+2-stAdd]);
448 A[i][i+1] = T_[i+1-stAdd];
449 b[i] = 3.0/(T_[i+1-stAdd]*T_[i+2-stAdd]) *
450 ( T_[i+1-stAdd]*T_[i+1-stAdd] *
451 (listPnt[i+2-stAdd] - listPnt[i+1-stAdd]) +
452 T_[i+2-stAdd]*T_[i+2-stAdd] * (listPnt[i+1-stAdd] - listPnt[i-stAdd]));
456 A[n-3+stAdd][n-4+stAdd] = T_[n-1];
457 A[n-3+stAdd][n-3+stAdd] = 2.0 * (T_[n-1] + T_[n-2]);
458 b[n-3+stAdd]= 3.0/(T_[n-1]*T_[n-2]) *
459 ( T_[n-2]*T_[n-2] * (listPnt[n-1] - listPnt[n-2]) +
460 T_[n-1]*T_[n-1] * (listPnt[n-2] - listPnt[n-3]) ) -
461 T_[n-2] * endTangent;
464 A[n-2+stAdd][n-3+stAdd] = T_[n-1];
465 A[n-2+stAdd][n-2+stAdd] = 2.0 * T_[n-1];
466 b[n-2+stAdd]= 3.0 * (listPnt[n-1] - listPnt[n-2]);
468 BIASDOUT(D_INTERPOL_SPLINE3,
" A:"<<A);
472 BIASERR(
"Lapack_LU_Linear_solve failed!");
476 BIASERR(
"SVD failed! Aborting...");
481 BIASDOUT(D_INTERPOL_SPLINE3,
"Vector x:"<<x);
491 a[2]= 3.0* (listPnt[1]-listPnt[0])/(t_i_1*t_i_1) -
492 2.0/t_i_1* startTangent - x[0]/t_i_1;
493 a[3]= 2.0/(t_i_1*t_i_1*t_i_1)* (listPnt[0]-listPnt[1]) +
494 (startTangent + x[0]) / (t_i_1*t_i_1);
497 BIASDOUT(D_INTERPOL_SPLINE3,
"First Polynom:"<<a);
498 for (i=1;i<n-2+stAdd+edAdd;i++) {
499 t_i_1= T_[i+1-stAdd];
500 a[0]= listPnt[i-stAdd];
502 a[2]= 3.0/(t_i_1*t_i_1)* (listPnt[i+1-stAdd]-listPnt[i-stAdd]) -
503 2.0/t_i_1* x[i-1] - x[i]/t_i_1;
504 a[3]= 2.0/(t_i_1*t_i_1*t_i_1)* (listPnt[i-stAdd]-listPnt[i+1-stAdd]) +
505 (x[i-1] + x[i]) / (t_i_1*t_i_1);
507 BIASDOUT(D_INTERPOL_SPLINE3,
"polynom "<<i<<
": "<<a);
515 a[2]= 3.0/(t_i_1*t_i_1)* (listPnt[n-1]-listPnt[n-2]) -
516 2.0/t_i_1* x[n-3+stAdd] - endTangent/t_i_1;
517 a[3]= 2.0/(t_i_1*t_i_1*t_i_1)* (listPnt[n-2]-listPnt[n-1]) +
518 (x[n-3+stAdd] + endTangent) / (t_i_1*t_i_1);
538 const std::vector<double>& listPnt,
541 unsigned int n=listPnt.size();
543 InitLinear(listP,listPnt);
547 const double eps=0.00000001;
549 double t0,t1, y0,y1,s1;
553 if (startTangent==-10000)
556 for (i=0;i<n-1;i++) {
557 t0=KPts_[i];t1=KPts_[i+1];
558 y0=listPnt[i];y1=listPnt[i+1];
559 if (i==0) t0Deriv=startTangent;
560 else t0Deriv=a[1]+ 2*a[2] * t0;
561 s1=2*t0*(t1-t0) - (t1*t1 - t0*t0);
562 if (fabs(s1)<eps) a[2]=0;
563 else a[2]=(t0Deriv*(t1-t0) - y1 + y0) / s1;
564 a[1]=t0Deriv - 2*a[2]*t0;
565 a[0]=y0 - a[2]*t0*t0 - a[1]*t0;
567 BIASDOUT(D_INTERPOL_SPLINE2,
"t0Deriv:"<<t0Deriv<<
" a:"<<a);
576 const std::vector<double>& listPnt)
578 unsigned int i,n=listPnt.size()-1;
582 a[1]=(listPnt[i+1]-listPnt[i]) / T_[i+1];
584 a[0]=listPnt[i]-a[1]*KPts_[i];
595 listPolynoms1_.clear();
596 listPolynoms2_.clear();
597 listPolynoms3_.clear();
601 InitLinear(listPolynoms1_,listPntDim1_);
603 InitSpline2(listPolynoms1_,listPntDim1_,startTangentX_);
605 InitSpline3(listPolynoms1_,listPntDim1_,startTangentX_,endTangentX_);
607 InitSplineAkima(listPolynoms1_,listPntDim1_,startTangentX_,endTangentX_);
609 if (listTangDim1_.size() == listPntDim1_.size()) {
612 InitSplineHermite(listTangDim1_,listPntDim1_,startTangentX_,endTangentX_);
618 InitLinear(listPolynoms1_,listPntDim1_);
619 InitLinear(listPolynoms2_,listPntDim2_);
622 InitSpline2(listPolynoms1_,listPntDim1_,startTangentX_);
623 InitSpline2(listPolynoms2_,listPntDim2_,startTangentY_);
626 InitSpline3(listPolynoms1_,listPntDim1_,startTangentX_,endTangentX_);
627 InitSpline3(listPolynoms2_,listPntDim2_,startTangentY_,endTangentY_);
630 InitSplineAkima(listPolynoms1_,listPntDim1_,startTangentX_,endTangentX_);
631 InitSplineAkima(listPolynoms2_,listPntDim2_,startTangentY_,endTangentY_);
636 InitLinear(listPolynoms1_,listPntDim1_);
637 InitLinear(listPolynoms2_,listPntDim2_);
638 InitLinear(listPolynoms3_,listPntDim3_);
641 InitSpline2(listPolynoms1_,listPntDim1_,startTangentX_);
642 InitSpline2(listPolynoms2_,listPntDim2_,startTangentY_);
643 InitSpline2(listPolynoms3_,listPntDim3_,startTangentZ_);
646 InitSpline3(listPolynoms1_,listPntDim1_,startTangentX_,endTangentX_);
647 InitSpline3(listPolynoms2_,listPntDim2_,startTangentY_,endTangentY_);
648 InitSpline3(listPolynoms3_,listPntDim3_,startTangentZ_,endTangentZ_);
651 InitSplineAkima(listPolynoms1_,listPntDim1_,startTangentX_,endTangentX_);
652 InitSplineAkima(listPolynoms2_,listPntDim2_,startTangentY_,endTangentY_);
653 InitSplineAkima(listPolynoms3_,listPntDim3_,startTangentZ_,endTangentZ_);
662 if (listPntDim1_.size()<=k && k < 5)
663 k=listPntDim1_.size()-1;
665 if (initializedPoly_!=k){
670 if (!validate(t,
true)){
671 BIASERR(
"invalid values, result is undefined");
676 if (t>KPts_[KPts_.size()-1]) {
677 res=listPntDim1_[actIndex_+1];
682 t = t-KPts_[actIndex_];
687 for (
int i=0;i<listPolynoms1_[actIndex_].size();i++) {
689 res+=listPolynoms1_[actIndex_][i]*pow(t,i);
691 res+=listPolynoms1_[actIndex_][i]*pow(t,3-i);
696 double h = KPts_[actIndex_+1] - KPts_[actIndex_];
697 t = (t - KPts_[actIndex_]) / h;
700 double h00 = 2*t3 - 3*t2 + 1;
701 double h10 = t3 - 2*t2 + t;
702 double h01 = -2*t3 + 3*t2;
703 double h11 = t3 - t2;
704 res = h00*listPntDim1_[actIndex_];
705 res += h10*h*listTangDim1_[actIndex_];
706 res += h01*listPntDim1_[actIndex_+1];
707 res += h11*h*listTangDim1_[actIndex_+1];
716 BIASERR(
"invalid values, result is undefined");
720 if (t>KPts_[KPts_.size()-1]) {
721 res[0]=listPntDim1_[actIndex_+1];
722 res[1]=listPntDim2_[actIndex_+1];
726 if (listPntDim1_.size()<=k) k=listPntDim1_.
size()-1;
728 if (initializedPoly_!=k)
731 double t0=KPts_[actIndex_], t1= KPts_[actIndex_+1];
732 double tint1= T_[actIndex_+1];
734 t = (t-t0)/(t1-t0) * tint1;
736 for (
int i=0;i<listPolynoms1_[actIndex_].size();i++) {
737 res[0]+=listPolynoms1_[actIndex_][i]*pow(t,(
int)i);
738 res[1]+=listPolynoms2_[actIndex_][i]*pow(t,(
int)i);
746 BIASERR(
"invalid values, result is undefined");
750 BIASDOUT(D_INTERPOL_COMMON,
"validate returned true");
751 if (t>KPts_.back()) {
752 res[0]=listPntDim1_[actIndex_+1];
753 res[1]=listPntDim2_[actIndex_+1];
754 res[2]=listPntDim3_[actIndex_+1];
758 if (listPntDim1_.size()<=k) k=listPntDim1_.
size()-1;
760 if (initializedPoly_!=k)
763 double t0=KPts_[actIndex_], t1= KPts_[actIndex_+1];
764 double tint1= T_[actIndex_+1];
766 t = (t-t0)/(t1-t0) * tint1;
768 BIASDOUT(D_INTERPOL_COMMON,
"evaluating result");
769 for (
int i=0;i<listPolynoms1_[actIndex_].size();i++) {
770 res[0]+=listPolynoms1_[actIndex_][i]*pow(t,(
int)i);
771 res[1]+=listPolynoms2_[actIndex_][i]*pow(t,(
int)i);
772 res[2]+=listPolynoms3_[actIndex_][i]*pow(t,(
int)i);
788 int n = listPntDim1_.size();
789 bezierInitialized_ =
true;
790 BIASDOUT(D_INTERPOL_BEZIER,
"Number of CPs: "<<n);
792 double stTanX, stTanY, stTanZ;
793 double edTanX, edTanY, edTanZ;
794 if (startTangentX_==-10000) {
797 stTanX = startTangentX_;
799 if (startTangentY_==-10000) {
802 stTanY = startTangentY_;
804 if (startTangentZ_==-10000) {
807 stTanZ = startTangentZ_;
809 if (endTangentX_==-10000) {
812 edTanX = endTangentX_;
814 if (endTangentY_==-10000) {
817 edTanY = endTangentY_;
819 if (endTangentZ_==-10000) {
822 edTanZ = endTangentZ_;
827 nmatrix_[1][0]=nmatrix_[0][1]=nmatrix_[1][2]=nmatrix_[2][1]=3;
828 nmatrix_[2][0]=nmatrix_[0][2]=-3;
830 nmatrix_[3][0]=nmatrix_[0][3]=1;
832 BIASDOUT(D_INTERPOL_BEZIER,
"NMatrix set");
843 bXK_1_.push_back(listPntDim1_[0]+stTanX);
844 bYK_1_.push_back(0.0);
847 for(
unsigned int i =1;i<listPntDim1_.size()-1;i++){
848 bXK_1_.push_back(listPntDim1_[i]+(listPntDim1_[i+1]-listPntDim1_[i-1])/2);
849 bYK_1_.push_back(listPntDim1_[i]-(listPntDim1_[i+1]-listPntDim1_[i-1])/2);
853 bYK_1_.push_back(listPntDim1_.back()-edTanX);
855 bXK_1_.push_back(0.0);
870 bXK_1_.push_back(listPntDim1_[0]+stTanX);
871 bXK_2_.push_back(listPntDim2_[0]+stTanY);
872 bYK_1_.push_back(0.0);
873 bYK_2_.push_back(0.0);
876 for(
unsigned int i =1;i<listPntDim1_.size()-1;i++){
877 bXK_1_.push_back(listPntDim1_[i]+(listPntDim1_[i+1]-listPntDim1_[i-1])/2);
878 bXK_2_.push_back(listPntDim2_[i]+(listPntDim2_[i+1]-listPntDim2_[i-1])/2);
879 bYK_1_.push_back(listPntDim1_[i]-(listPntDim1_[i+1]-listPntDim1_[i-1])/2);
880 bYK_2_.push_back(listPntDim2_[i]-(listPntDim2_[i+1]-listPntDim2_[i-1])/2);
884 bYK_1_.push_back(listPntDim1_.back()-edTanX);
885 bYK_2_.push_back(listPntDim2_.back()-edTanY);
887 bXK_1_.push_back(0.0);
888 bXK_2_.push_back(0.0);
890 BIASDOUT(D_INTERPOL_BEZIER,
"Alle koeffizienten berechnet");
910 BIASDOUT(D_INTERPOL_BEZIER,
"bXK and bYK resized.");
913 bXK_1_.push_back(listPntDim1_[0]+stTanX);
914 bXK_2_.push_back(listPntDim2_[0]+stTanY);
915 bXK_3_.push_back(listPntDim3_[0]+stTanZ);
917 bYK_1_.push_back(0.0);
918 bYK_2_.push_back(0.0);
919 bYK_3_.push_back(0.0);
922 for(
unsigned int i =1;i<listPntDim1_.size()-1;i++){
923 bXK_1_.push_back(listPntDim1_[i]+(listPntDim1_[i+1]-listPntDim1_[i-1])/2);
924 bXK_2_.push_back(listPntDim2_[i]+(listPntDim2_[i+1]-listPntDim2_[i-1])/2);
925 bXK_3_.push_back(listPntDim3_[i]+(listPntDim3_[i+1]-listPntDim3_[i-1])/2);
926 bYK_1_.push_back(listPntDim1_[i]-(listPntDim1_[i+1]-listPntDim1_[i-1])/2);
927 bYK_2_.push_back(listPntDim2_[i]-(listPntDim2_[i+1]-listPntDim2_[i-1])/2);
928 bYK_3_.push_back(listPntDim3_[i]-(listPntDim3_[i+1]-listPntDim3_[i-1])/2);
931 bYK_1_.push_back(listPntDim1_.back()-edTanX);
932 bYK_2_.push_back(listPntDim2_.back()-edTanY);
933 bYK_3_.push_back(listPntDim3_.back()-edTanZ);
936 bXK_1_.push_back(0.0);
937 bXK_2_.push_back(0.0);
938 bXK_3_.push_back(0.0);
940 BIASDOUT(D_INTERPOL_BEZIER,
"Alle koeffizienten berechnet");
944 cout<<
"WRONG DIMENSION IN BEZIER INTERPOLATION"<<endl;
956 if(!bezierInitialized_)
960 int n = listPntDim1_.size();
974 BIASERR(
"invalid values, result is undefined");
978 in_segment = actIndex_;
982 res=listPntDim1_.back();
988 cpoints[0][0]= listPntDim1_[in_segment];
990 cpoints[1][0]= bXK_1_[in_segment];
992 cpoints[2][0]= bYK_1_[in_segment+1];
994 cpoints[3][0]= listPntDim1_[in_segment+1];
998 t=(t-KPts_[in_segment])/(KPts_[in_segment+1]-KPts_[in_segment]);
1000 BIASDOUT(D_INTERPOL_BEZIER,
" t:"<<t<<
" Segs:"<<segments);
1001 BIASDOUT(D_INTERPOL_BEZIER,
"In Segment:"<<in_segment);
1006 tvector[0][1] = pow(t,2);
1007 tvector[0][0] = pow(t,3);
1009 BIASDOUT(D_INTERPOL_BEZIER,
"The TVector"<<tvector);
1010 BIASDOUT(D_INTERPOL_BEZIER,
"The NMatrix"<<nmatrix_);
1011 BIASDOUT(D_INTERPOL_BEZIER,
"The PMatrix"<<cpoints);
1014 tvector.
Mult(nmatrix_);
1015 BIASDOUT(D_INTERPOL_BEZIER,
"tvector mult nmatrix.");
1016 tvector.
Mult(cpoints);
1017 BIASDOUT(D_INTERPOL_BEZIER,
"tvector mult cpoints.");
1019 res = tvector[0][0];
1021 BIASDOUT(D_INTERPOL_BEZIER,
"Result : "<<res);
1034 if(!bezierInitialized_)
1038 int n = listPntDim1_.size();
1052 BIASERR(
"invalid values, result is undefined");
1059 in_segment = actIndex_;
1063 res[0]=listPntDim1_.back();
1064 res[1]=listPntDim2_.back();
1070 cpoints[0][0]=listPntDim1_[in_segment];
1071 cpoints[0][1]=listPntDim2_[in_segment];
1073 cpoints[1][0]= bXK_1_[in_segment];
1074 cpoints[1][1]= bXK_2_[in_segment];
1076 cpoints[2][0]= bYK_1_[in_segment+1];
1077 cpoints[2][1]= bYK_2_[in_segment+1];
1079 cpoints[3][0]= listPntDim1_[in_segment+1];
1080 cpoints[3][1]= listPntDim2_[in_segment+1];
1083 t=(t-KPts_[in_segment])/(KPts_[in_segment+1]-KPts_[in_segment]);
1085 BIASDOUT(D_INTERPOL_BEZIER,
" t:"<<t<<
" Segs:"<<segments);
1086 BIASDOUT(D_INTERPOL_BEZIER,
"In Segment:"<<in_segment);
1091 tvector[0][1] = pow(t,2);
1092 tvector[0][0] = pow(t,3);
1094 BIASDOUT(D_INTERPOL_BEZIER,
"The TVector"<<tvector);
1095 BIASDOUT(D_INTERPOL_BEZIER,
"The NMatrix"<<nmatrix_);
1096 BIASDOUT(D_INTERPOL_BEZIER,
"The PMatrix"<<cpoints);
1099 tvector.
Mult(nmatrix_);
1100 BIASDOUT(D_INTERPOL_BEZIER,
"tvector mult nmatrix.");
1101 tvector.
Mult(cpoints);
1102 BIASDOUT(D_INTERPOL_BEZIER,
"tvector mult cpoints.");
1105 res[0] = tvector[0][0];
1106 res[1] = tvector[0][1];
1108 BIASDOUT(D_INTERPOL_BEZIER,
"Result : "<<res[0]<<
" "<<res[1]);
1121 if(!bezierInitialized_)
1125 int n = listPntDim1_.size();
1138 BIASERR(
"invalid values, result is undefined");
1145 in_segment = actIndex_;
1148 if (t>KPts_.back()){
1149 res[0]=listPntDim1_.back();
1150 res[1]=listPntDim2_.back();
1151 res[2]=listPntDim3_.back();
1157 cpoints[0][0]=listPntDim1_[in_segment];
1158 cpoints[0][1]=listPntDim2_[in_segment];
1159 cpoints[0][2]=listPntDim3_[in_segment];
1161 cpoints[1][0]= bXK_1_[in_segment];
1162 cpoints[1][1]= bXK_2_[in_segment];
1163 cpoints[1][2]= bXK_3_[in_segment];
1165 cpoints[2][0]= bYK_1_[in_segment+1];
1166 cpoints[2][1]= bYK_2_[in_segment+1];
1167 cpoints[2][2]= bYK_3_[in_segment+1];
1169 cpoints[3][0]= listPntDim1_[in_segment+1];
1170 cpoints[3][1]= listPntDim2_[in_segment+1];
1171 cpoints[3][2]= listPntDim3_[in_segment+1];
1174 t=(t-KPts_[in_segment])/(KPts_[in_segment+1]-KPts_[in_segment]);
1176 BIASDOUT(D_INTERPOL_BEZIER,
" t:"<<t<<
" Segs:"<<segments);
1177 BIASDOUT(D_INTERPOL_BEZIER,
"In Segment:"<<in_segment);
1182 tvector[0][1] = pow(t,2);
1183 tvector[0][0] = pow(t,3);
1186 BIASDOUT(D_INTERPOL_BEZIER,
"The TVector"<<tvector);
1187 BIASDOUT(D_INTERPOL_BEZIER,
"The NMatrix"<<nmatrix_);
1188 BIASDOUT(D_INTERPOL_BEZIER,
"The PMatrix"<<cpoints);
1191 tvector.
Mult(nmatrix_);
1192 BIASDOUT(D_INTERPOL_BEZIER,
"tvector mult nmatrix.");
1193 tvector.
Mult(cpoints);
1194 BIASDOUT(D_INTERPOL_BEZIER,
"tvector mult cpoints.");
1196 res[0] = tvector[0][0];
1197 res[1] = tvector[0][1];
1198 res[2] = tvector[0][2];
1199 BIASDOUT(D_INTERPOL_BEZIER,
"Result :"<<res[0]<<
" "<<res[1]<<
" "<<res[2]);
1213 unsigned int N = SplineLuT1_.size();
1215 if(N != Ncompare || Ncompare <1 || N <1)
1218 bool theyDiffer =
false;
1219 for(
unsigned int i = 0; i<N && !theyDiffer; i++ ) {
1220 theyDiffer = (SplineLuT1_[i] != I.
SplineLuT1_[i]);
1230 SplineLuT1_.resize(N);
1233 LuTSampleDist1_ = (max-min) /
double(N-1);
1235 for (
unsigned int i=0;i<N; i++)
1236 Spline(SplineLuT1_[i], min +
double(i) * LuTSampleDist1_, k);
1248 if (t<LuTMin1_ || t>LuTMax1_ || SplineLuT1_.size() == 0)
return -1;
1249 int index = (int)rint((t - LuTMin1_) / LuTSampleDist1_);
1253 if(index > (
int)SplineLuT1_.size()-1 )
1254 index=(
int)SplineLuT1_.size()-1;
1256 BIASASSERT(index >= 0);
1257 BIASASSERT(index < (
int)SplineLuT1_.size());
1258 res = SplineLuT1_[index];
int Bezier3(double &res, double t)
these functions do the bezier interpolation as described in David Salomon 4...
void InitSpline()
call this for restart at t= first knot point initiates recalculation of all polynom coefficients at f...
void Set(const T *pv)
copy the array of vectorsize beginning at *T to this->data_
computes and holds the singular value decomposition of a rectangular (not necessarily quadratic) Matr...
void InitSpline3(std::vector< BIAS::Vector< double > > &listP, const std::vector< double > &listPnt, const double startTangent=0, const double endTangent=0)
void Fill(const T &scalar)
Takes the elements of a Vector and put them as diagonal elements into a matrix.
const unsigned int size() const
bool validate(double &t, bool debug=false)
std::vector< double > SplineLuT1_
void SetKnotPoints(const std::vector< double > &kPnt)
set the additional knot points, if you want nonuniform interpolation.
void InitBezier(int dim_of_CP)
here the calculation of all coefficients for the bezier interpolation is done and the nmatrix is set ...
void Clear()
resets everything.
int Compute(const Matrix< double > &M, double ZeroThreshold=DEFAULT_DOUBLE_ZERO_THRESHOLD)
set a new matrix and compute its decomposition.
void clear()
stl conform interface
BIAS::Vector< double > Lapack_LU_linear_solve(const BIAS::Matrix< double > &A, const BIAS::Vector< double > &b)
solve linear equations using LU factorization
const bool DoLuTSplinesDiffer(const Interpolator &I) const
Compare LuT data structures if matching perfectly.
this class interpolates a function y=f(t) between given control points (the y-values) ...
int SplineFromLuT(double &res, double t) const
Get spline interpolation using Look-up-Table.
void Set(const T &scalar)
set all elements to a scalar value
void InitLinear(std::vector< BIAS::Vector< double > > &listP, const std::vector< double > &listPnt)
void InitSplineAkima(std::vector< BIAS::Vector< double > > &listP, const std::vector< double > &listPnt, const double startTangent, const double endTangent)
int Spline(double &res, double t, unsigned int k=3)
these functions do the Spline interpolation which reaches each control point.
void InitSplineHermite(std::vector< double > &tangents, const std::vector< double > &listPnt, const double startTangent, const double endTangent)
void SetControlPoints(const std::vector< double > &cPnt1)
set the control points, which control the interpolating curve
void clear()
stl conform interface
void Mult(const Matrix< T > &arg, Matrix< T > &result) const
matrix multiplication, result is not allocated
void InitSpline2(std::vector< BIAS::Vector< double > > &listP, const std::vector< double > &listPnt, double startTangent=0)
Matrix< double > Invert()
returns pseudoinverse of A = U * S * V^T A^+ = V * S^+ * U^T
void GetControlPoints(std::vector< double > &cPnt) const
int PrepareLuTSpline(double min, double max, unsigned int N, unsigned int k=3)
Prepare Look-up-Table in range [min,max] with N samples.
const unsigned int size() const
void fakima(BIAS::Vector< double > &a, BIAS::Vector< double > Px, BIAS::Vector< double > Py, int from, int to, int intervall)