OTB  6.7.0
Orfeo Toolbox
otbGaborFilterGenerator.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999-2011 Insight Software Consortium
3  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 #ifndef otbGaborFilterGenerator_hxx
23 #define otbGaborFilterGenerator_hxx
24 
26 #include "otbMath.h"
27 
28 namespace otb
29 {
30 template <class TPrecision>
33 {
34  m_Radius.Fill(2);
35  m_A = 0;
36  m_B = 0;
37  m_U0 = 0;
38  m_V0 = 0;
39  m_Theta = 0;
40  m_Phi = 0;
41  m_NeedToRegenerateFilter = true;
42 }
43 template <class TPrecision>
45 ::ArrayType&
48 {
49  if (m_NeedToRegenerateFilter)
50  {
51  this->GenerateFilter();
52  }
53  return m_Filter;
54 }
55 
56 template <class TPrecision>
57 void
60 {
61  m_Filter.SetSize((2 * m_Radius[0] + 1) * (2 * m_Radius[1] + 1));
62  m_Filter.Fill(0);
63 
64  PrecisionType coef, xr, yr, costheta, sintheta;
65  unsigned int k = 0;
66 
67  costheta = std::cos(m_Theta * CONST_PI_180);
68  sintheta = std::sin(m_Theta * CONST_PI_180);
69 
70  for (PrecisionType y = -static_cast<PrecisionType>(m_Radius[1]);
71  y <= static_cast<PrecisionType>(m_Radius[1]); y += 1)
72  {
73  for (PrecisionType x = -static_cast<PrecisionType>(m_Radius[0]);
74  x <= static_cast<PrecisionType>(m_Radius[0]); x += 1)
75  {
76  xr = x * costheta + y * sintheta;
77  yr = y * costheta - x * sintheta;
78  coef = std::exp(-CONST_PI * (std::pow(m_A * xr, 2) + std::pow(m_B * yr, 2))) * cos(
79  CONST_2PI * (m_U0 * x + m_V0 * y) + m_Phi);
80  m_Filter.SetElement(k, coef);
81  ++k;
82  }
83  }
84 }
85 
86 template <class TPrecision>
87 void
89 ::Modified() const
90 {
91  this->Superclass::Modified();
92  m_NeedToRegenerateFilter = true;
93 }
94 
95 template <class TPrecision>
96 void
98 ::PrintSelf(std::ostream& os, itk::Indent indent) const
99 {
100  Superclass::PrintSelf(os, indent);
101  os << indent << "Radius: " << m_Radius << std::endl;
102  os << indent << "A: " << m_A << std::endl;
103  os << indent << "B: " << m_B << std::endl;
104  os << indent << "Theta: " << m_Theta << std::endl;
105  os << indent << "U0: " << m_U0 << std::endl;
106  os << indent << "V0: " << m_V0 << std::endl;
107  os << indent << "Phi: " << m_Phi << std::endl;
108  os << "Need to regenerate filter: " << m_NeedToRegenerateFilter << std::endl;
109 }
110 
111 }
112 #endif
constexpr double CONST_PI
Definition: otbMath.h:48
constexpr double CONST_2PI
Definition: otbMath.h:54
constexpr double CONST_PI_180
Definition: otbMath.h:55
void PrintSelf(std::ostream &os, itk::Indent indent) const override