cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nmrStandardPolynomial.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Ofri Sadowsky
7  Created on: 2003
8 
9  (C) Copyright 2003-2007 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 */
20 
21 
22 #ifndef _nmrStandardPolynomial_h
23 #define _nmrStandardPolynomial_h
24 
25 
28 
29 
56 {
57 public:
59 
62  nmrStandardPolynomial(VariableIndexType numVariables, PowerType minDegree, PowerType maxDegree)
63  : BaseType(numVariables, minDegree, maxDegree)
65  , PowerBasis(numVariables, maxDegree)
66 #endif // INCLUDE_DEPRECATED_POLYNOMIAL_CODE
67 
68  {
69 #if INCLUDE_DEPRECATED_POLYNOMIAL_CODE
70 #ifdef CISST_COMPILER_IS_MSVC
71 #pragma warning(push)
72 #pragma warning(disable:4996)
73 #endif // ifdef CISST_COMPILER_IS_MSVC
74  VariablePowers = &PowerBasis;
75 #ifdef CISST_COMPILER_IS_MSVC
76 #pragma warning(pop)
77 #endif // ifdef CISST_COMPILER_IS_MSVC
78 #endif // INCLUDE_DEPRECATED_POLYNOMIAL_CODE
79  }
80 
82  {}
83 
84 #if INCLUDE_DEPRECATED_POLYNOMIAL_CODE
85 #ifdef CISST_COMPILER_IS_MSVC
86 #pragma warning(push)
87 #pragma warning(disable:4996)
88 #endif // ifdef CISST_COMPILER_IS_MSVC
89  virtual void CISST_DEPRECATED SetVariable(VariableIndexType varIndex, VariableType value);
90 
91  virtual void CISST_DEPRECATED SetVariables(const VariableType vars[]);
92 
93  virtual bool CISST_DEPRECATED CanSetVariable(VariableIndexType varIndex) const
94  {
95  return ( (0 <= varIndex) && (varIndex < GetNumVariables()) );
96  }
97 #ifdef CISST_COMPILER_IS_MSVC
98 #pragma warning(pop)
99 #endif // ifdef CISST_COMPILER_IS_MSVC
100 #endif // INCLUDE_DEPRECATED_POLYNOMIAL_CODE
101 
103  virtual InsertStatus SetCoefficient(const nmrPolynomialTermPowerIndex & where, CoefficientType coefficient);
104 
106  {
107  DereferenceIterator(where) = coefficient;
108  return INSERT_REPLACE;
109  }
110 
111 
114  {
115  TermConstIteratorType it = FindTerm(where);
116 
117  return (it != EndTermIterator())
118  ? DereferenceConstIterator(it)
119  : 0;
120  }
121 
123  {
124  return DereferenceConstIterator(where);
125  }
126 
127  virtual CoefficientType GetCoefficient(const TermIteratorType & where) const
128  {
129  return DereferenceConstIterator(where);
130  }
131 
132 
133 
137  virtual void RemoveTerm(TermIteratorType & where);
138 
143  virtual void Clear();
144 
146  const nmrMultiVariablePowerBasis & variables) const
147  {
148  assert(where.GetNumVariables() == variables.GetNumVariables());
149  assert(where.GetDegree() <= variables.GetMaxDegree());
150  return variables.EvaluatePowerProduct(where.GetPowers());
151  }
152 
154  const nmrMultiVariablePowerBasis & variables) const
155  {
156  return EvaluateBasis( where->first, variables );
157  }
158 
159  virtual ValueType EvaluateBasis(const TermIteratorType & where,
160  const nmrMultiVariablePowerBasis & variables) const
161  {
162  return EvaluateBasis( where->first, variables );
163  }
164 
169  virtual void SerializeTermInfo(std::ostream & output, const TermConstIteratorType & termIterator) const;
170 
175  virtual void DeserializeTermInfo(std::istream & input, TermIteratorType & termIterator);
176 
181  virtual void AddConstant(CoefficientType shiftAmount);
182 
188  virtual void AddConstantToCoefficients(CoefficientType coefficients[],
189  CoefficientType shiftAmount) const;
190 
191 protected:
192 
194  {
195  CoefficientType * pCoeff = (CoefficientType *)(it->second);
196  return *pCoeff;
197  }
198 
200  { return *((CoefficientType *)(it->second)); }
201 
203  { return *((CoefficientType *)(it->second)); }
204 
205 #if INCLUDE_DEPRECATED_POLYNOMIAL_CODE
207 #endif // INCLUDE_DEPRECATED_POLYNOMIAL_CODE
208 
209 };
210 
211 
212 #endif // _nmrStandardPolynomial_h
213 
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
TermContainerType::iterator TermIteratorType
Definition: nmrPolynomialContainer.h:74
virtual void AddConstant(CoefficientType shiftAmount)=0
#define CISST_DEPRECATED
Definition: cmnPortability.h:310
VariableIndexType GetNumVariables() const
Definition: nmrPolynomialBase.h:69
virtual InsertStatus SetCoefficient(TermIteratorType &where, CoefficientType coefficient)
Definition: nmrStandardPolynomial.h:105
StandardPowerBasis(VariableIndexType numVariables, PowerType maxPower)
Definition: nmrMultiVariablePowerBasis.h:146
virtual void SerializeTermInfo(std::ostream &output, const TermConstIteratorType &termIterator) const =0
double ValueType
Definition: nmrPolynomialBase.h:54
VariableIndexType GetNumVariables() const
Definition: nmrMultiVariablePowerBasis.h:64
CoefficientType DereferenceIterator(const TermIteratorType &it) const
Definition: nmrStandardPolynomial.h:199
virtual void DeserializeTermInfo(std::istream &input, TermIteratorType &termIterator)=0
nmrPolynomialTermPowerIndex::PowerType PowerType
Definition: nmrPolynomialBase.h:58
TermContainerType::const_iterator TermConstIteratorType
Definition: nmrPolynomialContainer.h:75
virtual void AddConstantToCoefficients(CoefficientType coefficients[], CoefficientType shiftAmount) const =0
virtual ~nmrStandardPolynomial()
Definition: nmrStandardPolynomial.h:81
Definition: nmrStandardPolynomial.h:55
VariableIndexType GetNumVariables() const
Definition: nmrPolynomialTermPowerIndex.h:166
virtual CoefficientType GetCoefficient(const TermConstIteratorType &where) const
Definition: nmrStandardPolynomial.h:122
virtual ValueType EvaluateBasis(const TermConstIteratorType &where, const nmrMultiVariablePowerBasis &variables) const =0
virtual InsertStatus SetCoefficient(const nmrPolynomialTermPowerIndex &where, CoefficientType coefficient)=0
ValueType EvaluatePowerProduct(const PowerType powers[]) const
Definition: nmrPolynomialBase.h:61
int GetDegree() const
Definition: nmrPolynomialTermPowerIndex.h:121
Definition: nmrDynAllocPolynomialContainer.h:28
CoefficientType & DereferenceIterator(const TermIteratorType &it)
Definition: nmrStandardPolynomial.h:193
TermIteratorType FindTerm(const nmrPolynomialTermPowerIndex &target)
Definition: nmrPolynomialContainer.h:256
double CoefficientType
Definition: nmrPolynomialBase.h:56
nmrPolynomialTermPowerIndex::VariableIndexType VariableIndexType
Definition: nmrPolynomialBase.h:57
const PowerType * GetPowers() const
Definition: nmrPolynomialTermPowerIndex.h:181
virtual ValueType EvaluateBasis(const TermConstIteratorType &where, const nmrMultiVariablePowerBasis &variables) const
Definition: nmrStandardPolynomial.h:153
nmrStandardPolynomial(VariableIndexType numVariables, PowerType minDegree, PowerType maxDegree)
Definition: nmrStandardPolynomial.h:62
virtual void Clear()
Definition: nmrPolynomialContainer.h:291
virtual ValueType EvaluateBasis(const TermIteratorType &where, const nmrMultiVariablePowerBasis &variables) const
Definition: nmrStandardPolynomial.h:159
nmrDynAllocPolynomialContainer BaseType
Definition: nmrStandardPolynomial.h:58
Definition: nmrMultiVariablePowerBasis.h:37
PowerType GetMaxDegree() const
Definition: nmrMultiVariablePowerBasis.h:69
virtual CoefficientType GetCoefficient(const TermIteratorType &where) const
Definition: nmrStandardPolynomial.h:127
virtual ValueType EvaluateBasis(const nmrPolynomialTermPowerIndex &where, const nmrMultiVariablePowerBasis &variables) const
Definition: nmrStandardPolynomial.h:145
virtual void RemoveTerm(const nmrPolynomialTermPowerIndex &where)
Definition: nmrPolynomialContainer.h:276
Represents the power index of a single term in a multi-variable polynomial.
Definition: nmrPolynomialTermPowerIndex.h:89
virtual CoefficientType GetCoefficient(const nmrPolynomialTermPowerIndex &where) const
Definition: nmrStandardPolynomial.h:113
CoefficientType DereferenceConstIterator(const TermConstIteratorType &it) const
Definition: nmrStandardPolynomial.h:202
Rules of exporting.
TermIteratorType EndTermIterator()
Definition: nmrPolynomialContainer.h:249
#define INCLUDE_DEPRECATED_POLYNOMIAL_CODE
Definition: nmrPolynomialBase.h:37
InsertStatus
Definition: nmrPolynomialBase.h:61