Orfeo Toolbox  4.0
otbPrintableImageFilter.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  Some parts of this code are derived from ITK. See ITKCopyright.txt
13  for details.
14 
15 
16  This software is distributed WITHOUT ANY WARRANTY; without even
17  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18  PURPOSE. See the above copyright notices for more information.
19 
20 =========================================================================*/
21 
22 #ifndef __otbPrintableImageFilter_h
23 #define __otbPrintableImageFilter_h
24 
25 #include "otbImage.h"
26 #include "itkImageToImageFilter.h"
30 
31 namespace otb
32 {
33 namespace Functor
34 {
41 template<class TInputPixel, class TMaskPixel, class TOutputPixel>
42 class ITK_EXPORT MaskFunctor
43 {
44 public:
46  {
47  m_BackgroundValue = 0;
48  m_ObjectColor.SetSize(3);
49  m_ObjectColor.Fill(255);
50  };
52 
53  typedef TInputPixel InputPixelType;
54  typedef TMaskPixel MaskPixelType;
55  typedef TOutputPixel OutputPixelType;
56  typedef typename OutputPixelType::ValueType OutputInternalPixelType;
57 
58  MaskPixelType GetBackgroundValue()
59  {
60  return m_BackgroundValue;
61  }
62  void SetBackgroundValue(MaskPixelType val)
63  {
64  m_BackgroundValue = val;
65  }
66 
67  OutputPixelType GetObjectColor()
68  {
69  return m_ObjectColor;
70  }
71  void SetObjectColor(OutputPixelType val)
72  {
73  m_ObjectColor = val;
74  }
75 
76  inline OutputPixelType operator ()(InputPixelType inPix, MaskPixelType maskPix) const
77  {
78  OutputPixelType outPix;
79  if (maskPix == m_BackgroundValue)
80  {
81  outPix.SetSize(inPix.Size());
82  for (unsigned int i = 0; i < outPix.Size(); ++i)
83  {
84  outPix[i] = static_cast<OutputInternalPixelType>(inPix[i]);
85  }
86  }
87  else
88  {
89  outPix = m_ObjectColor;
90  }
91 
92  return outPix;
93  }
94 
95 protected:
98 };
99 }
100 
116 template <class TInputImage, class TMaskImage = otb::Image<unsigned char, 2> >
117 class ITK_EXPORT PrintableImageFilter :
118  public itk::ImageToImageFilter<TInputImage, otb::VectorImage<unsigned char, 2> >
119 {
120 public:
126 
127  typedef TInputImage InputImageType;
128  typedef typename InputImageType::PixelType InputPixelType;
129  typedef typename InputImageType::InternalPixelType InputInternalPixelType;
130 // typedef typename itk::NumericTraits<InputPixelType>::ValueType InputInternalPixelType;
131  typedef unsigned char OutputInternalPixelType;
134 
135  typedef TMaskImage MaskImageType;
136  typedef typename MaskImageType::Pointer MaskImagePointerType;
137  typedef typename MaskImageType::PixelType MaskPixelType;
138 
142 
145 
150 
152  itkNewMacro(Self);
153 
155  itkTypeMacro(PrintableImageFilter,
157 
159  void PrintSelf(std::ostream& os, itk::Indent indent) const;
160 
161  void SetChannel(unsigned int channel);
162  const ChannelsType GetChannels(void) const;
163 
164  otbSetObjectMemberMacro(Rescaler, AutomaticInputMinMaxComputation, bool);
165  otbGetObjectMemberMacro(Rescaler, AutomaticInputMinMaxComputation, bool);
166  otbSetObjectMemberMacro(Rescaler, InputMinimum, InputPixelType);
167  otbGetObjectMemberMacro(Rescaler, InputMinimum, InputPixelType);
168  otbSetObjectMemberMacro(Rescaler, InputMaximum, InputPixelType);
169  otbGetObjectMemberMacro(Rescaler, InputMaximum, InputPixelType);
170 
175  void SetInputMask(const MaskImageType * mask);
176 
181  MaskImageType * GetInputMask(void);
182 
183  itkSetMacro(UseMask, bool);
184  itkGetMacro(UseMask, bool);
185 
186  ChannelsType const GetChannelList()
187  {
188  return m_ChannelList;
189  }
190  /* Set the selected channle index (order is important) */
191  void SetChannelList(ChannelsType chList)
192  {
193  if (chList.size() != 3)
194  {
195  itkExceptionMacro(<< "Invalid channel list, size is " << chList.size() << " instead of 3");
196  }
197  m_ChannelList = chList;
198  this->Modified();
199  }
200 
202  void SetObjectColor(OutputPixelType val)
203  {
204  if (val.GetSize() != 3)
205  {
206  itkExceptionMacro(<< "Invalid object color, size is " << val.Size() << " instead of 3");
207  }
208  m_ObjectColor = val;
209  m_MaskFilter->GetFunctor().SetObjectColor(val);
210  this->Modified();
211  }
212  itkGetMacro(ObjectColor, OutputPixelType);
213 
214  void SetBackgroundMaskValue(MaskPixelType val)
215  {
216  m_BackgroundMaskValue = val;
217  m_MaskFilter->GetFunctor().SetBackgroundValue(val);
218  this->Modified();
219  }
220  itkGetMacro(BackgroundMaskValue, MaskPixelType);
221 
230  virtual void GenerateOutputInformation();
231 
232 protected:
233 
235 
236  void BeforeGenerateData();
237  void GenerateData();
238 
239 private:
240 
241  PrintableImageFilter(Self &); // intentionally not implemented
242  void operator =(const Self&); // intentionally not implemented
243 
246  // Foreground mask value
248  // Objects (of the mask) will be displayer with the choosen color.
250  // Use mask
251  bool m_UseMask;
252  // Used channel for output Image
254  // Foreground mask value
255  //MaskPixelType m_ForegroundMaskValue;
256  // Background mask value
258 
259 };
260 
261 } // end namespace otb
262 
263 #ifndef OTB_MANUAL_INSTANTIATION
265 #endif
266 
267 #endif

Generated at Sat Mar 8 2014 16:13:32 for Orfeo Toolbox with doxygen 1.8.3.1