Orfeo Toolbox  4.0
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 {
34 template <class TInputPixel>
35 class AmplitudeFunctor : public ChannelSelectorFunctor<TInputPixel>
36 {
37 public:
43 
45  itkNewMacro(Self);
46 
48  itkTypeMacro(AmplitudeFunctor, itk::Object);
49 
50  typedef TInputPixel PixelType;
55 
57 
60  {
61  std::vector<unsigned int> channels;
62  channels.push_back(0);
63  channels.push_back(1);
64  this->SetChannelList(channels);
65  }
66 
68  virtual ~AmplitudeFunctor() {}
69 
70  const char *GetDescription() const
71  {return "Amplitude"; }
72 
73  virtual unsigned int GetOutputSize() const
74  {
75  return 1;
76  }
77 
78  virtual OutputPixelType operator ()(const VectorPixelType& inPixel) const
79  {
80  OutputPixelType outPixel;
81  outPixel.SetSize(1);
82  assert((this->GetChannelList()).size() == 2);
83  assert((this->GetChannelList())[0] < inPixel.Size());
84  assert((this->GetChannelList())[1] < inPixel.Size());
85  outPixel[0] = ComputeAmplitude(inPixel[(this->GetChannelList())[0]], inPixel[(this->GetChannelList())[1]]);
86  return outPixel;
87  }
88 
90  {
91  //FIXME we don't handle the std::complex<> yet
92  itkExceptionMacro(<< "Can't compute amplitude from a scalar value");
93  }
94 
95  virtual OutputPixelType operator ()(const RGBPixelType& inPixel) const
96  {
97  OutputPixelType outPixel;
98  outPixel.SetSize(1);
99 
100  assert((this->GetChannelList()).size() == 2);
101  assert((this->GetChannelList())[0] < 3);
102  assert((this->GetChannelList())[1] < 3);
103 
104  outPixel[0] = ComputeAmplitude(inPixel[(this->GetChannelList())[0]], inPixel[(this->GetChannelList())[1]]);
105  return outPixel;
106  }
107 
108  virtual OutputPixelType operator ()(const RGBAPixelType& inPixel) const
109  {
110  OutputPixelType outPixel;
111  outPixel.SetSize(1);
112 
113  assert((this->GetChannelList()).size() == 2);
114  assert((this->GetChannelList())[0] < 4);
115  assert((this->GetChannelList())[1] < 4);
116 
117  outPixel[0] = ComputeAmplitude(inPixel[(this->GetChannelList())[0]], inPixel[(this->GetChannelList())[1]]);
118  return outPixel;
119  }
120 
121 private:
123  {
124  return vcl_sqrt(a * a + b * b);
125  }
126 
127 };
128 }
129 }
130 
131 #endif

Generated at Sat Mar 8 2014 15:49:39 for Orfeo Toolbox with doxygen 1.8.3.1