ocra-wbi-plugins
Doxygen documentation for the ocra-wbi-plugins repository
ocra-wbi-plugins/ocra-icub-clients/walking-client/include/walking-client/Interpolator.h
Go to the documentation of this file.
00001 #include <Eigen/Dense>
00002 #include <iostream>
00003 #include <vector>
00004 
00005 template <class indepVarType, class depVarType>
00006 void linearInterpolation(const indepVarType& xStart, const indepVarType& xEnd, const depVarType& yStart, const depVarType& yEnd, const indepVarType& dx, std::vector<indepVarType>& xInterp, std::vector<depVarType>& yInterp, bool overwrite=true, bool ignoreStart=false)
00007 {
00008     if (overwrite)
00009     {
00010         xInterp.clear();
00011         yInterp.clear();
00012     }
00013 
00014     indepVarType xRange = xEnd - xStart;
00015     depVarType yRange = yEnd - yStart;
00016     indepVarType x;
00017     x = xStart;
00018     if (ignoreStart)
00019     {
00020         x+=dx;
00021     }
00022     // Add a small margin for roundoff errors in a double comparison.
00023     while(x <= xEnd+(dx*0.001))
00024     {
00025         xInterp.push_back(x);
00026         yInterp.push_back(((x - xStart)/(xRange))*(yRange) + yStart);
00027         x += dx;
00028     }
00029 }
00030 
00031 template <class indepVarType, class depVarType>
00032 void linearInterpolation(const std::vector<indepVarType>& xVec, const std::vector<depVarType>& yVec, const indepVarType& dx, std::vector<indepVarType>& xInterp, std::vector<depVarType>& yInterp)
00033 {
00034     assert(xVec.size()>0);
00035     assert(yVec.size()>0);
00036     assert(xVec.size()==yVec.size());
00037 
00038     xInterp.clear();
00039     yInterp.clear();
00040 
00041     xInterp.push_back(xVec[0]);
00042     yInterp.push_back(yVec[0]);
00043 
00044     for (int i=0; i<xVec.size()-1; ++i)
00045     {
00046         linearInterpolation(xVec[i], xVec[i+1], yVec[i], yVec[i+1], dx, xInterp, yInterp, false, true);
00047     }
00048 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines