ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkColorTable.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkColorTable_h
19 #define __itkColorTable_h
20 
21 #include "itkObject.h"
22 #include "itkRGBPixel.h"
23 #include "itkObjectFactory.h"
24 
25 #include <string>
26 #include <vector>
27 namespace itk
28 {
39 template< class TPixel >
40 class ITK_EXPORT ColorTable:public Object
41 {
42 public:
44  typedef ColorTable Self;
45  typedef Object Superclass;
48 
50  itkNewMacro(Self);
51 
53  itkTypeMacro(ColorTable, Object);
54 
60  void UseDiscreteColors(void);
61 
66  void UseGrayColors(unsigned int n = 256);
67 
73  void UseHeatColors(unsigned int n = 256);
74 
79  void UseRandomColors(unsigned int n = 256);
80 
82  itkGetConstMacro(NumberOfColors, unsigned int);
83 
85  RGBPixel< TPixel > GetColor(unsigned int colorId);
86 
91  bool SetColor(unsigned int c, TPixel r, TPixel g, TPixel b,
92  const char *name = "UserDefined");
93  bool SetColor(unsigned int c, RGBPixel<TPixel> pixel,
94  const char *name = "UserDefined");
96 
100  TPixel GetColorComponent(unsigned int colorId, char rgb);
101 
103  std::string GetColorName(unsigned int colorId);
104 
108  unsigned int GetClosestColorTableId(TPixel r, TPixel g, TPixel b);
109 
110 protected:
111  ColorTable();
112  void PrintSelf(std::ostream & os, Indent indent) const;
113 
114  unsigned int m_NumberOfColors;
115 
116  std::vector<std::string> m_ColorName;
117  std::vector<RGBPixel< TPixel > > m_Color;
118 private:
119  ColorTable(const Self &); //purposely not implemented
120  void operator=(const Self &); //purposely not implemented
121 
122  void DeleteColors();
123 };
124 } // namespace itk
125 
126 // Define instantiation macro for this template.
127 #define ITK_TEMPLATE_ColorTable(_, EXPORT, TypeX, TypeY) \
128  namespace itk \
129  { \
130  _( 1 ( class EXPORT ColorTable< ITK_TEMPLATE_1 TypeX > ) ) \
131  namespace Templates \
132  { \
133  typedef ColorTable< ITK_TEMPLATE_1 TypeX > \
134  ColorTable##TypeY; \
135  } \
136  }
137 
138 #if ITK_TEMPLATE_EXPLICIT
139 #include "Templates/itkColorTable+-.h"
140 #endif
141 
142 #if ITK_TEMPLATE_TXX
143 #include "itkColorTable.hxx"
144 #endif
145 
146 #endif
147