Orfeo Toolbox  3.16
otbRenderingFunction.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 __otbRenderingFunction_h
19 #define __otbRenderingFunction_h
20 
21 #include "itkObject.h"
22 #include "itkObjectFactory.h"
24 #include "itkRGBPixel.h"
25 #include "itkRGBAPixel.h"
27 #include "itkHistogram.h"
28 #include "otbObjectList.h"
30 #include "itkListSample.h"
32 #include "itkConceptChecking.h"
34 
35 #include "itkMetaDataDictionary.h"
36 
37 namespace otb
38 {
39 
40 namespace Function
41 {
42 
49 template <class TPixel, class TRGBPixel>
51  : public itk::Object
52 {
53 public:
59 
61  itkTypeMacro(RenderingFunction, Object);
62 
64  typedef TRGBPixel OutputPixelType;
65  typedef TPixel PixelType;
66  typedef typename itk::NumericTraits<PixelType>::ValueType ScalarType;
70  typedef typename itk::NumericTraits<ScalarType>::RealType RealScalarType;
72 
76 
78 
86 
87  itkConceptMacro(SameTypeCheck,
89 
91 
93 
95  virtual OutputPixelType Evaluate(const PixelType& spixel) const
96  {
98  }
99 
101  virtual const std::string Describe(const PixelType& spixel) const = 0;
102 
104  virtual InternalPixelType EvaluatePixelRepresentation(const PixelType& spixel) const = 0; //FIXME pure virtual or exception?
105 
107  virtual unsigned int GetPixelRepresentationSize() const = 0; //FIXME pure virtual or exception?
108 
110  virtual OutputPixelType EvaluateTransferFunction(const InternalPixelType& spixel) const = 0; //FIXME pure virtual or exception?
111 
113  virtual void SetParameters(const ParametersType&)
114  {
115  itkExceptionMacro(<< "Subclasses should override this method");
116  }
118  {
119  itkExceptionMacro(<< "Subclasses should override this method");
120  }
121 
122  virtual void SetChannelList(std::vector<unsigned int>& /*channels*/)
123  {
124  itkExceptionMacro(<< "Subclasses should override this method");
125  }
126 
127  virtual std::vector<unsigned int> GetChannelList()
128  {
129  itkExceptionMacro(<< "Subclasses should override this method");
130  }
131 
132  virtual void SetAutoMinMax(bool /*autoMinMax*/)
133  {
134  itkExceptionMacro(<< "Subclasses should override this method");
135  }
136 
139  {
140  //FIXME Update condition?
141  return m_HistogramList;
142  }
143 
145  virtual void SetListSample(ListSamplePointerType listSample)
146  {
147  if (this->m_ListSample != listSample)
148  {
149  m_ListSample = listSample;
150  this->Modified();
151  }
152  }
153 
154 
156  itkSetMacro( NoDataValue, ScalarType );
157 
159  itkGetMacro( NoDataValue, ScalarType );
160  itkGetConstMacro( NoDataValue, ScalarType );
161 
165  // REVIEW: I agree, we should not be calling intialize ourselve, it
166  // would better be seamless
167  virtual void Initialize(const MetaDataDictionaryType& itkNotUsed(metadatadictionary)){} //FIXME should disappear and be
168  //automatic (IsModified())
169 
170 protected:
173  {
175  m_ListSample = NULL;
176  m_NoDataValue = itk::NumericTraits<ScalarType>::Zero;
177  }
179  virtual ~RenderingFunction() {}
180 
181  virtual void RenderHistogram()
182  {
183  int m_NumberOfHistogramBins = 255; //FIXME is it to be accessed from outside?
184  if (m_ListSample.IsNull())
185  {
186  itkExceptionMacro(<< "No listSample provided to render histogram");
187  }
188  // Create the histogram generation filter
189  ListSamplePointerType pixelRepresentationListSample = ListSampleType::New();
190  for (typename ListSampleType::ConstIterator it = m_ListSample->Begin(); it != m_ListSample->End(); ++it)
191  {
192  PixelType sample;
193  VisualizationPixelTraits::Convert(it.GetMeasurementVector(), sample);
194  SampleType sampleVector;
196  pixelRepresentationListSample->PushBack(sampleVector);
197  }
198 
199  typename HistogramFilterType::Pointer histogramFilter = HistogramFilterType::New();
200  histogramFilter->SetListSample(pixelRepresentationListSample);
201 
202  histogramFilter->SetNumberOfBins(m_NumberOfHistogramBins);
203  histogramFilter->NoDataFlagOn();
204  histogramFilter->SetNoDataValue(m_NoDataValue);
205 
206  // Generate
207  histogramFilter->Update();
208  otbMsgDevMacro(<< "ImageRenderingFunction::RenderHistogram(): Histogram has been updated");
209 
210  // Retrieve the histogram
211  m_HistogramList = histogramFilter->GetOutput();
212  }
213 
215  {
216  return m_ListSample;
217  }
218 
219 
220 private:
221  RenderingFunction(const Self&); //purposely not implemented
222  void operator =(const Self&); //purposely not implemented
226 };
227 } // end namespace Function
228 } // end namepsace otb
229 
230 #endif

Generated at Sun May 19 2013 00:47:00 for Orfeo Toolbox with doxygen 1.8.3.1