1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#ifndef mbl_linear_interpolator_h_
#define mbl_linear_interpolator_h_
//:
// \file
// \brief Linear interpolation of tabulated data
// \author Graham Vincent
#include <vcl_vector.h>
// Linear interpolation of tabulated data
class mbl_linear_interpolator
{
public:
mbl_linear_interpolator() ;
//: Remove all data
void clear();
//: Add a (x,y) data
bool set(const vcl_vector<double> &x, const vcl_vector<double> &y);
//! estimate y and x using linear interpolation. Returns NaN if there is no data
double y(double x) const;
private:
// sorts paired data so that x is monotonics
void sort();
// ordered x values
vcl_vector<double> x_;
// ordered y values
vcl_vector<double> y_;
};
#endif
|