00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkLabelOverlayImageFilter_h
00018 #define __itkLabelOverlayImageFilter_h
00019
00020 #include "itkLabelToRGBFunctor.h"
00021 #include "itkBinaryFunctorImageFilter.h"
00022 #include "itkConceptChecking.h"
00023
00024 namespace itk
00025 {
00026
00027 namespace Functor {
00028
00033 template< class TInputPixel, class TLabel, class TRGBPixel >
00034 class LabelOverlay
00035 {
00036 public:
00037 LabelOverlay()
00038 {
00039
00040
00041
00042 m_UseBackground = false;
00043 m_BackgroundValue = NumericTraits<TLabel>::Zero;
00044 }
00046
00047 inline TRGBPixel operator()( const TInputPixel & p1, const TLabel & p2)
00048 {
00049 TRGBPixel rgbPixel;
00050 if( m_UseBackground && p2 == m_BackgroundValue )
00051 {
00052
00053
00054 typename TRGBPixel::ValueType p =
00055 static_cast< typename TRGBPixel::ValueType >( p1 );
00056 rgbPixel[0] = p;
00057 rgbPixel[1] = p;
00058 rgbPixel[2] = p;
00059 return rgbPixel;
00060 }
00061
00062
00063
00064 TRGBPixel opaque = m_RGBFunctor(p2);
00065 for( unsigned int i = 0; i<3; i++ )
00066 {
00067 rgbPixel[i] = static_cast< typename TRGBPixel::ValueType >(
00068 opaque[i] * m_Opacity + p1 * ( 1.0 - m_Opacity ) );
00069 }
00070 return rgbPixel;
00071 }
00072
00073 bool operator != (const LabelOverlay &l) const
00074 {
00075 bool value = l.m_Opacity != m_Opacity ||
00076 m_UseBackground != l.m_UseBackground ||
00077 m_BackgroundValue != l.m_BackgroundValue;
00078
00079 return value;
00080 }
00081
00082 ~LabelOverlay() {}
00083
00084 void SetOpacity( double opacity )
00085 {
00086 m_Opacity = opacity;
00087 }
00088
00089 void SetBackgroundValue( TLabel v )
00090 {
00091 m_BackgroundValue = v;
00092 }
00093
00094 void SetUseBackground( bool b )
00095 {
00096 m_UseBackground = b;
00097 }
00098
00099 protected:
00100
00101 private:
00102 double m_Opacity;
00103 bool m_UseBackground;
00104 TLabel m_BackgroundValue;
00105
00106 typename Functor::LabelToRGBFunctor<TLabel, TRGBPixel> m_RGBFunctor;
00107 };
00108 }
00109
00110
00133 template <typename TInputImage, class TLabelImage, typename TOutputImage>
00134 class ITK_EXPORT LabelOverlayImageFilter :
00135 public
00136 BinaryFunctorImageFilter<TInputImage, TLabelImage, TOutputImage,
00137 Functor::LabelOverlay<
00138 typename TInputImage::PixelType,
00139 typename TLabelImage::PixelType,
00140 typename TOutputImage::PixelType> >
00141 {
00142 public:
00144 typedef LabelOverlayImageFilter Self;
00145
00146 typedef BinaryFunctorImageFilter<TInputImage, TLabelImage, TOutputImage,
00147 Functor::LabelOverlay<
00148 typename TInputImage::PixelType,
00149 typename TLabelImage::PixelType,
00150 typename TOutputImage::PixelType> > Superclass;
00151
00152 typedef SmartPointer<Self> Pointer;
00153 typedef SmartPointer<const Self> ConstPointer;
00154
00155 typedef TOutputImage OutputImageType;
00156 typedef TLabelImage LabelImageType;
00157 typedef TInputImage InputImageType;
00158
00159 typedef typename TOutputImage::PixelType OutputPixelType;
00160 typedef typename TLabelImage::PixelType LabelPixelType;
00161 typedef typename TInputImage::PixelType InputPixelType;
00162
00164 itkTypeMacro(LabelOverlayImageFilter, BinaryFunctorImageFilter);
00165
00167 itkNewMacro(Self);
00168
00170 void SetLabelImage( const TLabelImage *input);
00171
00173 const LabelImageType * GetLabelImage() const;
00174
00178 itkSetMacro( Opacity, double );
00179 itkGetConstReferenceMacro( Opacity, double );
00181
00183 itkSetMacro( BackgroundValue, LabelPixelType );
00184 itkGetConstReferenceMacro( BackgroundValue, LabelPixelType );
00186
00188 itkSetMacro( UseBackground, bool );
00189 itkGetConstReferenceMacro( UseBackground, bool );
00190 itkBooleanMacro(UseBackground);
00192
00193 #ifdef ITK_USE_CONCEPT_CHECKING
00194
00195 itkConceptMacro(OutputHasPixelTraitsCheck,
00196 (Concept::HasPixelTraits<OutputPixelType>));
00197 itkConceptMacro(OutputPixelShouldHaveValueType,
00198 (Concept::HasValueType<OutputPixelType>));
00199 itkConceptMacro(OutputPixelShouldHaveBracketOperator,
00200 (Concept::BracketOperator<
00201 OutputPixelType,
00202 unsigned int,
00203 typename OutputPixelType::ValueType>));
00204
00206 #endif
00207
00208 protected:
00209 LabelOverlayImageFilter();
00210 virtual ~LabelOverlayImageFilter() {};
00211
00213 void BeforeThreadedGenerateData(void);
00214
00216 void PrintSelf(std::ostream& os, Indent indent) const;
00217
00218 private:
00219 LabelOverlayImageFilter(const Self&);
00220 void operator=(const Self&);
00221
00222 double m_Opacity;
00223 bool m_UseBackground;
00224 LabelPixelType m_BackgroundValue;
00225
00226 };
00227
00228
00229
00230 }
00231
00232 #ifndef ITK_MANUAL_INSTANTIATION
00233 #include "itkLabelOverlayImageFilter.txx"
00234 #endif
00235
00236 #endif
00237