cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Protected Member Functions | List of all members
nmrBernsteinPolynomial Class Reference

#include <nmrBernsteinPolynomial.h>

Inheritance diagram for nmrBernsteinPolynomial:
nmrDynAllocPolynomialContainer nmrPolynomialContainer< void * > nmrPolynomialBase

Public Types

typedef
nmrDynAllocPolynomialContainer 
BaseType
 
typedef std::pair
< nmrPolynomialBase::CoefficientType,
nmrPolynomialTermPowerIndex::MultinomialCoefficientType
BernsteinTermInfo
 
- Public Types inherited from nmrDynAllocPolynomialContainer
typedef nmrPolynomialContainer
< void * > 
BaseType
 
- Public Types inherited from nmrPolynomialContainer< void * >
typedef nmrPolynomialBase BaseType
 
typedef void * TermInfoType
 
typedef std::pair
< nmrPolynomialTermPowerIndex,
TermInfoType
ContainerElementType
 
typedef std::list
< ContainerElementType
TermContainerType
 
typedef
TermContainerType::value_type 
TermType
 
typedef TermContainerType::iterator TermIteratorType
 
typedef
TermContainerType::const_iterator 
TermConstIteratorType
 
- Public Types inherited from nmrPolynomialBase
enum  InsertStatus { INSERT_FAIL = -1, INSERT_NEW = 0, INSERT_REPLACE = 1 }
 
typedef double ValueType
 
typedef double VariableType
 
typedef double CoefficientType
 
typedef
nmrPolynomialTermPowerIndex::VariableIndexType 
VariableIndexType
 
typedef
nmrPolynomialTermPowerIndex::PowerType 
PowerType
 
typedef
nmrPolynomialTermPowerIndex::MultinomialCoefficientType 
TermCounterType
 

Public Member Functions

 nmrBernsteinPolynomial (VariableIndexType numVariables, PowerType degree)
 
virtual InsertStatus SetCoefficient (const nmrPolynomialTermPowerIndex &where, CoefficientType coefficient)
 
virtual InsertStatus SetCoefficient (TermIteratorType &where, CoefficientType coefficient)
 
virtual CoefficientType GetCoefficient (const nmrPolynomialTermPowerIndex &where) const
 
virtual CoefficientType GetCoefficient (const TermConstIteratorType &where) const
 
virtual CoefficientType GetCoefficient (const TermIteratorType &where) const
 
virtual void RemoveTerm (TermIteratorType &where)
 
virtual void Clear ()
 
virtual ValueType EvaluateBasis (const nmrPolynomialTermPowerIndex &where, const nmrMultiVariablePowerBasis &variables) const
 
virtual ValueType EvaluateBasis (const TermConstIteratorType &where, const nmrMultiVariablePowerBasis &variables) const
 
virtual ValueType EvaluateBasis (const TermIteratorType &where, const nmrMultiVariablePowerBasis &variables) const
 
virtual void SerializeTermInfo (std::ostream &output, const TermConstIteratorType &termIterator) const
 
virtual void DeserializeTermInfo (std::istream &input, TermIteratorType &termIterator)
 
virtual void AddConstant (CoefficientType shiftAmount)
 
virtual void AddConstantToCoefficients (CoefficientType coefficients[], CoefficientType shiftAmount) const
 
const
nmrPolynomialTermPowerIndex::MultinomialCoefficientType
GetMultinomialCoefficient (const TermIteratorType &where) const
 
const
nmrPolynomialTermPowerIndex::MultinomialCoefficientType
GetMultinomialCoefficient (const TermConstIteratorType &where) const
 
- Public Member Functions inherited from nmrDynAllocPolynomialContainer
 nmrDynAllocPolynomialContainer (unsigned int numVariables, unsigned int minDegree, unsigned int maxDegree)
 
- Public Member Functions inherited from nmrPolynomialContainer< void * >
 nmrPolynomialContainer (VariableIndexType numVariables, PowerType minDegree, PowerType maxDegree)
 
virtual ~nmrPolynomialContainer ()
 
virtual TermCounterType GetNumberOfTerms () const
 
virtual bool IsEmpty () const
 
virtual void SetMinDegree (PowerType newMin) throw (std::runtime_error)
 
virtual void SetMaxDegree (PowerType newMax) throw (std::runtime_error)
 
virtual void FillAllTerms ()
 
virtual bool IncludesIndex (const nmrPolynomialTermPowerIndex &target) const
 
virtual TermCounterType GetIndexPosition (const nmrPolynomialTermPowerIndex &term) const
 
TermIteratorType GetTermIteratorForPosition (TermCounterType position)
 
TermIteratorType FirstTermIterator ()
 
TermConstIteratorType FirstTermIterator () const
 
TermIteratorType EndTermIterator ()
 
TermConstIteratorType EndTermIterator () const
 
TermIteratorType FindTerm (const nmrPolynomialTermPowerIndex &target)
 
TermConstIteratorType FindTerm (const nmrPolynomialTermPowerIndex &target) const
 
virtual void RemoveTerm (const nmrPolynomialTermPowerIndex &where)
 
virtual void CollectCoefficients (CoefficientType target[]) const
 
virtual void RestoreCoefficients (const CoefficientType source[])
 
const nmrPolynomialTermPowerIndexGetTermPowerIndex (const TermConstIteratorType &where) const
 
const nmrPolynomialTermPowerIndexGetTermPowerIndex (const TermIteratorType &where) const
 
ValueType EvaluateTerm (const TermConstIteratorType &where) const
 
ValueType EvaluateTerm (const TermIteratorType &where) const
 
ValueType EvaluateTerm (const TermConstIteratorType &where, const nmrMultiVariablePowerBasis &variables) const
 
ValueType EvaluateTerm (const TermIteratorType &where, const nmrMultiVariablePowerBasis &variables) const
 
virtual ValueType Evaluate (const nmrMultiVariablePowerBasis &variables) const
 
virtual void EvaluateBasisVector (const nmrMultiVariablePowerBasis &variables, ValueType termBaseValues[]) const
 
virtual ValueType EvaluateForCoefficients (const nmrMultiVariablePowerBasis &variables, const CoefficientType coefficients[]) const
 
virtual void Scale (CoefficientType scaleFactor)
 
virtual void SerializeRaw (std::ostream &output) const
 
virtual void DeserializeRaw (std::istream &input)
 
- Public Member Functions inherited from nmrPolynomialBase
 nmrPolynomialBase (VariableIndexType numVariables, PowerType minDegree, PowerType maxDegree)
 
virtual ~nmrPolynomialBase ()
 
VariableIndexType GetNumVariables () const
 
PowerType GetMinDegree () const
 
PowerType GetMaxDegree () const
 
TermCounterType GetMaxNumberOfTerms () const
 
bool CanIncludeIndex (const nmrPolynomialTermPowerIndex &term) const
 
virtual CoefficientType GetCoefficient (const nmrPolynomialTermPowerIndex &CMN_UNUSED(where)) const
 
ValueType EvaluateTerm (const nmrPolynomialTermPowerIndex &where, const nmrMultiVariablePowerBasis &variables) const
 
ValueType EvaluateTerm (const nmrPolynomialTermPowerIndex &where, const nmrMultiVariablePowerBasis &variables, CoefficientType coefficient) const
 
void CISST_DEPRECATED ScaleCoefficients (CoefficientType coefficients[], CoefficientType scaleFactor) const
 

Protected Member Functions

nmrPolynomialTermPowerIndex::MultinomialCoefficientTypeRefMultinomialCoefficient (const TermIteratorType &where)
 
const CoefficientTypeGetTermCoefficient (const TermConstIteratorType &where) const
 
const CoefficientTypeGetTermCoefficient (const TermIteratorType &where) const
 
CoefficientTypeRefTermCoefficient (const TermIteratorType &where)
 
- Protected Member Functions inherited from nmrPolynomialContainer< void * >
const TermInfoTypeGetTermInfo (const TermConstIteratorType &termIterator) const
 
TermInfoTypeGetTermInfo (const TermConstIteratorType &termIterator)
 

Additional Inherited Members

- Protected Attributes inherited from nmrPolynomialContainer< void * >
TermContainerType Terms
 
- Protected Attributes inherited from nmrPolynomialBase
VariableIndexType NumVariables
 
PowerType MinDegree
 
PowerType MaxDegree
 

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.

Member Typedef Documentation

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().

Member Function Documentation

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 * >.

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 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 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 ValueType nmrBernsteinPolynomial::EvaluateBasis ( const TermConstIteratorType where,
const nmrMultiVariablePowerBasis variables 
) const
virtual
virtual ValueType nmrBernsteinPolynomial::EvaluateBasis ( const TermIteratorType where,
const nmrMultiVariablePowerBasis variables 
) const
virtual
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
inlinevirtual

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

Implements nmrPolynomialContainer< void * >.

virtual CoefficientType nmrBernsteinPolynomial::GetCoefficient ( const TermIteratorType where) const
inlinevirtual
const nmrPolynomialTermPowerIndex::MultinomialCoefficientType& nmrBernsteinPolynomial::GetMultinomialCoefficient ( const TermIteratorType where) const
inline
const nmrPolynomialTermPowerIndex::MultinomialCoefficientType& nmrBernsteinPolynomial::GetMultinomialCoefficient ( const TermConstIteratorType where) const
inline
const CoefficientType& nmrBernsteinPolynomial::GetTermCoefficient ( const TermConstIteratorType where) const
inlineprotected
const CoefficientType& nmrBernsteinPolynomial::GetTermCoefficient ( const TermIteratorType where) const
inlineprotected
nmrPolynomialTermPowerIndex::MultinomialCoefficientType& nmrBernsteinPolynomial::RefMultinomialCoefficient ( const TermIteratorType where)
inlineprotected
CoefficientType& nmrBernsteinPolynomial::RefTermCoefficient ( const TermIteratorType where)
inlineprotected
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.

Reimplemented from nmrPolynomialContainer< void * >.

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 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.

Implements nmrPolynomialContainer< void * >.


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