3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
33 #include<lemon/bits/invalid.h>
35 #include<lemon/maps.h>
36 #include<lemon/bezier.h>
41 ///\brief Tools to manage RGB colors.
43 ///\author Alpar Juttner
50 ///Data structure representing RGB colors.
52 ///Data structure representing RGB colors.
58 ///Default constructor
61 Color(double r,double g,double b) :_r(r),_g(g),_b(b) {};
62 ///Set the red component
63 double & red() {return _r;}
64 ///Return the red component
65 const double & red() const {return _r;}
66 ///Set the green component
67 double & green() {return _g;}
68 ///Return the green component
69 const double & green() const {return _g;}
70 ///Set the blue component
71 double & blue() {return _b;}
72 ///Return the blue component
73 const double & blue() const {return _b;}
74 ///Set the color components
75 void set(double r,double g,double b) { _r=r;_g=g;_b=b; };
78 /// White color constant
79 extern const Color WHITE;
80 /// Black color constant
81 extern const Color BLACK;
82 /// Red color constant
83 extern const Color RED;
84 /// Green color constant
85 extern const Color GREEN;
86 /// Blue color constant
87 extern const Color BLUE;
88 /// Yellow color constant
89 extern const Color YELLOW;
90 /// Magenta color constant
91 extern const Color MAGENTA;
92 /// Cyan color constant
93 extern const Color CYAN;
94 /// Grey color constant
95 extern const Color GREY;
96 /// Dark red color constant
97 extern const Color DARK_RED;
98 /// Dark green color constant
99 extern const Color DARK_GREEN;
100 /// Drak blue color constant
101 extern const Color DARK_BLUE;
102 /// Dark yellow color constant
103 extern const Color DARK_YELLOW;
104 /// Dark magenta color constant
105 extern const Color DARK_MAGENTA;
106 /// Dark cyan color constant
107 extern const Color DARK_CYAN;
109 ///Maps <tt>int</tt>s to different \ref Color "Color"s
111 ///This map assigns one of the predefined \ref Color "Color"s
112 ///to each <tt>int</tt>. It is possible to change the colors as well as their
113 ///number. The integer range is cyclically mapped to the provided set of colors.
115 ///This is a true \ref concept::ReferenceMap "reference map", so you can also
116 ///change the actual colors.
118 class Palette : public MapBase<int,Color>
120 std::vector<Color> colors;
125 ///\param have_white indicates whether white is
126 ///amongst the provided color (\c true) or not (\c false). If it is true,
127 ///white will be assigned to \c 0.
128 ///\param num the number of the allocated colors. If it is \c 0,
129 ///the default color configuration is set up (26 color plus the white).
130 ///If \c num is less then 26/27 then the default color list is cut. Otherwise
131 ///the color list is filled repeatedly with the default color list.
132 ///(The colors can be changed later on.)
133 Palette(bool have_white=false,int num=0)
136 if(have_white) colors.push_back(Color(1,1,1));
138 colors.push_back(Color(0,0,0));
139 colors.push_back(Color(1,0,0));
140 colors.push_back(Color(0,1,0));
141 colors.push_back(Color(0,0,1));
142 colors.push_back(Color(1,1,0));
143 colors.push_back(Color(1,0,1));
144 colors.push_back(Color(0,1,1));
146 colors.push_back(Color(.5,0,0));
147 colors.push_back(Color(0,.5,0));
148 colors.push_back(Color(0,0,.5));
149 colors.push_back(Color(.5,.5,0));
150 colors.push_back(Color(.5,0,.5));
151 colors.push_back(Color(0,.5,.5));
153 colors.push_back(Color(.5,.5,.5));
154 colors.push_back(Color(1,.5,.5));
155 colors.push_back(Color(.5,1,.5));
156 colors.push_back(Color(.5,.5,1));
157 colors.push_back(Color(1,1,.5));
158 colors.push_back(Color(1,.5,1));
159 colors.push_back(Color(.5,1,1));
161 colors.push_back(Color(1,.5,0));
162 colors.push_back(Color(.5,1,0));
163 colors.push_back(Color(1,0,.5));
164 colors.push_back(Color(0,1,.5));
165 colors.push_back(Color(0,.5,1));
166 colors.push_back(Color(.5,0,1));
167 } while(int(colors.size())<num);
168 // colors.push_back(Color(1,1,1));
169 if(num>0) colors.resize(num);
172 Color &operator[](int i)
174 return colors[i%colors.size()];
177 const Color &operator[](int i) const
179 return colors[i%colors.size()];
182 void set(int i,const Color &c)
184 colors[i%colors.size()]=c;
186 ///Sets the number of the exiting colors.
187 void resize(int s) { colors.resize(s);}
188 ///Returns the number of the existing colors.
189 std::size_t size() const { return colors.size();}
192 ///Returns a visible distinct \ref Color
194 ///Returns a \ref Color which is as different from the given parameter
195 ///as it is possible.
196 inline Color distantColor(const Color &c)
198 return Color(c.red()<.5?1:0,c.green()<.5?1:0,c.blue()<.5?1:0);
200 ///Returns black for light colors and white for the dark ones.
202 ///Returns black for light colors and white for the dark ones.
203 inline Color distantBW(const Color &c){
204 return (.2125*c.red()+.7154*c.green()+.0721*c.blue())<.5 ? WHITE : BLACK;
209 } //END OF NAMESPACE LEMON
211 #endif // LEMON_COLOR_H