Orfeo Toolbox  3.16
itkLabelToRGBFunctor.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkLabelToRGBFunctor.h,v $
5  Language: C++
6  Date: $Date: 2009-07-07 12:27:34 $
7  Version: $Revision: 1.11 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 
18 #ifndef __itkLabelToRGBFunctor_h
19 #define __itkLabelToRGBFunctor_h
20 
21 namespace itk
22 {
23 
24 namespace Functor {
25 
40 template< class TLabel, class TRGBPixel >
42 {
43 public:
44 
46 
48  {
49 
50  TRGBPixel rgbPixel;
51  typedef typename TRGBPixel::ValueType ValueType;
52 
53  // the following colors are from "R", and named:
54  // "red" "green3" "blue" "cyan"
55  //"magenta" "darkorange1" "darkgreen" "blueviolet"
56  //"brown4" "navy" "yellow4" "violetred1"
57  //"salmon4" "turquoise4" "sienna3" "darkorchid1"
58  //"springgreen4" "mediumvioletred" "orangered3" "lightseagreen"
59  //"slateblue" "deeppink1" "aquamarine4" "royalblue1"
60  //"tomato3" "mediumblue" "violetred4" "darkmagenta"
61  //"violet" "red4"
62  // They are a good selection of distinct colours for plotting and
63  // overlays.
64 
65  AddColor( 255, 0, 0 );
66  AddColor( 0, 205, 0 );
67  AddColor( 0, 0, 255 );
68  AddColor( 0, 255, 255 );
69  AddColor( 255, 0, 255 );
70  AddColor( 255, 127, 0 );
71  AddColor( 0, 100, 0 );
72  AddColor( 138, 43, 226 );
73  AddColor( 139, 35, 35 );
74  AddColor( 0, 0, 128 );
75  AddColor( 139, 139, 0 );
76  AddColor( 255, 62, 150 );
77  AddColor( 139, 76, 57 );
78  AddColor( 0, 134, 139 );
79  AddColor( 205, 104, 57 );
80  AddColor( 191, 62, 255 );
81  AddColor( 0, 139, 69 );
82  AddColor( 199, 21, 133 );
83  AddColor( 205, 55, 0 );
84  AddColor( 32, 178, 170 );
85  AddColor( 106, 90, 205 );
86  AddColor( 255, 20, 147 );
87  AddColor( 69, 139, 116 );
88  AddColor( 72, 118, 255 );
89  AddColor( 205, 79, 57 );
90  AddColor( 0, 0, 205 );
91  AddColor( 139, 34, 82 );
92  AddColor( 139, 0, 139 );
93  AddColor( 238, 130, 238 );
94  AddColor( 139, 0, 0 );
95 
96  // provide some default value for external use (outside LabelToRGBImageFilter)
97  // Inside LabelToRGBImageFilter, the values are always initialized
98  m_BackgroundColor.Fill( NumericTraits<ValueType>::Zero );
99  m_BackgroundValue = NumericTraits<TLabel>::Zero;
100  }
101 
102  inline TRGBPixel operator()( const TLabel & p) const
103  {
104  // value is background
105  // return a gray pixel with the same intensity than the label pixel
106  if( p == m_BackgroundValue )
107  {
108  return m_BackgroundColor;
109  }
110 
111  // else, return a colored pixel from the color table
112  return m_Colors[ p % m_Colors.size()];
113  }
114 
115  void AddColor(unsigned char r, unsigned char g, unsigned char b)
116  {
117  TRGBPixel rgbPixel;
118  typedef typename TRGBPixel::ValueType ValueType;
119 
120  ValueType m = NumericTraits< ValueType >::max();
121 
122  rgbPixel.Set( static_cast< ValueType >( static_cast< double >( r ) / 255 * m ),
123  static_cast< ValueType >( static_cast< double >( g ) / 255 * m ),
124  static_cast< ValueType >( static_cast< double >( b ) / 255 * m ) );
125  m_Colors.push_back( rgbPixel );
126  }
127 
128  // Empty the color LUT
129  void ResetColors()
130  {
131  m_Colors.clear();
132  }
133 
134  // Get number of colors in the LUT
135  unsigned int GetNumberOfColors() const
136  {
137  return m_Colors.size();
138  }
139 
140  bool operator != (const Self &l) const
141  {
142  const bool areDifferent = m_BackgroundColor != l.m_BackgroundColor ||
144  return areDifferent;
145  }
146 
147  bool operator==( const Self & other ) const
148  {
149  return !(*this != other);
150  }
151 
152  void SetBackgroundValue( TLabel v )
153  {
154  m_BackgroundValue = v;
155  }
156 
157  void SetBackgroundColor( TRGBPixel rgb )
158  {
159  m_BackgroundColor = rgb;
160  }
161 
163 
164  std::vector< TRGBPixel > m_Colors;
165 
166  TRGBPixel m_BackgroundColor;
167 
169 
170 };
171 } // end namespace functor
172 
173 } // end namespace itk
174 
175 #endif

Generated at Sat Feb 2 2013 23:50:36 for Orfeo Toolbox with doxygen 1.8.1.1