Orfeo Toolbox  3.16
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 
68  itkNewMacro(Self);
69 
71  itkTypeMacro(RationalTransform, Transform);
72 
73  itkStaticConstMacro(SpaceDimension, unsigned int, Dimension);
74 
76  void SetNumeratorDegree(unsigned int value)
77  {
78  this->m_NumeratorDegree = value;
79  this->InitalizeParameters();
80  }
81 
83  itkGetConstMacro(NumeratorDegree, unsigned int);
84 
86  void SetDenominatorDegree(unsigned int value)
87  {
88  this->m_DenominatorDegree = value;
89  this->InitalizeParameters();
90  }
91 
93  itkGetConstMacro(DenominatorDegree, unsigned int);
94 
96  virtual OutputPointType TransformPoint(const InputPointType& point) const
97  {
98  // Check for consistency
99  if(this->GetNumberOfParameters() != this->m_Parameters.size())
100  {
101  {
102  itkExceptionMacro(<<"Wrong number of parameters: found "<<this->m_Parameters.Size()<<", expected "<<this->GetNumberOfParameters());
103  }
104  }
105 
106  InputPointType inputPoint = point;
107  OutputPointType outputPoint;
108 
109  unsigned int dimensionStride = (m_DenominatorDegree+1)+(m_NumeratorDegree+1);
110 
111  // Compute RPC transform
112  for(unsigned int dim = 0; dim < SpaceDimension; ++dim)
113  {
114  //1) Initialize numerator and denominator
115  TScalarType num = itk::NumericTraits<TScalarType>::Zero;
116  TScalarType denom = itk::NumericTraits<TScalarType>::Zero;
117  TScalarType currentPower = 1.;
118 
119  // 2) Compute numerator
120  for(unsigned int numDegree = 0; numDegree <= m_NumeratorDegree; ++numDegree)
121  {
122  num+=this->m_Parameters[dim*dimensionStride+numDegree]*currentPower;
123  currentPower*=inputPoint[dim];
124  }
125 
126  //3) Compute denominator
127  currentPower = 1.;
128  for(unsigned int denomDegree = 0; denomDegree <= m_DenominatorDegree; ++denomDegree)
129  {
130  denom+=this->m_Parameters[dim*dimensionStride+m_NumeratorDegree+denomDegree+1]*currentPower;
131  currentPower*=inputPoint[dim];
132  }
133 
134  //4) Fill the output
135  outputPoint[dim]=num/denom;
136  }
137 
138  // Return the output point
139  return outputPoint;
140  }
141 
143  virtual unsigned int GetNumberOfParameters() const
144  {
145  return (m_NumeratorDegree +1 + m_DenominatorDegree+1)*SpaceDimension;
146  }
147 
148  // Set parameter method
149  virtual void SetParameters(const typename Superclass::ParametersType & params)
150  {
151  // Check for the appropriate size
152  if(params.Size() != this->GetNumberOfParameters())
153  {
154  itkExceptionMacro(<<"Wrong number of parameters: found "<<params.Size()<<", expected "<<this->GetNumberOfParameters());
155  }
156 
157  // Set parameters
158  this->m_Parameters = params;
159  }
160 
162  void InitalizeParameters()
163  {
164  this->m_Parameters.SetSize(this->GetNumberOfParameters());
165  this->m_Parameters.Fill(0);
166  unsigned int dimensionStride = (m_DenominatorDegree+1)+(m_NumeratorDegree+1);
167 
168  for(unsigned int dim = 0; dim < SpaceDimension; ++dim)
169  {
170  this->m_Parameters[ dimensionStride *dim + m_NumeratorDegree+1] = 1.;
171  }
172  }
173 
174 
175 protected:
176  RationalTransform() : Superclass(SpaceDimension, 16), m_NumeratorDegree(3), m_DenominatorDegree(3)
177  {
178  this->InitalizeParameters();
179  }
180 
181 
182  virtual ~RationalTransform() {}
183 
184  void PrintSelf(std::ostream& os, itk::Indent indent) const
185  {
186  Superclass::PrintSelf(os, indent);
187  os << indent << "Numerator Degree : " << m_NumeratorDegree << std::endl;
188  os << indent << "Denominator Degree : " << m_DenominatorDegree << std::endl;
189 
190  }
191 
192 private:
193  RationalTransform(const Self &); //purposely not implemented
194  void operator =(const Self&); //purposely not implemented
195 
196  // Degree of numerator
197  unsigned int m_NumeratorDegree;
198 
199  // Degree of denominator
200  unsigned int m_DenominatorDegree;
201 };
202 
203 } // namespace otb
204 
205 #endif

Generated at Sun Feb 3 2013 00:44:14 for Orfeo Toolbox with doxygen 1.8.1.1