OTB  9.0.0
Orfeo Toolbox
otbInverseLogPolarTransform.hxx
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 otbInverseLogPolarTransform_hxx
22 #define otbInverseLogPolarTransform_hxx
23 
25 #include "otbMacro.h"
26 #include "otbMath.h"
27 
28 namespace otb
29 {
33 template <class TScalarType>
35 {
36  m_Center[0] = 0.0;
37  m_Center[1] = 0.0;
38  m_Scale[0] = 1.0;
39  m_Scale[1] = 1.0;
40 }
41 
45 template <class TScalarType>
47 {
48 }
49 
54 template <class TScalarType>
56 {
57  m_Center[0] = parameters[0];
58  m_Center[1] = parameters[1];
59  m_Scale[0] = parameters[2];
60  m_Scale[1] = parameters[3];
61  otbMsgDebugMacro(<< "Call To SetParameters: Center=" << m_Center << ", Scale=" << m_Scale);
62  this->m_Parameters = parameters;
63  this->Modified();
64 }
65 
70 template <class TScalarType>
72 {
73  // Filling parameters vector
74  this->m_Parameters[0] = m_Center[0];
75  this->m_Parameters[1] = m_Center[1];
76  this->m_Parameters[2] = m_Scale[0];
77  this->m_Parameters[3] = m_Scale[1];
78 
79  return this->m_Parameters;
80 }
81 
87 template <class TScalarType>
89 {
90  OutputPointType result;
91  double rho = std::sqrt(std::pow(point[0] - m_Center[0], 2) + std::pow(point[1] - m_Center[1], 2));
92  if (rho > 0)
93  {
94  result[0] = (1. / m_Scale[0]) * std::asin((point[1] - m_Center[1]) / rho);
95  // degree conversion
96  result[0] = result[0] * (180. / CONST_PI);
97  // Deplacing the range to [0, 90], [270, 360]
98  result[0] = result[0] > 0. ? result[0] : result[0] + 360.;
99  // Avoiding asin indetermination
100  if ((point[0] - m_Center[0]) >= 0)
101  {
102  result[0] = result[0] < 90. ? result[0] + 90. : result[0] - 90.;
103  }
104  result[1] = (1. / m_Scale[1]) * std::log(rho);
105  // otbMsgDebugMacro(<<std::log(std::pow(point[0]-m_Center[0], 2)+std::pow(point[1]-m_Center[1], 2)));
106  }
107  else
108  {
109  // for rho=0, reject the point outside the angular range to avoid nan error
110  result[0] = 400.;
111  result[1] = 0.;
112  }
113  return result;
114 }
115 
121 template <class TScalarType>
123 {
124  OutputVectorType result;
125  double rho = std::sqrt(std::pow(vector[0] - m_Center[0], 2) + std::pow(vector[1] - m_Center[1], 2));
126  if (rho > 0)
127  {
128  result[0] = (1 / m_Scale[0]) * std::asin((vector[1] - m_Center[1]) / rho);
129  // degree conversion
130  result[0] = result[0] * (180 / CONST_PI);
131  // Deplacing the range to [0, 90], [270, 360]
132  result[0] = result[0] > 0 ? result[0] : result[0] + 360;
133  // Avoiding asin indetermination
134  if ((vector[0] - m_Center[0]) >= 0)
135  {
136  result[0] = result[0] < 90 ? result[0] + 90 : result[0] - 90;
137  }
138  result[1] = (1 / m_Scale[1]) * std::log(rho);
139  // otbMsgDebugMacro(<<std::log(std::pow(vector[0]-m_Center[0], 2)+std::pow(vector[1]-m_Center[1], 2)));
140  }
141  else
142  {
143  // for rho=0, reject the vector outside the angular range to avoid nan error
144  result[0] = 400;
145  result[1] = 0;
146  }
147  return result;
148 }
149 
155 template <class TScalarType>
158 {
159  OutputVnlVectorType result;
160  double rho = std::sqrt(std::pow(vector[0], 2) + std::pow(vector[1], 2));
161  if (rho > 0)
162  {
163  result[0] = (1 / m_Scale[0]) * std::asin((vector[1] - m_Center[1]) / rho);
164  // degree conversion
165  result[0] = result[0] * (180 / CONST_PI);
166  // Deplacing the range to [0, 90], [270, 360]
167  result[0] = result[0] > 0 ? result[0] : result[0] + 360;
168  // Avoiding std::asin indetermination
169  if ((vector[0] - m_Center[0]) >= 0)
170  {
171  result[0] = result[0] < 90 ? result[0] + 90 : result[0] - 90;
172  }
173  result[1] = (1 / m_Scale[1]) * std::log(rho);
174  // otbMsgDebugMacro(<<log(std::pow(vector[0]-m_Center[0], 2)+std::pow(vector[1]-m_Center[1], 2)));
175  }
176  else
177  {
178  // for rho=0, reject the vector outside the angular range to avoid nan error
179  result[0] = 400;
180  result[1] = 0;
181  }
182  return result;
183 }
184 
188 template <class TScalarType>
189 void InverseLogPolarTransform<TScalarType>::PrintSelf(std::ostream& os, itk::Indent indent) const
190 {
191  Superclass::PrintSelf(os, indent);
192  os << indent << "Center: " << m_Center << std::endl;
193  os << indent << "Scale: " << m_Scale << std::endl;
194 }
196 
197 } // end namespace otb
198 #endif
otb::InverseLogPolarTransform::~InverseLogPolarTransform
~InverseLogPolarTransform() override
Definition: otbInverseLogPolarTransform.hxx:46
otb::InverseLogPolarTransform::m_Center
InputPointType m_Center
Definition: otbInverseLogPolarTransform.h:151
otb::CONST_PI
constexpr double CONST_PI
Definition: otbMath.h:49
otbMath.h
otb::InverseLogPolarTransform::InputVectorType
Superclass::InputVectorType InputVectorType
Definition: otbInverseLogPolarTransform.h:69
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::InverseLogPolarTransform::OutputPointType
Superclass::OutputPointType OutputPointType
Definition: otbInverseLogPolarTransform.h:68
otbMacro.h
otb::InverseLogPolarTransform::TransformVector
OutputVectorType TransformVector(const InputVectorType &vector) const override
Definition: otbInverseLogPolarTransform.hxx:122
otb::InverseLogPolarTransform::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbInverseLogPolarTransform.hxx:189
otb::InverseLogPolarTransform::TransformPoint
OutputPointType TransformPoint(const InputPointType &point) const override
Definition: otbInverseLogPolarTransform.hxx:88
otb::InverseLogPolarTransform::OutputVnlVectorType
Superclass::OutputVnlVectorType OutputVnlVectorType
Definition: otbInverseLogPolarTransform.h:72
otb::InverseLogPolarTransform::OutputVectorType
Superclass::OutputVectorType OutputVectorType
Definition: otbInverseLogPolarTransform.h:70
otb::InverseLogPolarTransform::SetParameters
void SetParameters(const ParametersType &parameters) override
Definition: otbInverseLogPolarTransform.hxx:55
otb::InverseLogPolarTransform::GetParameters
ParametersType & GetParameters(void) const override
Definition: otbInverseLogPolarTransform.hxx:71
otb::InverseLogPolarTransform::InputVnlVectorType
Superclass::InputVnlVectorType InputVnlVectorType
Definition: otbInverseLogPolarTransform.h:71
otb::Transform< TScalarType, 2, 2 >
otbMsgDebugMacro
#define otbMsgDebugMacro(x)
Definition: otbMacro.h:62
otbInverseLogPolarTransform.h
otb::InverseLogPolarTransform::m_Scale
ScaleType m_Scale
Definition: otbInverseLogPolarTransform.h:152
otb::InverseLogPolarTransform::InputPointType
Superclass::InputPointType InputPointType
Definition: otbInverseLogPolarTransform.h:67
otb::InverseLogPolarTransform::InverseLogPolarTransform
InverseLogPolarTransform()
Definition: otbInverseLogPolarTransform.hxx:34
otb::InverseLogPolarTransform::ParametersType
Superclass::ParametersType ParametersType
Definition: otbInverseLogPolarTransform.h:73