ERC CISST - cisst software

nmrBernsteinPolynomial Class Reference
[Numerical Methods]

#include <nmrBernsteinPolynomial.h>

Inheritance diagram for nmrBernsteinPolynomial:

Inheritance graph
[legend]
Collaboration diagram for nmrBernsteinPolynomial:

Collaboration graph
[legend]
List of all members.

Detailed Description

class nmrBernsteinPolynomial defines a polynomial in Bernstein basis. In a Bernstein polynomial, all the terms are of equal degree (that is, the sum of powers is a constant), and the variables sum up to a unity. Each term is associated with a scalar coefficient and with a multinomial factor, which reflects the relative weight of the term in the expression:

$1 = (x_0 + ... + x_{n-1}) ^ d = \sum_{(p_0 + ... + p_{n-1}) = d} \choose{d}{p_0 p_1 ... p_{n-1}} x_0^{p_0} ... x_{n-1}^{p_{n-1}}$

To make repeated evaluations quicker, we cache the multinomial factor along with the coefficient of the term in a BernsteinTermInfo object. Appropriate accessors are defined.

Since the sum of the variables is 1, one of the variables depends on the others. Typically, it is either the last or the first, but the user can choose any variable to be the ``implicit'' variable. Once the implicit variable has been determined, its value cannot be updated directly, and instead it is reassigned every time one of the other variables is set. However, the user of the class still has the flexibility to replace the choice of the implicit variable at any time. The only thing that matters is that the variables sum to 1.

Note: We use dynamic allocation for the term information (BernsteinTermInfo), which is separate from the STL provided dynamic allocation for the container elements. We store the pointer to the dynamically allocated term info in the container. Therefore:

1. We had to override the base-class's RemoveTerm() and Clear() methods. 2. Do not even try to make a copy of a nmrBernsteinPolynomial using copy-ctor or operator= (yeah, like you would). Just for safety, we declare these operations protected, and do not provide implementation. 3. A better solution may be to define a common base type for TermInfo, and have it declare a virtual dtor. Go for it, if you have time.

Definition at line 67 of file nmrBernsteinPolynomial.h.

Public Types

Public Member Functions

Protected Member Functions


Constructor & Destructor Documentation

nmrBernsteinPolynomial::nmrBernsteinPolynomial ( VariableIndexType  numVariables,
PowerType  degree 
) [inline]

Constructor determines the number of variables and the degree of the polynomial. Note that Bernstein polynomial contains an additional implicit variable. The argument numVariables must include the implicit variable, since we want to be consistent with the GetNumVariables() method. The degree defines both maximum and minimum degrees for the terms, as all terms are of equal degree. The constructor initializes the free variables to zero, and the implicit variable to 1, so that they all sum up to 1. The constructor sets the implicit variable to be the last one (the numVariable - 1) by default. The user can change this setting by calling SetImplicitVarIndex().

Definition at line 90 of file nmrBernsteinPolynomial.h.


Member Function Documentation

virtual InsertStatus nmrBernsteinPolynomial::SetCoefficient ( const nmrPolynomialTermPowerIndex where,
CoefficientType  coefficient 
) [virtual]

Overriding nmrPolynomial::SetCoefficient(). This implementation computes the multinomial factor for the term.

Implements nmrPolynomialContainer< void * >.

virtual InsertStatus nmrBernsteinPolynomial::SetCoefficient ( TermIteratorType where,
CoefficientType  coefficient 
) [virtual]

Set a coefficient for the given term iterator. Implemented from nmrPolynomialContainer.

virtual CoefficientType nmrBernsteinPolynomial::GetCoefficient ( const nmrPolynomialTermPowerIndex where  )  const [virtual]

Retrieve the value of the user defined coefficient for a given term.

virtual CoefficientType nmrBernsteinPolynomial::GetCoefficient ( const TermConstIteratorType where  )  const [inline, virtual]

Retrieve the value of the user defined coefficient for a term given by iterator.

Definition at line 164 of file nmrBernsteinPolynomial.h.

virtual void nmrBernsteinPolynomial::RemoveTerm ( TermIteratorType where  )  [virtual]

Remove a term from the polynomial. The term is given by iterator. The function also reclaims the space allocated for the term.

virtual void nmrBernsteinPolynomial::Clear (  )  [virtual]

Remove all the terms to make an empty (zero) polynomial We cannot use nmrPolynomialContainer::Clear(), since it does not reclaim the space allocated for the term. This implementation does.

Reimplemented from nmrPolynomialContainer< void * >.

virtual ValueType nmrBernsteinPolynomial::EvaluateBasis ( const nmrPolynomialTermPowerIndex where,
const nmrMultiVariablePowerBasis variables 
) const [virtual]

Evaluate the basis function for a term. This DOES NOT include the term's coefficient, but DOES include the multinomial factor.

Implements nmrPolynomialBase.

virtual void nmrBernsteinPolynomial::SerializeTermInfo ( std::ostream &  output,
const TermConstIteratorType termIterator 
) const [virtual]

This function is overridden to store the term coefficient to the stream. It is called from nmrPolynomialContainer::SerializeRaw().

Implements nmrDynAllocPolynomialContainer.

virtual void nmrBernsteinPolynomial::DeserializeTermInfo ( std::istream &  input,
TermIteratorType termIterator 
) [virtual]

This function is overridden to allocate memory for the multinomial factor and the term coefficient, read the latter from the stream and calculate the former from the term power index. It is called from nmrPolynomialContainer::DeserializeRaw().

Implements nmrDynAllocPolynomialContainer.

virtual void nmrBernsteinPolynomial::AddConstant ( CoefficientType  shiftAmount  )  [virtual]

Overloaded from nmrPolynomialBase. This implementation goes over all the possible for this polynomial, reads their current coefficient (which may be zero if the term is not included so far) then adds the given shift amount. It may not be the most efficient method, but it should not be called too many times.

Implements nmrPolynomialContainer< void * >.

virtual void nmrBernsteinPolynomial::AddConstantToCoefficients ( CoefficientType  coefficients[],
CoefficientType  shiftAmount 
) const [virtual]

Overloaded from nmrPolynomialBase. This implementation asserts that this polynomial contains all the possible terms, and then iterates on all the terms and adds the shift amount to the corresponding external coefficient.

Implements nmrPolynomialContainer< void * >.


The documentation for this class was generated from the following file:
erc-cisst-devel<at>lists.johnshopkins.edu