OTB  5.0.0
Orfeo Toolbox
otbAmplitudeFunctor.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbAmplitudeFunctor_h
19 #define __otbAmplitudeFunctor_h
20 
22 
23 namespace otb
24 {
25 namespace Function
26 {
36 template <class TInputPixel>
37 class AmplitudeFunctor : public ChannelSelectorFunctor<TInputPixel>
38 {
39 public:
45 
47  itkNewMacro(Self);
48 
50  itkTypeMacro(AmplitudeFunctor, itk::Object);
51 
52  typedef TInputPixel PixelType;
57 
59 
62  {
63  std::vector<unsigned int> channels;
64  channels.push_back(0);
65  channels.push_back(1);
66  this->SetChannelList(channels);
67  }
69 
71  virtual ~AmplitudeFunctor() {}
72 
73  const char *GetDescription() const
74  {return "Amplitude"; }
75 
76  virtual unsigned int GetOutputSize() const
77  {
78  return 1;
79  }
80 
81  virtual OutputPixelType operator ()(const VectorPixelType& inPixel) const
82  {
83  OutputPixelType outPixel;
84  outPixel.SetSize(1);
85  assert((this->GetChannelList()).size() == 2);
86  assert((this->GetChannelList())[0] < inPixel.Size());
87  assert((this->GetChannelList())[1] < inPixel.Size());
88  outPixel[0] = ComputeAmplitude(inPixel[(this->GetChannelList())[0]], inPixel[(this->GetChannelList())[1]]);
89  return outPixel;
90  }
91 
93  {
94  //FIXME we don't handle the std::complex<> yet
95  itkExceptionMacro(<< "Can't compute amplitude from a scalar value");
96  }
97 
98  virtual OutputPixelType operator ()(const RGBPixelType& inPixel) const
99  {
100  OutputPixelType outPixel;
101  outPixel.SetSize(1);
102 
103  assert((this->GetChannelList()).size() == 2);
104  assert((this->GetChannelList())[0] < 3);
105  assert((this->GetChannelList())[1] < 3);
106 
107  outPixel[0] = ComputeAmplitude(inPixel[(this->GetChannelList())[0]], inPixel[(this->GetChannelList())[1]]);
108  return outPixel;
109  }
110 
111  virtual OutputPixelType operator ()(const RGBAPixelType& inPixel) const
112  {
113  OutputPixelType outPixel;
114  outPixel.SetSize(1);
115 
116  assert((this->GetChannelList()).size() == 2);
117  assert((this->GetChannelList())[0] < 4);
118  assert((this->GetChannelList())[1] < 4);
119 
120  outPixel[0] = ComputeAmplitude(inPixel[(this->GetChannelList())[0]], inPixel[(this->GetChannelList())[1]]);
121  return outPixel;
122  }
123 
124 private:
126  {
127  return vcl_sqrt(a * a + b * b);
128  }
129 
130 };
131 }
132 }
133 
134 #endif
unsigned int Size(void) const
Base class for pixel representation functions.
itk::RGBAPixel< ScalarType > RGBAPixelType
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
const char * GetDescription() const
itk::SmartPointer< Self > Pointer
void SetSize(unsigned int sz, bool destroyExistingData=true)
virtual OutputPixelType operator()(const VectorPixelType &inPixel) const
ScalarType ComputeAmplitude(ScalarType a, ScalarType b) const
itk::RGBPixel< ScalarType > RGBPixelType
virtual unsigned int GetOutputSize() const