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-07-07 12:28:58 $
00007   Version:   $Revision: 1.6 $
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   void ResetColors() 
00100     { 
00101     m_RGBFunctor.ResetColors(); 
00102     }
00103 
00104   unsigned int GetNumberOfColors() const
00105     {
00106     return m_RGBFunctor.GetNumberOfColors();
00107     }
00108 
00110   typedef typename TRGBPixel::ComponentType ComponentType;
00111 
00112   void AddColor( ComponentType r, ComponentType g, ComponentType b )
00113     {
00114     m_RGBFunctor.AddColor( r, g, b );
00115     }
00116 
00117 protected:
00118 
00119 private: 
00120   double          m_Opacity;
00121   TLabel          m_BackgroundValue;
00122 
00123   typename Functor::LabelToRGBFunctor<TLabel, TRGBPixel> m_RGBFunctor;
00124 };
00125 
00126 }  // end namespace functor
00127 
00128 }  // end namespace itk
00129 
00130 #endif
00131 

Generated at Mon Jul 12 2010 18:59:16 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000