Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Interpolator.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #ifdef WIN32
26 # define _USE_MATH_DEFINES
27 #endif //WIN32
28 
29 #include <math.h>
30 #include <iostream>
31 #include "Interpolator.hh"
32 #include "Base/Debug/Error.hh"
33 //#include "Base/ImageUtils/ImageDraw.hh"
34 #include "Lapack.hh"
35 #include "SVD.hh"
36 
37 using namespace BIAS;
38 using namespace std;
39 
41  nmatrix_.newsize(4,4);
42  Clear();
43 
44 #ifdef BIAS_DEBUG
45  SetDebugLevel(0);
46  // AddDebugLevel(D_INTERPOL_COMMON);
47  // AddDebugLevel(D_INTERPOL_SPLINE3);
48 #endif
49 }
50 
52  Clear();
53  nmatrix_.clear();
54 
55 }
56 
58  nmatrix_.SetZero();
59  actIndex_=0; // the index of the actual intervall for t
60  listPolynoms1_.clear();
61  listPolynoms2_.clear();
62  listPolynoms3_.clear();
63  KPts_.clear();
64  T_.clear();
65  listPntDim1_.clear();
66  listPntDim2_.clear();
67  listPntDim3_.clear();
68  initializedPoly_=0;
69  startTangentX_=-10000;
70  startTangentY_=-10000;
71  startTangentZ_=-10000;
72  endTangentX_=-10000;
73  endTangentY_=-10000;
74  endTangentZ_=-10000;
75  bXK_1_.clear();
76  bXK_2_.clear();
77  bXK_3_.clear();
78  bYK_1_.clear();
79  bYK_2_.clear();
80  bYK_3_.clear();
81  bezierInitialized_ = false;
82  LuTMin1_ = -10000;
83  LuTMax1_ = -10000;
84  LuTSampleDist1_ = 0;
85  SplineLuT1_.clear();
86  listTangDim1_.clear();
87 }
88 
89 void
91 {
92  double temp;
93  unsigned n = cPnt.size();
94  if(n==0) return;
95 
96  listPntDim1_.clear();listPntDim1_.resize(n);
97  listPntDim2_.clear();listPntDim2_.resize(n);
98 
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;
102  }
103 }
104 
105 void
107 SetControlPoints(const std::vector<BIAS::Vector3<double> > &cPnt) {
108  double temp;
109  unsigned n = cPnt.size();
110  if(n==0) return;
111  listPntDim1_.clear();listPntDim1_.resize(n);
112  listPntDim2_.clear();listPntDim2_.resize(n);
113  listPntDim3_.clear();listPntDim3_.resize(n);
114 
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;
119  }
120 }
121 
122 void
124 {
125  Vector2<double> temp;
126  cPnt.clear();
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);
131  }
132 }
133 
134 void
136 GetControlPoints(std::vector<BIAS::Vector3<double> > &cPnt) const
137 {
138  Vector3<double> temp;
139  cPnt.clear();
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);
145  }
146 }
147 
148 bool Interpolator::validate(double &t, bool debug)
149 {
150  BIASDOUT(D_INTERPOL_COMMON,"validating t:"<<t);
151  if (listPntDim1_.size()>KPts_.size()) { // make it uniform
152  KPts_.clear();
153  T_.clear();
154  for (unsigned int i=0;i<listPntDim1_.size();i++)
155  KPts_.push_back((double)i/(double)(listPntDim1_.size()-1));
156  T_.push_back(1);
157  }
158  unsigned int tSize=KPts_.size()-1;
159  if ( (tSize<=0) || (listPntDim1_.size()<=1) ) {
160  BIASERR("less than 2 control points");
161  return false;
162  }
163  if (t<=KPts_[0]) {t=KPts_[0]; actIndex_=0; return true;}
164 
165  // find the correct intervall
166  unsigned int i=0;
167  while ((i<tSize) && (KPts_[i]<t))
168  i++;
169  actIndex_=i-1;
170 
171  if(debug && actIndex_ < 0){
172  cout<<"t:"<<t<<endl;
173  cout<<"ActIndex_ = "<<actIndex_<<endl;
174  }
175 
176  if(actIndex_<0)
177  return false;
178  else
179  return true;
180 }
181 
182 void Interpolator::SetKnotPoints(const std::vector<double> &kPnt){
183  unsigned int n=0;
184  if ((n=kPnt.size())==0) return;
185  //clear before resize
186  KPts_.clear();
187  T_.clear();
188 
189  KPts_.resize(n);
190  T_.resize(n);
191  for (unsigned int i=0;i<n;i++)
192  KPts_[i]=kPnt[i];
193  for (unsigned int i=1;i<n;i++)
194  T_[i]=kPnt[i]-kPnt[i-1];
195 }
196 
198 {
199  initializedPoly_=0;
200 }
201 
202 
204  const std::vector<double>& listPnt,
205  const double startTangent, const double endTangent)
206 {
207  int n=listPnt.size();
208  BIASDOUT(D_INTERPOL_SPLINE3,"n="<<n);
209  if (n<5) {
210  InitSpline2(listP,listPnt,-10000);
211  return;
212  }
213 
214  BIAS::Vector<double> a(4); // the polynom coefficients
215  BIAS::Vector<double> Px(6);
216  BIAS::Vector<double> Py(6);
217  int Min, Max;
218  int from, to;
219 
220  for (int j=0; j<n-1; j++) {
221  from = 0;
222  to = 5;
223 
224  Min = j - 2;
225  if (Min<0) {
226  if (startTangent==-10000) {
227  from -= Min;
228  }
229  Min = 0;
230  }
231  Max = j + 3;
232  if (Max>n-1) {
233  if (endTangent==-10000) {
234  to += n-1 - Max;
235  }
236  Max = n-1;
237  }
238 
239  int k = 0;
240  for (int i=j-2; i<=j+3; i++) {
241  if (i>=Min && i<=Max) {
242  Px[k] = KPts_[i];
243  Py[k] = listPnt[i];
244  } else {
245  if (i<Min) {
246  if (startTangent==-10000) {
247  Px[k] = KPts_[Min];
248  Py[k] = listPnt[Min];
249  } else {
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;
253  }
254  } else {
255  if (endTangent==-10000) {
256  Px[k] = KPts_[Max];
257  Py[k] = listPnt[Max];
258  } else {
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;
262  }
263  }
264  }
265  k++;
266  }
267  double xx=Px[2];
268  for (int i=0; i<6; i++) {
269  Px[i]-=xx;
270  }
271  fakima(a, Px, Py, from, to, 2);
272  listP.push_back(a);
273  }
274  initializedPoly_=4;
275 }
276 
277 
280  int from, int to, int intervall)
281 {
282  double d1,d2;
283  double a1,a2;
284  BIAS::Vector<double> dq(6);
285  BIAS::Vector<double> si(2);
286  BIAS::Matrix<double> A(4,4);
288 
289  for (int i=0; i<from; i++) {
290  d1 = Py[from+1] - Py[from];
291  d2 = Px[from+1] - Px[from];
292  if (d2 == 0)
293  dq[i] = 0.0;
294  else
295  dq[i] = d1/d2;
296  }
297  for (int i=from; i<to; i++) {
298  d1 = Py[i+1] - Py[i];
299  d2 = Px[i+1] - Px[i];
300  if (d2 == 0)
301  dq[i] = 0.0;
302  else
303  dq[i] = d1/d2;
304  }
305  for (int i=to; i<6; i++) {
306  d1 = Py[to] - Py[to-1];
307  d2 = Px[to] - Px[to-1];
308  if (d2 == 0)
309  dq[i] = 0.0;
310  else
311  dq[i] = d1/d2;
312  }
313 
314  // calculate tangent si0
315  double eps=0.000001;
316  a1 = fabs(dq[intervall+1] - dq[intervall]);
317  a2 = fabs(dq[intervall-1] - dq[intervall-2]);
318  if ((a1+a2) < eps) {
319  si[0] = (dq[intervall-1]+dq[intervall]) / 2;
320  } else {
321  si[0] = (a1 * dq[intervall-1] + a2 * dq[intervall]) / (a1+a2);
322  }
323 
324  // calculate tangent si1
325  intervall ++;
326  a1 = fabs(dq[intervall+1] - dq[intervall]);
327  a2 = fabs(dq[intervall-1] - dq[intervall-2]);
328  if ((a1+a2) <eps) {
329  si[1] = (dq[intervall-1]+dq[intervall]) / 2;
330  } else {
331  si[1] = (a1 * dq[intervall-1] + a2 * dq[intervall]) / (a1+a2);
332  }
333 
334  //construct LGS
335  intervall --;
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]);
340  A[0][3] = 1.0;
341 
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]);
346  A[1][3] = 1.0;
347 
348  A[2][0] = 3.0 * ((double)(Px[intervall])) * ((double)(Px[intervall]));
349  A[2][1] = 2.0 * ((double)(Px[intervall]));
350  A[2][2] = 1.0;
351  A[2][3] = 0.0;
352 
353  A[3][0] = 3.0 * ((double)(Px[intervall+1])) * ((double)(Px[intervall+1]));
354  A[3][1] = 2.0 * ((double)(Px[intervall+1]));
355  A[3][2] = 1.0;
356  A[3][3] = 0.0;
357 
358  b[0] = (double)(Py[intervall]);
359  b[1] = (double)(Py[intervall+1]);
360  b[2] = si[0];
361  b[3] = si[1];
362 
363  a=Lapack_LU_linear_solve(A,b);
364 }
365 
366 void Interpolator::
367 InitSplineHermite(std::vector<double> &tangents,
368  const std::vector<double> &listPnt,
369  const double startTangent, const double endTangent)
370 {
371  unsigned int n=listPnt.size();
372  BIASDOUT(D_INTERPOL_SPLINE3,"n="<<n);
373 
374  tangents.resize(n);
375 
376  if (startTangent == -10000) {
377  tangents[0] = 0.0f;
378  } else {
379  tangents[0] = startTangent;
380  }
381  if (endTangent == -10000) {
382  tangents[n-1] = 0.0f;
383  } else {
384  tangents[n-1] = endTangent;
385  }
386 
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);
391  }
392 
393 
394  initializedPoly_=5;
395 }
396 
397 
398 void
400 InitSpline3(std::vector<BIAS::Vector<double> > &listP,
401  const std::vector<double> &listPnt,
402  const double startTangent, const double endTangent)
403 {
404  // t0 is 0! different t values are handed by tOffset_
405  unsigned int i;
406  unsigned int n=listPnt.size();
407  BIASDOUT(D_INTERPOL_SPLINE3,"n="<<n);
408  if (n==3) {
409  InitSpline2(listP,listPnt,startTangent);
410  return;
411  }
412  // first calculate the tangents for all control points
413  // x is the solution with the tangent values
414  // if start or end tangent are not set, thenthe relaxed end condition
415  // P1''=0 or Pn''=0 is used
416  int stAdd=0;
417  if (startTangent==-10000) {
418  stAdd=1;
419  }
420  int edAdd=0;
421  if (endTangent==-10000) {
422  edAdd=1;
423  }
424  BIAS::Vector<double> x(n-2+stAdd+edAdd),b(n-2+stAdd+edAdd);
425  assert (n>2);
426  BIAS::Matrix<double> A(n-2+stAdd+edAdd,n-2+stAdd+edAdd);
427  A.Fill(0);
428 
429  // linear equations like those in
430  // David Salomon's CG, page 238 for nonuniform Splines
431  if (stAdd==0) {
432  // startTangent set
433  A[0][0]=2.0*(T_[1] + T_[2]);
434  A[0][1]=T_[1];
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;
439  } else {
440  // relaxed start condition
441  A[0][0]=2.0*T_[1];
442  A[0][1]=T_[1];
443  b[0]= 3.0 * (listPnt[1] - listPnt[0]);
444  }
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]));
453  }
454  if (edAdd==0) {
455  // endTangent set
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;
462  } else {
463  // relaxed end condition
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]);
467  }
468  BIASDOUT(D_INTERPOL_SPLINE3," A:"<<A);
469 
470  x=Lapack_LU_linear_solve(A,b);
471  if(x.size()==0){
472  BIASERR("Lapack_LU_Linear_solve failed!");
473  BIAS::SVD svdA;
474  int res = svdA.Compute(A);
475  if(res < 0){
476  BIASERR("SVD failed! Aborting...");
477  return;
478  }
479  x = svdA.Invert()*b;
480  }
481  BIASDOUT(D_INTERPOL_SPLINE3,"Vector x:"<<x);
482 
483  BIAS::Vector<double> a(4); // the polynom coefficients
484  double t_i_1;
485  if (stAdd==0) {
486  // startTangent set
487  // the first segment
488  t_i_1= T_[1];
489  a[0]= listPnt[0];
490  a[1]= startTangent;
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);
495  listP.push_back(a);
496  }
497  BIASDOUT(D_INTERPOL_SPLINE3,"First Polynom:"<<a);
498  for (i=1;i<n-2+stAdd+edAdd;i++) { // second segment to n-2 segment
499  t_i_1= T_[i+1-stAdd];
500  a[0]= listPnt[i-stAdd];
501  a[1]= x[i-1]; // x are the tangent values
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);
506  listP.push_back(a);
507  BIASDOUT(D_INTERPOL_SPLINE3,"polynom "<<i<<": "<<a);
508  }
509  if (edAdd==0) {
510  // endTangent set
511  // last (n-1) segment
512  t_i_1= T_[n-1];
513  a[0]= listPnt[n-2];
514  a[1]= x[n-3+stAdd];
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);
519  listP.push_back(a);
520  }
521  initializedPoly_=3;
522 
523 // for (int i=0; i<n; i++) {
524 // cout << i << " T:" << T_[i] << " listPnt:" << listPnt[i]
525 // << endl;
526 // }
527 
528 // cout << "ST x:" << startTangent << endl;
529 // for (int i=0; i<n-2; i++) {
530 // cout << i+1 << " x:" << x[i] << endl;
531 // }
532 // cout << "ET x:" << endTangent << endl;
533 }
534 
535 void
537 InitSpline2(std::vector<BIAS::Vector<double> > &listP,
538  const std::vector<double>& listPnt,
539  double startTangent)
540 {
541  unsigned int n=listPnt.size();
542  if (n<3) {
543  InitLinear(listP,listPnt);
544  return;
545  }
546  unsigned int i;
547  const double eps=0.00000001;
549  double t0,t1, y0,y1,s1;
550 
551  // take the next control point for each new polynom
552  double t0Deriv;
553  if (startTangent==-10000)
554  startTangent = 0;
555 
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;
566  listP.push_back(a);
567  BIASDOUT(D_INTERPOL_SPLINE2,"t0Deriv:"<<t0Deriv<<" a:"<<a);
568  }
569  // BIASDOUT(D_POLYNOM,"a0:"<<a[0]<<" a1:"<<a[1]<<" a2:"<<a[2]);
570  // cerr<<"a:"<<a;
571  initializedPoly_=2;
572 }
573 
574 void Interpolator::
575 InitLinear(std::vector<BIAS::Vector<double> > &listP,
576  const std::vector<double>& listPnt)
577 {
578  unsigned int i,n=listPnt.size()-1;
580  for (i=0;i<n;i++) {
581  if (T_[i+1]>0)
582  a[1]=(listPnt[i+1]-listPnt[i]) / T_[i+1];
583  else a[1]=0;
584  a[0]=listPnt[i]-a[1]*KPts_[i];
585  listP.push_back(a);
586  }
587  initializedPoly_=1;
588 }
589 
590 
591 // calculates the polynom coefficients for each intervall
592 void Interpolator::
593 InitSpline(const unsigned int k, const unsigned int dim)
594 {
595  listPolynoms1_.clear();
596  listPolynoms2_.clear();
597  listPolynoms3_.clear();
598  actIndex_=0;
599  if (dim==1) {
600  if (k==1)
601  InitLinear(listPolynoms1_,listPntDim1_);
602  if (k==2)
603  InitSpline2(listPolynoms1_,listPntDim1_,startTangentX_);
604  if (k==3)
605  InitSpline3(listPolynoms1_,listPntDim1_,startTangentX_,endTangentX_);
606  if (k==4)
607  InitSplineAkima(listPolynoms1_,listPntDim1_,startTangentX_,endTangentX_);
608  if (k==5) {
609  if (listTangDim1_.size() == listPntDim1_.size()) {
610  initializedPoly_=5;
611  } else {
612  InitSplineHermite(listTangDim1_,listPntDim1_,startTangentX_,endTangentX_);
613  }
614  }
615  }
616  if (dim==2) {
617  if (k==1) {
618  InitLinear(listPolynoms1_,listPntDim1_);
619  InitLinear(listPolynoms2_,listPntDim2_);
620  }
621  if (k==2) {
622  InitSpline2(listPolynoms1_,listPntDim1_,startTangentX_);
623  InitSpline2(listPolynoms2_,listPntDim2_,startTangentY_);
624  }
625  if (k==3) {
626  InitSpline3(listPolynoms1_,listPntDim1_,startTangentX_,endTangentX_);
627  InitSpline3(listPolynoms2_,listPntDim2_,startTangentY_,endTangentY_);
628  }
629  if (k==4) {
630  InitSplineAkima(listPolynoms1_,listPntDim1_,startTangentX_,endTangentX_);
631  InitSplineAkima(listPolynoms2_,listPntDim2_,startTangentY_,endTangentY_);
632  }
633  }
634  if (dim==3) {
635  if (k==1) {
636  InitLinear(listPolynoms1_,listPntDim1_);
637  InitLinear(listPolynoms2_,listPntDim2_);
638  InitLinear(listPolynoms3_,listPntDim3_);
639  }
640  if (k==2) {
641  InitSpline2(listPolynoms1_,listPntDim1_,startTangentX_);
642  InitSpline2(listPolynoms2_,listPntDim2_,startTangentY_);
643  InitSpline2(listPolynoms3_,listPntDim3_,startTangentZ_);
644  }
645  if (k==3) {
646  InitSpline3(listPolynoms1_,listPntDim1_,startTangentX_,endTangentX_);
647  InitSpline3(listPolynoms2_,listPntDim2_,startTangentY_,endTangentY_);
648  InitSpline3(listPolynoms3_,listPntDim3_,startTangentZ_,endTangentZ_);
649  }
650  if (k==4) {
651  InitSplineAkima(listPolynoms1_,listPntDim1_,startTangentX_,endTangentX_);
652  InitSplineAkima(listPolynoms2_,listPntDim2_,startTangentY_,endTangentY_);
653  InitSplineAkima(listPolynoms3_,listPntDim3_,startTangentZ_,endTangentZ_);
654  }
655  }
656 }
657 
658 
659 int Interpolator::Spline(double &res, double t, unsigned int k)
660 {
661  // if less than 4 control points and not hermite
662  if (listPntDim1_.size()<=k && k < 5)
663  k=listPntDim1_.size()-1;
664 
665  if (initializedPoly_!=k){
666  //cout<<"reinit spline:"<<k<<endl;
667  InitSpline(k,1);
668  }
669 
670  if (!validate(t,true)){
671  BIASERR("invalid values, result is undefined");
672  res=0;
673  return -1;
674  }
675 
676  if (t>KPts_[KPts_.size()-1]) {
677  res=listPntDim1_[actIndex_+1];
678  return 1;
679  }
680 
681  if (k==3 || k==4) {
682  t = t-KPts_[actIndex_];
683  }
684 
685  res=0;
686  if (k!=5) {
687  for (int i=0;i<listPolynoms1_[actIndex_].size();i++) {
688  if (k!=4) {
689  res+=listPolynoms1_[actIndex_][i]*pow(t,i);
690  } else {
691  res+=listPolynoms1_[actIndex_][i]*pow(t,3-i);
692  }
693  }
694  } else {
695  // hermite spline
696  double h = KPts_[actIndex_+1] - KPts_[actIndex_];
697  t = (t - KPts_[actIndex_]) / h;
698  double t2 = t*t;
699  double t3 = t*t2;
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];
708  }
709  return 0;
710 }
711 
712 
713 int Interpolator::Spline(Vector2<double> &res, double t, unsigned int k)
714 {
715  if (!validate(t)) {
716  BIASERR("invalid values, result is undefined");
717  res = 0;
718  return -1;
719  }
720  if (t>KPts_[KPts_.size()-1]) {
721  res[0]=listPntDim1_[actIndex_+1];
722  res[1]=listPntDim2_[actIndex_+1];
723  return 1;
724  }
725  // if less than 4 control points
726  if (listPntDim1_.size()<=k) k=listPntDim1_.size()-1;
727 
728  if (initializedPoly_!=k)
729  InitSpline(k,2);
730  res.Set(0);
731  double t0=KPts_[actIndex_], t1= KPts_[actIndex_+1];
732  double tint1= T_[actIndex_+1];
733  if (k==3 || k==4) {
734  t = (t-t0)/(t1-t0) * tint1;
735  }
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);
739  }
740  return 0;
741 }
742 
743 int Interpolator::Spline(Vector3<double> &res, double t, unsigned int k)
744 {
745  if (!validate(t)) {
746  BIASERR("invalid values, result is undefined");
747  res.Set(0.0);
748  return -1;
749  }
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];
755  return 1;
756  }
757  // if less than 4 control points
758  if (listPntDim1_.size()<=k) k=listPntDim1_.size()-1;
759 
760  if (initializedPoly_!=k)
761  InitSpline(k,3);
762  res.Set(0.0);
763  double t0=KPts_[actIndex_], t1= KPts_[actIndex_+1];
764  double tint1= T_[actIndex_+1];
765  if (k==3 || k==4) {
766  t = (t-t0)/(t1-t0) * tint1;
767  }
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);
773  }
774  return 0;
775 }
776 
777 /**
778  Calculation of the coefficients of the Bezier interpolation
779  @author Ingo Schiller
780  @param dimension of control points (int)
781  @status tested 12.05.03
782 */
783 
784 void
786 {
787  //n = number of control points
788  int n = listPntDim1_.size();
789  bezierInitialized_ = true;
790  BIASDOUT(D_INTERPOL_BEZIER,"Number of CPs: "<<n);
791 
792  double stTanX, stTanY, stTanZ;
793  double edTanX, edTanY, edTanZ;
794  if (startTangentX_==-10000) {
795  stTanX = 0;
796  } else {
797  stTanX = startTangentX_;
798  }
799  if (startTangentY_==-10000) {
800  stTanY = 0;
801  } else {
802  stTanY = startTangentY_;
803  }
804  if (startTangentZ_==-10000) {
805  stTanZ = 0;
806  } else {
807  stTanZ = startTangentZ_;
808  }
809  if (endTangentX_==-10000) {
810  edTanX = 0;
811  } else {
812  edTanX = endTangentX_;
813  }
814  if (endTangentY_==-10000) {
815  edTanY = 0;
816  } else {
817  edTanY = endTangentY_;
818  }
819  if (endTangentZ_==-10000) {
820  edTanZ = 0;
821  } else {
822  edTanZ = endTangentZ_;
823  }
824  //set the matrix(row,column)
825  nmatrix_.Fill(0.0);
826  nmatrix_[0][0]=-1;
827  nmatrix_[1][0]=nmatrix_[0][1]=nmatrix_[1][2]=nmatrix_[2][1]=3;
828  nmatrix_[2][0]=nmatrix_[0][2]=-3;
829  nmatrix_[1][1]=-6;
830  nmatrix_[3][0]=nmatrix_[0][3]=1;
831 
832  BIASDOUT(D_INTERPOL_BEZIER,"NMatrix set");
833 
834  switch(dim_of_CP){
835  case 1:
836  bXK_1_.clear();
837  bYK_1_.clear();
838  bXK_1_.reserve(n-1);
839  bYK_1_.reserve(n-1);
840 
841 
842  //set X0 according to start- and endtangents
843  bXK_1_.push_back(listPntDim1_[0]+stTanX);
844  bYK_1_.push_back(0.0);
845 
846  // rest of coefficients, Xn not requiered, Y0 not requiered
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);
850  }
851 
852  //Yn according to start- and endtangents
853  bYK_1_.push_back(listPntDim1_.back()-edTanX);
854  //Xn to keep the size
855  bXK_1_.push_back(0.0);
856  break;
857 
858  case 2:
859  bXK_1_.clear();
860  bXK_2_.clear();
861  bYK_1_.clear();
862  bYK_2_.clear();
863 
864  bXK_1_.reserve(n-1);
865  bXK_2_.reserve(n-1);
866  bYK_1_.reserve(n-1);
867  bYK_2_.reserve(n-1);
868 
869  //set X0 according to start- and endtangents
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);
874 
875  // rest of coefficients, Xn not requiered,Y0 not requiered
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);
881  }
882 
883  //set Yn according to start tangents
884  bYK_1_.push_back(listPntDim1_.back()-edTanX);
885  bYK_2_.push_back(listPntDim2_.back()-edTanY);
886  //set Xn to keep track of the size
887  bXK_1_.push_back(0.0);
888  bXK_2_.push_back(0.0);
889 
890  BIASDOUT(D_INTERPOL_BEZIER,"Alle koeffizienten berechnet");
891  break;
892 
893 
894  case 3:
895  bXK_1_.clear();
896  bXK_2_.clear();
897  bXK_3_.clear();
898 
899  bYK_1_.clear();
900  bYK_2_.clear();
901  bYK_3_.clear();
902 
903  bXK_1_.reserve(n-1);
904  bXK_2_.reserve(n-1);
905  bXK_3_.reserve(n-1);
906  bYK_1_.reserve(n-1);
907  bYK_2_.reserve(n-1);
908  bYK_3_.reserve(n-1);
909 
910  BIASDOUT(D_INTERPOL_BEZIER,"bXK and bYK resized.");
911 
912  //set X0 according to start- and endtangents
913  bXK_1_.push_back(listPntDim1_[0]+stTanX);
914  bXK_2_.push_back(listPntDim2_[0]+stTanY);
915  bXK_3_.push_back(listPntDim3_[0]+stTanZ);
916 
917  bYK_1_.push_back(0.0);
918  bYK_2_.push_back(0.0);
919  bYK_3_.push_back(0.0);
920 
921  // rest of coefficients, Xn not requiered Y0 not requiered
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);
929  }
930  //set Yn according to start- and endtangents
931  bYK_1_.push_back(listPntDim1_.back()-edTanX);
932  bYK_2_.push_back(listPntDim2_.back()-edTanY);
933  bYK_3_.push_back(listPntDim3_.back()-edTanZ);
934 
935  // set Xn to keep track of the size
936  bXK_1_.push_back(0.0);
937  bXK_2_.push_back(0.0);
938  bXK_3_.push_back(0.0);
939 
940  BIASDOUT(D_INTERPOL_BEZIER,"Alle koeffizienten berechnet");
941 
942  break;
943  default:
944  cout<<"WRONG DIMENSION IN BEZIER INTERPOLATION"<<endl;
945  break;
946  }
947 }
948 
949 /**
950  1 dimensional case
951  @status untested 12.05.03
952  @author Ingo Schiller
953 */
954 int Interpolator::Bezier3(double &res, double t)
955 {
956  if(!bezierInitialized_)
957  InitBezier(1);
958 
959 #ifdef BIAS_DEBUG
960  int n = listPntDim1_.size(); //= number of control points
961  int segments = n-1; // number of segments
962 #endif
963  int in_segment = 0; //in which segment is t?
964 
965  //tvalues
966  BIAS::Matrix<double> tvector(1,4);
967  // the used Control points are stored here
968  BIAS::Matrix<double> cpoints(4,1,0.0);
969 
970 
971  /** detection in which segment t is found starting with a segment 0
972  */
973  if (!validate(t)) {
974  BIASERR("invalid values, result is undefined");
975  res=0;
976  return -1;
977  }
978  in_segment = actIndex_;
979 
980  //if t > limit return the value of last control point
981  if(t>KPts_.back()) {
982  res=listPntDim1_.back();
983  return 1;
984  }
985 
986  // now store the valid points in cpoints
987  //Pi
988  cpoints[0][0]= listPntDim1_[in_segment];
989  //Xi
990  cpoints[1][0]= bXK_1_[in_segment];
991  //Yi+1
992  cpoints[2][0]= bYK_1_[in_segment+1];
993  //Pi+1
994  cpoints[3][0]= listPntDim1_[in_segment+1];
995 
996 
997  //now adjust t according to number of segments
998  t=(t-KPts_[in_segment])/(KPts_[in_segment+1]-KPts_[in_segment]);
999 
1000  BIASDOUT(D_INTERPOL_BEZIER," t:"<<t<<" Segs:"<<segments);
1001  BIASDOUT(D_INTERPOL_BEZIER,"In Segment:"<<in_segment);
1002 
1003 //set the tvector
1004  tvector[0][3] = 1;
1005  tvector[0][2] = t;
1006  tvector[0][1] = pow(t,2);
1007  tvector[0][0] = pow(t,3);
1008 
1009  BIASDOUT(D_INTERPOL_BEZIER,"The TVector"<<tvector);
1010  BIASDOUT(D_INTERPOL_BEZIER,"The NMatrix"<<nmatrix_);
1011  BIASDOUT(D_INTERPOL_BEZIER,"The PMatrix"<<cpoints);
1012 
1013 //do the Matrix multiplikations
1014  tvector.Mult(nmatrix_);
1015  BIASDOUT(D_INTERPOL_BEZIER,"tvector mult nmatrix.");
1016  tvector.Mult(cpoints);
1017  BIASDOUT(D_INTERPOL_BEZIER,"tvector mult cpoints.");
1018 
1019  res = tvector[0][0];
1020 
1021  BIASDOUT(D_INTERPOL_BEZIER,"Result : "<<res);
1022 
1023  return 0;
1024 }
1025 
1026 /**
1027  2 dimensional case
1028  @status tested 28.04.03
1029  @author Ingo Schiller
1030  */
1031 
1033 {
1034  if(!bezierInitialized_)
1035  InitBezier(2);
1036 
1037 #ifdef BIAS_DEBUG
1038  int n = listPntDim1_.size(); //= number of control points
1039  int segments = n-1; // number of segments
1040 #endif
1041  int in_segment = 0; //in which segment is t?
1042 
1043  //tvalues
1044  BIAS::Matrix<double> tvector(1,4);
1045  // the used Control points are stored here
1046  BIAS::Matrix<double> cpoints(4,2,0.0);
1047 
1048 
1049  /** detection in which segment t is found starting with a segment 0
1050  */
1051  if (!validate(t)) {
1052  BIASERR("invalid values, result is undefined");
1053  res[0]=0;
1054  res[1]=0;
1055  in_segment = 0;
1056  return -1;
1057  }
1058  else
1059  in_segment = actIndex_;
1060 
1061  //if t > limit, return the value of the last control point
1062  if(t>KPts_.back()){
1063  res[0]=listPntDim1_.back();
1064  res[1]=listPntDim2_.back();
1065  return 1;
1066  }
1067 
1068  // now store the valid points in cpoints
1069  //Pi
1070  cpoints[0][0]=listPntDim1_[in_segment];
1071  cpoints[0][1]=listPntDim2_[in_segment];
1072  //Xi
1073  cpoints[1][0]= bXK_1_[in_segment];
1074  cpoints[1][1]= bXK_2_[in_segment];
1075  //Yi+1
1076  cpoints[2][0]= bYK_1_[in_segment+1];
1077  cpoints[2][1]= bYK_2_[in_segment+1];
1078  //Pi+1
1079  cpoints[3][0]= listPntDim1_[in_segment+1];
1080  cpoints[3][1]= listPntDim2_[in_segment+1];
1081 
1082  //now adjust t according to number of segments
1083  t=(t-KPts_[in_segment])/(KPts_[in_segment+1]-KPts_[in_segment]);
1084 
1085  BIASDOUT(D_INTERPOL_BEZIER," t:"<<t<<" Segs:"<<segments);
1086  BIASDOUT(D_INTERPOL_BEZIER,"In Segment:"<<in_segment);
1087 
1088 //set the tvectorbXK_2_.size()
1089  tvector[0][3] = 1;
1090  tvector[0][2] = t;
1091  tvector[0][1] = pow(t,2);
1092  tvector[0][0] = pow(t,3);
1093 
1094  BIASDOUT(D_INTERPOL_BEZIER,"The TVector"<<tvector);
1095  BIASDOUT(D_INTERPOL_BEZIER,"The NMatrix"<<nmatrix_);
1096  BIASDOUT(D_INTERPOL_BEZIER,"The PMatrix"<<cpoints);
1097 
1098 //do the Matrix multiplikations
1099  tvector.Mult(nmatrix_);
1100  BIASDOUT(D_INTERPOL_BEZIER,"tvector mult nmatrix.");
1101  tvector.Mult(cpoints);
1102  BIASDOUT(D_INTERPOL_BEZIER,"tvector mult cpoints.");
1103 
1104 
1105  res[0] = tvector[0][0];
1106  res[1] = tvector[0][1];
1107 
1108  BIASDOUT(D_INTERPOL_BEZIER,"Result : "<<res[0]<<" "<<res[1]);
1109 
1110  return 0;
1111 }
1112 
1113 
1114 /**
1115  3 dimensional case
1116  @status 28.04.03 tested and working
1117  @author Ingo Schiller
1118  */
1120 {
1121  if(!bezierInitialized_)
1122  InitBezier(3);
1123 
1124 #ifdef BIAS_DEBUG
1125  int n = listPntDim1_.size(); //= number of control points
1126  int segments = n-1; // number of segments
1127 #endif
1128  int in_segment = 0; //in which segment is t?
1129 
1130  //tvalues
1131  BIAS::Matrix<double> tvector(1,4);
1132  // the used Control points are stored here
1133  BIAS::Matrix<double> cpoints(4,3,0.0);
1134 
1135  /** detection in which segment t is found starting with a segment 0
1136  */
1137  if (!validate(t)) {
1138  BIASERR("invalid values, result is undefined");
1139  res[0] = 0;
1140  res[1] = 0;
1141  res[2] = 0;
1142 
1143  return -1;
1144  }
1145  in_segment = actIndex_;
1146 
1147  //if t > last control point return value of last control point.
1148  if (t>KPts_.back()){
1149  res[0]=listPntDim1_.back();
1150  res[1]=listPntDim2_.back();
1151  res[2]=listPntDim3_.back();
1152  return 1;
1153  }
1154 
1155  // now store the valid points in cpoints
1156  //Pi
1157  cpoints[0][0]=listPntDim1_[in_segment];
1158  cpoints[0][1]=listPntDim2_[in_segment];
1159  cpoints[0][2]=listPntDim3_[in_segment];
1160  //Xi
1161  cpoints[1][0]= bXK_1_[in_segment];
1162  cpoints[1][1]= bXK_2_[in_segment];
1163  cpoints[1][2]= bXK_3_[in_segment];
1164  //Yi+1
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];
1168  //Pi+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];
1172 
1173  //now adjust t according to number of segments
1174  t=(t-KPts_[in_segment])/(KPts_[in_segment+1]-KPts_[in_segment]);
1175 
1176  BIASDOUT(D_INTERPOL_BEZIER," t:"<<t<<" Segs:"<<segments);
1177  BIASDOUT(D_INTERPOL_BEZIER,"In Segment:"<<in_segment);
1178 
1179 //set the tvector
1180  tvector[0][3] = 1;
1181  tvector[0][2] = t;
1182  tvector[0][1] = pow(t,2);
1183  tvector[0][0] = pow(t,3);
1184 
1185 
1186  BIASDOUT(D_INTERPOL_BEZIER,"The TVector"<<tvector);
1187  BIASDOUT(D_INTERPOL_BEZIER,"The NMatrix"<<nmatrix_);
1188  BIASDOUT(D_INTERPOL_BEZIER,"The PMatrix"<<cpoints);
1189 
1190 //do the Matrix multiplikations
1191  tvector.Mult(nmatrix_);
1192  BIASDOUT(D_INTERPOL_BEZIER,"tvector mult nmatrix.");
1193  tvector.Mult(cpoints);
1194  BIASDOUT(D_INTERPOL_BEZIER,"tvector mult cpoints.");
1195 
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]);
1200 
1201  return 0;
1202 
1203 }
1204 
1205 
1206 const bool Interpolator::
1208 {
1209  if(LuTMin1_ != I.LuTMin1_ || LuTMax1_ != I.LuTMax1_ ||
1210  LuTSampleDist1_ != I.LuTSampleDist1_)
1211  return true;
1212 
1213  unsigned int N = SplineLuT1_.size();
1214  unsigned int Ncompare = I.SplineLuT1_.size();
1215  if(N != Ncompare || Ncompare <1 || N <1)
1216  return true;
1217 
1218  bool theyDiffer = false;
1219  for(unsigned int i = 0; i<N && !theyDiffer; i++ ) {
1220  theyDiffer = (SplineLuT1_[i] != I.SplineLuT1_[i]);
1221  }
1222  return theyDiffer;
1223 }
1224 
1225 
1226 int Interpolator::PrepareLuTSpline(double min, double max, unsigned int N,
1227  unsigned int k)
1228 {
1229 
1230  SplineLuT1_.resize(N);
1231  LuTMin1_ = min;
1232  LuTMax1_ = max;
1233  LuTSampleDist1_ = (max-min) / double(N-1);
1234 
1235  for (unsigned int i=0;i<N; i++)
1236  Spline(SplineLuT1_[i], min + double(i) * LuTSampleDist1_, k);
1237 
1238 // for (unsigned int i=0;i<N; i++)
1239 // cout <<"LuT "<<i<<" : "<<min + double(i) * LuTSampleDist1_<<" -> "
1240 // <<SplineLuT1_[i]<<endl;
1241 
1242  return 0;
1243 }
1244 
1245 
1246 int Interpolator::SplineFromLuT(double &res, double t) const
1247 {
1248  if (t<LuTMin1_ || t>LuTMax1_ || SplineLuT1_.size() == 0) return -1;
1249  int index = (int)rint((t - LuTMin1_) / LuTSampleDist1_);
1250  //make sure we are within the bounds
1251  if(index < 0)
1252  index =0;
1253  if(index > (int)SplineLuT1_.size()-1 )
1254  index=(int)SplineLuT1_.size()-1;
1255 
1256  BIASASSERT(index >= 0);
1257  BIASASSERT(index < (int)SplineLuT1_.size());
1258  res = SplineLuT1_[index];
1259  //cout <<"t: "<<t<<" index: "<<index<<" res: "<<res<<endl;
1260  return 0;
1261 }
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-&gt;data_
Definition: Vector3.hh:532
computes and holds the singular value decomposition of a rectangular (not necessarily quadratic) Matr...
Definition: SVD.hh:92
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.
Definition: Matrix.cpp:82
const unsigned int size() const
Definition: Vector2.hh:225
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.
Definition: SVD.cpp:102
void clear()
stl conform interface
Definition: Vector3.hh:564
BIAS::Vector< double > Lapack_LU_linear_solve(const BIAS::Matrix< double > &A, const BIAS::Vector< double > &b)
solve linear equations using LU factorization
Definition: Lapack.cpp:269
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) ...
Definition: Interpolator.hh:71
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
Definition: Vector2.hh:190
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
Definition: Interpolator.hh:87
void clear()
stl conform interface
Definition: Vector2.hh:201
void Mult(const Matrix< T > &arg, Matrix< T > &result) const
matrix multiplication, result is not allocated
Definition: Matrix.hh:913
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
Definition: SVD.cpp:214
void GetControlPoints(std::vector< double > &cPnt) const
Definition: Interpolator.hh:91
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
Definition: Vector3.hh:185
void fakima(BIAS::Vector< double > &a, BIAS::Vector< double > Px, BIAS::Vector< double > Py, int from, int to, int intervall)