OTB  9.0.0
Orfeo Toolbox
otbAmplitudeFunctor.h
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 otbAmplitudeFunctor_h
22 #define otbAmplitudeFunctor_h
23 
25 
26 namespace otb
27 {
28 namespace Function
29 {
39 template <class TInputPixel>
40 class AmplitudeFunctor : public ChannelSelectorFunctor<TInputPixel>
41 {
42 public:
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(AmplitudeFunctor, 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  ~AmplitudeFunctor() override
75  {
76  }
77 
78  const char* GetDescription() const
79  {
80  return "Amplitude";
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] = ComputeAmplitude(inPixel[(this->GetChannelList())[0]], inPixel[(this->GetChannelList())[1]]);
96  return outPixel;
97  }
98 
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()).size() == 2);
111  assert((this->GetChannelList())[0] < 3);
112  assert((this->GetChannelList())[1] < 3);
113 
114  outPixel[0] = ComputeAmplitude(inPixel[(this->GetChannelList())[0]], inPixel[(this->GetChannelList())[1]]);
115  return outPixel;
116  }
117 
118  OutputPixelType operator()(const RGBAPixelType& inPixel) const override
119  {
120  OutputPixelType outPixel;
121  outPixel.SetSize(1);
122 
123  assert((this->GetChannelList()).size() == 2);
124  assert((this->GetChannelList())[0] < 4);
125  assert((this->GetChannelList())[1] < 4);
126 
127  outPixel[0] = ComputeAmplitude(inPixel[(this->GetChannelList())[0]], inPixel[(this->GetChannelList())[1]]);
128  return outPixel;
129  }
130 
131 private:
133  {
134  return std::sqrt(a * a + b * b);
135  }
136 };
137 }
138 }
139 
140 #endif
otb::Function::AmplitudeFunctor::RGBAPixelType
itk::RGBAPixel< ScalarType > RGBAPixelType
Definition: otbAmplitudeFunctor.h:59
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Function::AmplitudeFunctor::ComputeAmplitude
ScalarType ComputeAmplitude(ScalarType a, ScalarType b) const
Definition: otbAmplitudeFunctor.h:132
otb::Function::ChannelSelectorFunctor::RGBAPixelType
itk::RGBAPixel< ScalarType > RGBAPixelType
Definition: otbChannelSelectorFunctor.h:64
otb::Function::AmplitudeFunctor::RGBPixelType
itk::RGBPixel< ScalarType > RGBPixelType
Definition: otbAmplitudeFunctor.h:58
otb::Function::AmplitudeFunctor::ScalarType
itk::NumericTraits< PixelType >::ValueType ScalarType
Definition: otbAmplitudeFunctor.h:56
otb::Function::AmplitudeFunctor::Superclass
itk::Object Superclass
Definition: otbAmplitudeFunctor.h:45
otb::Function::AmplitudeFunctor::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbAmplitudeFunctor.h:47
otbChannelSelectorFunctor.h
otb::Function::AmplitudeFunctor::AmplitudeFunctor
AmplitudeFunctor()
Definition: otbAmplitudeFunctor.h:64
otb::Function::AmplitudeFunctor::GetOutputSize
unsigned int GetOutputSize() const override
Definition: otbAmplitudeFunctor.h:83
otb::Function::AmplitudeFunctor::VectorPixelType
itk::VariableLengthVector< ScalarType > VectorPixelType
Definition: otbAmplitudeFunctor.h:57
otb::Function::ChannelSelectorFunctor::RGBPixelType
itk::RGBPixel< ScalarType > RGBPixelType
Definition: otbChannelSelectorFunctor.h:63
otb::Function::ChannelSelectorFunctor::SetChannelList
virtual void SetChannelList(std::vector< unsigned int > channels)
Definition: otbChannelSelectorFunctor.h:137
otb::Function::ChannelSelectorFunctor::OutputPixelType
VectorPixelType OutputPixelType
Definition: otbChannelSelectorFunctor.h:66
otb::Function::AmplitudeFunctor::OutputPixelType
VectorPixelType OutputPixelType
Definition: otbAmplitudeFunctor.h:61
otb::Function::ChannelSelectorFunctor::GetChannelList
virtual std::vector< unsigned int > GetChannelList() const
Definition: otbChannelSelectorFunctor.h:132
otb::Function::AmplitudeFunctor::~AmplitudeFunctor
~AmplitudeFunctor() override
Definition: otbAmplitudeFunctor.h:74
otb::Function::ChannelSelectorFunctor::VectorPixelType
itk::VariableLengthVector< ScalarType > VectorPixelType
Definition: otbChannelSelectorFunctor.h:62
otb::Function::AmplitudeFunctor::GetDescription
const char * GetDescription() const
Definition: otbAmplitudeFunctor.h:78
otb::Function::AmplitudeFunctor::operator()
OutputPixelType operator()(ScalarType) const override
Definition: otbAmplitudeFunctor.h:99
otb::Function::AmplitudeFunctor::Self
AmplitudeFunctor Self
Definition: otbAmplitudeFunctor.h:44
otb::Function::ChannelSelectorFunctor::ScalarType
itk::NumericTraits< PixelType >::ValueType ScalarType
Definition: otbChannelSelectorFunctor.h:61
otb::Function::ChannelSelectorFunctor
Base class for pixel representation functions.
Definition: otbChannelSelectorFunctor.h:45
otb::Function::AmplitudeFunctor::operator()
OutputPixelType operator()(const VectorPixelType &inPixel) const override
Definition: otbAmplitudeFunctor.h:88
otb::Function::AmplitudeFunctor::PixelType
TInputPixel PixelType
Definition: otbAmplitudeFunctor.h:53
otb::Function::AmplitudeFunctor::operator()
OutputPixelType operator()(const RGBAPixelType &inPixel) const override
Definition: otbAmplitudeFunctor.h:118
otb::Function::AmplitudeFunctor::operator()
OutputPixelType operator()(const RGBPixelType &inPixel) const override
Definition: otbAmplitudeFunctor.h:105
otb::Function::AmplitudeFunctor::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbAmplitudeFunctor.h:46
otb::Function::AmplitudeFunctor
Compute the module from the selected channel in the input.
Definition: otbAmplitudeFunctor.h:40