OTB  9.0.0
Orfeo Toolbox
otbHuPathFunction.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 otbHuPathFunction_hxx
22 #define otbHuPathFunction_hxx
23 
24 #include "otbHuPathFunction.h"
26 #include "itkNumericTraits.h"
27 
28 #include "otbMacro.h"
29 
30 namespace otb
31 {
32 
36 template <class TInputPath, class TOutput, class TPrecision>
38 {
39  m_MomentNumber = -1;
40 }
41 
45 template <class TInputPath, class TOutput, class TPrecision>
46 void HuPathFunction<TInputPath, TOutput, TPrecision>::PrintSelf(std::ostream& os, itk::Indent indent) const
47 {
48  this->Superclass::PrintSelf(os, indent);
49  os << indent << " m_MomentNumber : " << m_MomentNumber << std::endl;
50 }
52 
53 template <class TInputPath, class TOutput, class TPrecision>
56 {
57  typedef ComplexMomentPathFunction<PathType> FunctionType;
58  typedef typename FunctionType::ComplexType ComplexType;
59 
60  RealType HuValue = 0.;
61  ComplexType HuValueComplex;
62 
63  typename FunctionType::Pointer function = FunctionType::New();
64 
65  function->SetInputPath(this->GetInputPath());
66 
67  switch (m_MomentNumber)
68  {
69  case 1:
70  {
71  ComplexType C11;
72  function->SetP(1);
73  function->SetQ(1);
74  C11 = function->Evaluate();
75  HuValue = C11.real();
76  }
77  break;
78  case 2:
79  {
80  ComplexType C20, C02;
81  function->SetP(2);
82  function->SetQ(0);
83  C20 = function->Evaluate();
84  function->SetP(0);
85  function->SetQ(2);
86  C02 = function->Evaluate();
87 
88  HuValue = std::abs(C20 * C02);
89  }
90  break;
91  case 3:
92  {
93  ComplexType C30, C03;
94  function->SetP(3);
95  function->SetQ(0);
96  C30 = function->Evaluate();
97  function->SetP(0);
98  function->SetQ(3);
99  C03 = function->Evaluate();
100 
101  HuValue = std::abs(C30 * C03);
102  }
103  break;
104  case 4:
105  {
106  ComplexType C21, C12;
107  function->SetP(2);
108  function->SetQ(1);
109  C21 = function->Evaluate();
110  function->SetP(1);
111  function->SetQ(2);
112  C12 = function->Evaluate();
113 
114  HuValue = std::abs(C21 * C12);
115  }
116  break;
117 
118  case 5:
119  {
120  ComplexType C30, C12;
121  function->SetP(3);
122  function->SetQ(0);
123  C30 = function->Evaluate();
124  function->SetP(1);
125  function->SetQ(2);
126  C12 = function->Evaluate();
127 
128  HuValueComplex = C30 * std::pow(C12, 3);
129  HuValue = HuValueComplex.real();
130  }
131  break;
132 
133  case 6:
134  {
135  ComplexType C20, C12;
136  function->SetP(2);
137  function->SetQ(0);
138  C20 = function->Evaluate();
139  function->SetP(1);
140  function->SetQ(2);
141  C12 = function->Evaluate();
142 
143  HuValueComplex = C20 * std::pow(C12, 2);
144  HuValue = HuValueComplex.real();
145  }
146  break;
147 
148  case 7:
149  {
150  ComplexType C30, C12;
151  function->SetP(3);
152  function->SetQ(0);
153  C30 = function->Evaluate();
154  function->SetP(1);
155  function->SetQ(2);
156  C12 = function->Evaluate();
157 
158  HuValueComplex = C30 * std::pow(C12, 3);
159  HuValue = HuValueComplex.imag();
160  }
161  break;
162 
163  default:
164  itkWarningMacro("Hu's invariant parameters are between 1 and 7");
165  }
166 
167  return (static_cast<RealType>(HuValue));
168 }
169 
170 template <class TInputPath, class TOutput, class TPrecision>
172 {
173  if (!this->GetInputPath())
174  {
175  otbMsgDevMacro(<< "Pb with GetInputPath");
176  return static_cast<RealType>(itk::NumericTraits<PrecisionType>::max());
177  }
178 
179  RealType Result = Evaluate(*(this->GetInputPath()));
180 
181  return Result;
182 }
183 
184 } // namespace otb
185 
186 #endif
otbComplexMomentPathFunction.h
otb::HuPathFunction::PathType
Superclass::PathType PathType
Definition: otbHuPathFunction.h:75
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbMacro.h
otbHuPathFunction.h
otb::ComplexMomentPathFunction
Calculate the complex moment value over a path.
Definition: otbComplexMomentPathFunction.h:54
otbMsgDevMacro
#define otbMsgDevMacro(x)
Definition: otbMacro.h:64
otb::HuPathFunction::RealType
Superclass::RealType RealType
Definition: otbHuPathFunction.h:85
otb::HuPathFunction::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbHuPathFunction.hxx:46
otb::HuPathFunction::HuPathFunction
HuPathFunction()
Definition: otbHuPathFunction.hxx:37
otb::HuPathFunction::Evaluate
virtual RealType Evaluate() const
Definition: otbHuPathFunction.hxx:171