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: 2009-07-07 12:27:34 $
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 
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     typedef typename TRGBPixel::ValueType ValueType;
00052 
00053     // the following colors are from "R", and named:
00054     // "red"             "green3"          "blue"            "cyan"
00055     //"magenta"         "darkorange1"     "darkgreen"       "blueviolet"
00056     //"brown4"          "navy"            "yellow4"         "violetred1"
00057     //"salmon4"         "turquoise4"      "sienna3"         "darkorchid1"
00058     //"springgreen4"    "mediumvioletred" "orangered3"      "lightseagreen"
00059     //"slateblue"       "deeppink1"       "aquamarine4"     "royalblue1"
00060     //"tomato3"         "mediumblue"      "violetred4"      "darkmagenta"
00061     //"violet"          "red4"
00062     // They are a good selection of distinct colours for plotting and
00063     // overlays.
00064     
00065     AddColor( 255, 0, 0 );
00066     AddColor( 0, 205, 0 );
00067     AddColor( 0, 0, 255 );
00068     AddColor( 0, 255, 255 );
00069     AddColor( 255, 0, 255 );
00070     AddColor( 255, 127, 0 );
00071     AddColor( 0, 100, 0 );
00072     AddColor( 138, 43, 226 );
00073     AddColor( 139, 35, 35 );
00074     AddColor( 0, 0, 128 );
00075     AddColor( 139, 139, 0 );
00076     AddColor( 255, 62, 150 );
00077     AddColor( 139, 76, 57 );
00078     AddColor( 0, 134, 139 );
00079     AddColor( 205, 104, 57 );
00080     AddColor( 191, 62, 255 );
00081     AddColor( 0, 139, 69 );
00082     AddColor( 199, 21, 133 );
00083     AddColor( 205, 55, 0 );
00084     AddColor( 32, 178, 170 );
00085     AddColor( 106, 90, 205 );
00086     AddColor( 255, 20, 147 );
00087     AddColor( 69, 139, 116 );
00088     AddColor( 72, 118, 255 );
00089     AddColor( 205, 79, 57 );
00090     AddColor( 0, 0, 205 );
00091     AddColor( 139, 34, 82 );
00092     AddColor( 139, 0, 139 );
00093     AddColor( 238, 130, 238 );
00094     AddColor( 139, 0, 0 );
00095 
00096     // provide some default value for external use (outside LabelToRGBImageFilter)
00097     // Inside LabelToRGBImageFilter, the values are always initialized
00098     m_BackgroundColor.Fill( NumericTraits<ValueType>::Zero );
00099     m_BackgroundValue = NumericTraits<TLabel>::Zero;
00100     }
00101 
00102   inline TRGBPixel operator()( const TLabel & p) const
00103     {
00104     // value is background
00105     // return a gray pixel with the same intensity than the label pixel
00106     if( p == m_BackgroundValue )
00107       {
00108       return m_BackgroundColor;
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   // Empty the color LUT
00129   void ResetColors()
00130     {
00131     m_Colors.clear();
00132     }
00133 
00134   // Get number of colors in the LUT
00135   unsigned int GetNumberOfColors() const
00136     {
00137     return m_Colors.size();
00138     }
00139 
00140   bool operator != (const Self &l) const
00141     { 
00142     const bool areDifferent = m_BackgroundColor != l.m_BackgroundColor || 
00143                             m_BackgroundValue != l.m_BackgroundValue; 
00144     return areDifferent;
00145     }
00146 
00147   bool operator==( const Self & other ) const
00148     {
00149     return !(*this != other);
00150     }
00151 
00152   void SetBackgroundValue( TLabel v ) 
00153     { 
00154     m_BackgroundValue = v; 
00155     }
00156 
00157   void SetBackgroundColor( TRGBPixel rgb ) 
00158     {
00159     m_BackgroundColor = rgb; 
00160     }
00161 
00162   ~LabelToRGBFunctor() {}
00163 
00164   std::vector< TRGBPixel > m_Colors;
00165 
00166   TRGBPixel m_BackgroundColor;
00167 
00168   TLabel m_BackgroundValue;
00169 
00170 };
00171 }  // end namespace functor
00172 
00173 }  // end namespace itk
00174 
00175 #endif
00176 

Generated at Fri Apr 16 18:55:56 2010 for ITK by doxygen 1.6.1 written by Dimitri van Heesch, © 1997-2000