DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Color.h
1 
17 #pragma once
18 
32 #if defined(Color_RECURSES)
33 #error Recursive header files inclusion detected in Color.h
34 #else // defined(Color_RECURSES)
35 
36 #define Color_RECURSES
37 
38 #if !defined Color_h
39 
40 #define Color_h
41 
43 // Inclusions
44 #include <iostream>
45 #include "DGtal/base/Common.h"
46 #include <boost/lexical_cast.hpp>
47 
49 
50 namespace DGtal
51 {
52 
54  // class Color
61  class Color
62  {
63  // ----------------------- Standard services ------------------------------
64  public:
65 
69  ~Color();
70 
71  // ----------------------- Interface --------------------------------------
72  public:
73 
81  Color( const unsigned int aRgb, unsigned char aAlpha = 255 );
82 
83 
92  Color( unsigned char aRedValue, unsigned char aGreenValue, unsigned char aBlueValue,
93  unsigned char aAlphaValue = 255 )
94  : myRed(aRedValue),myGreen(aGreenValue),myBlue(aBlueValue),myAlpha(aAlphaValue) { }
95 
96 
104  Color( unsigned char aGrayValue, unsigned char aAlphaValue = 255 )
105  : myRed(aGrayValue),myGreen(aGrayValue), myBlue(aGrayValue), myAlpha(aAlphaValue) { }
106 
107 
115  Color( const bool aValidColor = true )
116  : myRed(-1),myGreen(-1),myBlue(-1), myAlpha(255)
117  {
118  if ( aValidColor ) {
119  myRed = myGreen = myBlue = 0;
120  }
121  }
122 
123  Color& setRGBi( const unsigned char aRedValue,
124  const unsigned char aGreenValue,
125  const unsigned char aBlueValue,
126  const unsigned char aAlphaValue );
127 
128 
129  void red( const unsigned char aRedValue );
130 
131  void green( const unsigned char aGreenValue );
132 
133  void blue( const unsigned char aBlueValue );
134 
135  void alpha( const unsigned char aAlphaValue );
136 
137  unsigned char red() const ;
138 
139  unsigned char green() const ;
140 
141  unsigned char blue() const ;
142 
143  unsigned char alpha() const ;
144 
145  bool valid() const;
146 
147 
152  void selfDisplay ( std::ostream & out ) const;
153 
158  bool isValid() const;
159 
160 
161 
162  Color & setRGBf( float red,
163  float green,
164  float blue,
165  float alpha = 1.0 );
166 
167  bool operator==( const Color & aColor ) const;
168 
169  bool operator!=( const Color & aColor ) const;
170 
171  bool operator<( const Color & aColor ) const;
172 
173  void flushPostscript( std::ostream & ) const;
174 
175  std::string svg() const;
176 
185  std::string svgAlpha( const char * aPrefix ) const;
186 
187  std::string postscript() const;
188 
197  std::string tikz() const;
198 
199  static const Color None;
200  static const Color Black;
201  static const Color Gray;
202  static const Color White;
203  static const Color Red;
204  static const Color Green;
205  static const Color Lime;
206  static const Color Blue;
207  static const Color Cyan;
208  static const Color Magenta;
209  static const Color Yellow;
210  static const Color Silver;
211  static const Color Purple;
212  static const Color Navy;
213  static const Color Aqua;
214 
215 
216 
222  //Color ( const Color & aColor );
223 
230  // Color & operator= ( const Color & aColor );
231 
232 
233  // ------------------------- Protected Datas ------------------------------
234  private:
235  // ------------------------- Private Datas --------------------------------
236  private:
237  int myRed;
238  int myGreen;
239  int myBlue;
240  int myAlpha;
241  // ------------------------- Hidden services ------------------------------
242  protected:
243 
244 
245  private:
246 
247 
248 
249 
250 
251  // ------------------------- Internals ------------------------------------
252  private:
253 
254  }; // end of class Color
255 
256 
263  std::ostream&
264  operator<< ( std::ostream & out, const Color & aColor );
265 
266 
267 } // namespace DGtal
268 
269 
271 // Includes inline functions/methods
272 #include "DGtal/io/Color.ih"
273 
274 
275 // //
277 
278 #endif // !defined Color_h
279 
280 #undef Color_RECURSES
281 #endif // else defined(Color_RECURSES)