Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkLabelOverlayImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkLabelOverlayImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/03/30 16:50:00 $
00007   Version:   $Revision: 1.11 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
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     // provide some default value for external use (outside 
00040     // LabelOverlayImageFilter) Inside LabelOverlayImageFilter, 
00041     // the values are always initialized
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       // value is background
00053       // return a gray pixel with the same intensity than the input pixel
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     // taint the input pixel with the colored one returned by 
00063     // the color functor.
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 }  // end namespace functor
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&); //purposely not implemented
00220   void operator=(const Self&); //purposely not implemented
00221 
00222   double                        m_Opacity;
00223   bool                          m_UseBackground;
00224   LabelPixelType                m_BackgroundValue;
00225 
00226 };
00227 
00228 
00229   
00230 } // end namespace itk
00231   
00232 #ifndef ITK_MANUAL_INSTANTIATION
00233 #include "itkLabelOverlayImageFilter.txx"
00234 #endif
00235 
00236 #endif
00237 

Generated at Sun Sep 23 13:20:52 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000