ITK  5.0.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< typename TPixel >
40 class ITK_TEMPLATE_EXPORT ColorTable:public Object
41 {
42 public:
43  ITK_DISALLOW_COPY_AND_ASSIGN(ColorTable);
44 
46  using Self = ColorTable;
47  using Superclass = Object;
50 
52  itkNewMacro(Self);
53 
55  itkTypeMacro(ColorTable, Object);
56 
62  void UseDiscreteColors();
63 
68  void UseGrayColors(unsigned int n = 256);
69 
75  void UseHeatColors(unsigned int n = 256);
76 
81  void UseRandomColors(unsigned int n = 256);
82 
84  itkGetConstMacro(NumberOfColors, unsigned int);
85 
87  RGBPixel< TPixel > GetColor(unsigned int colorId);
88 
93  bool SetColor(unsigned int c, TPixel r, TPixel g, TPixel b,
94  const char *name = "UserDefined");
95  bool SetColor(unsigned int c, RGBPixel<TPixel> pixel,
96  const char *name = "UserDefined");
98 
102  TPixel GetColorComponent(unsigned int colorId, char rgb);
103 
105  std::string GetColorName(unsigned int colorId);
106 
110  unsigned int GetClosestColorTableId(TPixel r, TPixel g, TPixel b);
111 
112 protected:
113  ColorTable() = default;
114  void PrintSelf(std::ostream & os, Indent indent) const override;
115 
116 private:
117  using ColorNameVectorType = std::vector< std::string >;
118  using ColorVectorType = std::vector< RGBPixel< TPixel > >;
119 
120  void DeleteColors();
121 
122  unsigned int m_NumberOfColors{ 0 };
123 
126 };
127 } // namespace itk
128 
129 #ifndef ITK_MANUAL_INSTANTIATION
130 #include "itkColorTable.hxx"
131 #endif
132 
133 #endif
std::vector< RGBPixel< TPixel > > ColorVectorType
ColorVectorType m_Color
Define a color table for image visualisation.
Definition: itkColorTable.h:40
std::vector< std::string > ColorNameVectorType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Base class for most ITK classes.
Definition: itkObject.h:60
ColorNameVectorType m_ColorName