Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkColormapFunctor_h
00018 #define __itkColormapFunctor_h
00019
00020 #include "itkLightObject.h"
00021 #include "itkNumericTraits.h"
00022 #include "itkRGBPixel.h"
00023
00024 namespace itk {
00025
00026 namespace Functor {
00027
00042 template< class TScalar, class TRGBPixel >
00043 class ITK_EXPORT ColormapFunctor : public Object
00044 {
00045 public:
00046
00047 typedef ColormapFunctor Self;
00048 typedef Object Superclass;
00049 typedef SmartPointer<Self> Pointer;
00050 typedef SmartPointer<const Self> ConstPointer;
00051
00053 itkTypeMacro(ColormapFunctor, Object);
00054
00055 typedef TRGBPixel RGBPixelType;
00056 typedef typename TRGBPixel::ComponentType RGBComponentType;
00057 typedef TScalar ScalarType;
00058 typedef typename NumericTraits<ScalarType>::RealType RealType;
00059
00060 itkSetMacro( MinimumRGBComponentValue, RGBComponentType );
00061 itkGetConstMacro( MinimumRGBComponentValue, RGBComponentType );
00062
00063 itkSetMacro( MaximumRGBComponentValue, RGBComponentType );
00064 itkGetConstMacro( MaximumRGBComponentValue, RGBComponentType );
00065
00066 itkSetMacro( MinimumInputValue, ScalarType );
00067 itkGetConstMacro( MinimumInputValue, ScalarType );
00068
00069 itkSetMacro( MaximumInputValue, ScalarType );
00070 itkGetConstMacro( MaximumInputValue, ScalarType );
00071
00072 virtual bool operator!=( const ColormapFunctor & ) const
00073 {
00074 return false;
00075 }
00076 virtual bool operator==( const ColormapFunctor & other ) const
00077 {
00078 return !(*this != other);
00079 }
00080
00081 virtual RGBPixelType operator()( const ScalarType & ) const = 0;
00082
00083 protected:
00084 ColormapFunctor()
00085 {
00086 this->m_MinimumInputValue = NumericTraits<TScalar>::min();
00087 this->m_MaximumInputValue = NumericTraits<TScalar>::max();
00088 this->m_MinimumRGBComponentValue = NumericTraits<RGBComponentType>::min();
00089 this->m_MaximumRGBComponentValue = NumericTraits<RGBComponentType>::max();
00090 }
00091
00092 ~ColormapFunctor() {};
00093
00094
00098 RealType RescaleInputValue( ScalarType v ) const
00099 {
00100 RealType d = static_cast<RealType>( this->m_MaximumInputValue - this->m_MinimumInputValue );
00101 RealType value = ( static_cast<RealType>( v )
00102 - static_cast<RealType>( this->m_MinimumInputValue ) ) / d;
00103 value = vnl_math_max( 0.0, value );
00104 value = vnl_math_min( 1.0, value );
00105 return value;
00106 }
00108
00112 RGBComponentType RescaleRGBComponentValue( RealType v ) const
00113 {
00114 RealType d = static_cast<RealType>( m_MaximumRGBComponentValue - m_MinimumRGBComponentValue );
00115 const RGBComponentType rescaled =
00116 static_cast<RGBComponentType>( d * v ) + this->m_MinimumRGBComponentValue;
00117 return rescaled;
00118 }
00120
00121 void PrintSelf(std::ostream& os, Indent indent) const
00122 {
00123 Superclass::PrintSelf(os, indent);
00124
00125 os << indent << "Minimum RGB Component Value: "
00126 << static_cast<typename NumericTraits<RGBComponentType>::PrintType>(
00127 this->GetMinimumRGBComponentValue()) << std::endl;
00128 os << indent << "Maximum RGB Component Value: "
00129 << static_cast<typename NumericTraits<RGBComponentType>::PrintType>(
00130 this->GetMaximumRGBComponentValue()) << std::endl;
00131 os << indent << "Minimum Input Value: "
00132 << static_cast<typename NumericTraits<ScalarType>::PrintType>(
00133 this->GetMinimumInputValue()) << std::endl;
00134 os << indent << "Maximum Input Value: "
00135 << static_cast<typename NumericTraits<ScalarType>::PrintType>(
00136 this->GetMaximumInputValue()) << std::endl;
00137 }
00138
00139 private:
00140 ColormapFunctor(const Self&);
00141 void operator=(const Self&);
00142
00143 ScalarType m_MinimumInputValue;
00144 ScalarType m_MaximumInputValue;
00145
00146 RGBComponentType m_MinimumRGBComponentValue;
00147 RGBComponentType m_MaximumRGBComponentValue;
00148
00149 };
00150
00151 }
00152
00153 }
00154
00155 #endif
00156