OTB  6.1.0
Orfeo Toolbox
otbAmplitudeFunctor.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2017 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:
48 
50  itkNewMacro(Self);
51 
53  itkTypeMacro(AmplitudeFunctor, itk::Object);
54 
55  typedef TInputPixel PixelType;
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() ITK_OVERRIDE {}
75 
76  const char *GetDescription() const
77  {return "Amplitude"; }
78 
79  unsigned int GetOutputSize() const ITK_OVERRIDE
80  {
81  return 1;
82  }
83 
84  OutputPixelType operator ()(const VectorPixelType& inPixel) const ITK_OVERRIDE
85  {
86  OutputPixelType outPixel;
87  outPixel.SetSize(1);
88  assert((this->GetChannelList()).size() == 2);
89  assert((this->GetChannelList())[0] < inPixel.Size());
90  assert((this->GetChannelList())[1] < inPixel.Size());
91  outPixel[0] = ComputeAmplitude(inPixel[(this->GetChannelList())[0]], inPixel[(this->GetChannelList())[1]]);
92  return outPixel;
93  }
94 
96  {
97  //FIXME we don't handle the std::complex<> yet
98  itkExceptionMacro(<< "Can't compute amplitude from a scalar value");
99  }
100 
101  OutputPixelType operator ()(const RGBPixelType& inPixel) const ITK_OVERRIDE
102  {
103  OutputPixelType outPixel;
104  outPixel.SetSize(1);
105 
106  assert((this->GetChannelList()).size() == 2);
107  assert((this->GetChannelList())[0] < 3);
108  assert((this->GetChannelList())[1] < 3);
109 
110  outPixel[0] = ComputeAmplitude(inPixel[(this->GetChannelList())[0]], inPixel[(this->GetChannelList())[1]]);
111  return outPixel;
112  }
113 
114  OutputPixelType operator ()(const RGBAPixelType& inPixel) const ITK_OVERRIDE
115  {
116  OutputPixelType outPixel;
117  outPixel.SetSize(1);
118 
119  assert((this->GetChannelList()).size() == 2);
120  assert((this->GetChannelList())[0] < 4);
121  assert((this->GetChannelList())[1] < 4);
122 
123  outPixel[0] = ComputeAmplitude(inPixel[(this->GetChannelList())[0]], inPixel[(this->GetChannelList())[1]]);
124  return outPixel;
125  }
126 
127 private:
129  {
130  return vcl_sqrt(a * a + b * b);
131  }
132 
133 };
134 }
135 }
136 
137 #endif
Base class for pixel representation functions.
itk::RGBAPixel< ScalarType > RGBAPixelType
OutputPixelType operator()(const VectorPixelType &inPixel) const ITK_OVERRIDE
itk::NumericTraits< PixelType >::ValueType ScalarType
itk::NumericTraits< PixelType >::ValueType ScalarType
Compute the module from the selected channel in the input.
virtual void SetChannelList(std::vector< unsigned int > channels)
itk::VariableLengthVector< ScalarType > VectorPixelType
itk::SmartPointer< const Self > ConstPointer
virtual std::vector< unsigned int > GetChannelList() const
unsigned int GetOutputSize() const ITK_OVERRIDE
const char * GetDescription() const
itk::SmartPointer< Self > Pointer
ScalarType ComputeAmplitude(ScalarType a, ScalarType b) const
void SetSize(unsigned int sz, TReallocatePolicy reallocatePolicy, TKeepValuesPolicy keepValues)
itk::RGBPixel< ScalarType > RGBPixelType