OTB  6.7.0
Orfeo Toolbox
otbInverseLogPolarTransform.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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>
36  : Superclass(4)
37 {
38  m_Center[0] = 0.0;
39  m_Center[1] = 0.0;
40  m_Scale[0] = 1.0;
41  m_Scale[1] = 1.0;
42 }
43 
47 template <class TScalarType>
50 {}
51 
56 template <class TScalarType>
57 void
59 ::SetParameters(const ParametersType& parameters)
60 {
61  m_Center[0] = parameters[0];
62  m_Center[1] = parameters[1];
63  m_Scale[0] = parameters[2];
64  m_Scale[1] = parameters[3];
65  otbMsgDebugMacro(<< "Call To SetParameters: Center=" << m_Center << ", Scale=" << m_Scale);
66  this->m_Parameters = parameters;
67  this->Modified();
68 }
69 
74 template <class TScalarType>
78 ::GetParameters(void) const
79 {
80  // Filling parameters vector
81  this->m_Parameters[0] = m_Center[0];
82  this->m_Parameters[1] = m_Center[1];
83  this->m_Parameters[2] = m_Scale[0];
84  this->m_Parameters[3] = m_Scale[1];
85 
86  return this->m_Parameters;
87 }
88 
94 template <class TScalarType>
96 ::OutputPointType
98 ::TransformPoint(const InputPointType& point) const
99 {
100  OutputPointType result;
101  double rho = std::sqrt(std::pow(point[0] - m_Center[0], 2) + std::pow(point[1] - m_Center[1], 2));
102  if (rho > 0)
103  {
104  result[0] = (1. / m_Scale[0]) * std::asin((point[1] - m_Center[1]) / rho);
105  // degree conversion
106  result[0] = result[0] * (180. / CONST_PI);
107  // Deplacing the range to [0, 90], [270, 360]
108  result[0] = result[0] > 0. ? result[0] : result[0] + 360.;
109  // Avoiding asin indetermination
110  if ((point[0] - m_Center[0]) >= 0)
111  {
112  result[0] = result[0] < 90. ? result[0] + 90. : result[0] - 90.;
113  }
114  result[1] = (1. / m_Scale[1]) * std::log(rho);
115  // otbMsgDebugMacro(<<std::log(std::pow(point[0]-m_Center[0], 2)+std::pow(point[1]-m_Center[1], 2)));
116  }
117  else
118  {
119  // for rho=0, reject the point outside the angular range to avoid nan error
120  result[0] = 400.;
121  result[1] = 0.;
122  }
123  return result;
124 }
125 
131 template <class TScalarType>
133 ::OutputVectorType
135 ::TransformVector(const InputVectorType& vector) const
136 {
137  OutputVectorType result;
138  double rho = std::sqrt(std::pow(vector[0] - m_Center[0], 2) + std::pow(vector[1] - m_Center[1], 2));
139  if (rho > 0)
140  {
141  result[0] = (1 / m_Scale[0]) * std::asin((vector[1] - m_Center[1]) / rho);
142  // degree conversion
143  result[0] = result[0] * (180 / CONST_PI);
144  // Deplacing the range to [0, 90], [270, 360]
145  result[0] = result[0] > 0 ? result[0] : result[0] + 360;
146  // Avoiding asin indetermination
147  if ((vector[0] - m_Center[0]) >= 0)
148  {
149  result[0] = result[0] < 90 ? result[0] + 90 : result[0] - 90;
150  }
151  result[1] = (1 / m_Scale[1]) * std::log(rho);
152  // otbMsgDebugMacro(<<std::log(std::pow(vector[0]-m_Center[0], 2)+std::pow(vector[1]-m_Center[1], 2)));
153  }
154  else
155  {
156  // for rho=0, reject the vector outside the angular range to avoid nan error
157  result[0] = 400;
158  result[1] = 0;
159  }
160  return result;
161 }
162 
168 template <class TScalarType>
170 ::OutputVnlVectorType
173 {
174  OutputVnlVectorType result;
175  double rho = std::sqrt(std::pow(vector[0], 2) + std::pow(vector[1], 2));
176  if (rho > 0)
177  {
178  result[0] = (1 / m_Scale[0]) * std::asin((vector[1] - m_Center[1]) / rho);
179  // degree conversion
180  result[0] = result[0] * (180 / CONST_PI);
181  // Deplacing the range to [0, 90], [270, 360]
182  result[0] = result[0] > 0 ? result[0] : result[0] + 360;
183  // Avoiding std::asin indetermination
184  if ((vector[0] - m_Center[0]) >= 0)
185  {
186  result[0] = result[0] < 90 ? result[0] + 90 : result[0] - 90;
187  }
188  result[1] = (1 / m_Scale[1]) * std::log(rho);
189  // otbMsgDebugMacro(<<log(std::pow(vector[0]-m_Center[0], 2)+std::pow(vector[1]-m_Center[1], 2)));
190  }
191  else
192  {
193  // for rho=0, reject the vector outside the angular range to avoid nan error
194  result[0] = 400;
195  result[1] = 0;
196  }
197  return result;
198 }
199 
203 template <class TScalarType>
204 void
206 ::PrintSelf(std::ostream& os, itk::Indent indent) const
207 {
208  Superclass::PrintSelf(os, indent);
209  os << indent << "Center: " << m_Center << std::endl;
210  os << indent << "Scale: " << m_Scale << std::endl;
211 }
213 
214 } // end namespace otb
215 #endif
Superclass::InputVnlVectorType InputVnlVectorType
ParametersType & GetParameters(void) const override
OutputPointType TransformPoint(const InputPointType &point) const override
constexpr double CONST_PI
Definition: otbMath.h:48
#define otbMsgDebugMacro(x)
Definition: otbMacro.h:64
void SetParameters(const ParametersType &parameters) override
Superclass::OutputPointType OutputPointType
itk::Array< double > ParametersType
Definition: mvdTypes.h:122
void PrintSelf(std::ostream &os, itk::Indent indent) const override
OutputVectorType TransformVector(const InputVectorType &vector) const override
Superclass::OutputVnlVectorType OutputVnlVectorType
This transform is the back transform of the LogPolarTransform.
Superclass::InputVectorType InputVectorType
Superclass::InputPointType InputPointType