cisst-saw
Loading...
Searching...
No Matches
nmrPolynomialBase Class Referenceabstract

#include <nmrPolynomialBase.h>

Inheritance diagram for nmrPolynomialBase:
nmrPolynomialContainer< void * > nmrPolynomialContainer< _TermInfo > nmrDynAllocPolynomialContainer nmrStandardPolynomial

Public Types

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

 nmrPolynomialBase (VariableIndexType numVariables, PowerType minDegree, PowerType maxDegree)
virtual ~nmrPolynomialBase ()
VariableIndexType GetNumVariables () const
PowerType GetMinDegree () const
PowerType GetMaxDegree () const
virtual TermCounterType GetNumberOfTerms () const =0
TermCounterType GetMaxNumberOfTerms () const
virtual bool IsEmpty () const =0
virtual void virtual SetMinDegree(PowerType newMin) CISST_THROW(std void virtual SetMaxDegree(PowerType newMax) CISST_THROW(std void FillAllTerms ()=0
bool CanIncludeIndex (const nmrPolynomialTermPowerIndex &term) const
virtual bool IncludesIndex (const nmrPolynomialTermPowerIndex &target) const =0
virtual TermCounterType GetIndexPosition (const nmrPolynomialTermPowerIndex &term) const =0
virtual void RemoveTerm (const nmrPolynomialTermPowerIndex &where)=0
virtual void Clear ()=0
virtual InsertStatus SetCoefficient (const nmrPolynomialTermPowerIndex &where, CoefficientType coefficient)=0
virtual CoefficientType GetCoefficient (const nmrPolynomialTermPowerIndex &CMN_UNUSED(where)) const
virtual void CollectCoefficients (CoefficientType source[]) const =0
virtual void RestoreCoefficients (const CoefficientType source[])=0
virtual ValueType EvaluateBasis (const nmrPolynomialTermPowerIndex &where, const nmrMultiVariablePowerBasis &variables) const =0
virtual void EvaluateBasisVector (const nmrMultiVariablePowerBasis &variables, ValueType termBaseValues[]) const =0
virtual ValueType EvaluateForCoefficients (const nmrMultiVariablePowerBasis &variables, const CoefficientType coefficients[]) const =0
virtual ValueType Evaluate (const nmrMultiVariablePowerBasis &variables) const =0
virtual void Scale (CoefficientType scaleFactor)=0
void CISST_DEPRECATED ScaleCoefficients (CoefficientType coefficients[], CoefficientType scaleFactor) const
virtual void AddConstant (CoefficientType shiftAmount)=0
virtual void AddConstantToCoefficients (CoefficientType coefficients[], CoefficientType shiftAmount) const =0
virtual void SerializeRaw (std::ostream &output) const
virtual void DeserializeRaw (std::istream &input)

Protected Attributes

VariableIndexType NumVariables
PowerType MinDegree
PowerType MaxDegree

Member Typedef Documentation

◆ CoefficientType

◆ PowerType

◆ TermCounterType

◆ ValueType

◆ VariableIndexType

◆ VariableType

Member Enumeration Documentation

◆ InsertStatus

Enumerator
INSERT_FAIL 
INSERT_NEW 
INSERT_REPLACE 

Constructor & Destructor Documentation

◆ nmrPolynomialBase()

nmrPolynomialBase::nmrPolynomialBase ( VariableIndexType numVariables,
PowerType minDegree,
PowerType maxDegree )

◆ ~nmrPolynomialBase()

virtual nmrPolynomialBase::~nmrPolynomialBase ( )
inlinevirtual

Member Function Documentation

◆ AddConstant()

virtual void nmrPolynomialBase::AddConstant ( CoefficientType shiftAmount)
pure virtual

Add a constant value to this polynomial. That is, if p is a polynomial and s is a constant then the following returns true: ValueType v0 = p.Evaluate(); p.AddConstant(s); ValueType v1 = p.Evaluate(); v1 - v0 == s // up to floating point precision error

Note
the implementation varies between different representations of the polynomial. Specifically, terms may be added to this polynomial to support the addition of the constant.

Implemented in nmrPolynomialContainer< _TermInfo >, nmrPolynomialContainer< void * >, and nmrStandardPolynomial.

◆ AddConstantToCoefficients()

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

Modify external coefficients so that they evaluate a new polynomial shifted by a constant amount. That is, if p is a polynomial, c is an array of external coefficients, and s is a constant, the following returns true: ValueType v0 = p.EvaluateForCoefficients(c); p.AddConstantToCoefficients(c, s); ValueType v1 = p.EvaluateForCoefficients(c); v1 - v0 == s; // up to floating point precision error

Note
The implementation of this function may vary based on the representation of the polynomial. In particular, for a Bernstein polynomial it requires that all possible terms be present in the polynomial and in the coefficients correspondingly. For a standard polynomial, it requires that this polynomial actually contains a term of power zero.
The current implementations assert that this polynomial and the external coefficients meet the preconditions for the operation. That is, we do not throw an exception but rather issue an assertion error.

Implemented in nmrPolynomialContainer< _TermInfo >, nmrPolynomialContainer< void * >, and nmrStandardPolynomial.

◆ CanIncludeIndex()

bool nmrPolynomialBase::CanIncludeIndex ( const nmrPolynomialTermPowerIndex & term) const

◆ Clear()

virtual void nmrPolynomialBase::Clear ( )
pure virtual

◆ CollectCoefficients()

virtual void nmrPolynomialBase::CollectCoefficients ( CoefficientType source[]) const
pure virtual

◆ DeserializeRaw()

virtual void nmrPolynomialBase::DeserializeRaw ( std::istream & input)
virtual

Deserialize NumVariables, MinDegree, MaxDegree

Reimplemented in nmrPolynomialContainer< _TermInfo >, and nmrPolynomialContainer< void * >.

◆ Evaluate()

virtual ValueType nmrPolynomialBase::Evaluate ( const nmrMultiVariablePowerBasis & variables) const
pure virtual

Evaluate the polynomial for externally given variables

Implemented in nmrPolynomialContainer< _TermInfo >, and nmrPolynomialContainer< void * >.

◆ EvaluateBasis()

virtual ValueType nmrPolynomialBase::EvaluateBasis ( const nmrPolynomialTermPowerIndex & where,
const nmrMultiVariablePowerBasis & variables ) const
pure virtual

Evaluate the basis function for a term. The term is regarded as a list of powers, without any user defined coefficient. However, for different families of polynomial the set of basis functions are different. For example, Bezier polynomials have the multinomial coefficient in addition to each user defined coefficient. Implemented for each concrete polynomial class.

Implemented in nmrStandardPolynomial.

◆ EvaluateBasisVector()

virtual void nmrPolynomialBase::EvaluateBasisVector ( const nmrMultiVariablePowerBasis & variables,
ValueType termBaseValues[] ) const
pure virtual

Evaluate a single term at the point specified by the `variables' argument, including the basis function and the term's coefficient. This function uses the internally stored coefficient. */ ValueType EvaluateTerm(const nmrPolynomialTermPowerIndex & where, const nmrMultiVariablePowerBasis & variables) const { CoefficientType coefficient = GetCoefficient(where); return EvaluateTerm(where, variables, coefficient); }

/*! Evaluate a single term at the point specified by the `variables' argument, including the basis function and the term's coefficient. This function takes the coefficient as a parameter. */ ValueType EvaluateTerm(const nmrPolynomialTermPowerIndex & where, const nmrMultiVariablePowerBasis & variables, CoefficientType coefficient) const { if (coefficient == 0) return 0; return coefficient * EvaluateBasis(where, variables); }

/*! Evaluate the basis vector for extrnally given variables. Evaluate the basis function for each terms in the polynomial, and store the results into an array of termBaseValues.

Implemented in nmrPolynomialContainer< _TermInfo >, and nmrPolynomialContainer< void * >.

◆ EvaluateForCoefficients()

virtual ValueType nmrPolynomialBase::EvaluateForCoefficients ( const nmrMultiVariablePowerBasis & variables,
const CoefficientType coefficients[] ) const
pure virtual

Evaluate the polynomial at the currently specified point, using externally defined coefficients. This lets the user create many polynomials over the same set of basis functions without having to duplicate the terms. The input coefficients must be ordered the same way as the terms in this object. It is best to order them using CollectCoefficients()

Implemented in nmrPolynomialContainer< _TermInfo >, and nmrPolynomialContainer< void * >.

◆ FillAllTerms()

virtual void virtual SetMinDegree(PowerType newMin) CISST_THROW(std void virtual SetMaxDegree(PowerType newMax) CISST_THROW(std void nmrPolynomialBase::FillAllTerms ( )
pure virtual

◆ GetCoefficient()

virtual CoefficientType nmrPolynomialBase::GetCoefficient ( const nmrPolynomialTermPowerIndex & CMN_UNUSEDwhere) const
inlinevirtual

◆ GetIndexPosition()

virtual TermCounterType nmrPolynomialBase::GetIndexPosition ( const nmrPolynomialTermPowerIndex & term) const
pure virtual

◆ GetMaxDegree()

PowerType nmrPolynomialBase::GetMaxDegree ( ) const
inline

◆ GetMaxNumberOfTerms()

TermCounterType nmrPolynomialBase::GetMaxNumberOfTerms ( ) const
inline

◆ GetMinDegree()

PowerType nmrPolynomialBase::GetMinDegree ( ) const
inline

◆ GetNumberOfTerms()

virtual TermCounterType nmrPolynomialBase::GetNumberOfTerms ( ) const
pure virtual

◆ GetNumVariables()

VariableIndexType nmrPolynomialBase::GetNumVariables ( ) const
inline

◆ IncludesIndex()

virtual bool nmrPolynomialBase::IncludesIndex ( const nmrPolynomialTermPowerIndex & target) const
pure virtual

◆ IsEmpty()

virtual bool nmrPolynomialBase::IsEmpty ( ) const
pure virtual

◆ RemoveTerm()

virtual void nmrPolynomialBase::RemoveTerm ( const nmrPolynomialTermPowerIndex & where)
pure virtual

◆ RestoreCoefficients()

virtual void nmrPolynomialBase::RestoreCoefficients ( const CoefficientType source[])
pure virtual

◆ Scale()

virtual void nmrPolynomialBase::Scale ( CoefficientType scaleFactor)
pure virtual

Scale the polynomial by a given scalar value. Basically, it means multiplying all the term coefficient by the scale factor.

Implemented in nmrPolynomialContainer< _TermInfo >, and nmrPolynomialContainer< void * >.

◆ ScaleCoefficients()

void CISST_DEPRECATED nmrPolynomialBase::ScaleCoefficients ( CoefficientType coefficients[],
CoefficientType scaleFactor ) const

Scale a given set of external coefficients which correspond to the terms of this polynomial. Basically, it means multiplying them all by the scale factor.

Parameters
coefficients[i/o] the external coefficients to be scales (in place).
scaleFactorthe scaling factor.
Note
this function is not declared virtual, as it seems to behave uniformly for all types of polynomial representations we use. But it may have to be declared virtual eventually. Technically, it could be declared static, but I find it too far fetched.
The same rules that apply to evaluating the polynomial for external coefficients apply here as well.
the function is declared as deprecated. Generally, using the Multiply operation on cisstVector containers of coefficients should be prefered.

◆ SerializeRaw()

virtual void nmrPolynomialBase::SerializeRaw ( std::ostream & output) const
virtual

Serialize NumVariables, MinDegree, MaxDegree

Reimplemented in nmrPolynomialContainer< _TermInfo >, and nmrPolynomialContainer< void * >.

◆ SetCoefficient()

virtual InsertStatus nmrPolynomialBase::SetCoefficient ( const nmrPolynomialTermPowerIndex & where,
CoefficientType coefficient )
pure virtual

Member Data Documentation

◆ MaxDegree

PowerType nmrPolynomialBase::MaxDegree
protected

◆ MinDegree

PowerType nmrPolynomialBase::MinDegree
protected

◆ NumVariables

VariableIndexType nmrPolynomialBase::NumVariables
protected

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