OTB  5.0.0
Orfeo Toolbox
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 {
47 template <class TScalarType = double,
48  unsigned int Dimension = 2>
49 class ITK_EXPORT RationalTransform : public Transform<TScalarType, Dimension, Dimension>
50 {
51 public:
53  typedef Transform<TScalarType, Dimension,
54  Dimension> Superclass;
58 
59  typedef typename Superclass::ScalarType ScalarType;
62 
65 
66  typedef typename Superclass::InverseTransformBasePointer InverseTransformBasePointer;
67  typedef typename Superclass::ParametersType ParametersType;
68 
69  typedef typename Superclass::ParametersValueType ParametersValueType;
70  typedef typename Superclass::NumberOfParametersType NumberOfParametersType;
71 
73  itkNewMacro(Self);
74 
76  itkTypeMacro(RationalTransform, Transform);
77 
78  itkStaticConstMacro(SpaceDimension, unsigned int, Dimension);
79 
81  void SetNumeratorDegree(unsigned int value)
82  {
83  this->m_NumeratorDegree = value;
84  this->InitalizeParameters();
85  }
87 
89  itkGetConstMacro(NumeratorDegree, unsigned int);
90 
92  void SetDenominatorDegree(unsigned int value)
93  {
94  this->m_DenominatorDegree = value;
95  this->InitalizeParameters();
96  }
98 
100  itkGetConstMacro(DenominatorDegree, unsigned int);
101 
103  virtual OutputPointType TransformPoint(const InputPointType& point) const
104  {
105  // Check for consistency
106  if(this->GetNumberOfParameters() != this->m_Parameters.size())
107  {
108  {
109  itkExceptionMacro(<<"Wrong number of parameters: found "<<this->m_Parameters.Size()<<", expected "<<this->GetNumberOfParameters());
110  }
111  }
113 
114  InputPointType inputPoint = point;
115  OutputPointType outputPoint;
116 
117  unsigned int dimensionStride = (m_DenominatorDegree+1)+(m_NumeratorDegree+1);
118 
119  // Compute RPC transform
120  for(unsigned int dim = 0; dim < SpaceDimension; ++dim)
121  {
122  //1) Initialize numerator and denominator
123  TScalarType num = itk::NumericTraits<TScalarType>::Zero;
124  TScalarType denom = itk::NumericTraits<TScalarType>::Zero;
125  TScalarType currentPower = 1.;
126 
127  // 2) Compute numerator
128  for(unsigned int numDegree = 0; numDegree <= m_NumeratorDegree; ++numDegree)
129  {
130  num+=this->m_Parameters[dim*dimensionStride+numDegree]*currentPower;
131  currentPower*=inputPoint[dim];
132  }
133 
134  //3) Compute denominator
135  currentPower = 1.;
136  for(unsigned int denomDegree = 0; denomDegree <= m_DenominatorDegree; ++denomDegree)
137  {
138  denom+=this->m_Parameters[dim*dimensionStride+m_NumeratorDegree+denomDegree+1]*currentPower;
139  currentPower*=inputPoint[dim];
140  }
141 
142  //4) Fill the output
143  outputPoint[dim]=num/denom;
144  }
145 
146  // Return the output point
147  return outputPoint;
148  }
149 
152  {
153  return (static_cast <NumberOfParametersType> ( (m_NumeratorDegree +1 + m_DenominatorDegree+1)*SpaceDimension ));
154  }
155 
156  // Set parameter method
157  virtual void SetParameters(const typename Superclass::ParametersType & params)
158  {
159  // Check for the appropriate size
160  if(params.Size() != this->GetNumberOfParameters())
161  {
162  itkExceptionMacro(<<"Wrong number of parameters: found "<<params.Size()<<", expected "<<this->GetNumberOfParameters());
163  }
164 
165  // Set parametersg
166  this->m_Parameters = params;
167  }
168 
171  {
172  this->m_Parameters.SetSize(this->GetNumberOfParameters());
173  this->m_Parameters.Fill(0);
174  unsigned int dimensionStride = (m_DenominatorDegree+1)+(m_NumeratorDegree+1);
176 
177  for(unsigned int dim = 0; dim < SpaceDimension; ++dim)
178  {
179  this->m_Parameters[ dimensionStride *dim + m_NumeratorDegree+1] = 1.;
180  }
181  }
182 
183 
184 protected:
185  RationalTransform() : Superclass(16), m_NumeratorDegree(3), m_DenominatorDegree(3)
186  {
187  this->InitalizeParameters();
188  }
189 
190 
191  virtual ~RationalTransform() {}
192 
193  void PrintSelf(std::ostream& os, itk::Indent indent) const
194  {
195  Superclass::PrintSelf(os, indent);
196  os << indent << "Numerator Degree : " << m_NumeratorDegree << std::endl;
197  os << indent << "Denominator Degree : " << m_DenominatorDegree << std::endl;
198 
199  }
200 
201 private:
202  RationalTransform(const Self &); //purposely not implemented
203  void operator =(const Self&); //purposely not implemented
204 
205  // Degree of numerator
206  unsigned int m_NumeratorDegree;
207 
208  // Degree of denominator
209  unsigned int m_DenominatorDegree;
210 };
211 
212 } // namespace otb
213 
214 #endif
void SetNumeratorDegree(unsigned int value)
Superclass::ParametersType ParametersType
Superclass::ScalarType ScalarType
itk::Point< double, Dimension > OriginType
itk::SmartPointer< const Self > ConstPointer
virtual NumberOfParametersType GetNumberOfParameters() const
Transform< TScalarType, Dimension, Dimension > Superclass
itk::SmartPointer< Self > Pointer
Superclass::ParametersValueType ParametersValueType
void PrintSelf(std::ostream &os, itk::Indent indent) const
itk::Point< ScalarType, Dimension > OutputPointType
itk::Point< ScalarType, Dimension > InputPointType
Superclass::InverseTransformBasePointer InverseTransformBasePointer
IdentifierType NumberOfParametersType
virtual void SetParameters(const typename Superclass::ParametersType &params)
Superclass::NumberOfParametersType NumberOfParametersType
virtual OutputPointType TransformPoint(const InputPointType &point) const
void SetDenominatorDegree(unsigned int value)
This class implements a rational transfom.
itk::Vector< double, Dimension > SpacingType
Class to overload method passed to virtual pure in ITK V4.
Definition: otbTransform.h:37