00001
00002
00004
00005 #ifdef WIN32
00006 #pragma warning(disable:4786)
00007 #endif
00008 #include "LinearInterpolator1D.h"
00009
00010 #include <iostream>
00012
00014 namespace Interpolator
00015 {
00017 LinearInterpolator1D::LinearInterpolator1D()
00018 {
00019
00020 }
00021
00023 LinearInterpolator1D::~LinearInterpolator1D()
00024 {
00025 gsl_spline_free (spline);
00026 gsl_interp_accel_free (acc);
00027 }
00028
00033 LinearInterpolator1D::LinearInterpolator1D( std::string sName,
00034 std::string sDescription,
00035 InterpolationData1D* mInterpolationData) :
00036 Interpolator1D(sName,sDescription,"Linear",mInterpolationData)
00037
00038 {
00039 acc = gsl_interp_accel_alloc ();
00040 spline = gsl_spline_alloc (gsl_interp_linear, getNbData());
00041
00042 if(Interpolator::_verb == true) cout << "Values at init" << endl;
00043 for (unsigned int i=0;i<getNbData();i++)
00044 {
00045 if(Interpolator::_verb == true) cout << i << " --> " << *(mInterpolationData->getXValues()+i) << " " << *(mInterpolationData->getYValues()+i) << endl;
00046 }
00047
00048 gsl_spline_init (spline, mInterpolationData->getXValues(), mInterpolationData->getYValues(), getNbData());
00049 }
00050
00052 double LinearInterpolator1D::getInterpolatedValue(double dValue)
00053 {
00054 if(Interpolator::_verb == true) cout << "Values used to interpolate : " << endl;
00055 for (unsigned int i=0;i<spline->size;i++)
00056 {
00057 if(Interpolator::_verb == true) cout << i << " --> " << *(spline->x+i) << " " << *(spline->y+i) << endl;
00058 }
00059 return gsl_spline_eval (spline, dValue, acc);
00060
00061 }
00062
00064 void LinearInterpolator1D::updateInterpolator()
00065 {
00066 gsl_spline_free (spline);
00067 gsl_interp_accel_free (acc);
00068 acc = gsl_interp_accel_alloc ();
00069 spline = gsl_spline_alloc (gsl_interp_linear, getNbData());
00070 gsl_spline_init (spline, getInterpolatedData()->getXValues(), getInterpolatedData()->getYValues(), getNbData());
00071 }
00072
00073 }
00074