contrib/mul/mbl/mbl_linear_interpolator.h
Go to the documentation of this file.
00001 #ifndef mbl_linear_interpolator_h_
00002 #define mbl_linear_interpolator_h_
00003 //:
00004 // \file
00005 // \brief Linear interpolation of tabulated data
00006 // \author Graham Vincent
00007 
00008 #include <vcl_vector.h>
00009 
00010 // Linear interpolation of tabulated data
00011 class mbl_linear_interpolator
00012 {
00013  public:
00014   mbl_linear_interpolator() ;
00015 
00016   //: Remove all data
00017   void clear();
00018 
00019   //: Add a (x,y) data
00020   bool set(const vcl_vector<double> &x, const vcl_vector<double> &y);
00021 
00022   //! estimate y and x using linear interpolation. Returns NaN if there is no data
00023   double y(double x) const;
00024 
00025  private:
00026 
00027   // sorts paired data so that x is monotonics
00028   void sort();
00029 
00030   // ordered x values
00031   vcl_vector<double> x_;
00032 
00033   // ordered y values
00034   vcl_vector<double> y_;
00035 };
00036 
00037 #endif