inlib
1.2.0
|
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved. 00002 // See the file inlib.license for terms. 00003 00004 #ifndef inlib_colorf 00005 #define inlib_colorf 00006 00007 #include "vec3f" 00008 #include <sstream> 00009 00010 namespace inlib { 00011 00012 class colorf : public vec3f { 00013 public: 00014 colorf(){} 00015 colorf(float a_r,float a_g,float a_b):vec3f(a_r,a_g,a_b){} 00016 virtual ~colorf() {} 00017 public: 00018 colorf(const colorf& a_from):vec3f(a_from){} 00019 colorf& operator=(const colorf& a_from){ 00020 vec3f::operator=(a_from); 00021 return *this; 00022 } 00023 public: 00024 float r() const {return m_vector[0];} 00025 float g() const {return m_vector[1];} 00026 float b() const {return m_vector[2];} 00027 00028 public: 00029 // our forever 65 named colors taken long time ago from X11. 00030 00031 //NOTE : don't handle a static object because of mem balance. 00032 //0-9 00033 static colorf aquamarine() {return colorf(0.496101F,0.996109F,0.828138F);} 00034 static colorf mediumaquamarine() {return colorf(0.398444F,0.800793F,0.664073F);} 00035 static colorf black() {return colorf(0,0,0);} 00036 static colorf blue() {return colorf(0,0,1);} 00037 static colorf cadetblue() {return colorf(0.371099F,0.617197F,0.62501F);} 00038 static colorf cornflowerblue() {return colorf(0.390631F,0.58204F,0.925795F);} 00039 static colorf darkslateblue() {return colorf(0.281254F,0.238285F,0.542977F);} 00040 static colorf lightblue() {return colorf(0.675792F,0.843763F,0.898451F);} 00041 static colorf lightsteelblue() {return colorf(0.68751F,0.765637F,0.867201F);} 00042 static colorf mediumblue() {return colorf(0,0,0.800793F);} 00043 00044 //10-19 00045 static colorf mediumslateblue() {return colorf(0.480476F,0.406256F,0.929702F);} 00046 static colorf midnightblue() {return colorf(0.0976577F,0.0976577F,0.437507F);} 00047 static colorf navyblue() {return colorf(0,0,0.500008F);} 00048 static colorf navy() {return colorf(0,0,0.500008F);} 00049 static colorf skyblue() {return colorf(0.527352F,0.8047F,0.917983F);} 00050 static colorf slateblue() {return colorf(0.414069F,0.351568F,0.800793F);} 00051 static colorf steelblue() {return colorf(0.273442F,0.50782F,0.703136F);} 00052 static colorf coral() {return colorf(0.996109F,0.496101F,0.312505F);} 00053 static colorf cyan() {return colorf(0,1,1);} 00054 static colorf firebrick() {return colorf(0.695323F,0.132815F,0.132815F);} 00055 00056 //20-29 00057 static colorf brown() {return colorf(0.644541F,0.164065F,0.164065F);} 00058 static colorf gold() {return colorf(0.996109F,0.839857F,0);} 00059 static colorf goldenrod() {return colorf(0.851575F,0.644541F,0.125002F);} 00060 static colorf green() {return colorf(0,1,0);} 00061 static colorf darkgreen() {return colorf(0,0.390631F,0);} 00062 static colorf darkolivegreen() {return colorf(0.332036F,0.417975F,0.183597F);} 00063 static colorf forestgreen() {return colorf(0.132815F,0.542977F,0.132815F);} 00064 static colorf limegreen() {return colorf(0.195315F,0.800793F,0.195315F);} 00065 static colorf mediumseagreen() {return colorf(0.234379F,0.699229F,0.441413F);} 00066 static colorf mediumspringgreen() {return colorf(0,0.976577F,0.601572F);} 00067 00068 //30-39 00069 static colorf palegreen() {return colorf(0.593759F,0.980484F,0.593759F);} 00070 static colorf seagreen() {return colorf(0.17969F,0.542977F,0.339849F);} 00071 static colorf springgreen() {return colorf(0,0.996109F,0.496101F);} 00072 static colorf yellowgreen() {return colorf(0.601572F,0.800793F,0.195315F);} 00073 static colorf darkslategrey() {return colorf(0.183597F,0.308598F,0.308598F);} 00074 static colorf dimgrey() {return colorf(0.410163F,0.410163F,0.410163F);} 00075 static colorf lightgrey() {return colorf(0.824231F,0.824231F,0.824231F);} 00076 static colorf grey() {return colorf(0.750011F,0.750011F,0.750011F);} 00077 static colorf khaki() {return colorf(0.937514F,0.898451F,0.546883F);} 00078 static colorf magenta() {return colorf(1,0,1);} 00079 00080 //40-49 00081 static colorf maroon() {return colorf(0.68751F,0.187503F,0.375006F);} 00082 static colorf orange() {return colorf(0.996109F,0.644541F,0);} 00083 static colorf orchid() {return colorf(0.851575F,0.437507F,0.83595F);} 00084 static colorf darkorchid() {return colorf(0.597665F,0.195315F,0.796887F);} 00085 static colorf mediumorchid() {return colorf(0.726574F,0.332036F,0.824231F);} 00086 static colorf pink() {return colorf(0.996109F,0.750011F,0.792981F);} 00087 static colorf plum() {return colorf(0.863294F,0.62501F,0.863294F);} 00088 static colorf red() {return colorf(1,0,0);} 00089 static colorf indianred() {return colorf(0.800793F,0.35938F,0.35938F);} 00090 static colorf mediumvioletred() {return colorf(0.777356F,0.0820325F,0.519539F);} 00091 00092 //50-59 00093 static colorf orangered() {return colorf(0.996109F,0.269535F,0);} 00094 static colorf violetred() {return colorf(0.812512F,0.125002F,0.562509F);} 00095 static colorf salmon() {return colorf(0.976577F,0.500008F,0.445319F);} 00096 static colorf sienna() {return colorf(0.62501F,0.320317F,0.175784F);} 00097 static colorf tan() {return colorf(0.820325F,0.703136F,0.546883F);} 00098 static colorf thistle() {return colorf(0.843763F,0.746105F,0.843763F);} 00099 static colorf turquoise() {return colorf(0.250004F,0.875013F,0.812512F);} 00100 static colorf darkturquoise() {return colorf(0,0.8047F,0.816419F);} 00101 static colorf mediumturquoise() {return colorf(0.281254F,0.816419F,0.796887F);} 00102 static colorf violet() {return colorf(0.929702F,0.50782F,0.929702F);} 00103 00104 //60-64 00105 static colorf blueviolet() {return colorf(0.539071F,0.167971F,0.882826F);} 00106 static colorf wheat() {return colorf(0.957046F,0.867201F,0.699229F);} 00107 static colorf white() {return colorf(1,1,1);} 00108 static colorf yellow() {return colorf(1,1,0);} 00109 static colorf greenyellow() {return colorf(0.675792F,0.996109F,0.18359F);} 00110 00111 public: //a list form of the uppers : 00112 00113 // because of sg/style_colormap, do we still want the below ? 00114 00115 static unsigned int named_color_number() {return 65;} 00116 typedef char name[24]; 00117 static const name* named_color_names() { 00118 static const char list[65][24] = { //read only static. 00119 "aquamarine", 00120 "mediumaquamarine", 00121 "black", 00122 "blue", 00123 "cadetblue", 00124 "cornflowerblue", 00125 "darkslateblue", 00126 "lightblue", 00127 "lightsteelblue", 00128 "mediumblue", 00129 00130 "mediumslateblue", 00131 "midnightblue", 00132 "navyblue", 00133 "navy", 00134 "skyblue", 00135 "slateblue", 00136 "steelblue", 00137 "coral", 00138 "cyan", 00139 "firebrick", 00140 00141 "brown", 00142 "gold", 00143 "goldenrod", 00144 "green", 00145 "darkgreen", 00146 "darkolivegreen", 00147 "forestgreen", 00148 "limegreen", 00149 "mediumseagreen", 00150 "mediumspringgreen", 00151 00152 "palegreen", 00153 "seagreen", 00154 "springgreen", 00155 "yellowgreen", 00156 "darkslategrey", 00157 "dimgrey", 00158 "lightgrey", 00159 "grey", 00160 "khaki", 00161 "magenta", 00162 00163 "maroon", 00164 "orange", 00165 "orchid", 00166 "darkorchid", 00167 "mediumorchid", 00168 "pink", 00169 "plum", 00170 "red", 00171 "indianred", 00172 "mediumvioletred", 00173 00174 "orangered", 00175 "violetred", 00176 "salmon", 00177 "sienna", 00178 "tan", 00179 "thistle", 00180 "turquoise", 00181 "darkturquoise", 00182 "mediumturquoise", 00183 "violet", 00184 00185 "blueviolet", 00186 "wheat", 00187 "white", 00188 "yellow", 00189 "greenyellow" 00190 }; 00191 return list; 00192 } 00193 00194 typedef float rgb[3]; 00195 static const rgb* named_color_rgbs() { 00196 static const float list[65][3] = { 00197 {0.496101f,0.996109f,0.828138f}, //aquamarine 00198 {0.398444f,0.800793f,0.664073f}, //mediumaquamarine 00199 {0,0,0}, //black 00200 {0,0,1}, //blue 00201 {0.371099f,0.617197f,0.62501f}, //cadetblue 00202 {0.390631f,0.58204f,0.925795f}, //cornflowerblue 00203 {0.281254f,0.238285f,0.542977f}, //darkslateblue 00204 {0.675792f,0.843763f,0.898451f}, //lightblue 00205 {0.68751f,0.765637f,0.867201f}, //lightsteelblue 00206 {0,0,0.800793f}, //mediumblue 00207 00208 {0.480476f,0.406256f,0.929702f}, //mediumslateblue 00209 {0.0976577f,0.0976577f,0.437507f}, //midnightblue 00210 {0,0,0.500008f}, //navyblue 00211 {0,0,0.500008f}, //navy 00212 {0.527352f,0.8047f,0.917983f}, //skyblue 00213 {0.414069f,0.351568f,0.800793f}, //slateblue 00214 {0.273442f,0.50782f,0.703136f}, //steelblue 00215 {0.996109f,0.496101f,0.312505f}, //coral 00216 {0,1,1}, //cyan 00217 {0.695323f,0.132815f,0.13281f}, //firebrick 00218 00219 {0.644541f,0.164065f,0.164065f}, //brown 00220 {0.996109f,0.839857f,0}, //gold 00221 {0.851575f,0.644541f,0.125002f}, //goldenrod 00222 {0,1,0}, //green 00223 {0,0.390631f,0}, //darkgreen 00224 {0.332036f,0.417975f,0.183597f}, //darkolivegreen 00225 {0.132815f,0.542977f,0.132815f}, //forestgreen 00226 {0.195315f,0.800793f,0.195315f}, //limegreen 00227 {0.234379f,0.699229f,0.441413f}, //mediumseagreen 00228 {0,0.976577f,0.601572f}, //mediumspringgreen 00229 00230 {0.593759f,0.980484f,0.593759f}, //palegreen 00231 {0.17969f,0.542977f,0.339849f}, //seagreen 00232 {0,0.996109f,0.496101f}, //springgreen 00233 {0.601572f,0.800793f,0.195315f}, //yellowgreen 00234 {0.183597f,0.308598f,0.308598f}, //darkslategrey 00235 {0.410163f,0.410163f,0.410163f}, //dimgrey 00236 {0.824231f,0.824231f,0.824231f}, //lightgrey 00237 {0.750011f,0.750011f,0.750011f}, //grey 00238 {0.937514f,0.898451f,0.546883f}, //khaki 00239 {1,0,1}, //magenta 00240 00241 {0.68751f,0.187503f,0.375006f}, //maroon 00242 {0.996109f,0.644541f,0}, //orange 00243 {0.851575f,0.437507f,0.83595f}, //orchid 00244 {0.597665f,0.195315f,0.796887f}, //darkorchid 00245 {0.726574f,0.332036f,0.824231f}, //mediumorchid 00246 {0.996109f,0.750011f,0.792981f}, //pink 00247 {0.863294f,0.62501f,0.863294f}, //plum 00248 {1,0,0}, //red 00249 {0.800793f,0.35938f,0.35938f}, //indianred 00250 {0.777356f,0.0820325f,0.519539f}, //mediumvioletred 00251 00252 {0.996109f,0.269535f,0}, //orangered 00253 {0.812512f,0.125002f,0.562509f}, //violetred 00254 {0.976577f,0.500008f,0.445319f}, //salmon 00255 {0.62501f,0.320317f,0.175784f}, //sienna 00256 {0.820325f,0.703136f,0.546883f}, //tan 00257 {0.843763f,0.746105f,0.843763f}, //thistle 00258 {0.250004f,0.875013f,0.812512f}, //turquoise 00259 {0,0.8047f,0.816419f}, //darkturquoise 00260 {0.281254f,0.816419f,0.796887f}, //mediumturquoise 00261 {0.929702f,0.50782f,0.929702f}, //violet 00262 00263 {0.539071f,0.167971f,0.882826f}, //blueviolet 00264 {0.957046f,0.867201f,0.699229f}, //wheat 00265 {1,1,1}, //white 00266 {1,1,0}, //yellow 00267 {0.675792f,0.996109f,0.18359f} //greenyellow 00268 }; 00269 return list; 00270 } 00271 00272 static bool to(const std::string& a_string, 00273 float& a_r,float& a_g,float& a_b){ 00274 unsigned int number = named_color_number(); 00275 const colorf::name* names = named_color_names(); 00276 const colorf::rgb* rgbs = named_color_rgbs(); 00277 for(unsigned int index=0;index<number;index++) { 00278 if(a_string==names[index]) { 00279 a_r = rgbs[index][0]; 00280 a_g = rgbs[index][1]; 00281 a_b = rgbs[index][2]; 00282 return true; 00283 } 00284 } 00285 a_r = 0.5f; 00286 a_g = 0.5f; 00287 a_b = 0.5f; 00288 return false; 00289 } 00290 00291 static std::string to(colorf& a_color){ 00292 std::ostringstream strm; 00293 strm << a_color[0]; 00294 strm << " "; 00295 strm << a_color[1]; 00296 strm << " "; 00297 strm << a_color[2]; 00298 return strm.str(); 00299 } 00300 00301 }; 00302 00303 inline std::ostream& operator<<(std::ostream& a_out,const colorf& a_this){ 00304 a_out << "r = " << a_this[0] 00305 << ",g = " << a_this[1] 00306 << ",b = " << a_this[2] 00307 << std::endl; 00308 return a_out; 00309 } 00310 00311 } 00312 00313 #endif