OTB  9.0.0
Orfeo Toolbox
otbRationalTransform.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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, unsigned int Dimension = 2>
51 class ITK_EXPORT RationalTransform : public Transform<TScalarType, Dimension, Dimension>
52 {
53 public:
57  typedef itk::SmartPointer<Self> Pointer;
58  typedef itk::SmartPointer<const Self> ConstPointer;
59 
61  typedef itk::Point<ScalarType, Dimension> InputPointType;
62  typedef itk::Point<ScalarType, Dimension> OutputPointType;
63 
64  typedef itk::Vector<double, Dimension> SpacingType;
65  typedef itk::Point<double, Dimension> OriginType;
66 
69 
72 
74  itkNewMacro(Self);
75 
77  itkTypeMacro(RationalTransform, Transform);
78 
79  itkStaticConstMacro(SpaceDimension, unsigned int, Dimension);
80 
82  void SetNumeratorDegree(unsigned int value)
83  {
84  this->m_NumeratorDegree = value;
85  this->InitializeParameters();
86  }
88 
90  itkGetConstMacro(NumeratorDegree, unsigned int);
91 
93  void SetDenominatorDegree(unsigned int value)
94  {
95  this->m_DenominatorDegree = value;
96  this->InitializeParameters();
97  }
99 
101  itkGetConstMacro(DenominatorDegree, unsigned int);
102 
104  OutputPointType TransformPoint(const InputPointType& point) const override
105  {
106  // Check for consistency
107  if (this->GetNumberOfParameters() != this->m_Parameters.size())
108  {
109  {
110  itkExceptionMacro(<< "Wrong number of parameters: found " << this->m_Parameters.Size() << ", expected " << this->GetNumberOfParameters());
111  }
112  }
114 
115  InputPointType inputPoint = point;
116  OutputPointType outputPoint;
117 
118  unsigned int dimensionStride = (m_DenominatorDegree + 1) + (m_NumeratorDegree + 1);
119 
120  // Compute RPC transform
121  for (unsigned int dim = 0; dim < SpaceDimension; ++dim)
122  {
123  // 1) Initialize numerator and denominator
124  TScalarType num = itk::NumericTraits<TScalarType>::Zero;
125  TScalarType denom = itk::NumericTraits<TScalarType>::Zero;
126  TScalarType currentPower = 1.;
127 
128  // 2) Compute numerator
129  for (unsigned int numDegree = 0; numDegree <= m_NumeratorDegree; ++numDegree)
130  {
131  num += this->m_Parameters[dim * dimensionStride + numDegree] * currentPower;
132  currentPower *= inputPoint[dim];
133  }
134 
135  // 3) Compute denominator
136  currentPower = 1.;
137  for (unsigned int denomDegree = 0; denomDegree <= m_DenominatorDegree; ++denomDegree)
138  {
139  denom += this->m_Parameters[dim * dimensionStride + m_NumeratorDegree + denomDegree + 1] * currentPower;
140  currentPower *= inputPoint[dim];
141  }
142 
143  // 4) Fill the output
144  outputPoint[dim] = num / denom;
145  }
146 
147  // Return the output point
148  return outputPoint;
149  }
150 
153  {
154  return (static_cast<NumberOfParametersType>((m_NumeratorDegree + 1 + m_DenominatorDegree + 1) * SpaceDimension));
155  }
156 
157  // Set parameter method
158  void SetParameters(const typename Superclass::ParametersType& params) override
159  {
160  // Check for the appropriate size
161  if (params.Size() != this->GetNumberOfParameters())
162  {
163  itkExceptionMacro(<< "Wrong number of parameters: found " << params.Size() << ", expected " << this->GetNumberOfParameters());
164  }
165 
166  // Set parametersg
167  this->m_Parameters = params;
168  }
169 
172  {
173  this->m_Parameters.SetSize(this->GetNumberOfParameters());
174  this->m_Parameters.Fill(0);
175  unsigned int dimensionStride = (m_DenominatorDegree + 1) + (m_NumeratorDegree + 1);
177 
178  for (unsigned int dim = 0; dim < SpaceDimension; ++dim)
179  {
180  this->m_Parameters[dimensionStride * dim + m_NumeratorDegree + 1] = 1.;
181  }
182  }
183 
184 
185 protected:
186  RationalTransform() : Superclass(16), m_NumeratorDegree(3), m_DenominatorDegree(3)
187  {
188  this->InitializeParameters();
189  }
190 
191 
193  {
194  }
195 
196  void PrintSelf(std::ostream& os, itk::Indent indent) const 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 private:
204  RationalTransform(const Self&) = delete;
205  void operator=(const Self&) = delete;
206 
207  // Degree of numerator
208  unsigned int m_NumeratorDegree;
209 
210  // Degree of denominator
211  unsigned int m_DenominatorDegree;
212 };
213 
214 } // namespace otb
215 
216 #endif
otb::RationalTransform::RationalTransform
RationalTransform()
Definition: otbRationalTransform.h:186
otb::RationalTransform::TransformPoint
OutputPointType TransformPoint(const InputPointType &point) const override
Definition: otbRationalTransform.h:104
otb::RationalTransform::GetNumberOfParameters
NumberOfParametersType GetNumberOfParameters() const override
Definition: otbRationalTransform.h:152
otb::RationalTransform::SetDenominatorDegree
void SetDenominatorDegree(unsigned int value)
Definition: otbRationalTransform.h:93
otb::RationalTransform::~RationalTransform
~RationalTransform() override
Definition: otbRationalTransform.h:192
otbTransform.h
otb::Transform::ScalarType
TScalarType ScalarType
Definition: otbTransform.h:71
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Transform::InverseTransformBasePointer
Superclass::InverseTransformBasePointer InverseTransformBasePointer
Definition: otbTransform.h:101
otb::RationalTransform::Superclass
Transform< TScalarType, Dimension, Dimension > Superclass
Definition: otbRationalTransform.h:55
otb::RationalTransform::m_NumeratorDegree
unsigned int m_NumeratorDegree
Definition: otbRationalTransform.h:208
otb::Transform::NumberOfParametersType
Superclass::NumberOfParametersType NumberOfParametersType
Definition: otbTransform.h:76
otb::RationalTransform::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbRationalTransform.h:58
otb::RationalTransform::m_DenominatorDegree
unsigned int m_DenominatorDegree
Definition: otbRationalTransform.h:211
otb::RationalTransform::ScalarType
Superclass::ScalarType ScalarType
Definition: otbRationalTransform.h:60
otb::Transform::ParametersValueType
Superclass::ParametersValueType ParametersValueType
Definition: otbTransform.h:75
otb::RationalTransform::SetParameters
void SetParameters(const typename Superclass::ParametersType &params) override
Definition: otbRationalTransform.h:158
otb::RationalTransform::Self
RationalTransform Self
Definition: otbRationalTransform.h:56
otb::Transform
Class to overload method passed to virtual pure in ITK V4.
Definition: otbTransform.h:39
otb::RationalTransform::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbRationalTransform.h:196
otb::RationalTransform::SpacingType
itk::Vector< double, Dimension > SpacingType
Definition: otbRationalTransform.h:64
otb::RationalTransform
This class implements a rational transform.
Definition: otbRationalTransform.h:51
otb::RationalTransform::ParametersValueType
Superclass::ParametersValueType ParametersValueType
Definition: otbRationalTransform.h:70
otb::RationalTransform::NumberOfParametersType
Superclass::NumberOfParametersType NumberOfParametersType
Definition: otbRationalTransform.h:71
otb::RationalTransform::InitializeParameters
void InitializeParameters()
Definition: otbRationalTransform.h:171
otb::RationalTransform::OutputPointType
itk::Point< ScalarType, Dimension > OutputPointType
Definition: otbRationalTransform.h:62
otb::RationalTransform::SetNumeratorDegree
void SetNumeratorDegree(unsigned int value)
Definition: otbRationalTransform.h:82
otb::RationalTransform::InputPointType
itk::Point< ScalarType, Dimension > InputPointType
Definition: otbRationalTransform.h:61
otb::RationalTransform::InverseTransformBasePointer
Superclass::InverseTransformBasePointer InverseTransformBasePointer
Definition: otbRationalTransform.h:67
otb::RationalTransform::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbRationalTransform.h:57
otb::RationalTransform::ParametersType
Superclass::ParametersType ParametersType
Definition: otbRationalTransform.h:68
otb::Transform::ParametersType
Superclass::ParametersType ParametersType
Definition: otbTransform.h:74
otb::RationalTransform::OriginType
itk::Point< double, Dimension > OriginType
Definition: otbRationalTransform.h:65