OTB  10.0.0
Orfeo Toolbox
otbPhaseFunctor.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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 otbPhaseFunctor_h
22 #define otbPhaseFunctor_h
23 
25 
26 namespace otb
27 {
28 namespace Function
29 {
39 template <class TInputPixel>
40 class PhaseFunctor : public ChannelSelectorFunctor<TInputPixel>
41 {
42 public:
44  typedef PhaseFunctor Self;
45  typedef itk::Object Superclass;
46  typedef itk::SmartPointer<Self> Pointer;
47  typedef itk::SmartPointer<const Self> ConstPointer;
48 
50  itkNewMacro(Self);
51 
53  itkTypeMacro(PhaseFunctor, itk::Object);
54 
55  typedef TInputPixel PixelType;
56  typedef typename itk::NumericTraits<PixelType>::ValueType ScalarType;
57  typedef itk::VariableLengthVector<ScalarType> VectorPixelType;
58  typedef itk::RGBPixel<ScalarType> RGBPixelType;
59  typedef itk::RGBAPixel<ScalarType> RGBAPixelType;
60 
62 
65  {
66  std::vector<unsigned int> channels;
67  channels.push_back(0);
68  channels.push_back(1);
69  this->SetChannelList(channels);
70  }
72 
74  ~PhaseFunctor() override
75  {
76  }
77 
78  const char* GetDescription() const
79  {
80  return "Phase";
81  }
82 
83  unsigned int GetOutputSize() const override
84  {
85  return 1;
86  }
87 
88  OutputPixelType operator()(const VectorPixelType& inPixel) const override
89  {
90  OutputPixelType outPixel;
91  outPixel.SetSize(1);
92  assert((this->GetChannelList()).size() == 2);
93  assert((this->GetChannelList())[0] < inPixel.Size());
94  assert((this->GetChannelList())[1] < inPixel.Size());
95  outPixel[0] = ComputePhase(inPixel[(this->GetChannelList())[0]], inPixel[(this->GetChannelList())[1]]);
96  return outPixel;
97  }
98 
99  OutputPixelType operator()(ScalarType /*inPixel*/) const override
100  {
101  // FIXME we don't handle the std::complex<> yet
102  itkExceptionMacro(<< "Can't compute amplitude from a scalar value");
103  }
104 
105  OutputPixelType operator()(const RGBPixelType& inPixel) const override
106  {
107  OutputPixelType outPixel;
108  outPixel.SetSize(1);
109 
110  assert((this->GetChannelList())[0] < 3);
111  assert((this->GetChannelList())[1] < 3);
112 
113  outPixel[0] = ComputePhase(inPixel[(this->GetChannelList())[0]], inPixel[(this->GetChannelList())[1]]);
114  return outPixel;
115  }
116 
117  OutputPixelType operator()(const RGBAPixelType& inPixel) const override
118  {
119  OutputPixelType outPixel;
120  outPixel.SetSize(1);
121 
122  assert((this->GetChannelList())[0] < 4);
123  assert((this->GetChannelList())[1] < 4);
124 
125  outPixel[0] = ComputePhase(inPixel[(this->GetChannelList())[0]], inPixel[(this->GetChannelList())[1]]);
126  return outPixel;
127  }
128 
129 private:
131  {
132  return std::atan2(b, a);
133  }
134 };
135 }
136 }
137 
138 #endif
Base class for pixel representation functions.
virtual std::vector< unsigned int > GetChannelList() const
typename itk::NumericTraits< PixelType >::ValueType ScalarType
itk::VariableLengthVector< ScalarType > VectorPixelType
virtual void SetChannelList(std::vector< unsigned int > channels)
Compute the module from the selected channel in the input.
const char * GetDescription() const
itk::SmartPointer< const Self > ConstPointer
ScalarType ComputePhase(ScalarType a, ScalarType b) const
itk::RGBPixel< ScalarType > RGBPixelType
itk::SmartPointer< Self > Pointer
OutputPixelType operator()(const RGBAPixelType &inPixel) const override
unsigned int GetOutputSize() const override
itk::RGBAPixel< ScalarType > RGBAPixelType
itk::NumericTraits< PixelType >::ValueType ScalarType
OutputPixelType operator()(const VectorPixelType &inPixel) const override
OutputPixelType operator()(const RGBPixelType &inPixel) const override
OutputPixelType operator()(ScalarType) const override
VectorPixelType OutputPixelType
itk::VariableLengthVector< ScalarType > VectorPixelType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.