KrisLibrary  1.0.0
TimeSegmentation.h
1 #ifndef SPLINE_TIME_SEGMENTATION_H
2 #define SPLINE_TIME_SEGMENTATION_H
3 
5 #include <vector>
6 #include <algorithm>
7 
8 namespace Spline {
9 
10  using namespace Math;
11 
13 struct TimeSegmentation : public std::vector<Real>
14 {
15  static int Map(const std::vector<Real>& timing,Real t) {
16  if(timing.empty() || t < timing.front()) return -1;
17  std::vector<Real>::const_iterator i=--std::upper_bound(timing.begin(),timing.end(),t);
18  if(i == timing.end()) { return (int)timing.size()-1; }
19  else { return int(i-timing.begin()); }
20  }
21 
24  static int Map(const std::vector<Real>& timing,Real t,Real& param) {
25  if(timing.empty() || t < timing.front()) { param=0.0; return -1; }
26  std::vector<Real>::const_iterator i=--std::upper_bound(timing.begin(),timing.end(),t),n;
27  if(i == timing.end() || i==--timing.end()) { param=1.0; return (int)timing.size()-1; }
28  else { n=i; ++n; }
29  param = (t-*i)/(*n-*i);
30  return int(i-timing.begin());
31  }
32 
36  int Map(Real t) const {
37  return TimeSegmentation::Map(*this,t);
38  }
39 
42  int Map(Real t,Real& param) const {
43  return TimeSegmentation::Map(*this,t,param);
44  }
45 
46 };
47 
48 } //namespace Spline
49 
50 #endif
Common math typedefs, constants, functions.
static int Map(const std::vector< Real > &timing, Real t, Real &param)
Definition: TimeSegmentation.h:24
int Map(Real t, Real &param) const
Definition: TimeSegmentation.h:42
Divides a real-valued range t[0],t[1],...,t[n-1] into segments.
Definition: TimeSegmentation.h:13
Definition: BSpline.cpp:9
int Map(Real t) const
Definition: TimeSegmentation.h:36
Contains all definitions in the Math package.
Definition: WorkspaceBound.h:12