OTB  9.0.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-2022 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>
32 {
33  m_Radius.Fill(2);
34  m_A = 0;
35  m_B = 0;
36  m_U0 = 0;
37  m_V0 = 0;
38  m_Theta = 0;
39  m_Phi = 0;
40  m_NeedToRegenerateFilter = true;
41 }
42 template <class TPrecision>
44 {
45  if (m_NeedToRegenerateFilter)
46  {
47  this->GenerateFilter();
48  }
49  return m_Filter;
50 }
51 
52 template <class TPrecision>
54 {
55  m_Filter.SetSize((2 * m_Radius[0] + 1) * (2 * m_Radius[1] + 1));
56  m_Filter.Fill(0);
57 
58  PrecisionType coef, xr, yr, costheta, sintheta;
59  unsigned int k = 0;
60 
61  costheta = std::cos(m_Theta * CONST_PI_180);
62  sintheta = std::sin(m_Theta * CONST_PI_180);
63 
64  for (PrecisionType y = -static_cast<PrecisionType>(m_Radius[1]); y <= static_cast<PrecisionType>(m_Radius[1]); y += 1)
65  {
66  for (PrecisionType x = -static_cast<PrecisionType>(m_Radius[0]); x <= static_cast<PrecisionType>(m_Radius[0]); x += 1)
67  {
68  xr = x * costheta + y * sintheta;
69  yr = y * costheta - x * sintheta;
70  coef = std::exp(-CONST_PI * (std::pow(m_A * xr, 2) + std::pow(m_B * yr, 2))) * cos(CONST_2PI * (m_U0 * x + m_V0 * y) + m_Phi);
71  m_Filter.SetElement(k, coef);
72  ++k;
73  }
74  }
75 }
76 
77 template <class TPrecision>
79 {
80  this->Superclass::Modified();
81  m_NeedToRegenerateFilter = true;
82 }
83 
84 template <class TPrecision>
85 void GaborFilterGenerator<TPrecision>::PrintSelf(std::ostream& os, itk::Indent indent) const
86 {
87  Superclass::PrintSelf(os, indent);
88  os << indent << "Radius: " << m_Radius << std::endl;
89  os << indent << "A: " << m_A << std::endl;
90  os << indent << "B: " << m_B << std::endl;
91  os << indent << "Theta: " << m_Theta << std::endl;
92  os << indent << "U0: " << m_U0 << std::endl;
93  os << indent << "V0: " << m_V0 << std::endl;
94  os << indent << "Phi: " << m_Phi << std::endl;
95  os << "Need to regenerate filter: " << m_NeedToRegenerateFilter << std::endl;
96 }
97 }
98 #endif
otb::CONST_PI
constexpr double CONST_PI
Definition: otbMath.h:49
otb::GaborFilterGenerator::ArrayType
itk::Array< PrecisionType > ArrayType
Definition: otbGaborFilterGenerator.h:88
otb::GaborFilterGenerator::PrecisionType
TPrecision PrecisionType
Definition: otbGaborFilterGenerator.h:84
otbMath.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbGaborFilterGenerator.h
otb::GaborFilterGenerator::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbGaborFilterGenerator.hxx:85
otb::GaborFilterGenerator::GenerateFilter
void GenerateFilter()
Definition: otbGaborFilterGenerator.hxx:53
otb::CONST_PI_180
constexpr double CONST_PI_180
Definition: otbMath.h:56
otb::CONST_2PI
constexpr double CONST_2PI
Definition: otbMath.h:55
otb::GaborFilterGenerator::GetFilter
const ArrayType & GetFilter()
Definition: otbGaborFilterGenerator.hxx:43
otb::GaborFilterGenerator::GaborFilterGenerator
GaborFilterGenerator()
Definition: otbGaborFilterGenerator.hxx:31
otb::GaborFilterGenerator::Modified
void Modified() const override
Definition: otbGaborFilterGenerator.hxx:78