Orfeo Toolbox  3.16
otbRenderingImageFilter.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 __otbRenderingImageFilter_h
19 #define __otbRenderingImageFilter_h
20 
23 #include "otbImage.h"
24 #include "itkRGBAPixel.h"
25 #include "otbRenderingFunction.h"
27 
28 #include "itkMetaDataDictionary.h"
29 
30 namespace otb
31 {
32 namespace Functor
33 {
51 template <class TPixel, class TRGBPixel>
53 {
54 public:
60  typedef TPixel PixelType;
61  typedef typename itk::NumericTraits<PixelType>::ValueType ScalarPixelType;
65 
67 
69  inline TRGBPixel operator ()(const PixelType& pixel) const
70  {
71  return m_Function->Evaluate(pixel);
72  }
73 
76  {
77  // Default rendering function
78 // m_Function = DefaultRenderingFunctionType::New();
79  }
80 
82  virtual ~RenderingFunctor(){}
83 
88  {
89  m_Function = function;
90  }
91 
96  {
97  return m_Function;
98  }
99 
103  void InitializeFunction(const MetaDataDictionaryType& metadatadictionary)
104  {
105  m_Function->Initialize(metadatadictionary);
106  }
107 
108 private:
111 };
112 } // end namespace Functor
113 
123 template <class TInputImage, class TOutputImage = Image<itk::RGBAPixel<unsigned char>, 2> >
125  : public itk::UnaryFunctorImageFilter<TInputImage, TOutputImage,
126  Functor::RenderingFunctor
127  <typename TInputImage::PixelType,
128  typename TOutputImage::PixelType> >
129 {
130 public:
134  <TInputImage, TOutputImage, Functor::RenderingFunctor
135  <typename TInputImage::PixelType,
136  typename TOutputImage::PixelType> > Superclass;
139 
141  itkNewMacro(Self);
142 
145 
148  <typename TInputImage::PixelType,
149  typename TOutputImage::PixelType> RenderingFunctorType;
151 
157  {
158  this->GetFunctor().SetFunction(function);
159  this->Modified();
160  }
161 
167  {
168  if (this->GetFunctor().GetFunction() == NULL)
169  {
171  }
172  return this->GetFunctor().GetFunction();
173  }
174 
178  virtual void BeforeThreadedGenerateData(void)
179  {
180  // Call the superclass implementation
182 
183  if (this->GetFunctor().GetFunction() == NULL)
184  {
185  otbMsgDevMacro(<< "RenderingFunction set to default");
187  }
188 
189  // Initialize the rendering function
190  this->GetFunctor().InitializeFunction(this->GetInput()->GetMetaDataDictionary());
191 
192  otbMsgDevMacro(<< "RenderingImageFilter::BeforeThreadedGenerateData():");
193  otbMsgDevMacro(<< " - Output functor size "
194  << (this->GetFunctor().GetFunction())->GetPixelRepresentationSize());
195  otbMsgDevMacro(<< "Rendering Funtion:" << this->GetFunctor().GetFunction());
196 
197  //Check if the rendering function channels are compatible with the image
198  //might want to be more generic here one day.
199 // unsigned int numberOfInputChannels = this->GetInput()->GetNumberOfComponentsPerPixel();
200  itk::ImageRegionConstIterator<TInputImage> it(this->GetInput(), this->GetInput()->GetBufferedRegion());
201  unsigned int numberOfInputChannels = VisualizationPixelTraits::PixelSize(it.Get());
202  std::vector<unsigned int> channels = (this->GetFunctor().GetFunction())->GetChannelList();
203  for (unsigned int i = 0; i < channels.size(); ++i)
204  {
205  if (channels[i] >= numberOfInputChannels)
206  {
207  itkExceptionMacro(<< "Channels specified as input (" << channels[i] << ") is not compatible "
208  << "with the size of the image: " << numberOfInputChannels);
209  }
210  }
211 
212  }
213 
214 protected:
219 
221  typename TInputImage::PixelType,
222  typename TOutputImage::PixelType> DefaultRenderingFunctionType;
223 
225  {
226  otbMsgDevMacro(<< "WARNING: using the default rendering function");
227 
228  this->GetFunctor().SetFunction(DefaultRenderingFunctionType::New());
229  }
230 
231 private:
232  RenderingImageFilter(const Self&); //purposely not implemented
233  void operator =(const Self&); //purposely not implemented
234 };
235 } // end namespace otb
236 
237 #endif

Generated at Sun Feb 3 2013 00:44:58 for Orfeo Toolbox with doxygen 1.8.1.1