Anti-Grain Geometry - AGG (libagg)  2.5
agg-2.5/include/agg_bspline.h
Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 // Anti-Grain Geometry (AGG) - Version 2.5
00003 // A high quality rendering engine for C++
00004 // Copyright (C) 2002-2006 Maxim Shemanarev
00005 // Contact: mcseem@antigrain.com
00006 //          mcseemagg@yahoo.com
00007 //          http://antigrain.com
00008 // 
00009 // AGG is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU General Public License
00011 // as published by the Free Software Foundation; either version 2
00012 // of the License, or (at your option) any later version.
00013 // 
00014 // AGG is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 // 
00019 // You should have received a copy of the GNU General Public License
00020 // along with AGG; if not, write to the Free Software
00021 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00022 // MA 02110-1301, USA.
00023 //----------------------------------------------------------------------------
00024 
00025 #ifndef AGG_BSPLINE_INCLUDED
00026 #define AGG_BSPLINE_INCLUDED
00027 
00028 #include "agg_array.h"
00029 
00030 namespace agg
00031 {
00032     //----------------------------------------------------------------bspline
00033     // A very simple class of Bi-cubic Spline interpolation.
00034     // First call init(num, x[], y[]) where num - number of source points, 
00035     // x, y - arrays of X and Y values respectively. Here Y must be a function 
00036     // of X. It means that all the X-coordinates must be arranged in the ascending
00037     // order. 
00038     // Then call get(x) that calculates a value Y for the respective X. 
00039     // The class supports extrapolation, i.e. you can call get(x) where x is
00040     // outside the given with init() X-range. Extrapolation is a simple linear 
00041     // function.
00042     //
00043     //  See Implementation agg_bspline.cpp
00044     //------------------------------------------------------------------------
00045     class bspline 
00046     {
00047     public:
00048         bspline();
00049         bspline(int num);
00050         bspline(int num, const double* x, const double* y);
00051 
00052         void   init(int num);
00053         void   add_point(double x, double y);
00054         void   prepare();
00055 
00056         void   init(int num, const double* x, const double* y);
00057 
00058         double get(double x) const;
00059         double get_stateful(double x) const;
00060     
00061     private:
00062         bspline(const bspline&);
00063         const bspline& operator = (const bspline&);
00064 
00065         static void bsearch(int n, const double *x, double x0, int *i);
00066         double extrapolation_left(double x) const;
00067         double extrapolation_right(double x) const;
00068         double interpolation(double x, int i) const;
00069 
00070         int               m_max;
00071         int               m_num;
00072         double*           m_x;
00073         double*           m_y;
00074         pod_array<double> m_am;
00075         mutable int       m_last_idx;
00076     };
00077 
00078 
00079 }
00080 
00081 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines