ENH: fixing vis to work with RGBA pixels: DirectRenderingFunction now becomes useless
1.1 --- a/Code/Visualization/otbDirectRenderingFunction.h Fri Jul 03 00:07:10 2009 +0800
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,204 +0,0 @@
1.4 -/*=========================================================================
1.5 -
1.6 - Program: ORFEO Toolbox
1.7 - Language: C++
1.8 - Date: $Date$
1.9 - Version: $Revision$
1.10 -
1.11 -
1.12 - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
1.13 - See OTBCopyright.txt for details.
1.14 -
1.15 -
1.16 - This software is distributed WITHOUT ANY WARRANTY; without even
1.17 - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
1.18 - PURPOSE. See the above copyright notices for more information.
1.19 -
1.20 -=========================================================================*/
1.21 -#ifndef __otbDirectRenderingFunction_h
1.22 -#define __otbDirectRenderingFunction_h
1.23 -
1.24 -#include "otbRenderingFunction.h"
1.25 -#include "otbMacro.h"
1.26 -#include <assert.h>
1.27 -#include <iomanip>
1.28 -
1.29 -namespace otb
1.30 -{
1.31 -namespace Function
1.32 -{
1.33 -
1.34 -/** \class DirectRenderingFunction
1.35 - * \brief Standard rendering.
1.36 - *
1.37 - * This function just reproduce the input value at the output
1.38 - * with the risk of truncated values. Use it if you know that
1.39 - * your input values are between 0 and 255.
1.40 - *
1.41 - * \ingroup Visualization
1.42 - */
1.43 -template <class TPixelPrecision, class TRGBPixel >
1.44 -class DirectRenderingFunction
1.45 - : public RenderingFunction<TPixelPrecision,TRGBPixel>
1.46 -{
1.47 -public:
1.48 - /** Standard class typedefs */
1.49 - typedef DirectRenderingFunction Self;
1.50 - typedef RenderingFunction<TPixelPrecision,TRGBPixel> Superclass;
1.51 - typedef itk::SmartPointer<Self> Pointer;
1.52 - typedef itk::SmartPointer<const Self> ConstPointer;
1.53 -
1.54 - /** type macro */
1.55 - itkTypeMacro(DirectRenderingFunction,RenderingFunction);
1.56 -
1.57 - /** new macro */
1.58 - itkNewMacro(Self);
1.59 -
1.60 - /** PixelType macros */
1.61 - typedef TRGBPixel OutputPixelType;
1.62 - typedef typename OutputPixelType::ValueType OutputValueType;
1.63 - typedef TPixelPrecision PixelType;
1.64 - typedef typename itk::NumericTraits<PixelType>::ValueType ScalarType;
1.65 - typedef itk::VariableLengthVector<ScalarType> VectorPixelType;
1.66 - typedef itk::RGBPixel<ScalarType> RGBPixelType;
1.67 - typedef itk::RGBAPixel<ScalarType> RGBAPixelType;
1.68 -
1.69 - /** Evaluate method (scalar version) */
1.70 - inline virtual const OutputPixelType Evaluate(ScalarType spixel) const
1.71 - {
1.72 - OutputPixelType resp;
1.73 - resp.SetRed(spixel);
1.74 - resp.SetGreen(spixel);
1.75 - resp.SetBlue(spixel);
1.76 - return resp;
1.77 - }
1.78 - /** Evaluate method (vector version) */
1.79 - inline virtual const OutputPixelType Evaluate(const VectorPixelType & vpixel) const
1.80 - {
1.81 - OutputPixelType resp;
1.82 - resp.Fill(itk::NumericTraits<typename OutputPixelType::ValueType>::max());
1.83 - resp.SetRed(vpixel[m_RedChannelIndex]);
1.84 - resp.SetGreen(vpixel[m_GreenChannelIndex]);
1.85 - resp.SetBlue(vpixel[m_BlueChannelIndex]);
1.86 - return resp;
1.87 - }
1.88 - /** Evaluate method (RGB pixel version) */
1.89 - inline virtual const OutputPixelType Evaluate(const RGBPixelType & vpixel) const
1.90 - {
1.91 - OutputPixelType resp;
1.92 - resp.Fill(itk::NumericTraits<typename OutputPixelType::ValueType>::max());
1.93 - resp.SetRed(vpixel[m_RedChannelIndex]);
1.94 - resp.SetGreen(vpixel[m_GreenChannelIndex]);
1.95 - resp.SetBlue(vpixel[m_BlueChannelIndex]);
1.96 - return resp;
1.97 - }
1.98 - /** Evaluate method (RGBA pixel version) */
1.99 - inline virtual const OutputPixelType Evaluate(const RGBAPixelType & vpixel) const
1.100 - {
1.101 - OutputPixelType resp;
1.102 -// resp.Fill(itk::NumericTraits<typename OutputPixelType::ValueType>::max());
1.103 - if (OutputPixelType::Length == 4)
1.104 - {//Propagate the alpha channel
1.105 - resp[3] = vpixel[3];
1.106 - }
1.107 - resp.SetRed(vpixel[m_RedChannelIndex]);
1.108 - resp.SetGreen(vpixel[m_GreenChannelIndex]);
1.109 - resp.SetBlue(vpixel[m_BlueChannelIndex]);
1.110 - return resp;
1.111 - }
1.112 -
1.113 - inline const std::string Describe(ScalarType spixel) const
1.114 - {
1.115 - itk::OStringStream oss;
1.116 - OutputPixelType output = this->Evaluate(spixel);
1.117 - oss<<"Grayscale [value: "<< static_cast<typename itk::NumericTraits<PixelType>::PrintType>(spixel)<<", displayed: "<< static_cast<unsigned int>(output[0])<<"]";
1.118 - return oss.str();
1.119 - }
1.120 -
1.121 - inline const std::string Describe(const VectorPixelType & vpixel) const
1.122 - {
1.123 - itk::OStringStream oss;
1.124 - OutputPixelType output = this->Evaluate(vpixel);
1.125 - for(unsigned int channel = 0; channel < vpixel.Size();++channel)
1.126 - {
1.127 - oss<<"c= "<< channel << ", ";
1.128 - if(channel == m_RedChannelIndex)
1.129 - {
1.130 - oss <<"R= " << std::setw(3) <<(int)output[0]<< ", ";
1.131 - }
1.132 - else if(channel == m_GreenChannelIndex)
1.133 - {
1.134 - oss <<"G= " << std::setw(3) <<(int)output[1]<< ", ";
1.135 - }
1.136 - else if(channel == m_BlueChannelIndex)
1.137 - {
1.138 - oss <<"B= " << std::setw(3) <<(int)output[2]<< ", ";
1.139 - }
1.140 - else
1.141 - {
1.142 - oss <<" ";
1.143 - }
1.144 - oss<<"v= "<<static_cast<typename itk::NumericTraits<PixelType>::PrintType>(vpixel[channel])<<std::endl;
1.145 - }
1.146 - return oss.str();
1.147 - }
1.148 -
1.149 - inline const std::string Describe(const RGBPixelType & spixel) const
1.150 - {
1.151 - itk::OStringStream oss;
1.152 - OutputPixelType output = this->Evaluate(spixel);
1.153 - oss<<"RGB value: "<< static_cast<typename itk::NumericTraits<ScalarType>::PrintType>(spixel[0])
1.154 - << ", "<< static_cast<typename itk::NumericTraits<ScalarType>::PrintType>(spixel[1])
1.155 - << ", "<< static_cast<typename itk::NumericTraits<ScalarType>::PrintType>(spixel[2])
1.156 - << std::endl;
1.157 - oss <<" displayed: "<< static_cast<typename itk::NumericTraits<ScalarType>::PrintType>(output[0])
1.158 - << ", "<< static_cast<typename itk::NumericTraits<ScalarType>::PrintType>(output[1])
1.159 - << ", "<< static_cast<typename itk::NumericTraits<ScalarType>::PrintType>(output[2])
1.160 - <<std::endl;
1.161 - return oss.str();
1.162 - }
1.163 -
1.164 - inline const std::string Describe(const RGBAPixelType & spixel) const
1.165 - {
1.166 - itk::OStringStream oss;
1.167 - OutputPixelType output = this->Evaluate(spixel);
1.168 - oss<<"RGBA value: "<< static_cast<typename itk::NumericTraits<ScalarType>::PrintType>(spixel[0])
1.169 - << ", "<< static_cast<typename itk::NumericTraits<ScalarType>::PrintType>(spixel[1])
1.170 - << ", "<< static_cast<typename itk::NumericTraits<ScalarType>::PrintType>(spixel[2])
1.171 - << " alpha: "<< static_cast<typename itk::NumericTraits<ScalarType>::PrintType>(spixel[3])
1.172 - << std::endl;
1.173 - oss <<" displayed: "<< static_cast<typename itk::NumericTraits<ScalarType>::PrintType>(output[0])
1.174 - << ", "<< static_cast<typename itk::NumericTraits<ScalarType>::PrintType>(output[1])
1.175 - << ", "<< static_cast<typename itk::NumericTraits<ScalarType>::PrintType>(output[2])
1.176 - << " alpha: "<< static_cast<typename itk::NumericTraits<ScalarType>::PrintType>(output[3])
1.177 - <<std::endl;
1.178 - return oss.str();
1.179 - }
1.180 -
1.181 -
1.182 -
1.183 -protected:
1.184 - /** Constructor */
1.185 - DirectRenderingFunction() : m_RedChannelIndex(0), m_GreenChannelIndex(1), m_BlueChannelIndex(2)
1.186 - {}
1.187 - /** Destructor */
1.188 - ~DirectRenderingFunction() {}
1.189 -
1.190 -private:
1.191 - DirectRenderingFunction(const Self&); //purposely not implemented
1.192 - void operator=(const Self&); //purposely not implemented
1.193 -
1.194 - /** Index of the channels to display (vector mode only, has no effet
1.195 - * on scalar mode)
1.196 - */
1.197 - unsigned int m_RedChannelIndex;
1.198 - unsigned int m_GreenChannelIndex;
1.199 - unsigned int m_BlueChannelIndex;
1.200 -
1.201 -};
1.202 -} // end namespace Functor
1.203 -} // end namespace otb
1.204 -
1.205 -#endif
1.206 -
1.207 -
2.1 --- a/Code/Visualization/otbRenderingFunction.h Fri Jul 03 00:07:10 2009 +0800
2.2 +++ b/Code/Visualization/otbRenderingFunction.h Fri Jul 03 15:56:40 2009 +0800
2.3 @@ -126,6 +126,11 @@
2.4 itkExceptionMacro(<<"Subclasses should override this method");
2.5 }
2.6
2.7 + virtual void SetAutoMinMax(bool autoMinMax)
2.8 + {
2.9 + itkExceptionMacro(<<"Subclasses should override this method");
2.10 + }
2.11 +
2.12 /** Get the histogram of the pixel representation generated from the sample list */
2.13 virtual HistogramListPointerType GetHistogramList()
2.14 {
3.1 --- a/Code/Visualization/otbRenderingImageFilter.h Fri Jul 03 00:07:10 2009 +0800
3.2 +++ b/Code/Visualization/otbRenderingImageFilter.h Fri Jul 03 15:56:40 2009 +0800
3.3 @@ -197,7 +197,9 @@
3.4
3.5 //Check if the rendering function channels are compatible with the image
3.6 //might want to be more generic here one day.
3.7 - unsigned int numberOfInputChannels = this->GetInput()->GetNumberOfComponentsPerPixel();
3.8 +// unsigned int numberOfInputChannels = this->GetInput()->GetNumberOfComponentsPerPixel();
3.9 + itk::ImageRegionConstIterator<TInputImage> it(this->GetInput(),this->GetInput()->GetBufferedRegion());
3.10 + unsigned int numberOfInputChannels = VisualizationPixelTraits::PixelSize(it.Get());
3.11 std::vector<unsigned int> channels = (this->GetFunctor().GetFunction())->GetChannelList();
3.12 for (unsigned int i=0; i<channels.size(); ++i)
3.13 {
4.1 --- a/Code/Visualization/otbStandardRenderingFunction.h Fri Jul 03 00:07:10 2009 +0800
4.2 +++ b/Code/Visualization/otbStandardRenderingFunction.h Fri Jul 03 15:56:40 2009 +0800
4.3 @@ -142,14 +142,7 @@
4.4 // << "m_TransferFunction(spixel[0])" << m_TransferFunction(spixel[0])
4.5 // << ", m_TransferedMinimum[0] " << m_TransferedMinimum[0]
4.6 // << ", m_TransferedMaximum[0] " << m_TransferedMaximum[0])
4.7 -// otbMsgDevMacro(<<"StandardRenderingFunction::EvaluateTransferFunction "
4.8 -// << "m_TransferFunction(spixel[1])" << m_TransferFunction(spixel[1])
4.9 -// << ", m_TransferedMinimum[1] " << m_TransferedMinimum[1]
4.10 -// << ", m_TransferedMaximum[1] " << m_TransferedMaximum[1])
4.11 -// otbMsgDevMacro(<<"StandardRenderingFunction::EvaluateTransferFunction "
4.12 -// << "m_TransferFunction(spixel[2])" << m_TransferFunction(spixel[2])
4.13 -// << ", m_TransferedMinimum[2] " << m_TransferedMinimum[2]
4.14 -// << ", m_TransferedMaximum[2] " << m_TransferedMaximum[2])
4.15 +
4.16 if (spixel.Size() == 1)
4.17 {
4.18 OutputValueType value = ClampRescale(m_TransferFunction(spixel[0]),m_TransferedMinimum[0],m_TransferedMaximum[0]);
4.19 @@ -225,6 +218,18 @@
4.20 }
4.21
4.22 }
4.23 + else
4.24 + {
4.25 + unsigned int nbComps = m_PixelRepresentationFunction.GetOutputSize();
4.26 + if (m_Minimum.empty())
4.27 + {
4.28 + m_Minimum.resize(nbComps,0);
4.29 + }
4.30 + if (m_Maximum.empty())
4.31 + {
4.32 + m_Maximum.resize(nbComps,255);
4.33 + }
4.34 + }
4.35
4.36 typename ExtremaVectorType::const_iterator minIt = this->m_Minimum.begin();
4.37 typename ExtremaVectorType::const_iterator maxIt = this->m_Maximum.begin();
4.38 @@ -280,75 +285,6 @@
4.39 return oss.str();
4.40 }
4.41
4.42 -// inline const std::string Describe(const ScalarType & spixel) const //FIXME not updated yet
4.43 -// {
4.44 -// itk::OStringStream oss;
4.45 -// OutputPixelType output = this->Evaluate(spixel);
4.46 -// oss<<"Grayscale [value: "<< static_cast<typename itk::NumericTraits<PixelType>::PrintType>(spixel)<<", displayed: "<< static_cast<unsigned int>(output[0])<<"]";
4.47 -// return oss.str();
4.48 -// }
4.49 -//
4.50 -// inline const std::string Describe(const VectorPixelType & vpixel) const//FIXME not updated yet
4.51 -// {
4.52 -// itk::OStringStream oss;
4.53 -// OutputPixelType output = this->Evaluate(vpixel);
4.54 -//
4.55 -// for(unsigned int channel = 0; channel < vpixel.Size();++channel)
4.56 -// {
4.57 -// oss<<"c= "<< channel << ", ";
4.58 -// if(channel == m_RedChannelIndex)
4.59 -// {
4.60 -// oss <<"R= " << std::setw(3) <<(int)output[0]<< ", ";
4.61 -// }
4.62 -// else if(channel == m_GreenChannelIndex)
4.63 -// {
4.64 -// oss <<"G= " << std::setw(3) <<(int)output[1]<< ", ";
4.65 -// }
4.66 -// else if(channel == m_BlueChannelIndex)
4.67 -// {
4.68 -// oss <<"B= " << std::setw(3) <<(int)output[2]<< ", ";
4.69 -// }
4.70 -// else
4.71 -// {
4.72 -// oss <<" ";
4.73 -// }
4.74 -// oss<<"v= "<<static_cast<typename itk::NumericTraits<PixelType>::PrintType>(vpixel[channel])<<std::endl;
4.75 -// }
4.76 -// return oss.str();
4.77 -// }
4.78 -//
4.79 -// inline const std::string Describe(const RGBPixelType & spixel) const //FIXME not updated yet
4.80 -// {
4.81 -// itk::OStringStream oss;
4.82 -// OutputPixelType output = this->Evaluate(spixel);
4.83 -// oss<<"RGB value: "<< static_cast<typename itk::NumericTraits<ScalarType>::PrintType>(spixel[0])
4.84 -// << ", "<< static_cast<typename itk::NumericTraits<ScalarType>::PrintType>(spixel[1])
4.85 -// << ", "<< static_cast<typename itk::NumericTraits<ScalarType>::PrintType>(spixel[2])
4.86 -// << std::endl;
4.87 -// oss <<" displayed: "<< static_cast<typename itk::NumericTraits<OutputPixelType>::PrintType>(output[0])
4.88 -// << ", "<< static_cast<typename itk::NumericTraits<OutputPixelType>::PrintType>(output[1])
4.89 -// << ", "<< static_cast<typename itk::NumericTraits<OutputPixelType>::PrintType>(output[2])
4.90 -// <<std::endl;
4.91 -// return oss.str();
4.92 -// }
4.93 -//
4.94 -// inline const std::string Describe(const RGBAPixelType & spixel) const //FIXME not updated yet
4.95 -// {
4.96 -// itk::OStringStream oss;
4.97 -// OutputPixelType output = this->Evaluate(spixel);
4.98 -// oss<<"RGBA value: "<< static_cast<typename itk::NumericTraits<ScalarType>::PrintType>(spixel[0])
4.99 -// << ", "<< static_cast<typename itk::NumericTraits<ScalarType>::PrintType>(spixel[1])
4.100 -// << ", "<< static_cast<typename itk::NumericTraits<ScalarType>::PrintType>(spixel[2])
4.101 -// << " alpha: "<< static_cast<typename itk::NumericTraits<ScalarType>::PrintType>(spixel[3])
4.102 -// << std::endl;
4.103 -// oss <<" displayed: "<< static_cast<typename itk::NumericTraits<OutputPixelType>::PrintType>(output[0])
4.104 -// << ", "<< static_cast<typename itk::NumericTraits<OutputPixelType>::PrintType>(output[1])
4.105 -// << ", "<< static_cast<typename itk::NumericTraits<OutputPixelType>::PrintType>(output[2])
4.106 -// << " alpha: "<< static_cast<typename itk::NumericTraits<OutputPixelType>::PrintType>(output[3])
4.107 -// <<std::endl;
4.108 -// return oss.str();
4.109 -// }
4.110 -
4.111 /** Set the minimum and maximum for the different bands.
4.112 * Has to be provided as [minBand0, maxBand0, minBand1, maxBand1,...]
4.113 */
5.1 --- a/Code/Visualization/otbVisualizationPixelTraits.h Fri Jul 03 00:07:10 2009 +0800
5.2 +++ b/Code/Visualization/otbVisualizationPixelTraits.h Fri Jul 03 15:56:40 2009 +0800
5.3 @@ -105,9 +105,7 @@
5.4 template< class TScalarTypeInput >
5.5 static unsigned int PixelSize(const itk::RGBAPixel<TScalarTypeInput>& in)
5.6 {
5.7 - //We return only the useful size of the pixel, the alpha channel may be used later
5.8 - //but only for display purposes
5.9 - return 3;
5.10 + return 4;
5.11 }
5.12
5.13 template< class TScalarTypeInput >