00001 ////////////////////////////////////////////////////////////////////////////////////////////////// 00002 /*! \file LinearInterpolator.h 00003 * \brief Interface to the Linear Interpolator. 00004 * \author $Author: jayhawk_hokie $ 00005 * \version $Revision: 1.2 $ 00006 * \date $Date: 2005/06/10 12:53:29 $ 00007 *////////////////////////////////////////////////////////////////////////////////////////////////// 00008 /* 00009 */ 00010 ////////////////////////////////////////////////////////////////////////////////////////////////// 00011 00012 #ifndef __SSF_LINEAR_INTERPOLATOR_H__ 00013 #define __SSF_LINEAR_INTERPOLATOR_H__ 00014 00015 #include <matrix/Matrix.h> 00016 #include <utils/Interpolator.h> 00017 00018 namespace O_SESSAME { 00019 /*! \brief Interpolates between a given set of data points to create a linear functional approximation. 00020 * \ingroup InterpolationLibrary 00021 * 00022 * \detail Works for either a single function, or Vector of functions (such as interpolating a state). 00023 00024 \par Example: 00025 \code 00026 // Interpolate the sin() function 00027 00028 // Build the sin() function 00029 int stepsize = 0.1; 00030 Vector timeVec(2*M_PI / stepsize); 00031 Matrix sinOutput(timeVec[MatrixRowsIndex].getIndexBound(), 1); 00032 for (int jj = 1; jj < timeVec[MatrixRowsIndex].getIndexBound(); ++jj) 00033 { 00034 timeVec(jj) = jj * stepsize; 00035 sinOutput(jj,1) = sin(jj * stepsize); 00036 } 00037 00038 // Create interpolator 00039 LinearInterpolator interp(timeVec,sinOutput); 00040 Vector chk = interp.Evaluate(0.25); 00041 \endcode 00042 */ 00043 class LinearInterpolator : public Interpolator 00044 { 00045 public: 00046 /*! \brief Creates an empty linear interpolation. 00047 * 00048 */ 00049 LinearInterpolator(); 00050 00051 /*! \brief Creates a linear interpolation from the data points. 00052 * 00053 * \detail See Interpolate 00054 */ 00055 LinearInterpolator(const Vector& _timePoints, const Matrix& _dataPoints); 00056 00057 /*! \brief Default Deconstructor 00058 * 00059 */ 00060 virtual ~LinearInterpolator(); 00061 00062 /*! \brief Creates an interpolation from the vector of time points and matrix of corresponding data points. 00063 * 00064 * @param _timePoints Vector of time (seconds) points of the data values. 00065 * @param _dataPoints Matrix of data points at each time step in the _timePoints vector. 00066 *\f[\begin{bmatrix} 00067 * x1(t1) & x2(t1) & x3(t1) & ... \\ 00068 * x1(t2) & x2(t2) & x3(t2)& ... \\ 00069 * x1(t3) & x2(t3) & x3(t3) & ... \\ 00070 * ... & ... & ... & ... \\ 00071 * \end{bmatrix}\f] 00072 */ 00073 virtual void Interpolate(const Vector& _timePoints, const Matrix& _dataPoints); 00074 00075 /*! \brief Evaluate interpolation curve at a specified time. 00076 * 00077 * \detail Output = m_Slope * _inputPoint + m_Offset 00078 * @param _inputPoint Input point (time) at which to evaluate the vector of interpolations. 00079 * @return Vector of output values from the evaluated interpolation. 00080 */ 00081 virtual Vector Evaluate(const double& _inputPoint); 00082 00083 /*! \brief Returns the number of data points required for interpolation. 00084 * 00085 * \detail the number of data points is the number of X-values (time) required to interpolate. 00086 * @return the number of data points, centered about the evaluation time, req'd to interpolate. 00087 */ 00088 virtual int GetNumberDataPoints() {return m_NumDataPoints;}; 00089 00090 /*! \brief Return a pointer to a new instance of a linear interpolator type. 00091 * 00092 * \detail This is used to request memory for a new instance of a LinearInterpolator. It is necessary 00093 * when attempting to get a pointer from the abstract data type Interpolator 00094 * and the actual representation type isn't known. 00095 * @return a pointer to a new allocation of memory for the LinearInterpolator object. 00096 */ 00097 virtual LinearInterpolator* NewPointer(); 00098 /*! \brief Return a pointer to a copy of the linear interpolator instance. 00099 * 00100 * \detail This is used to request memory for a copy of this instance of LinearInterpolator. It is necessary 00101 * when attempting to get a pointer from the abstract data type Interpolator 00102 * and the actual representation type isn't known. 00103 * @return a pointer to a copy of the LinearInterpolator object. 00104 */ 00105 virtual LinearInterpolator* Clone(); 00106 00107 protected: 00108 /*! \brief Computes the slope and offset (intercept) of the linear interpolation given two data points. 00109 * 00110 * \detail point1: (_x1, _y1) | point2: (_x2, _y2) 00111 * \f$ slope=\frac{y_2 - y_1}{x_2-x_1}\quad offset=y_2-slope * x_2 \f$ 00112 */ 00113 void BuildLinearInterpolation(const double& _x1, const double& _y1, const double& _x2, const double& _y2, double& _Slope, double& _Offset); 00114 00115 /*! \brief Doesn't do anything for linear interpolator since there are always only 2 data points. */ 00116 virtual void SetNumberDataPoints(const int& _numberDataPoints) {}; 00117 private: 00118 /** Number of data points used for interpolation, should always be 2 for linear interpolation */ 00119 int m_NumDataPoints; 00120 /** Number of elements in the state vector. Used to determine how many linear interpolations there are per data set. */ 00121 int m_NumElements; 00122 /** Vector of slope parameters. One slope parameter per element. */ 00123 Vector m_Slope; 00124 /** Vector of offset parameters. One slope parameter per element. */ 00125 Vector m_Offset; 00126 Vector m_tempOutput; // this is faster, but larger could be a problem for big histories 00127 }; 00128 } // close namespace O_SESSAME 00129 00130 #endif 00131 00132 00133 // Do not change the comments below - they will be added automatically by CVS 00134 /***************************************************************************** 00135 * $Log: LinearInterpolator.h,v $ 00136 * Revision 1.2 2005/06/10 12:53:29 jayhawk_hokie 00137 * Changed header file format to make it easier to link to the spacecraft code by only having to specify dsacss/dep/spacecraft/src (ex. "file.h" changed to <dir/file.h> where dir is a folder in src). 00138 * 00139 * Revision 1.1.1.1 2005/04/26 17:41:00 cakinli 00140 * Adding OpenSESSAME to DSACSS distrib to capture fixed version. 00141 * 00142 * Revision 1.2 2003/06/06 00:34:47 nilspace 00143 * ? 00144 * 00145 * Revision 1.1 2003/05/13 18:42:08 nilspace 00146 * Initial Submission. 00147 * 00148 * 00149 ******************************************************************************/