NAME
BSpline - representation of usual B-spline function y=f(x)
INCLUDE
include "BSpline.h"
SYNTAX
class BSpline
{
protected:
SplineSpace space;
Vec(NUMT) coef;
SplineCurveInterpolBox Ibox; // a tool box which has many interpolation methods
Handle(MatBand(NUMT)) A; // concerning the cubicInterpolation function
NUMT funcValue(int order, real x); // this function takes care of
// both operator() and derivative
public:
BSpline() {}
~BSpline() {}
bool redim(const SplineSpace& space_) {
return this->space.redim(space_);
}
bool ok() const
{ return getbool
( space.ok() && coef.ok() && coef.size()==space.dimension() ); }
SplineSpace getSpace() const;
void getCoef(Vec(NUMT)& c) const { int m=coef.size(); c.redim(m); c=coef;}
void setCoef(const Vec(NUMT)& c) { coef.redim(c.size()); coef=c; }
NUMT operator()(real x); // calculates the function value
NUMT derivative(int order, real x); // the derivative value
void makeTable
(const VecSimple(real)& vx, // input: vector of x-values
VecSimple(NUMT)& fx); // output: vector of function values
void interpolation(const VecSimple(real)& x, const VecSimple(NUMT)& f,
bool repeat = false);
void leastSquareInterpolation
(const VecSimple(real)& x, const VecSimple(NUMT)& f);
void leastSquareInterpolation
(const VecSimple(real)& x, const VecSimple(NUMT)& f,
const VecSimple(real)& weights);
void linearInterpolation(const VecSimple(real)& x, const VecSimple(NUMT)& f);
void quadraticInterpolation(const VecSimple(real)& x,
const VecSimple(NUMT)& f);
void cubicHermiteInterpolation(const VecSimple(real)& x,
const VecSimple(NUMT)& f,
const VecSimple(real)& df);
void cubicInterpolation(const VecSimple(real)& x,
const VecSimple(NUMT)& f,
const char* boundcond = "Free",
bool repeat = false);
// Free boundary condition as default
void scan(Is is); // read in data and carry out cubic interpolation
};
KEYWORDS
B-spline, spline space, knot vector
DESCRIPTION
This class has one SplineSpace ,one VecSimple(real) and an
instance of the tool class SplineCurveInterpolBoxas as its pri
vate data part. To calculate the spline function value correctly,
the restriction that dimension of the space should be equal with
length of the coefficient vector must be fulfilled.
And two kinds of interpolation are supported: 1. genreal interpo
lation: member function interpolation can only be called after
space is already created. In other words, the order of the spline
is decided by space, and the input vector must has the length of
spaces dimension. 2. special interpolation: in f.ex. member
function linearInterpolation, no space is needed when the func
tion is called. It is inside the function where space and coef
are built up at the same time
Calculation of the function's derivatives is also allowed as long
as the order is between 0 and k-1.
MEMBER FUNCTIONS
redim - attaches a new spline space to the spline.
ok - checks whether both spline space and coefficients are ready.
getCoef - gets the coefficients of the spline.
setcoef - assigns new coefficients.
operator() - calculates the function value f(x).
derivative - calculates the derivative value. (order kan be has
the value between 0 and k-1, where order=0 returns the same
result as operator().)
makeTable - calculates spline function values for a vector of
x's.
interpolation - carries out an interpolation when the spline
space is already built up. This function may prove to be not very
pratical in normal cases. If there are too many interpolation
conditions, a least square process will be taken.
leastSquareInterpolation - carries out an interpolation based on
least squre theory. This is usually the case when we have too
many interpolation conditions. Normally a VecSimple(real) weights
should also be sent in. If not, we assumn that all the weights
are equally 1.0.
linearInterpolation - for the case of k=2. (notice: the spline
space is built up at the same time inside the function!)
quadraticInterpolation - for the case of k=3. (notice: the spline
space is built up inside the function!)
cubicInterpolation - cubic interpolation (k=4) with different
boundary conditions. (notice: a new spline space is built in the
function!) If no boundary condition is specified, the Free
boundary condition is used as default.
cubicHermiteInterpolation - cubic Hermite interpolation. A spea
cial case of cubic interplation. 3 VecSimple(real) should be sent
in as input arguments. (notice: a new spline space is built in
the function!)
scan - reads interpolating data directly from an ASCII file and
carries out a cubic interpolation with boundary condition can be
chosen between "Free" and "Natural".
SEE ALSO
class SplineSpace, class KnotVec and class SplineCurveInterpolBox
DEVELOPED BY
SINTEF Applied Mathematics, Oslo, Norway, and University of Oslo,
Dept. of Mathematics, Norway
AUTHOR
Xing Cai, SINTEF/UiO