Whiteboard
An interface and tools for visualizing large and complex datasets
Color.h
Go to the documentation of this file.
1 
2 
3 #ifndef COLOR_H
4 #define COLOR_H
5 
6 #include <iostream>
7 using namespace std;
8 
12 class color {
13 
14  public:
15 
16  color( float r,
17  float g,
18  float b ) : r_(r), g_(g), b_(b) { }
19 
20  color( ) :
21  r_(0.0),
22  g_(0.0),
23  b_(0.0)
24  { }
25 
29  float R( ) const { return r_; }
30 
34  float G( ) const { return g_; }
35 
39  float B( ) const { return b_; }
40 
44  friend bool operator==( const color& lhs, const color& rhs )
45  { return ( lhs.r_ == rhs.r_ && lhs.g_ == rhs.g_ && lhs.b_ == rhs.b_); }
46 
50  friend bool operator!=( const color& lhs, const color& rhs )
51  { return !( lhs == rhs ); }
52 
53  friend std::ostream& operator<<( std::ostream& o, const color& c);
54 
55  private:
56 
57  float r_, g_, b_;
58  };
59 
63  const color white(1, 1, 1), black(0, 0, 0);
64  const color red(1, 0, 0), green(0, 1, 0), blue(0, 0, 1);
65 
66  const color pink(1, 0.5, 0.5);
67  const color lighterpink(1, 0.8, 0.8);
68 
69  const color magenta(1, 0, 1), yellow(1, 1, 0), cyan(0, 1, 1);
70 
71  const color gray(0.5, 0.5, 0.5);
72  const color darkergray(0.3, 0.3, 0.3);
73  const color darkgray(0.3, 0.3, 0.3);
74  const color lightgray(0.6, 0.6, 0.6);
75  const color lightergray(0.8, 0.8, 0.8);
76 
77  const color azure(0, 0.5, 1);
78  const color orangered(1, 0.27, 0);
79  const color seashell(1, 0.96, 0.93);
80  const color limegreen(0.2, 0.8, 0.2);
81  const color wheat(0.96, 0.87, 0.7);
82 
83 
87 color MakeUpColor(int num);
88 
93 inline color Gradient(double val, const color & base, const color & back = color(0.99, 0.99, 0.99))
94 {
95  if (val > 0.999)
96  val = 0.999;
97  double r = base.R() * val + back.R() * (1.-val);
98  double g = base.G() * val + back.G() * (1.-val);
99  double b = base.B() * val + back.B() * (1.-val);
100  return color(r, g, b);
101 }
102 
106 inline color GradientMult(double val, const color & neg, const color & pos, const color & back = color(0.99, 0.99, 0.99))
107 {
108  if (val >= 0) {
109  if (val > 0.999)
110  val = 0.999;
111  double r = pos.R() * val + back.R() * (1.-val);
112  double g = pos.G() * val + back.G() * (1.-val);
113  double b = pos.B() * val + back.B() * (1.-val);
114  return color(r, g, b);
115  } else {
116  val = -val;
117  if (val > 0.999)
118  val = 0.999;
119  double r = neg.R() * val + back.R() * (1.-val);
120  double g = neg.G() * val + back.G() * (1.-val);
121  double b = neg.B() * val + back.B() * (1.-val);
122  return color(r, g, b);
123 
124  }
125 }
126 
127 #endif
const color limegreen(0.2, 0.8, 0.2)
const color green(0, 1, 0)
const color blue(0, 0, 1)
float B() const
Definition: Color.h:39
const color lightgray(0.6, 0.6, 0.6)
float g_
Definition: Color.h:57
const color magenta(1, 0, 1)
float b_
Definition: Color.h:57
const color pink(1, 0.5, 0.5)
float R() const
Definition: Color.h:29
const color darkergray(0.3, 0.3, 0.3)
const color yellow(1, 1, 0)
float G() const
Definition: Color.h:34
const color orangered(1, 0.27, 0)
const color black(0, 0, 0)
color Gradient(double val, const color &base, const color &back=color(0.99, 0.99, 0.99))
Definition: Color.h:93
color MakeUpColor(int num)
Definition: Color.cc:733
const color azure(0, 0.5, 1)
const color wheat(0.96, 0.87, 0.7)
friend bool operator==(const color &lhs, const color &rhs)
Definition: Color.h:44
friend bool operator!=(const color &lhs, const color &rhs)
Definition: Color.h:50
const color gray(0.5, 0.5, 0.5)
const color darkgray(0.3, 0.3, 0.3)
const color seashell(1, 0.96, 0.93)
const color red(1, 0, 0)
color()
Definition: Color.h:20
const color lightergray(0.8, 0.8, 0.8)
color(float r, float g, float b)
Definition: Color.h:16
ostream & operator<<(ostream &o, const color &c)
Definition: Color.cc:13
const color lighterpink(1, 0.8, 0.8)
const color cyan(0, 1, 1)
Definition: Color.h:12
float r_
Definition: Color.h:57
color GradientMult(double val, const color &neg, const color &pos, const color &back=color(0.99, 0.99, 0.99))
Definition: Color.h:106
const color white(1, 1, 1)