ITK  5.3.0
Insight Toolkit
itkColorTable.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 <typename TPixel>
40 class ITK_TEMPLATE_EXPORT ColorTable : public Object
41 {
42 public:
43  ITK_DISALLOW_COPY_AND_MOVE(ColorTable);
44 
46  using Self = ColorTable;
47  using Superclass = Object;
50 
52  itkNewMacro(Self);
53 
55  itkTypeMacro(ColorTable, Object);
56 
62  void
63  UseDiscreteColors();
64 
69  void
70  UseGrayColors(unsigned int n = 256);
71 
77  void
78  UseHeatColors(unsigned int n = 256);
79 
84  void
85  UseRandomColors(unsigned int n = 256);
86 
88  itkGetConstMacro(NumberOfColors, unsigned int);
89 
92  GetColor(unsigned int c);
93 
98  bool
99  SetColor(unsigned int c, TPixel r, TPixel g, TPixel b, const char * name = "UserDefined");
100  bool
101  SetColor(unsigned int c, RGBPixel<TPixel> pixel, const char * name = "UserDefined");
103 
107  TPixel
108  GetColorComponent(unsigned int c, char rgb);
109 
111  std::string
112  GetColorName(unsigned int c);
113 
117  unsigned int
118  GetClosestColorTableId(TPixel r, TPixel g, TPixel b);
119 
120 protected:
121  ColorTable() = default;
122  void
123  PrintSelf(std::ostream & os, Indent indent) const override;
124 
125 private:
126  using ColorNameVectorType = std::vector<std::string>;
127  using ColorVectorType = std::vector<RGBPixel<TPixel>>;
128 
129  void
130  DeleteColors();
131 
132  unsigned int m_NumberOfColors{ 0 };
133 
136 };
137 } // namespace itk
138 
139 #ifndef ITK_MANUAL_INSTANTIATION
140 # include "itkColorTable.hxx"
141 #endif
142 
143 #endif
itkObjectFactory.h
itk::RGBPixel< TPixel >
itkRGBPixel.h
itk::ColorTable::ColorNameVectorType
std::vector< std::string > ColorNameVectorType
Definition: itkColorTable.h:126
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ColorTable::m_Color
ColorVectorType m_Color
Definition: itkColorTable.h:135
itk::ColorTable
Define a color table for image visualisation.
Definition: itkColorTable.h:40
itk::ColorTable::m_ColorName
ColorNameVectorType m_ColorName
Definition: itkColorTable.h:134
itk::ColorTable::ColorVectorType
std::vector< RGBPixel< TPixel > > ColorVectorType
Definition: itkColorTable.h:127
itkObject.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62