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

itkLabelOverlayFunctor.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkLabelOverlayFunctor.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-02-24 19:03:15 $
00007   Version:   $Revision: 1.3 $
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 
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     // provide some default value for external use (outside 
00047     // LabelOverlayFunctorImageFilter) Inside LabelOverlayFunctorImageFilter, 
00048     // the values are always initialized
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       // value is background
00058       // return a gray pixel with the same intensity than the input pixel
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     // taint the input pixel with the colored one returned by 
00068     // the color functor.
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 }  // end namespace functor
00109 
00110 }  // end namespace itk
00111 
00112 #endif
00113 

Generated at Sat Feb 28 12:54:16 2009 for ITK by doxygen 1.5.6 written by Dimitri van Heesch, © 1997-2000