Orfeo Toolbox  4.0
itkMultivariateLegendrePolynomial.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkMultivariateLegendrePolynomial_h
19 #define __itkMultivariateLegendrePolynomial_h
20 
21 #include "itkIntTypes.h"
22 #include "itkIndent.h"
23 #include <vector>
24 #include "itkArray.h"
25 
26 namespace itk
27 {
75 {
76 public:
78 
79  typedef std::vector< double > DoubleArrayType;
80  typedef std::vector< unsigned long > ULongArrayType;
81  typedef std::vector< long > LongArrayType;
82 
85 
89 
93 
95  MultivariateLegendrePolynomial(unsigned int dimension,
96  unsigned int degree,
97  const DomainSizeType & domainSize);
100 
102  unsigned int GetDimension(void) const
103  { return m_Dimension; }
104 
106  unsigned int GetDegree(void) const
107  { return m_Degree; }
108 
115  unsigned int GetNumberOfCoefficients(void) const
116  { return m_NumberOfCoefficients; }
117 
119  const DomainSizeType & GetDomainSize(void) const
120  { return m_DomainSize; }
121 
127  {
128 public:
129  CoefficientVectorSizeMismatch(int given, int required)
130  {
131  m_Required = required;
132  m_Given = given;
133  }
134 
136  int m_Given;
137  };
138 
143  void SetCoefficients(const CoefficientArrayType & coef)
145 
146  void SetCoefficients(const ParametersType & coef)
148 
150  const CoefficientArrayType & GetCoefficients(void) const;
151 
154  double Evaluate(IndexType & index)
155  {
156  if ( m_Dimension == 2 )
157  {
158  if ( index[1] != m_PrevY )
159  {
160  // normalized y [-1, 1]
161  double norm_y = m_NormFactor[1]
162  * static_cast< double >( index[1] - 1 );
163  this->CalculateXCoef(norm_y, m_CoefficientArray);
164  m_PrevY = index[1];
165  }
166 
167  // normalized x [-1, 1]
168  double norm_x = m_NormFactor[0]
169  * static_cast< double >( index[0] - 1 );
170 
171  return LegendreSum(norm_x, m_Degree, m_CachedXCoef);
172  }
173  else if ( m_Dimension == 3 )
174  {
175  if ( index[2] != m_PrevZ )
176  {
177  // normalized z [-1, 1]
178  double norm_z = m_NormFactor[2]
179  * static_cast< double >( index[2] - 1 );
180  this->CalculateYCoef(norm_z, m_CoefficientArray);
181  m_PrevZ = index[2];
182  }
183 
184  if ( index[1] != m_PrevY )
185  {
186  // normalized y [-1, 1]
187  double norm_y = m_NormFactor[1]
188  * static_cast< double >( index[1] - 1 );
189  this->CalculateXCoef(norm_y, m_CachedYCoef);
190  m_PrevY = index[1];
191  }
192 
193  // normalized x [-1, 1]
194  double norm_x = m_NormFactor[0]
195  * static_cast< double >( index[0] - 1 );
196  return this->LegendreSum(norm_x, m_Degree, m_CachedXCoef);
197  }
198  return 0;
199  }
200 
202  unsigned int GetNumberOfCoefficients();
203 
205  unsigned int GetNumberOfCoefficients(unsigned int dimension, unsigned int degree);
206 
214  {
215 public:
217  {
221  m_Index.resize(m_Dimension);
222  std::fill(m_Index.begin(), m_Index.end(), 0);
223  }
224 
225  void Begin(void)
226  {
227  m_IsAtEnd = false;
228  for ( unsigned int dim = 0; dim < m_Dimension; dim++ )
229  {
230  m_Index[dim] = 0;
231  }
232  }
233 
234  bool IsAtEnd()
235  { return m_IsAtEnd; }
236 
238  {
239  for ( unsigned int dim = 0; dim < m_Dimension; dim++ )
240  {
241  if ( m_Index[dim] < static_cast< int >( m_DomainSize[dim] - 1 ) )
242  {
243  m_Index[dim] += 1;
244  return *this;
245  }
246  else
247  {
248  if ( dim == m_Dimension - 1 )
249  {
250  m_IsAtEnd = true;
251  break;
252  }
253  else
254  {
255  m_Index[dim] = 0;
256  }
257  }
258  }
259  return *this;
260  }
261 
262  double Get()
264 
265 private:
267  unsigned int m_Dimension;
270  bool m_IsAtEnd;
271  }; // end of class Iterator
272 
273  void Print(std::ostream & os);
274 
275 protected:
276  void PrintSelf(std::ostream & os, Indent indent) const;
277 
278  double LegendreSum(const double x, int n,
279  const CoefficientArrayType & coef,
280  int offset = 0);
281 
282  void CalculateXCoef(double norm_y, const CoefficientArrayType & coef);
283 
284  void CalculateYCoef(double norm_z, const CoefficientArrayType & coef);
285 
286 private:
288  unsigned int m_Dimension;
289  unsigned int m_Degree;
291 
296 
300 }; // end of class
301 
302  std::ostream & operator<<(std::ostream & os,
304 } // end of namespace itk
305 #endif

Generated at Sat Mar 8 2014 15:15:13 for Orfeo Toolbox with doxygen 1.8.3.1