ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkColorTable.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkColorTable_h
00019 #define __itkColorTable_h
00020 
00021 #include "itkObject.h"
00022 #include "itkRGBPixel.h"
00023 #include "itkObjectFactory.h"
00024 
00025 #include <string>
00026 #include <vector>
00027 namespace itk
00028 {
00039 template< class TPixel >
00040 class ITK_EXPORT ColorTable:public Object
00041 {
00042 public:
00044   typedef ColorTable                 Self;
00045   typedef Object                     Superclass;
00046   typedef SmartPointer< Self >       Pointer;
00047   typedef SmartPointer< const Self > ConstPointer;
00048 
00050   itkNewMacro(Self);
00051 
00053   itkTypeMacro(ColorTable, Object);
00054 
00060   void    UseDiscreteColors(void);
00061 
00066   void    UseGrayColors(unsigned int n = 256);
00067 
00073   void    UseHeatColors(unsigned int n = 256);
00074 
00079   void    UseRandomColors(unsigned int n = 256);
00080 
00082   itkGetConstMacro(NumberOfColors, unsigned int);
00083 
00085   RGBPixel< TPixel > GetColor(unsigned int colorId);
00086 
00091   bool    SetColor(unsigned int c, TPixel r, TPixel g, TPixel b,
00092                    const char *name = "UserDefined");
00093   bool    SetColor(unsigned int c, RGBPixel<TPixel> pixel,
00094                    const char *name = "UserDefined");
00096 
00100   TPixel  GetColorComponent(unsigned int colorId, char rgb);
00101 
00103   std::string  GetColorName(unsigned int colorId);
00104 
00108   unsigned int GetClosestColorTableId(TPixel r, TPixel g, TPixel b);
00109 
00110 protected:
00111   ColorTable();
00112   void PrintSelf(std::ostream & os, Indent indent) const;
00113 
00114   unsigned int m_NumberOfColors;
00115 
00116   std::vector<std::string>         m_ColorName;
00117   std::vector<RGBPixel< TPixel > > m_Color;
00118 private:
00119   ColorTable(const Self &);     //purposely not implemented
00120   void operator=(const Self &); //purposely not implemented
00121 
00122   void DeleteColors();
00123 };
00124 } // namespace itk
00125 
00126 // Define instantiation macro for this template.
00127 #define ITK_TEMPLATE_ColorTable(_, EXPORT, TypeX, TypeY)     \
00128   namespace itk                                              \
00129   {                                                          \
00130   _( 1 ( class EXPORT ColorTable< ITK_TEMPLATE_1 TypeX > ) ) \
00131   namespace Templates                                        \
00132   {                                                          \
00133   typedef ColorTable< ITK_TEMPLATE_1 TypeX >                 \
00134   ColorTable##TypeY;                                       \
00135   }                                                          \
00136   }
00137 
00138 #if ITK_TEMPLATE_EXPLICIT
00139 #include "Templates/itkColorTable+-.h"
00140 #endif
00141 
00142 #if ITK_TEMPLATE_TXX
00143 #include "itkColorTable.hxx"
00144 #endif
00145 
00146 #endif
00147