ITK  6.0.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  * https://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 TComponent>
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  itkOverrideGetNameOfClassMacro(ColorTable);
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, TComponent r, TComponent g, TComponent b, const char * name = "UserDefined");
100  bool
101  SetColor(unsigned int c, RGBPixel<TComponent> pixel, const char * name = "UserDefined");
107  TComponent
108  GetColorComponent(unsigned int c, char rgb);
109 
111  std::string
112  GetColorName(unsigned int c);
113 
117  unsigned int
118  GetClosestColorTableId(TComponent r, TComponent g, TComponent 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<TComponent>>;
128 
129  void
130  DeleteColors();
131 
132  unsigned int m_NumberOfColors{ 0 };
133 
134  ColorNameVectorType m_ColorName{};
135  ColorVectorType m_Color{};
136 };
137 } // namespace itk
138 
139 #ifndef ITK_MANUAL_INSTANTIATION
140 # include "itkColorTable.hxx"
141 #endif
142 
143 #endif
itkObjectFactory.h
itk::RGBPixel
Represent Red, Green and Blue components for color images.
Definition: itkRGBPixel.h:58
itkRGBPixel.h
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ColorTable
Define a color table for image visualisation.
Definition: itkColorTable.h:40
itk::ColorTable::ColorNameVectorType
std::vector< std::string > ColorNameVectorType
Definition: itkColorTable.h:126
itkObject.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::ColorTable::ColorVectorType
std::vector< RGBPixel< TComponent > > ColorVectorType
Definition: itkColorTable.h:127