cisst-saw
Loading...
Searching...
No Matches
nmrBernsteinPolynomial.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: 2001-10-17
8
9 (C) Copyright 2001-2007 Johns Hopkins University (JHU), All Rights
10 Reserved.
11
12--- begin cisst license - do not edit ---
13
14This software is provided "as is" under an open source license, with
15no warranty. The complete license can be found in license.txt and
16http://www.cisst.org/cisst/license.txt.
17
18--- end cisst license ---
19*/
20
21
22#ifndef _nmrBernsteinPolynomial_h
23#define _nmrBernsteinPolynomial_h
24
26
27#include <assert.h>
28
30
67{
68public:
69 typedef nmrDynAllocPolynomialContainer BaseType;
70
71 typedef std::pair<nmrPolynomialBase::CoefficientType,
73
74#ifdef CISST_COMPILER_IS_MSVC
75#pragma warning(push)
76#pragma warning(disable:4996)
77#endif // ifdef CISST_COMPILER_IS_MSVC
89 nmrBernsteinPolynomial(VariableIndexType numVariables, PowerType degree)
90 : BaseType(numVariables, degree, degree)
92 , PowerBasis(numVariables, degree, numVariables - 1)
93#endif // INCLUDE_DEPRECATED_POLYNOMIAL_CODE
94 {
95#if INCLUDE_DEPRECATED_POLYNOMIAL_CODE
96 VariablePowers = &PowerBasis;
97#endif // INCLUDE_DEPRECATED_POLYNOMIAL_CODE
98 }
99
100#if INCLUDE_DEPRECATED_POLYNOMIAL_CODE
107 virtual void CISST_DEPRECATED SetVariables(const VariableType values[])
108 {
109 PowerBasis.SetVariables(values);
110 }
111
115 virtual void CISST_DEPRECATED SetVariable(VariableIndexType varIndex, VariableType value)
116 {
117 PowerBasis.SetVariable(varIndex, value);
118 }
119
120
121 virtual bool CISST_DEPRECATED CanSetVariable(VariableIndexType varIndex) const
122 {
123 return ( (0 <= varIndex) &&
124 (varIndex < GetNumVariables()) &&
125 (varIndex != GetImplicitVarIndex()) );
126 }
127
129 VariableType CISST_DEPRECATED GetImplicitVariable() const
130 {
131 return PowerBasis.GetImplicitVariable();
132 }
133
135 VariableIndexType CISST_DEPRECATED GetImplicitVarIndex() const
136 {
137 return PowerBasis.GetImplicitVarIndex();
138 }
139
141 void CISST_DEPRECATED SetImplicitVarIndex(VariableIndexType newIndex)
142 {
143 PowerBasis.SetImplicitVarIndex(newIndex);
144 }
145#ifdef CISST_COMPILER_IS_MSVC
146#pragma warning(pop)
147#endif // ifdef CISST_COMPILER_IS_MSVC
148#endif // INCLUDE_DEPRECATED_POLYNOMIAL_CODE
149
152 virtual InsertStatus SetCoefficient(const nmrPolynomialTermPowerIndex & where,
153 CoefficientType coefficient);
154
157 virtual InsertStatus SetCoefficient(TermIteratorType & where, CoefficientType coefficient);
158
160 virtual CoefficientType GetCoefficient(const nmrPolynomialTermPowerIndex & where) const;
161
163 virtual CoefficientType GetCoefficient(const TermConstIteratorType & where) const
164 { return GetTermCoefficient(where); }
165 virtual CoefficientType GetCoefficient(const TermIteratorType & where) const
166 { return GetTermCoefficient(where); }
167
171 virtual void RemoveTerm(TermIteratorType & where);
172
177 virtual void Clear();
178
182 virtual ValueType EvaluateBasis(const nmrPolynomialTermPowerIndex & where,
183 const nmrMultiVariablePowerBasis & variables) const;
184 virtual ValueType EvaluateBasis(const TermConstIteratorType & where,
185 const nmrMultiVariablePowerBasis & variables) const;
186 virtual ValueType EvaluateBasis(const TermIteratorType & where,
187 const nmrMultiVariablePowerBasis & variables) const;
188
193 virtual void SerializeTermInfo(std::ostream & output, const TermConstIteratorType & termIterator) const;
194
201 virtual void DeserializeTermInfo(std::istream & input, TermIteratorType & termIterator);
202
209 virtual void AddConstant(CoefficientType shiftAmount);
210
216 virtual void AddConstantToCoefficients(CoefficientType coefficients[],
217 CoefficientType shiftAmount) const;
218
220 GetMultinomialCoefficient(const TermIteratorType & where) const
221 {
222 return ((BernsteinTermInfo *)(where->second))->second;
223 }
224
226 GetMultinomialCoefficient(const TermConstIteratorType & where) const
227 {
228 return ((BernsteinTermInfo *)(where->second))->second;
229 }
230
231
232protected:
234 RefMultinomialCoefficient(const TermIteratorType & where)
235 {
236 return ((BernsteinTermInfo *)(where->second))->second;
237 }
238
239 const CoefficientType & GetTermCoefficient(const TermConstIteratorType & where) const
240 {
241 return ((BernsteinTermInfo *)(where->second))->first;
242 }
243
244 const CoefficientType & GetTermCoefficient(const TermIteratorType & where) const
245 {
246 return ((BernsteinTermInfo *)(where->second))->first;
247 }
248
249 CoefficientType & RefTermCoefficient(const TermIteratorType & where)
250 {
251 return ((BernsteinTermInfo *)(where->second))->first;
252 }
253
254#if INCLUDE_DEPRECATED_POLYNOMIAL_CODE
255 CISST_DEPRECATED nmrMultiVariablePowerBasis::BarycentricBasis PowerBasis;
256#endif // INCLUDE_DEPRECATED_POLYNOMIAL_CODE
257
258};
259
260
261#endif // _nmrBernsteinPolynomial_h
262
Definition nmrDynAllocPolynomialContainer.h:29
Definition nmrMultiVariablePowerBasis.h:38
double CoefficientType
Definition nmrPolynomialBase.h:56
Represents the power index of a single term in a multi-variable polynomial.
Definition nmrPolynomialTermPowerIndex.h:90
unsigned long MultinomialCoefficientType
Definition nmrPolynomialTermPowerIndex.h:101
#define CISST_EXPORT
Definition cmnExportMacros.h:50
#define CISST_DEPRECATED
Definition cmnPortability.h:314
nmrBernsteinPolynomial(VariableIndexType numVariables, PowerType degree)
Definition nmrBernsteinPolynomial.h:89
virtual void RemoveTerm(TermIteratorType &where)
virtual void AddConstant(CoefficientType shiftAmount)
virtual ValueType EvaluateBasis(const nmrPolynomialTermPowerIndex &where, const nmrMultiVariablePowerBasis &variables) const
virtual void Clear()
virtual InsertStatus SetCoefficient(const nmrPolynomialTermPowerIndex &where, CoefficientType coefficient)
virtual void AddConstantToCoefficients(CoefficientType coefficients[], CoefficientType shiftAmount) const
CoefficientType & RefTermCoefficient(const TermIteratorType &where)
Definition nmrBernsteinPolynomial.h:249
nmrPolynomialTermPowerIndex::MultinomialCoefficientType & RefMultinomialCoefficient(const TermIteratorType &where)
Definition nmrBernsteinPolynomial.h:234
virtual void SerializeTermInfo(std::ostream &output, const TermConstIteratorType &termIterator) const
const nmrPolynomialTermPowerIndex::MultinomialCoefficientType & GetMultinomialCoefficient(const TermIteratorType &where) const
Definition nmrBernsteinPolynomial.h:220
const CoefficientType & GetTermCoefficient(const TermConstIteratorType &where) const
Definition nmrBernsteinPolynomial.h:239
virtual CoefficientType GetCoefficient(const nmrPolynomialTermPowerIndex &where) const
virtual void DeserializeTermInfo(std::istream &input, TermIteratorType &termIterator)
Rules of exporting.
#define INCLUDE_DEPRECATED_POLYNOMIAL_CODE
Definition nmrPolynomialBase.h:37
vctDynamicNArrayBase< vctDynamicNArrayOwner< _elementType, _dimension >, _elementType, _dimension > BaseType
Definition vctDynamicNArray.h:133