1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef _Color_H_
#define _Color_H_

#include <cstring>
#include <sstream>
#include <iostream>

#include "Tools/Math/Vector_n.h"

/**
* class Color encodes a color by 4 double values.
* The values represent red, green, blue and the alpha chanels.
* every value has to be between 0.0 and 1.0
*/
class Color: public Vector_n<double,4>
{
public:
  enum ColorPalett
  {
    white,
    gray,
    black,
    pink,
    red,
    orange,
    yellow,
    green,
    skyblue,
    blue
  };

  enum Chanel
  {
    Red,
    Green,
    Blue,
    Alpha,
    numberOfChanel
  };

  // default color is black
  Color();

  Color(const Vector_n<double,4>& colorVector);

  Color(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255);

  Color(double r, double g, double b, double a = 1.0);

  Color(const char* color);

  Color(ColorPalett c);

  /**
  * Generate a color using an index number.
  *
  * The generation is done by more or less random parameters which showed that
  * they generate differing colors for the first indexes.
  */
  Color(unsigned int colorIndex);

  unsigned char getRed() const;
  unsigned char getGreen() const;
  unsigned char getBlue() const;
  unsigned char getAlpha() const;

  // html style hex string
  std::string toString() const;

  static std::string charToHexString(unsigned char c);
  static int hexCharToInt(char c);
  static char intToHexChar(int n);

public:
  static Color RED;
  static Color BLUE;
  static Color GREEN;
};//end class Color

/**
 * Streaming operator that writes a Color to a stream.
 * @param stream The stream to write on.
 * @param image The Color object.
 * @return The stream.
 */ 
std::ostream& operator<<(std::ostream& stream, const Color& color);

#endif  /* _Color_H_ */