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

itkLabelToRGBFunctor.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkLabelToRGBFunctor.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/02/26 15:46:54 $
00007   Version:   $Revision: 1.5 $
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 __itkLabelToRGBFunctor_h
00019 #define __itkLabelToRGBFunctor_h
00020 
00021 namespace itk
00022 {
00023 
00024 namespace Functor {
00025  
00040 template< class TLabel, class TRGBPixel >
00041 class LabelToRGBFunctor
00042 {
00043 public:
00044 
00045   typedef LabelToRGBFunctor Self;
00046 
00047   LabelToRGBFunctor()
00048     {
00049     
00050     TRGBPixel rgbPixel;
00051     // the following colors are from "R", and named:
00052     // "red"             "green3"          "blue"            "cyan"
00053     //"magenta"         "darkorange1"     "darkgreen"       "blueviolet"
00054     //"brown4"          "navy"            "yellow4"         "violetred1"
00055     //"salmon4"         "turquoise4"      "sienna3"         "darkorchid1"
00056     //"springgreen4"    "mediumvioletred" "orangered3"      "lightseagreen"
00057     //"slateblue"       "deeppink1"       "aquamarine4"     "royalblue1"
00058     //"tomato3"         "mediumblue"      "violetred4"      "darkmagenta"
00059     //"violet"          "red4"
00060     // They are a good selection of distinct colours for plotting and
00061     // overlays.
00062     
00063     AddColor( 255, 0, 0 );
00064     AddColor( 0, 205, 0 );
00065     AddColor( 0, 0, 255 );
00066     AddColor( 0, 255, 255 );
00067     AddColor( 255, 0, 255 );
00068     AddColor( 255, 127, 0 );
00069     AddColor( 0, 100, 0 );
00070     AddColor( 138, 43, 226 );
00071     AddColor( 139, 35, 35 );
00072     AddColor( 0, 0, 128 );
00073     AddColor( 139, 139, 0 );
00074     AddColor( 255, 62, 150 );
00075     AddColor( 139, 76, 57 );
00076     AddColor( 0, 134, 139 );
00077     AddColor( 205, 104, 57 );
00078     AddColor( 191, 62, 255 );
00079     AddColor( 0, 139, 69 );
00080     AddColor( 199, 21, 133 );
00081     AddColor( 205, 55, 0 );
00082     AddColor( 32, 178, 170 );
00083     AddColor( 106, 90, 205 );
00084     AddColor( 255, 20, 147 );
00085     AddColor( 69, 139, 116 );
00086     AddColor( 72, 118, 255 );
00087     AddColor( 205, 79, 57 );
00088     AddColor( 0, 0, 205 );
00089     AddColor( 139, 34, 82 );
00090     AddColor( 139, 0, 139 );
00091     AddColor( 238, 130, 238 );
00092     AddColor( 139, 0, 0 );
00093 
00094     // provide some default value for external use (outside LabelToRGBImageFilter)
00095     // Inside LabelToRGBImageFilter, the values are always initialized
00096     m_UseBackground = false;
00097     m_BackgroundValue = NumericTraits<TLabel>::Zero;
00098     }
00099 
00100   inline TRGBPixel operator()( const TLabel & p)
00101     {
00102     // value is background
00103     // return a gray pixel with the same intensity than the label pixel
00104     if( m_UseBackground && p == m_BackgroundValue )
00105       {
00106       TRGBPixel rgbPixel;
00107       rgbPixel.Set( p, p, p );
00108       return rgbPixel;
00109       }
00110 
00111     // else, return a colored pixel from the color table
00112     return m_Colors[ p % m_Colors.size()];
00113     }
00114 
00115   void AddColor(unsigned char r, unsigned char g, unsigned char b)
00116     {
00117     TRGBPixel rgbPixel;
00118     typedef typename TRGBPixel::ValueType ValueType;
00119 
00120     ValueType m = NumericTraits< ValueType >::max();
00121 
00122     rgbPixel.Set( static_cast< ValueType >( static_cast< double >( r ) / 255 * m ),
00123                   static_cast< ValueType >( static_cast< double >( g ) / 255 * m ),
00124                   static_cast< ValueType >( static_cast< double >( b ) / 255 * m ) );
00125     m_Colors.push_back( rgbPixel );
00126     }
00127 
00128   bool operator != (const Self &l) const
00129     { 
00130     const bool areDifferent = m_UseBackground != l.m_UseBackground || 
00131                             m_BackgroundValue != l.m_BackgroundValue; 
00132     return areDifferent;
00133     }
00134 
00135   bool operator==( const Self & other ) const
00136     {
00137     return !(*this != other);
00138     }
00139 
00140   void SetBackgroundValue( TLabel v ) 
00141     { 
00142     m_BackgroundValue = v; 
00143     }
00144 
00145   void SetUseBackground( bool b ) 
00146     {
00147     m_UseBackground = b; 
00148     }
00149 
00150   ~LabelToRGBFunctor() {}
00151 
00152   std::vector< TRGBPixel > m_Colors;
00153 
00154   bool m_UseBackground;
00155 
00156   TLabel m_BackgroundValue;
00157 
00158 };
00159 }  // end namespace functor
00160 
00161 }  // end namespace itk
00162 
00163 #endif
00164 

Generated at Mon Mar 12 01:28:21 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000