Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

QwtSpline Class Reference

A class for spline interpolation. More...

#include <qwt_spline.h>

List of all members.

Public Member Functions

 QwtSpline ()
 ~QwtSpline ()
double value (double x) const
int recalc (double *x, double *y, int n, int periodic=0)
void copyValues (int tf=1)

Private Member Functions

int buildPerSpline ()
int buildNatSpline ()
int lookup (double x) const
void cleanup ()

Private Attributes

double * d_a
double * d_b
double * d_c
double * d_d
double * d_x
double * d_y
double * d_xbuffer
double * d_ybuffer
int d_size
int d_buffered


Detailed Description

A class for spline interpolation.

The QwtSpline class is used for cubical spline interpolation. Two types of splines, natural and periodic, are supported.

Usage:
  1. First call QwtSpline::recalc() to determine the spline coefficients for a tabulated function y(x).
  2. After the coefficients have been set up, the interpolated function value for an argument x can be determined by calling QwtSpline::value().
In order to save storage space, QwtSpline can be advised not to buffer the contents of x and y. This means that the arrays have to remain valid and unchanged for the interpolation to work properly. This can be achieved by calling QwtSpline::copyValues().
Example:
#include<qwt_spline.h>
#include<iostream.h>

QwtSpline s;
double x[30], y[30], xInter[300], yInter[300];
int i;

for(i=0;i<30;i++)               // fill up x[] and y[]
cin >> x[i] >> y[i];

if (s.recalc(x,y,30,0) == 0)    // build natural spline
{
   for(i=0;i<300;i++)          // interpolate
   {
     xInter[i] = x[0] + double(i) * (x[29] - x[0]) / 299.0;
     yInter[i] = s.value( xInter[i] );
   }

   do_something(xInter, yInter, 300);
}
else
  cerr << "Uhhh...\n";

Definition at line 62 of file qwt_spline.h.


Constructor & Destructor Documentation

QwtSpline::QwtSpline  ) 
 

CTOR.

Definition at line 31 of file qwt_spline.cpp.

References d_a, d_b, d_buffered, d_c, d_size, d_x, d_xbuffer, d_y, and d_ybuffer.

QwtSpline::~QwtSpline  ) 
 

DTOR.

Definition at line 68 of file qwt_spline.cpp.

References cleanup().


Member Function Documentation

int QwtSpline::buildNatSpline  )  [private]
 

Determines the coefficients for a natural spline.

Returns:
0
successful
Qwt::ErrMono<dd>Sequence of x values is not strictly monotone increasing
Qwt::ErrNoMem<dd>Couldn't allocate memory

Definition at line 194 of file qwt_spline.cpp.

References cleanup(), d_a, d_b, d_c, d_size, d_x, d_y, Qwt::ErrMono, and Qwt::ErrNoMem.

Referenced by recalc().

int QwtSpline::buildPerSpline  )  [private]
 

Determines the coefficients for a periodic spline.

Returns:
0
successful
Qwt::ErrMono<dd>Sequence of x values is not strictly monotone increasing
Qwt::ErrNoMem<dd>Couldn't allocate memory

Definition at line 288 of file qwt_spline.cpp.

References cleanup(), d_a, d_b, d_c, d_size, d_x, d_y, Qwt::ErrMono, Qwt::ErrNoMem, and qwtSqr().

Referenced by recalc().

void QwtSpline::cleanup  )  [private]
 

Free allocated memory and set size to 0.

Definition at line 395 of file qwt_spline.cpp.

References d_a, d_b, d_c, d_size, d_x, d_xbuffer, d_y, and d_ybuffer.

Referenced by buildNatSpline(), buildPerSpline(), copyValues(), recalc(), and ~QwtSpline().

void QwtSpline::copyValues int  tf = 1  ) 
 

Advise recalc() to buffer the tabulated function or switch off internal buffering.

By default, QwtSpline maintains an internal copy of the tabulated function given as *x and *y arguments of QwtSpline::recalc().

If QwtSpline::copyValues() is called with zero argument, subsequent calls to QwtSpline::recalc() will not buffer these values anymore and just store the pointers instead. The QwtSpline::value() function will then silently assume that these pointers remained valid and that the contents of the arrays have not been changed since the last QwtSpline::recalc().

If called with no or nonzero argument, any following QwtSpline::recalc() calls will use the internal buffer.

Parameters:
tf if nonzero, the function table will be buffered
Warning:
copyValues() resets all the contents of QwtSpline. A subsequent recalc() will be necessary.

Definition at line 61 of file qwt_spline.cpp.

References cleanup(), and d_buffered.

int QwtSpline::lookup double  x  )  const [private]
 

Determine the function table index corresponding to a value x.

Definition at line 74 of file qwt_spline.cpp.

References d_size, and d_x.

Referenced by value().

int QwtSpline::recalc double *  x,
double *  y,
int  n,
int  periodic = 0
 

re-calculate the spline coefficients

Depending on the value of periodic, this function will determine the coefficients for a natural or a periodic spline and store them internally. By default, it also buffers the values of x and y, which are needed for the interpolation (See QwtSpline::value()). In order to save memory, this last behaviour may be changed with the QwtSpline::copyValues() function.

Parameters:
x 
y points
n number of points
periodic if non-zero, calculate periodic spline
Returns:
0
successful
Qwt::ErrMono<dd>Sequence of x values is not strictly monotone increasing
Qwt::ErrNoMem<dd>Couldn't allocate memory
Warning:
The sequence of x (but not y) values has to be strictly monotone increasing, which means x[0] < x[1] < .... < x[n-1]. If this is not the case, the function will return an error.

Definition at line 127 of file qwt_spline.cpp.

References buildNatSpline(), buildPerSpline(), cleanup(), d_a, d_b, d_buffered, d_c, d_size, d_x, d_xbuffer, d_y, d_ybuffer, Qwt::ErrMono, and Qwt::ErrNoMem.

Referenced by QwtCurve::drawSpline().

double QwtSpline::value double  x  )  const
 

Calculate the interpolated function value corresponding to a given argument x.

Definition at line 18 of file qwt_spline.cpp.

References d_a, d_b, d_c, d_x, d_y, and lookup().

Referenced by QwtCurve::drawSpline().


Member Data Documentation

double* QwtSpline::d_a [private]
 

Definition at line 79 of file qwt_spline.h.

Referenced by buildNatSpline(), buildPerSpline(), cleanup(), QwtSpline(), recalc(), and value().

double* QwtSpline::d_b [private]
 

Definition at line 80 of file qwt_spline.h.

Referenced by buildNatSpline(), buildPerSpline(), cleanup(), QwtSpline(), recalc(), and value().

int QwtSpline::d_buffered [private]
 

Definition at line 92 of file qwt_spline.h.

Referenced by copyValues(), QwtSpline(), and recalc().

double* QwtSpline::d_c [private]
 

Definition at line 81 of file qwt_spline.h.

Referenced by buildNatSpline(), buildPerSpline(), cleanup(), QwtSpline(), recalc(), and value().

double* QwtSpline::d_d [private]
 

Definition at line 82 of file qwt_spline.h.

int QwtSpline::d_size [private]
 

Definition at line 89 of file qwt_spline.h.

Referenced by buildNatSpline(), buildPerSpline(), cleanup(), lookup(), QwtSpline(), and recalc().

double* QwtSpline::d_x [private]
 

Definition at line 85 of file qwt_spline.h.

Referenced by buildNatSpline(), buildPerSpline(), cleanup(), lookup(), QwtSpline(), recalc(), and value().

double* QwtSpline::d_xbuffer [private]
 

Definition at line 87 of file qwt_spline.h.

Referenced by cleanup(), QwtSpline(), and recalc().

double* QwtSpline::d_y [private]
 

Definition at line 86 of file qwt_spline.h.

Referenced by buildNatSpline(), buildPerSpline(), cleanup(), QwtSpline(), recalc(), and value().

double* QwtSpline::d_ybuffer [private]
 

Definition at line 88 of file qwt_spline.h.

Referenced by cleanup(), QwtSpline(), and recalc().


The documentation for this class was generated from the following files:
Generated on Fri Nov 7 14:11:50 2003 for Qwt Developer's Guide by doxygen 1.3.2