Orfeo Toolbox  4.0
otbRationalTransform.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbRationalTransform_h
19 #define __otbRationalTransform_h
20 
21 #include "otbTransform.h"
22 #include "itkMacro.h"
23 
24 namespace otb
25 {
45 template <class TScalarType = double,
46  unsigned int Dimension = 2>
47 class ITK_EXPORT RationalTransform : public Transform<TScalarType, Dimension, Dimension>
48 {
49 public:
51  typedef Transform<TScalarType, Dimension,
52  Dimension> Superclass;
56 
60 
63 
66 
69 
71  itkNewMacro(Self);
72 
74  itkTypeMacro(RationalTransform, Transform);
75 
76  itkStaticConstMacro(SpaceDimension, unsigned int, Dimension);
77 
79  void SetNumeratorDegree(unsigned int value)
80  {
81  this->m_NumeratorDegree = value;
82  this->InitalizeParameters();
83  }
84 
86  itkGetConstMacro(NumeratorDegree, unsigned int);
87 
89  void SetDenominatorDegree(unsigned int value)
90  {
91  this->m_DenominatorDegree = value;
92  this->InitalizeParameters();
93  }
94 
96  itkGetConstMacro(DenominatorDegree, unsigned int);
97 
99  virtual OutputPointType TransformPoint(const InputPointType& point) const
100  {
101  // Check for consistency
102  if(this->GetNumberOfParameters() != this->m_Parameters.size())
103  {
104  {
105  itkExceptionMacro(<<"Wrong number of parameters: found "<<this->m_Parameters.Size()<<", expected "<<this->GetNumberOfParameters());
106  }
107  }
108 
109  InputPointType inputPoint = point;
110  OutputPointType outputPoint;
111 
112  unsigned int dimensionStride = (m_DenominatorDegree+1)+(m_NumeratorDegree+1);
113 
114  // Compute RPC transform
115  for(unsigned int dim = 0; dim < SpaceDimension; ++dim)
116  {
117  //1) Initialize numerator and denominator
118  TScalarType num = itk::NumericTraits<TScalarType>::Zero;
119  TScalarType denom = itk::NumericTraits<TScalarType>::Zero;
120  TScalarType currentPower = 1.;
121 
122  // 2) Compute numerator
123  for(unsigned int numDegree = 0; numDegree <= m_NumeratorDegree; ++numDegree)
124  {
125  num+=this->m_Parameters[dim*dimensionStride+numDegree]*currentPower;
126  currentPower*=inputPoint[dim];
127  }
128 
129  //3) Compute denominator
130  currentPower = 1.;
131  for(unsigned int denomDegree = 0; denomDegree <= m_DenominatorDegree; ++denomDegree)
132  {
133  denom+=this->m_Parameters[dim*dimensionStride+m_NumeratorDegree+denomDegree+1]*currentPower;
134  currentPower*=inputPoint[dim];
135  }
136 
137  //4) Fill the output
138  outputPoint[dim]=num/denom;
139  }
140 
141  // Return the output point
142  return outputPoint;
143  }
144 
146  virtual NumberOfParametersType GetNumberOfParameters() const
147  {
148  return (static_cast <NumberOfParametersType> ( (m_NumeratorDegree +1 + m_DenominatorDegree+1)*SpaceDimension ));
149  }
150 
151  // Set parameter method
152  virtual void SetParameters(const typename Superclass::ParametersType & params)
153  {
154  // Check for the appropriate size
155  if(params.Size() != this->GetNumberOfParameters())
156  {
157  itkExceptionMacro(<<"Wrong number of parameters: found "<<params.Size()<<", expected "<<this->GetNumberOfParameters());
158  }
159 
160  // Set parametersg
161  this->m_Parameters = params;
162  }
163 
165  void InitalizeParameters()
166  {
167  this->m_Parameters.SetSize(this->GetNumberOfParameters());
168  this->m_Parameters.Fill(0);
169  unsigned int dimensionStride = (m_DenominatorDegree+1)+(m_NumeratorDegree+1);
170 
171  for(unsigned int dim = 0; dim < SpaceDimension; ++dim)
172  {
173  this->m_Parameters[ dimensionStride *dim + m_NumeratorDegree+1] = 1.;
174  }
175  }
176 
177 
178 protected:
179  RationalTransform() : Superclass(16), m_NumeratorDegree(3), m_DenominatorDegree(3)
180  {
181  this->InitalizeParameters();
182  }
183 
184 
185  virtual ~RationalTransform() {}
186 
187  void PrintSelf(std::ostream& os, itk::Indent indent) const
188  {
189  Superclass::PrintSelf(os, indent);
190  os << indent << "Numerator Degree : " << m_NumeratorDegree << std::endl;
191  os << indent << "Denominator Degree : " << m_DenominatorDegree << std::endl;
192 
193  }
194 
195 private:
196  RationalTransform(const Self &); //purposely not implemented
197  void operator =(const Self&); //purposely not implemented
198 
199  // Degree of numerator
200  unsigned int m_NumeratorDegree;
201 
202  // Degree of denominator
203  unsigned int m_DenominatorDegree;
204 };
205 
206 } // namespace otb
207 
208 #endif

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