00001
00002
00008
00009
00011
00012 #include "LinearInterpolator.h"
00013
00014 namespace O_SESSAME {
00015 LinearInterpolator::LinearInterpolator() : m_NumDataPoints(2), m_NumElements(0), m_Slope(m_NumElements), m_Offset(m_NumElements), m_tempOutput(m_NumElements)
00016 {
00017
00018 }
00019
00020 LinearInterpolator::LinearInterpolator(const Vector& _timePoints, const Matrix& _dataPoints) : m_NumDataPoints(2), m_NumElements(_dataPoints[MatrixColsIndex].getIndexBound()), m_Slope(m_NumElements), m_Offset(m_NumElements), m_tempOutput(m_NumElements)
00021 {
00022 Interpolate(_timePoints, _dataPoints);
00023 }
00024
00025 LinearInterpolator::~LinearInterpolator()
00026 {
00027 }
00028
00029 void LinearInterpolator::Interpolate(const Vector& _timePoints, const Matrix& _dataPoints)
00030 {
00031 m_NumElements = _dataPoints[MatrixColsIndex].getIndexBound();
00032 if(m_Slope.getIndexBound() != m_NumElements)
00033 m_Slope.initialize(m_NumElements);
00034 if(m_Offset.getIndexBound() != m_NumElements)
00035 m_Offset.initialize(m_NumElements);
00036
00037 for(int ii = MatrixIndexBase; ii <= m_NumElements; ++ii)
00038 {
00039 BuildLinearInterpolation(_timePoints(VectorIndexBase), _dataPoints(VectorIndexBase,ii),
00040 _timePoints(VectorIndexBase+1), _dataPoints(VectorIndexBase+1,ii),
00041 m_Slope(ii), m_Offset(ii));
00042 }
00043 SetValid(TRUE);
00044 }
00045
00046 Vector LinearInterpolator::Evaluate(const double& _timeEvalPoint)
00047 {
00048 if(m_tempOutput.getIndexBound() != m_NumElements)
00049 m_tempOutput.initialize(m_NumElements);
00050
00051 for(int ii = VectorIndexBase; ii <= m_Slope.getIndexBound(); ++ii)
00052 {
00053 m_tempOutput(ii) = _timeEvalPoint * m_Slope(ii) + m_Offset(ii);
00054 }
00055 return m_tempOutput;
00056 }
00057
00058 void LinearInterpolator::BuildLinearInterpolation(const double& _x1, const double& _y1, const double& _x2, const double& _y2, double& _Slope, double& _Offset)
00059 {
00060 _Slope = (_y2 - _y1) / (_x2 - _x1);
00061 _Offset = _y2 - _Slope * _x2;
00062 }
00063
00064 LinearInterpolator* LinearInterpolator::NewPointer()
00065 {
00066 return new LinearInterpolator();
00067 }
00068
00069 LinearInterpolator* LinearInterpolator::Clone()
00070 {
00071 return new LinearInterpolator(*this);
00072 }
00073
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090