vspline 1.1.0
Generic C++11 Code for Uniform B-Splines
Public Member Functions | Public Attributes | List of all members
vspline::basis_functor< math_type > Struct Template Reference

basis_functor is an object producing the b-spline basis function value for given arguments, or optionally a derivative of the basis function. While basis_functor can produce single basis function values for single arguments, it can also produce a set of basis function values for a given 'delta'. This set is a unit-spaced sampling of the basis function sampled at n + delta for all n E N. Such samplings are used to evaluate b-splines; they constitute the set of weights which have to be applied to a set of b-spline coefficients to form the weighted sum which is the spline's value at a given position. More...

#include <basis.h>

Public Member Functions

 basis_functor (int _degree, int _derivative=0)
 
math_type operator() (int x, math_type delta) const
 operator() taking a column index and a remainder. If these values are known already, the only thing left to do is the evaluation of the partial polynomial. Note that this overload is not safe for arbitrary x, it's assumed that calling code makes sure no invalid arguments are passed - as in the overload below. More...
 
math_type operator() (math_type rx) const
 operator() taking an arbitrary argument. This is the overload which will likely be called from user code. The argument is clamped and split, the split value is fed to the previous overload. This routine provides a single result for a single argument and is used if the basis function itself needs to be evaluated, which doesn't happen much inside vspline. Access to sets of basis function values used as weights in b-spline evaluation is coded below. More...
 
template<class target_type , class delta_type >
void operator() (target_type *result, const delta_type &delta) const
 operator() overload to produce a set of weights for a given delta in [-.5,.5] or [0,1]. This set of weights is needed if a b-spline has to be evaluated at some coordinate k + delta, where k is a whole number. For this evaluation, a set of coefficients has to be multiplied with a set of weights, and the products summed up. So this routine provides the set of weights. It deposits weights for the given delta at the location 'result' points to. target_type and delta_type may be fundamentals or simdized types. note that, if 'delta' is zero, 'power' will also be zero, and therefore everything after the initialization of the result with the first row of the weight matrix is futile. One might consider testing for this special case, but this would cost extra cycles. Instead, below, there is an overload which does not take a 'delta'. Why so? The special case of delta == zero occurs certainly when discrete coordinates are used, but rarely in 'normal' operation, when the whole point of using a spline is to evaluate at real coordinates with some delta. More...
 
template<class target_type , class delta_type >
void weights (target_type *result, const delta_type &delta) const
 
template<class target_type >
void operator() (target_type *result) const
 overload without delta, implies (all) delta(s) == 0. this is used for evaluation with discrete coordinates More...
 

Public Attributes

vigra::MultiArray< 2, math_type > weight_matrix
 
int degree
 

Detailed Description

template<typename math_type = vspline::xlf_type>
struct vspline::basis_functor< math_type >

basis_functor is an object producing the b-spline basis function value for given arguments, or optionally a derivative of the basis function. While basis_functor can produce single basis function values for single arguments, it can also produce a set of basis function values for a given 'delta'. This set is a unit-spaced sampling of the basis function sampled at n + delta for all n E N. Such samplings are used to evaluate b-splines; they constitute the set of weights which have to be applied to a set of b-spline coefficients to form the weighted sum which is the spline's value at a given position.

The calculation is done by using a 'weight matrix'. The columns of the weight matrix contain the coefficients for the partial polynomials defining the basis function for the corresponding interval. In 'general' evaluation, all partial polynomials are evaluated. To obtain single basis function values, we pick out a single column only. By evaluating the partial polynomial for this slot, we obtain a single basis function value.

This functor provides the value(s) in constant time and there is no recursion. Setting up the functor costs a bit of time (for calculating the 'weight matrix'), evaluating it merely evaluates the partial polynomial(s) which is quick by comparison. So this is the way to go if basis function values are needed - especially if there is a need for several values of a given basis function. I refrain from giving a 'one-shot' function using a basis_functor - this is easily achieved by coding

b = basis_functor ( degree , derivative ) ( x ) ;

... which does the trick, but 'wastes' the weight matrix.

The weight matrix and all variables use 'math_type' which defaults to xlf_type, vspline's most exact type. By instantiating with a lesser type, The computation can be done more quickly, but less precisely.

Definition at line 401 of file basis.h.

Constructor & Destructor Documentation

◆ basis_functor()

template<typename math_type = vspline::xlf_type>
vspline::basis_functor< math_type >::basis_functor ( int  _degree,
int  _derivative = 0 
)
inline

Definition at line 406 of file basis.h.

Member Function Documentation

◆ operator()() [1/4]

template<typename math_type = vspline::xlf_type>
math_type vspline::basis_functor< math_type >::operator() ( int  x,
math_type  delta 
) const
inline

operator() taking a column index and a remainder. If these values are known already, the only thing left to do is the evaluation of the partial polynomial. Note that this overload is not safe for arbitrary x, it's assumed that calling code makes sure no invalid arguments are passed - as in the overload below.

Definition at line 434 of file basis.h.

◆ operator()() [2/4]

template<typename math_type = vspline::xlf_type>
math_type vspline::basis_functor< math_type >::operator() ( math_type  rx) const
inline

operator() taking an arbitrary argument. This is the overload which will likely be called from user code. The argument is clamped and split, the split value is fed to the previous overload. This routine provides a single result for a single argument and is used if the basis function itself needs to be evaluated, which doesn't happen much inside vspline. Access to sets of basis function values used as weights in b-spline evaluation is coded below.

Definition at line 458 of file basis.h.

◆ operator()() [3/4]

template<typename math_type = vspline::xlf_type>
template<class target_type >
void vspline::basis_functor< math_type >::operator() ( target_type result) const
inline

overload without delta, implies (all) delta(s) == 0. this is used for evaluation with discrete coordinates

Definition at line 563 of file basis.h.

◆ operator()() [4/4]

template<typename math_type = vspline::xlf_type>
template<class target_type , class delta_type >
void vspline::basis_functor< math_type >::operator() ( target_type result,
const delta_type &  delta 
) const
inline

operator() overload to produce a set of weights for a given delta in [-.5,.5] or [0,1]. This set of weights is needed if a b-spline has to be evaluated at some coordinate k + delta, where k is a whole number. For this evaluation, a set of coefficients has to be multiplied with a set of weights, and the products summed up. So this routine provides the set of weights. It deposits weights for the given delta at the location 'result' points to. target_type and delta_type may be fundamentals or simdized types. note that, if 'delta' is zero, 'power' will also be zero, and therefore everything after the initialization of the result with the first row of the weight matrix is futile. One might consider testing for this special case, but this would cost extra cycles. Instead, below, there is an overload which does not take a 'delta'. Why so? The special case of delta == zero occurs certainly when discrete coordinates are used, but rarely in 'normal' operation, when the whole point of using a spline is to evaluate at real coordinates with some delta.

Definition at line 508 of file basis.h.

◆ weights()

template<typename math_type = vspline::xlf_type>
template<class target_type , class delta_type >
void vspline::basis_functor< math_type >::weights ( target_type result,
const delta_type &  delta 
) const
inline

Definition at line 554 of file basis.h.

Member Data Documentation

◆ degree

template<typename math_type = vspline::xlf_type>
int vspline::basis_functor< math_type >::degree

Definition at line 404 of file basis.h.

◆ weight_matrix

template<typename math_type = vspline::xlf_type>
vigra::MultiArray< 2 , math_type > vspline::basis_functor< math_type >::weight_matrix

Definition at line 403 of file basis.h.


The documentation for this struct was generated from the following file: