File: mbl_linear_interpolator.h

package info (click to toggle)
vxl 1.17.0.dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 153,280 kB
  • ctags: 105,123
  • sloc: cpp: 747,420; ansic: 209,130; fortran: 34,230; lisp: 14,915; sh: 6,187; python: 5,856; makefile: 340; perl: 294; xml: 160
file content (37 lines) | stat: -rw-r--r-- 723 bytes parent folder | download
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