28 template <
typename Data_T,
class Alloc_Data = Eigen::aligned_allocator<Data_T>,
typename SCALAR =
double>
32 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
55 const DiscreteArray_t& dataArray,
58 int greatestLessTimeStampIndex = -1)
60 if (timeArray.size() == 0)
61 throw std::runtime_error(
"Interpolation.h : TimeArray is size 0.");
63 if (dataArray.size() == 0)
64 throw std::runtime_error(
"Interpolation.h : DataArray is size 0.");
66 if (timeArray.size() != dataArray.size())
67 throw std::runtime_error(
"Interpolation.h : The size of timeStamp vector (=" +
68 std::to_string(timeArray.size()) +
") is not equal to the size of data vector (=" +
69 std::to_string(dataArray.size()) +
").");
73 if (dataArray.size() == 1)
75 enquiryData = dataArray.front();
80 if (greatestLessTimeStampIndex == -1)
84 ind = greatestLessTimeStampIndex;
85 index_ = greatestLessTimeStampIndex;
88 if (enquiryTime < timeArray.front())
90 enquiryData = dataArray.front();
94 if (ind == (
int)timeArray.size() - 1)
96 enquiryData = dataArray.back();
100 SCALAR alpha = (enquiryTime - timeArray.at(ind + 1)) / (timeArray.at(ind) - timeArray.at(ind + 1));
104 enquiryData = alpha * dataArray.at(ind) + (1 - alpha) * dataArray.at(ind + 1);
106 enquiryData = dataArray.at(ind);
108 throw std::runtime_error(
"Unknown Interpolation type!");
125 if (timeArray.at(
index_) > enquiryTime)
130 if (timeArray.at(
i) <= enquiryTime)
136 for (
int i =
index_;
i < (int)timeArray.size();
i++)
139 if (timeArray.at(
i) > enquiryTime)
149 throw std::runtime_error(
150 "Interpolation.h : index in protected member findIndex((const SCALAR& enquiryTime) not computed " Interpolation(const InterpolationType &type=LIN)
Default constructor.
Definition: Interpolation.h:43
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef DiscreteArray< Data_T, Alloc_Data > DiscreteArray_t
Definition: Interpolation.h:34
int findIndex(const tpl::TimeArray< SCALAR > &timeArray, const SCALAR &enquiryTime)
find an index corresponding to a certain inquiry time
Definition: Interpolation.h:119
void interpolate(const tpl::TimeArray< SCALAR > &timeArray, const DiscreteArray_t &dataArray, const SCALAR &enquiryTime, Data_T &enquiryData, int greatestLessTimeStampIndex=-1)
This method performs the interpolation.
Definition: Interpolation.h:54
Interpolation(const Interpolation &arg)
Copy Constructor.
Definition: Interpolation.h:45
int index_
Definition: Interpolation.h:160
CppAD::AD< CppAD::cg::CG< double > > SCALAR
InterpolationType
Definition: Interpolation.h:14
InterpolationType getInterpolationType() const
get the employed interpolation type
Definition: Interpolation.h:115
Class that performs interpolation of data in time.
Definition: Interpolation.h:29
An array in time.
Definition: TimeArray.h:22
LIN.
Definition: Interpolation.h:17
InterpolationType type_
Definition: Interpolation.h:162
int getGreatestLessTimeStampIndex()
access the greatest index which is smaller than the inquired interpolation time
Definition: Interpolation.h:113
Zero-Order hold.
Definition: Interpolation.h:16
void changeInterpolationType(const InterpolationType &type)
change the interpolation type
Definition: Interpolation.h:117