OTB  6.1.0
Orfeo Toolbox
otbRationalTransform.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbRationalTransform_h
22 #define otbRationalTransform_h
23 
24 #include "otbTransform.h"
25 #include "itkMacro.h"
26 
27 namespace otb
28 {
50 template <class TScalarType = double,
51  unsigned int Dimension = 2>
52 class ITK_EXPORT RationalTransform : public Transform<TScalarType, Dimension, Dimension>
53 {
54 public:
56  typedef Transform<TScalarType, Dimension,
57  Dimension> Superclass;
61 
62  typedef typename Superclass::ScalarType ScalarType;
65 
68 
69  typedef typename Superclass::InverseTransformBasePointer InverseTransformBasePointer;
71 
72  typedef typename Superclass::ParametersValueType ParametersValueType;
73  typedef typename Superclass::NumberOfParametersType NumberOfParametersType;
74 
76  itkNewMacro(Self);
77 
79  itkTypeMacro(RationalTransform, Transform);
80 
81  itkStaticConstMacro(SpaceDimension, unsigned int, Dimension);
82 
84  void SetNumeratorDegree(unsigned int value)
85  {
86  this->m_NumeratorDegree = value;
87  this->InitializeParameters();
88  }
90 
92  itkGetConstMacro(NumeratorDegree, unsigned int);
93 
95  void SetDenominatorDegree(unsigned int value)
96  {
97  this->m_DenominatorDegree = value;
98  this->InitializeParameters();
99  }
101 
103  itkGetConstMacro(DenominatorDegree, unsigned int);
104 
106  OutputPointType TransformPoint(const InputPointType& point) const ITK_OVERRIDE
107  {
108  // Check for consistency
109  if(this->GetNumberOfParameters() != this->m_Parameters.size())
110  {
111  {
112  itkExceptionMacro(<<"Wrong number of parameters: found "<<this->m_Parameters.Size()<<", expected "<<this->GetNumberOfParameters());
113  }
114  }
116 
117  InputPointType inputPoint = point;
118  OutputPointType outputPoint;
119 
120  unsigned int dimensionStride = (m_DenominatorDegree+1)+(m_NumeratorDegree+1);
121 
122  // Compute RPC transform
123  for(unsigned int dim = 0; dim < SpaceDimension; ++dim)
124  {
125  //1) Initialize numerator and denominator
126  TScalarType num = itk::NumericTraits<TScalarType>::Zero;
127  TScalarType denom = itk::NumericTraits<TScalarType>::Zero;
128  TScalarType currentPower = 1.;
129 
130  // 2) Compute numerator
131  for(unsigned int numDegree = 0; numDegree <= m_NumeratorDegree; ++numDegree)
132  {
133  num+=this->m_Parameters[dim*dimensionStride+numDegree]*currentPower;
134  currentPower*=inputPoint[dim];
135  }
136 
137  //3) Compute denominator
138  currentPower = 1.;
139  for(unsigned int denomDegree = 0; denomDegree <= m_DenominatorDegree; ++denomDegree)
140  {
141  denom+=this->m_Parameters[dim*dimensionStride+m_NumeratorDegree+denomDegree+1]*currentPower;
142  currentPower*=inputPoint[dim];
143  }
144 
145  //4) Fill the output
146  outputPoint[dim]=num/denom;
147  }
148 
149  // Return the output point
150  return outputPoint;
151  }
152 
155  {
156  return (static_cast <NumberOfParametersType> ( (m_NumeratorDegree +1 + m_DenominatorDegree+1)*SpaceDimension ));
157  }
158 
159  // Set parameter method
160  void SetParameters(const typename Superclass::ParametersType & params) ITK_OVERRIDE
161  {
162  // Check for the appropriate size
163  if(params.Size() != this->GetNumberOfParameters())
164  {
165  itkExceptionMacro(<<"Wrong number of parameters: found "<<params.Size()<<", expected "<<this->GetNumberOfParameters());
166  }
167 
168  // Set parametersg
169  this->m_Parameters = params;
170  }
171 
174  {
175  this->m_Parameters.SetSize(this->GetNumberOfParameters());
176  this->m_Parameters.Fill(0);
177  unsigned int dimensionStride = (m_DenominatorDegree+1)+(m_NumeratorDegree+1);
179 
180  for(unsigned int dim = 0; dim < SpaceDimension; ++dim)
181  {
182  this->m_Parameters[ dimensionStride *dim + m_NumeratorDegree+1] = 1.;
183  }
184  }
185 
186 
187 protected:
188  RationalTransform() : Superclass(16), m_NumeratorDegree(3), m_DenominatorDegree(3)
189  {
190  this->InitializeParameters();
191  }
192 
193 
194  ~RationalTransform() ITK_OVERRIDE {}
195 
196  void PrintSelf(std::ostream& os, itk::Indent indent) const ITK_OVERRIDE
197  {
198  Superclass::PrintSelf(os, indent);
199  os << indent << "Numerator Degree : " << m_NumeratorDegree << std::endl;
200  os << indent << "Denominator Degree : " << m_DenominatorDegree << std::endl;
201 
202  }
203 
204 private:
205  RationalTransform(const Self &); //purposely not implemented
206  void operator =(const Self&); //purposely not implemented
207 
208  // Degree of numerator
209  unsigned int m_NumeratorDegree;
210 
211  // Degree of denominator
212  unsigned int m_DenominatorDegree;
213 };
214 
215 } // namespace otb
216 
217 #endif
void PrintSelf(std::ostream &os, itk::Indent indent) const ITK_OVERRIDE
void SetNumeratorDegree(unsigned int value)
Superclass::ParametersType ParametersType
Superclass::ScalarType ScalarType
itk::Point< double, Dimension > OriginType
itk::SmartPointer< const Self > ConstPointer
IdentifierType NumberOfParametersType
Transform< TScalarType, Dimension, Dimension > Superclass
itk::SmartPointer< Self > Pointer
Superclass::ParametersValueType ParametersValueType
itk::Point< ScalarType, Dimension > OutputPointType
void SetParameters(const typename Superclass::ParametersType &params) ITK_OVERRIDE
itk::Point< ScalarType, Dimension > InputPointType
Superclass::InverseTransformBasePointer InverseTransformBasePointer
NumberOfParametersType GetNumberOfParameters() const ITK_OVERRIDE
itk::Array< double > ParametersType
Definition: mvdTypes.h:131
OutputPointType TransformPoint(const InputPointType &point) const ITK_OVERRIDE
Superclass::NumberOfParametersType NumberOfParametersType
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:40