TMultidimensionalPolynomial.h
Go to the documentation of this file.
1 #ifndef imath_TMultidimensionalPolynomial_included
2 #define imath_TMultidimensionalPolynomial_included
3 
4 
5 // ACF includes
6 #include <istd/TArray.h>
7 #include <imath/TVector.h>
10 
11 
12 namespace imath
13 {
14 
15 
21 template <int Dimensions, class Element = double>
22 class TMultidimensionalPolynomial: public imath::TIMathFunction<TVector<Dimensions>, Element>
23 {
24 public:
27 
29  explicit TMultidimensionalPolynomial(const Coefficients& coefficients);
30 
31  const Coefficients& GetCoefficients() const;
32  void SetCoefficients(const Coefficients& coefficients);
33 
34  // reimplemented (imath::TIMathFunction)
35  virtual bool GetValueAt(const ArgumentType& argument, ResultType& result) const;
36  virtual ResultType GetValueAt(const ArgumentType& argument) const;
37 
38  // static public methods
42  static double GetBaseFunctionValue(const ArgumentType& argument, const istd::TIndex<Dimensions>& coeffIndex);
43 
44 protected:
54  const ArgumentType& argument,
55  int dimension,
56  typename istd::TIndex<Dimensions>& index,
57  ResultType& result) const;
58 
59 private:
60  istd::TArray<Element, Dimensions> m_coefficients;
61 };
62 
63 
64 // public methods
65 
66 template <int Dimensions, class Element>
68 {
69 }
70 
71 
72 template <int Dimensions, class Element>
74 : m_coefficients(coefficients)
75 {
76 }
77 
78 
79 template <int Dimensions, class Element>
81 {
82  return m_coefficients;
83 }
84 
85 
86 template <int Dimensions, class Element>
88 {
89  m_coefficients = coefficients;
90 }
91 
92 
93 // reimplemented (imath::TIMathFunction)
94 
95 template <int Dimensions, class Element>
97 {
99  CumulateRecursiveValueAt(argument, Dimensions - 1, index, result);
100 
101  return true;
102 }
103 
104 
105 template <int Dimensions, class Element>
107 {
108  typename BaseClass::ResultType retVal;
109 
110  GetValueAt(argument, retVal);
111 
112  return retVal;
113 }
114 
115 
116 // static public methods
117 
118 template <int Dimensions, class Element>
120 {
121  Element retVal = 1;
122 
123  for (int dimension = 0; dimension < Dimensions; ++dimension){
124  retVal *= std::pow(argument.GetElement(dimension), coeffIndex.GetAt(dimension));
125  }
126 
127  return retVal;
128 }
129 
130 
131 // protected methods
132 
133 template <int Dimensions, class Element>
135  const ArgumentType& argument,
136  int dimension,
137  typename istd::TIndex<Dimensions>& index,
138  ResultType& result) const
139 {
140  Q_ASSERT(dimension < Dimensions);
141  Q_ASSERT(dimension >= 0);
142 
143  int& indexElement = index[dimension];
144  int dimensionSize = m_coefficients.GetSize(dimension);
145 
146  double partArgument = argument[dimension];
147 
148  result = 0;
149 
150  if (dimension <= 0){
151  for (indexElement = dimensionSize - 1; indexElement >= 0; --indexElement){
152  result = result * partArgument + m_coefficients.GetAt(index);
153  }
154  }
155  else{
156  for (indexElement = dimensionSize - 1; indexElement >= 0; --indexElement){
157  ResultType partResult;
158 
159  CumulateRecursiveValueAt(argument, dimension - 1, index, partResult);
160 
161  result = result * partArgument + partResult;
162  }
163  }
164 }
165 
166 
167 } // namespace imath
168 
169 
170 #endif // !imath_TMultidimensionalPolynomial_included
171 
172 
istd::TArray< Element, Dimensions > Coefficients
const Coefficients & GetCoefficients() const
Multidimensional polynomial function.
void CumulateRecursiveValueAt(const ArgumentType &argument, int dimension, typename istd::TIndex< Dimensions > &index, ResultType &result) const
Cumulate interpolated value or derivative at specified recursion level.
Multidimensional index used to addressing fixed-size array.
Definition: TIndex.h:17
imath::TIMathFunction< TVector< Dimensions >, Element > BaseClass
Multidimensional array with fixed number of dimensions.
Definition: TArray.h:23
Implementation of fixed-size mathematical vector with specified type of elements. ...
Definition: TVector.h:27
static double GetBaseFunctionValue(const ArgumentType &argument, const istd::TIndex< Dimensions > &coeffIndex)
Get value of base function for single coefficient.
Template interface for any mathematical function.
int GetAt(int index) const
Get element stored at specified index.
Definition: TIndex.h:268
const Element & GetElement(int i) const
Get element at specified i.
Definition: TVector.h:237
virtual bool GetValueAt(const ArgumentType &argument, ResultType &result) const
Get function value for specified argument value.
void SetCoefficients(const Coefficients &coefficients)

© 2007-2017 Witold Gantzke and Kirill Lepskiy