1.1 --- a/lemon/color.h Wed Mar 07 11:56:53 2007 +0000
1.2 +++ b/lemon/color.h Wed Mar 07 11:57:23 2007 +0000
1.3 @@ -33,35 +33,35 @@
1.4 namespace lemon {
1.5
1.6
1.7 -/// \addtogroup misc
1.8 -/// @{
1.9 + /// \addtogroup misc
1.10 + /// @{
1.11
1.12 -///Data structure representing RGB colors.
1.13 + ///Data structure representing RGB colors.
1.14
1.15 -///Data structure representing RGB colors.
1.16 -class Color
1.17 -{
1.18 - double _r,_g,_b;
1.19 -public:
1.20 - ///Default constructor
1.21 - Color() {}
1.22 - ///Constructor
1.23 - Color(double r,double g,double b) :_r(r),_g(g),_b(b) {};
1.24 - ///Set the red component
1.25 - double & red() {return _r;}
1.26 - ///Return the red component
1.27 - const double & red() const {return _r;}
1.28 - ///Set the green component
1.29 - double & green() {return _g;}
1.30 - ///Return the green component
1.31 - const double & green() const {return _g;}
1.32 - ///Set the blue component
1.33 - double & blue() {return _b;}
1.34 - ///Return the blue component
1.35 - const double & blue() const {return _b;}
1.36 - ///Set the color components
1.37 - void set(double r,double g,double b) { _r=r;_g=g;_b=b; };
1.38 -};
1.39 + ///Data structure representing RGB colors.
1.40 + class Color
1.41 + {
1.42 + double _r,_g,_b;
1.43 + public:
1.44 + ///Default constructor
1.45 + Color() {}
1.46 + ///Constructor
1.47 + Color(double r,double g,double b) :_r(r),_g(g),_b(b) {};
1.48 + ///Set the red component
1.49 + double & red() {return _r;}
1.50 + ///Return the red component
1.51 + const double & red() const {return _r;}
1.52 + ///Set the green component
1.53 + double & green() {return _g;}
1.54 + ///Return the green component
1.55 + const double & green() const {return _g;}
1.56 + ///Set the blue component
1.57 + double & blue() {return _b;}
1.58 + ///Return the blue component
1.59 + const double & blue() const {return _b;}
1.60 + ///Set the color components
1.61 + void set(double r,double g,double b) { _r=r;_g=g;_b=b; };
1.62 + };
1.63
1.64 /// White color constant
1.65 extern const Color WHITE;
1.66 @@ -94,105 +94,113 @@
1.67 /// Dark cyan color constant
1.68 extern const Color DARK_CYAN;
1.69
1.70 -///Map <tt>int</tt>s to different \ref Color "Color"s
1.71 + ///Map <tt>int</tt>s to different \ref Color "Color"s
1.72
1.73 -///This map assigns one of the predefined \ref Color "Color"s
1.74 -///to each <tt>int</tt>. It is possible to change the colors as well as their
1.75 -///number. The integer range is cyclically mapped to the provided set of colors.
1.76 -///
1.77 -///This is a true \ref concepts::ReferenceMap "reference map", so you can also
1.78 -///change the actual colors.
1.79 + ///This map assigns one of the predefined \ref Color "Color"s to
1.80 + ///each <tt>int</tt>. It is possible to change the colors as well as
1.81 + ///their number. The integer range is cyclically mapped to the
1.82 + ///provided set of colors.
1.83 + ///
1.84 + ///This is a true \ref concepts::ReferenceMap "reference map", so
1.85 + ///you can also change the actual colors.
1.86
1.87 -class Palette : public MapBase<int,Color>
1.88 -{
1.89 - std::vector<Color> colors;
1.90 -public:
1.91 - ///Constructor
1.92 + class Palette : public MapBase<int,Color>
1.93 + {
1.94 + std::vector<Color> colors;
1.95 + public:
1.96 + ///Constructor
1.97
1.98 - ///Constructor
1.99 - ///\param have_white indicates whether white is
1.100 - ///amongst the provided color (\c true) or not (\c false). If it is true,
1.101 - ///white will be assigned to \c 0.
1.102 - ///\param num the number of the allocated colors. If it is \c 0,
1.103 - ///the default color configuration is set up (26 color plus the white).
1.104 - ///If \c num is less then 26/27 then the default color list is cut. Otherwise
1.105 - ///the color list is filled repeatedly with the default color list.
1.106 - ///(The colors can be changed later on.)
1.107 - Palette(bool have_white=false,int num=0)
1.108 + ///Constructor
1.109 + ///\param num the number of the allocated colors. If it is \c -1,
1.110 + ///the default color configuration is set up (26 color plus the
1.111 + ///white). If \c num is less then 26/27 then the default color
1.112 + ///list is cut. Otherwise the color list is filled repeatedly with
1.113 + ///the default color list. (The colors can be changed later on.)
1.114 + ///\param have_white indicates whether white is amongst the
1.115 + ///provided color (\c true) or not (\c false). If it is true,
1.116 + ///white will be assigned to \c 0.
1.117 + Palette(int num=-1,bool have_white=false)
1.118 + {
1.119 + if (num==0) return;
1.120 + do {
1.121 + if(have_white) colors.push_back(Color(1,1,1));
1.122 +
1.123 + colors.push_back(Color(0,0,0));
1.124 + colors.push_back(Color(1,0,0));
1.125 + colors.push_back(Color(0,1,0));
1.126 + colors.push_back(Color(0,0,1));
1.127 + colors.push_back(Color(1,1,0));
1.128 + colors.push_back(Color(1,0,1));
1.129 + colors.push_back(Color(0,1,1));
1.130 +
1.131 + colors.push_back(Color(.5,0,0));
1.132 + colors.push_back(Color(0,.5,0));
1.133 + colors.push_back(Color(0,0,.5));
1.134 + colors.push_back(Color(.5,.5,0));
1.135 + colors.push_back(Color(.5,0,.5));
1.136 + colors.push_back(Color(0,.5,.5));
1.137 +
1.138 + colors.push_back(Color(.5,.5,.5));
1.139 + colors.push_back(Color(1,.5,.5));
1.140 + colors.push_back(Color(.5,1,.5));
1.141 + colors.push_back(Color(.5,.5,1));
1.142 + colors.push_back(Color(1,1,.5));
1.143 + colors.push_back(Color(1,.5,1));
1.144 + colors.push_back(Color(.5,1,1));
1.145 +
1.146 + colors.push_back(Color(1,.5,0));
1.147 + colors.push_back(Color(.5,1,0));
1.148 + colors.push_back(Color(1,0,.5));
1.149 + colors.push_back(Color(0,1,.5));
1.150 + colors.push_back(Color(0,.5,1));
1.151 + colors.push_back(Color(.5,0,1));
1.152 + } while(int(colors.size())<num);
1.153 + // colors.push_back(Color(1,1,1));
1.154 + if(num>=0) colors.resize(num);
1.155 + }
1.156 + ///\e
1.157 + Color &operator[](int i)
1.158 + {
1.159 + return colors[i%colors.size()];
1.160 + }
1.161 + ///\e
1.162 + const Color &operator[](int i) const
1.163 + {
1.164 + return colors[i%colors.size()];
1.165 + }
1.166 + ///\e
1.167 + void set(int i,const Color &c)
1.168 + {
1.169 + colors[i%colors.size()]=c;
1.170 + }
1.171 + ///\e
1.172 + void add(const Color &c)
1.173 + {
1.174 + colors.push_back(c);
1.175 + }
1.176 +
1.177 + ///Sets the number of the exiting colors.
1.178 + void resize(int s) { colors.resize(s);}
1.179 + ///Returns the number of the existing colors.
1.180 + int size() const { return int(colors.size());}
1.181 + };
1.182 +
1.183 + ///Returns a visible distinct \ref Color
1.184 +
1.185 + ///Returns a \ref Color which is as different from the given parameter
1.186 + ///as it is possible.
1.187 + inline Color distantColor(const Color &c)
1.188 {
1.189 - do {
1.190 - if(have_white) colors.push_back(Color(1,1,1));
1.191 + return Color(c.red()<.5?1:0,c.green()<.5?1:0,c.blue()<.5?1:0);
1.192 + }
1.193 + ///Returns black for light colors and white for the dark ones.
1.194
1.195 - colors.push_back(Color(0,0,0));
1.196 - colors.push_back(Color(1,0,0));
1.197 - colors.push_back(Color(0,1,0));
1.198 - colors.push_back(Color(0,0,1));
1.199 - colors.push_back(Color(1,1,0));
1.200 - colors.push_back(Color(1,0,1));
1.201 - colors.push_back(Color(0,1,1));
1.202 -
1.203 - colors.push_back(Color(.5,0,0));
1.204 - colors.push_back(Color(0,.5,0));
1.205 - colors.push_back(Color(0,0,.5));
1.206 - colors.push_back(Color(.5,.5,0));
1.207 - colors.push_back(Color(.5,0,.5));
1.208 - colors.push_back(Color(0,.5,.5));
1.209 -
1.210 - colors.push_back(Color(.5,.5,.5));
1.211 - colors.push_back(Color(1,.5,.5));
1.212 - colors.push_back(Color(.5,1,.5));
1.213 - colors.push_back(Color(.5,.5,1));
1.214 - colors.push_back(Color(1,1,.5));
1.215 - colors.push_back(Color(1,.5,1));
1.216 - colors.push_back(Color(.5,1,1));
1.217 -
1.218 - colors.push_back(Color(1,.5,0));
1.219 - colors.push_back(Color(.5,1,0));
1.220 - colors.push_back(Color(1,0,.5));
1.221 - colors.push_back(Color(0,1,.5));
1.222 - colors.push_back(Color(0,.5,1));
1.223 - colors.push_back(Color(.5,0,1));
1.224 - } while(int(colors.size())<num);
1.225 - // colors.push_back(Color(1,1,1));
1.226 - if(num>0) colors.resize(num);
1.227 + ///Returns black for light colors and white for the dark ones.
1.228 + inline Color distantBW(const Color &c){
1.229 + return (.2125*c.red()+.7154*c.green()+.0721*c.blue())<.5 ? WHITE : BLACK;
1.230 }
1.231 - ///\e
1.232 - Color &operator[](int i)
1.233 - {
1.234 - return colors[i%colors.size()];
1.235 - }
1.236 - ///\e
1.237 - const Color &operator[](int i) const
1.238 - {
1.239 - return colors[i%colors.size()];
1.240 - }
1.241 - ///\e
1.242 - void set(int i,const Color &c)
1.243 - {
1.244 - colors[i%colors.size()]=c;
1.245 - }
1.246 - ///Sets the number of the exiting colors.
1.247 - void resize(int s) { colors.resize(s);}
1.248 - ///Returns the number of the existing colors.
1.249 - std::size_t size() const { return colors.size();}
1.250 -};
1.251
1.252 -///Returns a visible distinct \ref Color
1.253 -
1.254 -///Returns a \ref Color which is as different from the given parameter
1.255 -///as it is possible.
1.256 -inline Color distantColor(const Color &c)
1.257 -{
1.258 - return Color(c.red()<.5?1:0,c.green()<.5?1:0,c.blue()<.5?1:0);
1.259 -}
1.260 -///Returns black for light colors and white for the dark ones.
1.261 -
1.262 -///Returns black for light colors and white for the dark ones.
1.263 -inline Color distantBW(const Color &c){
1.264 - return (.2125*c.red()+.7154*c.green()+.0721*c.blue())<.5 ? WHITE : BLACK;
1.265 -}
1.266 -
1.267 -/// @}
1.268 + /// @}
1.269
1.270 } //END OF NAMESPACE LEMON
1.271