Orfeo Toolbox  4.0
otbMultiChannelGAndRIndexImageFilter.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 __otbMultiChannelGAndRIndexImageFilter_h
19 #define __otbMultiChannelGAndRIndexImageFilter_h
20 
21 #include "itkUnaryFunctorImageFilter.h"
23 #include "otbSoilIndicesFunctor.h"
24 
25 namespace otb
26 {
27 
38 template <class TInputImage, class TOutputImage,
39  class TFunction = Functor::IR<typename TInputImage::InternalPixelType,
40  typename TInputImage::InternalPixelType,
41  typename TOutputImage::PixelType> >
43  : public itk::UnaryFunctorImageFilter<TInputImage, TOutputImage, TFunction>
44 {
45 public:
51 
53  itkNewMacro(Self);
54 
57 
59  typedef TFunction FunctorType;
60 
62  itkSetMacro(GreenIndex, unsigned int);
63  itkGetMacro(GreenIndex, unsigned int);
65  itkSetMacro(RedIndex, unsigned int);
66  itkGetMacro(RedIndex, unsigned int);
67 
69  void SetIndex(BandName::BandName band, unsigned int channel)
70  {
71  if (band == BandName::RED)
72  {
73  m_RedIndex = channel;
74  }
75  if (band == BandName::GREEN)
76  {
77  m_GreenIndex = channel;
78  }
79  }
81  unsigned int GetIndex(BandName::BandName band) const
82  {
83  if (band == BandName::RED)
84  {
85  return m_RedIndex;
86  }
87  if (band == BandName::GREEN)
88  {
89  return m_GreenIndex;
90  }
91  }
92 
93 protected:
95  MultiChannelGAndRIndexImageFilter() : m_GreenIndex(1), m_RedIndex(2) {};
99  virtual void BeforeThreadedGenerateData()
100  {
101  unsigned int lNbChan = this->GetInput()->GetNumberOfComponentsPerPixel();
102  if (m_GreenIndex < 1 || m_RedIndex < 1 ||
103  m_GreenIndex > lNbChan || m_RedIndex > lNbChan)
104  {
105  itkExceptionMacro(<< "Channel indices must belong to range [1, ...[");
106  }
107  this->GetFunctor().SetGreenIndex(m_GreenIndex);
108  this->GetFunctor().SetRedIndex(m_RedIndex);
109  }
111  void PrintSelf(std::ostream& os, itk::Indent indent) const
112  {
113  this->Superclass::PrintSelf(os, indent);
114  os << indent << "Green index: " << m_GreenIndex << std::endl;
115  os << indent << "Red index: " << m_RedIndex << std::endl;
116  }
117 private:
118  MultiChannelGAndRIndexImageFilter(const Self &); //purposely not implemented
119  void operator =(const Self&); //purposely not implemented
121  unsigned int m_GreenIndex;
123  unsigned int m_RedIndex;
124 };
125 } // end namespace otb
126 
127 #endif

Generated at Sat Mar 8 2014 16:10:07 for Orfeo Toolbox with doxygen 1.8.3.1