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