00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __itkLabelOverlayFunctor_h
00019 #define __itkLabelOverlayFunctor_h
00020
00021 #include "itkLabelToRGBFunctor.h"
00022
00023 namespace itk
00024 {
00025
00026 namespace Functor {
00027
00040 template< class TInputPixel, class TLabel, class TRGBPixel >
00041 class LabelOverlayFunctor
00042 {
00043 public:
00044 LabelOverlayFunctor()
00045 {
00046
00047
00048
00049 m_BackgroundValue = NumericTraits<TLabel>::Zero;
00050 }
00051
00052 inline TRGBPixel operator()( const TInputPixel & p1, const TLabel & p2) const
00053 {
00054 TRGBPixel rgbPixel;
00055 if( p2 == m_BackgroundValue )
00056 {
00057
00058
00059 typename TRGBPixel::ValueType p =
00060 static_cast< typename TRGBPixel::ValueType >( p1 );
00061 rgbPixel[0] = p;
00062 rgbPixel[1] = p;
00063 rgbPixel[2] = p;
00064 return rgbPixel;
00065 }
00066
00067
00068
00069 TRGBPixel opaque = m_RGBFunctor(p2);
00070 for( unsigned int i = 0; i<3; i++ )
00071 {
00072 rgbPixel[i] = static_cast< typename TRGBPixel::ValueType >(
00073 opaque[i] * m_Opacity + p1 * ( 1.0 - m_Opacity ) );
00074 }
00075 return rgbPixel;
00076 }
00077
00078 bool operator != (const LabelOverlayFunctor &l) const
00079 {
00080 bool value = l.m_Opacity != m_Opacity ||
00081 m_BackgroundValue != l.m_BackgroundValue;
00082
00083 return value;
00084 }
00085
00086 ~LabelOverlayFunctor() {}
00087
00088 void SetOpacity( double opacity )
00089 {
00090 m_Opacity = opacity;
00091 }
00092
00093 void SetBackgroundValue( TLabel v )
00094 {
00095 m_BackgroundValue = v;
00096 m_RGBFunctor.SetBackgroundValue( v );
00097 }
00098
00099 protected:
00100
00101 private:
00102 double m_Opacity;
00103 TLabel m_BackgroundValue;
00104
00105 typename Functor::LabelToRGBFunctor<TLabel, TRGBPixel> m_RGBFunctor;
00106 };
00107
00108 }
00109
00110 }
00111
00112 #endif
00113