Orfeo Toolbox  3.16
itkMultivariateLegendrePolynomial.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: itkMultivariateLegendrePolynomial.h,v $
5 Language: C++
6 Date: $Date: 2009-05-12 17:19:47 $
7 Version: $Revision: 1.27 $
8 
9 Copyright (c) Insight Software Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkMultivariateLegendrePolynomial_h
18 #define __itkMultivariateLegendrePolynomial_h
19 
20 #include "itkIndent.h"
21 #include <vector>
22 #include "itkArray.h"
23 
24 namespace itk {
25 
72 {
73 public:
75 
76  typedef std::vector< double > DoubleArrayType;
77  typedef std::vector< unsigned long > ULongArrayType;
78  typedef std::vector< long > LongArrayType;
79 
82 
86 
90 
92  MultivariateLegendrePolynomial( unsigned int dimension,
93  unsigned int degree,
94  const DomainSizeType & domainSize );
97 
99  unsigned int GetDimension(void) const
100  { return m_Dimension; }
101 
103  unsigned int GetDegree(void) const
104  { return m_Degree; }
105 
112  unsigned int GetNumberOfCoefficients(void) const
113  { return m_NumberOfCoefficients; }
114 
116  const DomainSizeType & GetDomainSize( void ) const
117  { return m_DomainSize; }
118 
121  {
122  public:
123  CoefficientVectorSizeMismatch(int given, int required)
124  {
125  m_Required = required;
126  m_Given = given;
127  }
128 
130  int m_Given;
131  };
132 
137  void SetCoefficients(const CoefficientArrayType& coef)
139 
140  void SetCoefficients(const ParametersType& coef)
142 
144  const CoefficientArrayType& GetCoefficients(void) const;
145 
148  double Evaluate(IndexType& index)
149  {
150  if (m_Dimension == 2)
151  {
152  if (index[1] != m_PrevY)
153  {
154  // normalized y [-1, 1]
155  double norm_y = m_NormFactor[1] *
156  static_cast<double>( index[1] - 1 );
157  this->CalculateXCoef(norm_y, m_CoefficientArray);
158  m_PrevY = index[1];
159  }
160 
161  // normalized x [-1, 1]
162  double norm_x = m_NormFactor[0] *
163  static_cast<double>( index[0] - 1 );
164 
165  return LegendreSum(norm_x, m_Degree, m_CachedXCoef);
166  }
167  else if (m_Dimension == 3)
168  {
169  if (index[2] != m_PrevZ )
170  {
171  // normalized z [-1, 1]
172  double norm_z = m_NormFactor[2] *
173  static_cast<double>( index[2] - 1 );
174  this->CalculateYCoef(norm_z, m_CoefficientArray);
175  m_PrevZ = index[2];
176  }
177 
178  if (index[1] != m_PrevY)
179  {
180  // normalized y [-1, 1]
181  double norm_y = m_NormFactor[1] *
182  static_cast<double>( index[1] - 1 );
183  this->CalculateXCoef(norm_y, m_CachedYCoef);
184  m_PrevY = index[1];
185  }
186 
187  // normalized x [-1, 1]
188  double norm_x = m_NormFactor[0] *
189  static_cast<double>( index[0] - 1 );
190  return this->LegendreSum(norm_x, m_Degree, m_CachedXCoef);
191  }
192  return 0;
193  }
194 
196  unsigned int GetNumberOfCoefficients();
197 
199  unsigned int GetNumberOfCoefficients(unsigned int dimension, unsigned int degree);
200 
207  {
208  public:
210  {
211  m_MultivariateLegendrePolynomial = polynomial;
212  m_Dimension = m_MultivariateLegendrePolynomial->GetDimension();
213  m_DomainSize = m_MultivariateLegendrePolynomial->GetDomainSize();
214  m_Index.resize(m_Dimension);
215  std::fill(m_Index.begin(), m_Index.end(), 0);
216  }
217 
218  void Begin( void )
219  {
220  m_IsAtEnd = false;
221  for (unsigned int dim = 0; dim < m_Dimension; dim++)
222  {
223  m_Index[dim] = 0;
224  }
225  }
226 
227  bool IsAtEnd()
228  { return m_IsAtEnd; }
229 
230  SimpleForwardIterator& operator++()
231  {
232  for (unsigned int dim = 0; dim < m_Dimension; dim++)
233  {
234  if (m_Index[dim] < static_cast<int>(m_DomainSize[dim] - 1))
235  {
236  m_Index[dim] += 1;
237  return *this;
238  }
239  else
240  {
241  if (dim == m_Dimension - 1 )
242  {
243  m_IsAtEnd = true;
244  break;
245  }
246  else
247  {
248  m_Index[dim] = 0;
249  }
250  }
251  }
252  return *this;
253  }
254 
255  double Get()
256  { return m_MultivariateLegendrePolynomial->Evaluate(m_Index); }
257 
258  private:
260  unsigned int m_Dimension;
263  bool m_IsAtEnd;
264  }; // end of class Iterator
265 
266  void Print(std::ostream& os);
267 
268 protected:
269  void PrintSelf(std::ostream& os, Indent indent) const;
270  double LegendreSum(const double x, int n,
271  const CoefficientArrayType& coef,
272  int offset = 0);
273  void CalculateXCoef(double norm_y, const CoefficientArrayType& coef);
274  void CalculateYCoef(double norm_z, const CoefficientArrayType& coef);
275 
276 private:
278  unsigned int m_Dimension;
279  unsigned int m_Degree;
282 
287 
289  long m_PrevY;
290  long m_PrevZ;
291 }; // end of class
292 
293 std::ostream& operator<< (std::ostream& os,
295 } // end of namespace itk
296 #endif

Generated at Sat Feb 2 2013 23:54:55 for Orfeo Toolbox with doxygen 1.8.1.1