4 #ifndef tools_sg_style_colormap
5 #define tools_sg_style_colormap
12 #include "../S_STRING"
21 typedef std::map<unsigned int,style_color> parent;
23 typedef std::map<unsigned int,style_color>
map_t;
29 mem::increment(s_class().c_str());
34 mem::decrement(s_class().c_str());
40 mem::increment(s_class().c_str());
44 parent::operator=(a_from);
49 map_t::const_iterator it =
find(a_index);
54 a_col = (*it).second.second;
59 if((*it).second.first==a_s) {
60 a_col = (*it).second.second;
68 map_t::const_iterator it =
find(a_index);
69 if(it==
end()) {a_s.clear();
return false;}
70 colorf c = (*it).second.second;
73 snpf(ss,
sizeof(ss),
"%g %g %g",c[0],c[1],c[2]);
74 a_s = std::string(ss);
79 (*this)[
uint32((*this).size())] = a_color;
94 #define STYLE_COLORMAP_ADD(a__name) \
95 tmp.set_name(#a__name);\
96 set_color_##a__name(tmp);\
173 #undef STYLE_COLORMAP_ADD
182 enum EColor { kWhite =0, kBlack =1, kGray=920,
183 kRed =632, kGreen =416, kBlue=600, kYellow=400, kMagenta=616, kCyan=432,
184 kOrange=800, kSpring=820, kTeal=840, kAzure =860, kViolet =880, kPink=900};
247 #define TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR(a__i,a__name) \
248 new_TColor(a__i,get_color_ROOT_##a__name<colorf>(),#a__name);
262 #undef TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR
270 {
float saturation = 1;
271 float lightness = 0.5;
274 unsigned int MaxPretty = 50;
278 std::string head(
"Color");
279 for(
unsigned int i=0 ; i<MaxPretty ; i++) {
280 hue = MaxHue-(i+1)*((MaxHue-MinHue)/MaxPretty);
281 hls_to_rgb(hue, lightness, saturation, r, g, b);
290 {
for(
unsigned int i=1 ; i<=50 ; i++) {
291 map_t::const_iterator it =
find(i);
293 const std::string& nam = (*it).second.first;
294 const colorf& col = (*it).second.second;
295 rgb_to_hls<double>(col.
r(),col.
g(),col.
b(),h,l,s);
296 hls_to_rgb<double>(h,0.7*l,s, r, g, b);
303 {
for(
unsigned int i=1 ; i<=50 ; i++) {
304 map_t::const_iterator it =
find(i);
306 const std::string& nam = (*it).second.first;
307 const colorf& col = (*it).second.second;
308 rgb_to_hls<double>(col.
r(),col.
g(),col.
b(),h,l,s);
309 hls_to_rgb<double>(h,1.2*l,s, r, g, b);
315 {std::string head(
"Color");
317 for(
unsigned int i = 1; i <= 7; i++) {
318 map_t::const_iterator it =
find(i);
320 const colorf& col = (*it).second.second;
324 if (i == 1) { r = 0.6; g = 0.6; b = 0.6; }
359 double a_r,
double a_g,
double a_b,
360 const std::string& a_n) {
361 (*this)[a_i] =
style_color(a_n,
float(a_r),
float(a_g),
float(a_b));
364 double a_r,
double a_g,
double a_b,
365 const std::string& a_head,
unsigned int a_index) {
367 if(!
num2s(a_index,stmp)) {}
371 (*this)[a_i] =
style_color(a_n,a_color.
r(),a_color.
g(),a_color.
b());
375 const std::string& a_name,
376 unsigned char a_rgb[]) {
378 for(
unsigned int n=0;n<15;n++) {
379 int colorn = a_offset+n-10;
380 if(colorn<0)
continue;
382 new_TColor(colorn,a_rgb[3*n]/255.,a_rgb[3*n+1]/255.,a_rgb[3*n+2]/255.,a_name+
"+",n-10);
384 new_TColor(colorn,a_rgb[3*n]/255.,a_rgb[3*n+1]/255.,a_rgb[3*n+2]/255.,a_name+
"-",10-n);
386 new_TColor(colorn,a_rgb[3*n]/255.,a_rgb[3*n+1]/255.,a_rgb[3*n+2]/255.,a_name);
393 const std::string& a_name,
394 unsigned char a_rgb[]) {
396 for (
unsigned int n=0;n<20;n++) {
397 int colorn = a_offset+n-9;
398 if(colorn<0)
continue;
400 new_TColor(colorn,a_rgb[3*n]/255.,a_rgb[3*n+1]/255.,a_rgb[3*n+2]/255.,a_name+
"+",n-9);
402 new_TColor(colorn,a_rgb[3*n]/255.,a_rgb[3*n+1]/255.,a_rgb[3*n+2]/255.,a_name+
"-",9-n);
404 new_TColor(colorn,a_rgb[3*n]/255.,a_rgb[3*n+1]/255.,a_rgb[3*n+2]/255.,a_name);
413 typedef unsigned char UChar_t;
414 UChar_t magenta[46]= {255,204,255
415 ,255,153,255, 204,153,204
416 ,255,102,255, 204,102,204, 153,102,153
417 ,255, 51,255, 204, 51,204, 153, 51,153, 102, 51,102
418 ,255, 0,255, 204, 0,204, 153, 0,153, 102, 0,102, 51, 0, 51};
420 UChar_t red[46] = {255,204,204
421 ,255,153,153, 204,153,153
422 ,255,102,102, 204,102,102, 153,102,102
423 ,255, 51, 51, 204, 51, 51, 153, 51, 51, 102, 51, 51
424 ,255, 0, 0, 204, 0, 0, 153, 0, 0, 102, 0, 0, 51, 0, 0};
426 UChar_t yellow[46] = {255,255,204
427 ,255,255,153, 204,204,153
428 ,255,255,102, 204,204,102, 153,153,102
429 ,255,255, 51, 204,204, 51, 153,153, 51, 102,102, 51
430 ,255,255, 0, 204,204, 0, 153,153, 0, 102,102, 0, 51, 51, 0};
432 UChar_t green[46] = {204,255,204
433 ,153,255,153, 153,204,153
434 ,102,255,102, 102,204,102, 102,153,102
435 , 51,255, 51, 51,204, 51, 51,153, 51, 51,102, 51
436 , 0,255, 0, 0,204, 0, 0,153, 0, 0,102, 0, 0, 51, 0};
438 UChar_t cyan[46] = {204,255,255
439 ,153,255,255, 153,204,204
440 ,102,255,255, 102,204,204, 102,153,153
441 , 51,255,255, 51,204,204, 51,153,153, 51,102,102
442 , 0,255,255, 0,204,204, 0,153,153, 0,102,102, 0, 51, 51};
444 UChar_t blue[46] = {204,204,255
445 ,153,153,255, 153,153,204
446 ,102,102,255, 102,102,204, 102,102,153
447 , 51, 51,255, 51, 51,204, 51, 51,153, 51, 51,102
448 , 0, 0,255, 0, 0,204, 0, 0,153, 0, 0,102, 0, 0, 51};
451 255, 51,153, 204, 0,102, 102, 0, 51, 153, 0, 51, 204, 51,102
452 ,255,102,153, 255, 0,102, 255, 51,102, 204, 0, 51, 255, 0, 51
453 ,255,153,204, 204,102,153, 153, 51,102, 153, 0,102, 204, 51,153
454 ,255,102,204, 255, 0,153, 204, 0,153, 255, 51,204, 255, 0,153};
457 255,204,153, 204,153,102, 153,102, 51, 153,102, 0, 204,153, 51
458 ,255,204,102, 255,153, 0, 255,204, 51, 204,153, 0, 255,204, 0
459 ,255,153, 51, 204,102, 0, 102, 51, 0, 153, 51, 0, 204,102, 51
460 ,255,153,102, 255,102, 0, 255,102, 51, 204, 51, 0, 255, 51, 0};
463 153,255, 51, 102,204, 0, 51,102, 0, 51,153, 0, 102,204, 51
464 ,153,255,102, 102,255, 0, 102,255, 51, 51,204, 0, 51,255, 0
465 ,204,255,153, 153,204,102, 102,153, 51, 102,153, 0, 153,204, 51
466 ,204,255,102, 153,255, 0, 204,255, 51, 153,204, 0, 204,255, 0};
469 153,255,204, 102,204,153, 51,153,102, 0,153,102, 51,204,153
470 ,102,255,204, 0,255,102, 51,255,204, 0,204,153, 0,255,204
471 , 51,255,153, 0,204,102, 0,102, 51, 0,153, 51, 51,204,102
472 ,102,255,153, 0,255,153, 51,255,102, 0,204, 51, 0,255, 51};
475 153,204,255, 102,153,204, 51,102,153, 0, 51,153, 51,102,204
476 ,102,153,255, 0,102,255, 51,102,255, 0, 51,204, 0, 51,255
477 , 51,153,255, 0,102,204, 0, 51,102, 0,102,153, 51,153,204
478 ,102,204,255, 0,153,255, 51,204,255, 0,153,204, 0,204,255};
481 204,153,255, 153,102,204, 102, 51,153, 102, 0,153, 153, 51,204
482 ,204,102,255, 153, 0,255, 204, 51,255, 153, 0,204, 204, 0,255
483 ,153, 51,255, 102, 0,204, 51, 0,102, 51, 0,153, 102, 51,204
484 ,153,102,255, 102, 0,255, 102, 51,255, 51, 0,204, 51, 0,255};
501 new_TColor(kGray ,204./255.,204./255.,204./255.,
"kGray");
502 new_TColor(kGray+1,153./255.,153./255.,153./255.,
"kGray+1");
503 new_TColor(kGray+2,102./255.,102./255.,102./255.,
"kGray+2");
504 new_TColor(kGray+3, 51./255., 51./255., 51./255.,
"kGray+3");
536 typedef std::map<std::string,style_colormap>
cmaps_t;
538 inline bool to_ulong(
const std::string& a_s,
unsigned long& a_v){
540 if(::sscanf(a_s.c_str(),
"%lx",&a_v)!=1) {
541 if(::sscanf(a_s.c_str(),
"%lu",&a_v)!=1) {
552 std::string::size_type pos_slash = a_s.rfind(
'/');
553 if(pos_slash!=std::string::npos) {
554 std::string cmap = a_s.substr(0,pos_slash);
555 std::string cnam = a_s.substr(pos_slash+1,a_s.size()-(pos_slash+1));
556 cmaps_t::const_iterator it = a_cmaps.find(cmap);
557 if(it==a_cmaps.end())
return false;
558 return (*it).second.get_color(cnam,a_col);
562 if( (a_s.size()==7) && (a_s[0]==
'#') ) {
565 unsigned long rr,gg,bb;
567 {std::string s(
"0x");
568 s += a_s.substr(1,2);
571 {std::string s(
"0x");
572 s += a_s.substr(3,2);
575 {std::string s(
"0x");
576 s += a_s.substr(5,2);
579 a_col =
colorf(((
float)rr)/255,((
float)gg)/255,((
float)bb)/255);
586 {std::vector<std::string> ws;
587 words(a_s,
" ",
false,ws);
590 if( to<float>(ws[0],r) && ((0<=r)&&(r<=1)) &&
591 to<float>(ws[1],g) && ((0<=g)&&(g<=1)) &&
592 to<float>(ws[2],b) && ((0<=b)&&(b<=1)) ){
597 }
else if(ws.size()==4) {
599 if( to<float>(ws[0],r) && ((0<=r)&&(r<=1)) &&
600 to<float>(ws[1],g) && ((0<=g)&&(g<=1)) &&
601 to<float>(ws[2],b) && ((0<=b)&&(b<=1)) &&
602 to<float>(ws[3],a) && ((0<=a)&&(a<=1)) ){
610 {cmaps_t::const_iterator it = a_cmaps.find(style_default_colormap::s_default());
611 if(it!=a_cmaps.end()) {
612 if((*it).second.get_color(a_s,a_col))
return true;