cisst-saw
Loading...
Searching...
No Matches
nmrStandardPolynomial Class Reference

#include <nmrStandardPolynomial.h>

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

Public Types

typedef nmrDynAllocPolynomialContainer BaseType
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, TermInfoTypeContainerElementType
typedef std::list< ContainerElementTypeTermContainerType
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

 nmrStandardPolynomial (VariableIndexType numVariables, PowerType minDegree, PowerType maxDegree)
virtual ~nmrStandardPolynomial ()
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
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) CISST_THROW(std
virtual void SetMaxDegree (PowerType newMax) CISST_THROW(std
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
void CISST_DEPRECATED ScaleCoefficients (CoefficientType coefficients[], CoefficientType scaleFactor) const

Protected Member Functions

CoefficientTypeDereferenceIterator (const TermIteratorType &it)
CoefficientType DereferenceIterator (const TermIteratorType &it) const
CoefficientType DereferenceConstIterator (const TermConstIteratorType &it) const
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 nmrStandardPolynomial represents a polynomial in standard (power) basis. Each term consists of a power index and a coefficient. The structure of nmrStandardPolynomial is based on nmrPolynomialContainer, and it implements the required methods in a straightforward way.

Note: some methods include assertions. To avoid including the <assert.h> header file by all the files that use polynomials, I put these methods, and some which were more than one-liners, in the .cpp file. But in every practical way, nmrStandardPolynomial could be implemented completely as inline.

Note: We use dynamic allocation for the term information (Coefficient), 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

◆ BaseType

Constructor & Destructor Documentation

◆ nmrStandardPolynomial()

nmrStandardPolynomial::nmrStandardPolynomial ( VariableIndexType numVariables,
PowerType minDegree,
PowerType maxDegree )
inline

Constructor determines the number of variables and the degree of the polynomial.

◆ ~nmrStandardPolynomial()

virtual nmrStandardPolynomial::~nmrStandardPolynomial ( )
inlinevirtual

Member Function Documentation

◆ AddConstant()

virtual void nmrStandardPolynomial::AddConstant ( CoefficientType shiftAmount)
virtual

An actual implementation overriding nmrPolynomialBase. In this implementation, the coefficient of the term with degree zero is increased by the given shift amount.

Implements nmrPolynomialContainer< void * >.

◆ AddConstantToCoefficients()

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

Overloaded from nmrPolynomialBase. This implementation verifies that this polynomial contains a term of degree zero, and adds the shift amount to the corresponding external coefficient.

Implements nmrPolynomialContainer< void * >.

◆ Clear()

virtual void nmrStandardPolynomial::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 * >.

◆ DereferenceConstIterator()

CoefficientType nmrStandardPolynomial::DereferenceConstIterator ( const TermConstIteratorType & it) const
inlineprotected

◆ DereferenceIterator() [1/2]

CoefficientType & nmrStandardPolynomial::DereferenceIterator ( const TermIteratorType & it)
inlineprotected

◆ DereferenceIterator() [2/2]

CoefficientType nmrStandardPolynomial::DereferenceIterator ( const TermIteratorType & it) const
inlineprotected

◆ DeserializeTermInfo()

virtual void nmrStandardPolynomial::DeserializeTermInfo ( std::istream & input,
TermIteratorType & termIterator )
virtual

This function is overridden to allocate memory for and read the term coefficient. It is called from nmrPolynomialContainer::DeserializeRaw().

Implements nmrDynAllocPolynomialContainer.

◆ EvaluateBasis() [1/3]

virtual ValueType nmrStandardPolynomial::EvaluateBasis ( const nmrPolynomialTermPowerIndex & where,
const nmrMultiVariablePowerBasis & variables ) const
inlinevirtual

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.

Implements nmrPolynomialBase.

◆ EvaluateBasis() [2/3]

virtual ValueType nmrStandardPolynomial::EvaluateBasis ( const TermConstIteratorType & where,
const nmrMultiVariablePowerBasis & variables ) const
inlinevirtual

◆ EvaluateBasis() [3/3]

virtual ValueType nmrStandardPolynomial::EvaluateBasis ( const TermIteratorType & where,
const nmrMultiVariablePowerBasis & variables ) const
inlinevirtual

◆ GetCoefficient() [1/3]

virtual CoefficientType nmrStandardPolynomial::GetCoefficient ( const nmrPolynomialTermPowerIndex & where) const
inlinevirtual

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

◆ GetCoefficient() [2/3]

virtual CoefficientType nmrStandardPolynomial::GetCoefficient ( const TermConstIteratorType & where) const
inlinevirtual

◆ GetCoefficient() [3/3]

virtual CoefficientType nmrStandardPolynomial::GetCoefficient ( const TermIteratorType & where) const
inlinevirtual

◆ RemoveTerm()

virtual void nmrStandardPolynomial::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 * >.

◆ SerializeTermInfo()

virtual void nmrStandardPolynomial::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.

◆ SetCoefficient() [1/2]

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

Set a coefficient for the given term.

Implements nmrPolynomialContainer< void * >.

◆ SetCoefficient() [2/2]

virtual InsertStatus nmrStandardPolynomial::SetCoefficient ( TermIteratorType & where,
CoefficientType coefficient )
inlinevirtual

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