Orfeo Toolbox  3.16
otbNoStretchRenderingFunction.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 __otbNoStretchRenderingFunction_h
19 #define __otbNoStretchRenderingFunction_h
20 
21 #include <cassert>
22 #include <iomanip>
23 #include <vector>
24 
25 #include "otbMacro.h"
26 #include "otbI18n.h"
29 #include "otbViewerConst.h"
30 
31 #include "otbRenderingFunction.h"
32 
33 
34 namespace otb
35 {
36  namespace Function
37  {
38  // Identity class template defined in otbStandardRenderingFunction.h
39  // template <class TInputPixel, class TOutputPixel> class Identity;
40 
48  template <class TPixel, class TRGBPixel,
49  class TPixelRepresentationFunction = ChannelSelectorFunctor<TPixel>,
50  class TTransferFunction = Identity<
51  typename itk::NumericTraits<typename itk::NumericTraits<TPixel>::ValueType>::RealType,
52  typename itk::NumericTraits<typename itk::NumericTraits<TPixel>::ValueType>::RealType
53  > >
55  : public StandardRenderingFunction<TPixel, TRGBPixel, TPixelRepresentationFunction, TTransferFunction>
56  {
57  public:
63 
65  //itkTypeMacro(NoStretchRenderingFunction, RenderingFunction);
67 
69  itkNewMacro(Self);
70 
72  typedef TRGBPixel OutputPixelType;
73  typedef typename OutputPixelType::ValueType OutputValueType;
74  typedef TPixel PixelType;
75  typedef typename itk::NumericTraits<PixelType>::ValueType ScalarType;
78  typedef typename itk::NumericTraits<ScalarType>::RealType RealScalarType;
81 
82  // MDE
83  typedef TTransferFunction TransferFunctionType;
84  typedef TPixelRepresentationFunction PixelRepresentationFunctionType;
85 
86  typedef typename PixelRepresentationFunctionType::Pointer PixelRepresentationFunctionPointerType;
87  typedef typename PixelRepresentationFunctionType::ChannelListType ChannelListType;
88  // \MDE
89 
101  {
102  if ((spixel.Size() != 1) && (spixel.Size() != 3) && (spixel.Size() != 4))
103  {
104  itkExceptionMacro( << "the PixelRepresentation function should give an output of "
105  << "size 1, 3 or 4 otherwise I don't know how to make an RGB of it !" );
106  }
107 
109 
110  if (spixel.Size() == 1)
111  {
112  OutputValueType value = ClippedValue(this->m_TransferFunction(spixel[0]));
113  output[0] = value;
114  output[1] = value;
115  output[2] = value;
116  }
117  else
118  {
119  output[0] = ClippedValue(this->m_TransferFunction(spixel[0]));
120  output[1] = ClippedValue(this->m_TransferFunction(spixel[1]));
121  output[2] = ClippedValue(this->m_TransferFunction(spixel[2]));
122  }
123 
124  if ((spixel.Size() == 4) && (output.Size() == 4))
125  {
126  assert((spixel[3] >= SCREEN_COLOR_MIN_VALUE) && (spixel[3] <= SCREEN_COLOR_MAX_VALUE));
127  output[3] = static_cast<OutputValueType>(spixel[3]); //just copy the alpha channel
128  }
129 
130  return output;
131  }
132 
133  virtual void Initialize() //FIXME should disappear and be automatic (IsModified())
134  {
135  if ((this->GetMTime() > this->m_UTime)
136  || (this->GetPixelRepresentationFunction()->GetMTime() > this->m_UTime))
137  //NOTE: we assume that Transfer function have no parameters
138  {
139  if ((this->GetListSample()).IsNotNull())
140  {
141  // The size of the Vector was unknow at construction time for
142  // the m_PixelRepresentationFunction, now, we may get a better
143  // default
144  if (this->m_PixelRepresentationFunction->IsUsingDefaultParameters())
145  {
146  // Case of image with 4 bands or more : Display in the
147  // B, G, R, NIR channel order
148  if (this->GetListSample()->GetMeasurementVectorSize() >= 4)
149  {
150  this->m_PixelRepresentationFunction->SetRedChannelIndex(2);
151  this->m_PixelRepresentationFunction->SetGreenChannelIndex(1);
152  this->m_PixelRepresentationFunction->SetBlueChannelIndex(0);
153  }
154 
155  // Classic case
156  if (this->GetListSample()->GetMeasurementVectorSize() == 3)
157  {
158  this->m_PixelRepresentationFunction->SetRedChannelIndex(0);
159  this->m_PixelRepresentationFunction->SetGreenChannelIndex(1);
160  this->m_PixelRepresentationFunction->SetBlueChannelIndex(2);
161  }
162 
163  }
164  }
165 
166  this->RenderHistogram();
167 
168  this->m_UTime.Modified();
169  }
170  }
171 
175  virtual void SetParameters(const ParametersType & /* parameters */)
176  {
177  otbMsgDevMacro(<< "NoStretchRenderingFunction::SetParameters: no parameters needed");
178  }
179 
184  {
185  unsigned int nbBands = this->m_PixelRepresentationFunction->GetOutputSize();
186  ParametersType param;
187  param.SetSize(2 * nbBands);
188 
189  for (unsigned int i = 0; i < nbBands; ++i)
190  {
191  // Min Band
192  param.SetElement(2 * i, SCREEN_COLOR_MIN_VALUE);
193  // Max Band
194  param.SetElement(2 * i + 1, SCREEN_COLOR_MAX_VALUE);
195  }
196 
197  return param;
198  }
199 
203  virtual void SetAutoMinMax(bool /*val*/)
204  {
205  }
206 
207  protected:
212 
217 
223  {
224  if (input > SCREEN_COLOR_MAX_VALUE)
225  {
226  return SCREEN_COLOR_MAX_VALUE;
227  }
228  else if (input < SCREEN_COLOR_MIN_VALUE)
229  {
230  return SCREEN_COLOR_MIN_VALUE;
231  }
232  else
233  {
234  return static_cast<OutputValueType>(input);
235  }
236  }
237 
238  private:
239 
240  NoStretchRenderingFunction(const Self&); //purposely not implemented
241  void operator=(const Self&); //purposely not implemented
242 
243  };
244 
245  } // end namespace Functor
246 
247 } // end namespace otb
248 
249 #endif /* __otbNoStretchRenderingFunction_h */

Generated at Sun Feb 3 2013 00:40:32 for Orfeo Toolbox with doxygen 1.8.1.1