agg_bspline.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //----------------------------------------------------------------------------
  2. // Anti-Grain Geometry - Version 2.4
  3. // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
  4. //
  5. // Permission to copy, use, modify, sell and distribute this software
  6. // is granted provided this copyright notice appears in all copies.
  7. // This software is provided "as is" without express or implied
  8. // warranty, and with no claim as to its suitability for any purpose.
  9. //
  10. //----------------------------------------------------------------------------
  11. // Contact: mcseem@antigrain.com
  12. // mcseemagg@yahoo.com
  13. // http://www.antigrain.com
  14. //----------------------------------------------------------------------------
  15. //
  16. // class bspline
  17. //
  18. //----------------------------------------------------------------------------
  19. #ifndef AGG_BSPLINE_INCLUDED
  20. #define AGG_BSPLINE_INCLUDED
  21. #include "agg_array.h"
  22. namespace agg
  23. {
  24. //----------------------------------------------------------------bspline
  25. // A very simple class of Bi-cubic Spline interpolation.
  26. // First call init(num, x[], y[]) where num - number of source points,
  27. // x, y - arrays of X and Y values respectively. Here Y must be a function
  28. // of X. It means that all the X-coordinates must be arranged in the ascending
  29. // order.
  30. // Then call get(x) that calculates a value Y for the respective X.
  31. // The class supports extrapolation, i.e. you can call get(x) where x is
  32. // outside the given with init() X-range. Extrapolation is a simple linear
  33. // function.
  34. //
  35. // See Implementation agg_bspline.cpp
  36. //------------------------------------------------------------------------
  37. class bspline
  38. {
  39. public:
  40. bspline();
  41. bspline(int num);
  42. bspline(int num, const double* x, const double* y);
  43. void init(int num);
  44. void add_point(double x, double y);
  45. void prepare();
  46. void init(int num, const double* x, const double* y);
  47. double get(double x) const;
  48. double get_stateful(double x) const;
  49. private:
  50. bspline(const bspline&);
  51. const bspline& operator = (const bspline&);
  52. static void bsearch(int n, const double *x, double x0, int *i);
  53. double extrapolation_left(double x) const;
  54. double extrapolation_right(double x) const;
  55. double interpolation(double x, int i) const;
  56. int m_max;
  57. int m_num;
  58. double* m_x;
  59. double* m_y;
  60. pod_array<double> m_am;
  61. mutable int m_last_idx;
  62. };
  63. }
  64. #endif