Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/sg/style_colormap is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_sg_style_colormap
0005 #define tools_sg_style_colormap
0006 
0007 #include "style_color"
0008 
0009 #include "../hls"
0010 #include "../sto"
0011 #include "../num2s"
0012 #include "../S_STRING"
0013 #include "../forit"
0014 
0015 #include <map>
0016 
0017 namespace tools {
0018 namespace sg {
0019 
0020 class style_colormap : public std::map<unsigned int,style_color> {
0021   typedef std::map<unsigned int,style_color> parent;
0022 protected:
0023   typedef std::map<unsigned int,style_color> map_t;
0024 public:
0025   TOOLS_SCLASS(tools::sg::style_colormap)
0026 public:
0027   style_colormap():parent(){
0028   }
0029   virtual ~style_colormap(){
0030   }
0031 public:
0032   style_colormap(const style_colormap& a_from):parent(a_from){
0033   }
0034   style_colormap& operator=(const style_colormap& a_from){
0035     parent::operator=(a_from);
0036     return *this;
0037   }
0038 public:
0039   bool get_color(unsigned int a_index,colorf& a_col) const {
0040     map_t::const_iterator it = find(a_index);
0041     if(it==end()) {
0042       a_col.set_value(0.5F,0.5F,0.5F,1);
0043       return false;
0044     }
0045     a_col = (*it).second.second;
0046     return true;
0047   }
0048   bool get_color(const std::string& a_s,colorf& a_col) const {
0049     for(auto it = (*this).cbegin(); it != (*this).cend(); ++it) {
0050       if((*it).second.first==a_s) {
0051         a_col = (*it).second.second;
0052         return true;
0053       }
0054     }
0055     //we do not set a_col to something.
0056     return false;
0057   }
0058   bool get_string_color(unsigned int a_index,std::string& a_s) const{
0059     map_t::const_iterator it = find(a_index);
0060     if(it==end()) {a_s.clear();return false;}
0061     colorf c = (*it).second.second;
0062 
0063     char ss[192]; //3*64 = 192
0064     snpf(ss,sizeof(ss),"%g %g %g",c[0],c[1],c[2]);
0065     a_s = std::string(ss);
0066     return true;
0067   }
0068 public:
0069   void add(const style_color& a_color) {
0070     (*this)[uint32((*this).size())] = a_color;
0071   }
0072 };
0073 
0074 }}
0075 
0076 #include "../colors"
0077 
0078 namespace tools {
0079 namespace sg {
0080 
0081 class style_default_colormap : public style_colormap {
0082 public:
0083   TOOLS_CLASS_STRING(default)
0084 public:
0085 #define STYLE_COLORMAP_ADD(a__name) \
0086     tmp.set_name(#a__name);\
0087     set_color_##a__name(tmp);\
0088     add(tmp);
0089 
0090   style_default_colormap() {
0091     style_color tmp;
0092     STYLE_COLORMAP_ADD(aquamarine)
0093     STYLE_COLORMAP_ADD(mediumaquamarine)
0094     STYLE_COLORMAP_ADD(black)
0095     STYLE_COLORMAP_ADD(blue)
0096     STYLE_COLORMAP_ADD(cadetblue)
0097     STYLE_COLORMAP_ADD(cornflowerblue)
0098     STYLE_COLORMAP_ADD(darkslateblue)
0099     STYLE_COLORMAP_ADD(lightblue)
0100     STYLE_COLORMAP_ADD(lightsteelblue)
0101     STYLE_COLORMAP_ADD(mediumblue)
0102 
0103     STYLE_COLORMAP_ADD(mediumslateblue)
0104     STYLE_COLORMAP_ADD(midnightblue)
0105     STYLE_COLORMAP_ADD(navyblue)
0106     STYLE_COLORMAP_ADD(navy)
0107     STYLE_COLORMAP_ADD(skyblue)
0108     STYLE_COLORMAP_ADD(slateblue)
0109     STYLE_COLORMAP_ADD(steelblue)
0110     STYLE_COLORMAP_ADD(coral)
0111     STYLE_COLORMAP_ADD(cyan)
0112     STYLE_COLORMAP_ADD(firebrick)
0113 
0114     STYLE_COLORMAP_ADD(brown)
0115     STYLE_COLORMAP_ADD(gold)
0116     STYLE_COLORMAP_ADD(goldenrod)
0117     STYLE_COLORMAP_ADD(green)
0118     STYLE_COLORMAP_ADD(darkgreen)
0119     STYLE_COLORMAP_ADD(darkolivegreen)
0120     STYLE_COLORMAP_ADD(forestgreen)
0121     STYLE_COLORMAP_ADD(limegreen)
0122     STYLE_COLORMAP_ADD(mediumseagreen)
0123     STYLE_COLORMAP_ADD(mediumspringgreen)
0124 
0125     STYLE_COLORMAP_ADD(palegreen)
0126     STYLE_COLORMAP_ADD(seagreen)
0127     STYLE_COLORMAP_ADD(springgreen)
0128     STYLE_COLORMAP_ADD(yellowgreen)
0129     STYLE_COLORMAP_ADD(darkslategrey)
0130     STYLE_COLORMAP_ADD(dimgrey)
0131     STYLE_COLORMAP_ADD(lightgrey)
0132     STYLE_COLORMAP_ADD(grey)
0133     STYLE_COLORMAP_ADD(khaki)
0134     STYLE_COLORMAP_ADD(magenta)
0135 
0136     STYLE_COLORMAP_ADD(maroon)
0137     STYLE_COLORMAP_ADD(orange)
0138     STYLE_COLORMAP_ADD(orchid)
0139     STYLE_COLORMAP_ADD(darkorchid)
0140     STYLE_COLORMAP_ADD(mediumorchid)
0141     STYLE_COLORMAP_ADD(pink)
0142     STYLE_COLORMAP_ADD(plum)
0143     STYLE_COLORMAP_ADD(red)
0144     STYLE_COLORMAP_ADD(indianred)
0145     STYLE_COLORMAP_ADD(mediumvioletred)
0146 
0147     STYLE_COLORMAP_ADD(orangered)
0148     STYLE_COLORMAP_ADD(violetred)
0149     STYLE_COLORMAP_ADD(salmon)
0150     STYLE_COLORMAP_ADD(sienna)
0151     STYLE_COLORMAP_ADD(tan)
0152     STYLE_COLORMAP_ADD(thistle)
0153     STYLE_COLORMAP_ADD(turquoise)
0154     STYLE_COLORMAP_ADD(darkturquoise)
0155     STYLE_COLORMAP_ADD(mediumturquoise)
0156     STYLE_COLORMAP_ADD(violet)
0157 
0158     STYLE_COLORMAP_ADD(blueviolet)
0159     STYLE_COLORMAP_ADD(wheat)
0160     STYLE_COLORMAP_ADD(white)
0161     STYLE_COLORMAP_ADD(yellow)
0162     STYLE_COLORMAP_ADD(greenyellow)
0163   }
0164 #undef STYLE_COLORMAP_ADD
0165 };
0166 
0167 class style_ROOT_colormap : public style_colormap {
0168   //enum EColor {kWhite,kBlack,kRed,kGreen,kBlue,kYellow,kMagenta,kCyan};
0169                //0    1      2    3      4     5       6        7
0170 
0171 
0172   // ROOT-5.24.00b/Rtypes.h
0173   enum EColor { kWhite =0,   kBlack =1,   kGray=920,
0174     kRed   =632, kGreen =416, kBlue=600, kYellow=400, kMagenta=616, kCyan=432,
0175     kOrange=800, kSpring=820, kTeal=840, kAzure =860, kViolet =880, kPink=900};
0176 
0177 public:
0178   style_ROOT_colormap() {
0179     // ROOT-4.00.08/TApplication.cxx/InitializeColors
0180     // ROOT-5.18.00d/TColor.cxx/InitializeColors
0181     //resize(51+50+50+50); //201
0182 
0183     // from index 0   to 50  : default colors.
0184     // from index 51  to 100 : pretty.
0185     // from index 101 to 150 : dark version of default colors.
0186     // from index 151 to 200 : bright version of default colors.
0187 
0188     //base/inc/Gtypes.h
0189 
0190     new_TColor(kWhite,1,1,1,"background");
0191     new_TColor(kBlack,0,0,0,"black");
0192     new_TColor(2,1,0,0,"red");
0193     new_TColor(3,0,1,0,"green");
0194     new_TColor(4,0,0,1,"blue");
0195     new_TColor(5,1,1,0,"yellow");
0196     new_TColor(6,1,0,1,"magenta");
0197     new_TColor(7,0,1,1,"cyan");
0198     new_TColor(10,0.999,0.999,0.999,"white");
0199     new_TColor(11,0.754,0.715,0.676,"editcol");
0200 
0201     // The color white above is defined as being nearly white.
0202     // Sets the associated dark color also to white.
0203     //new_TColor(110,0.999,0.999,.999,"Color110");
0204 
0205     // Initialize Custom colors
0206     new_TColor(20,0.8,0.78,0.67,"Color20");
0207     new_TColor(31,0.54,0.66,0.63,"Color31");
0208     new_TColor(41,0.83,0.81,0.53,"Color41");
0209     new_TColor(30,0.52,0.76,0.64,"Color30");
0210     new_TColor(32,0.51,0.62,0.55,"Color32");
0211     new_TColor(24,0.70,0.65,0.59,"Color24");
0212     new_TColor(21,0.8,0.78,0.67,"Color21");
0213     new_TColor(47,0.67,0.56,0.58,"Color47");
0214     new_TColor(35,0.46,0.54,0.57,"Color35");
0215     new_TColor(33,0.68,0.74,0.78,"Color33");
0216     new_TColor(39,0.5,0.5,0.61,"Color39");
0217     new_TColor(37,0.43,0.48,0.52,"Color37");
0218     new_TColor(38,0.49,0.6,0.82,"Color38");
0219     new_TColor(36,0.41,0.51,0.59,"Color36");
0220     new_TColor(49,0.58,0.41,0.44,"Color49");
0221     new_TColor(43,0.74,0.62,0.51,"Color43");
0222     new_TColor(22,0.76,0.75,0.66,"Color22");
0223     new_TColor(45,0.75,0.51,0.47,"Color45");
0224     new_TColor(44,0.78,0.6,0.49,"Color44");
0225     new_TColor(26,0.68,0.6,0.55,"Color26");
0226     new_TColor(28,0.53,0.4,0.34,"Color28");
0227     new_TColor(25,0.72,0.64,0.61,"Color25");
0228     new_TColor(27,0.61,0.56,0.51,"Color27");
0229     new_TColor(23,0.73,0.71,0.64,"Color23");
0230     new_TColor(42,0.87,0.73,0.53,"Color42");
0231     new_TColor(46,0.81,0.37,0.38,"Color46");
0232     new_TColor(48,0.65,0.47,0.48,"Color48");
0233     new_TColor(34,0.48,0.56,0.6,"Color34");
0234     new_TColor(40,0.67,0.65,0.75,"Color40");
0235     new_TColor(29,0.69,0.81,0.78,"Color29");
0236 
0237     // Initialize some additional greyish non saturated colors
0238 #define TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR(a__i,a__name) \
0239     new_TColor(a__i,get_color_ROOT_##a__name<colorf>(),#a__name);
0240 
0241     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR( 8,Color8)
0242     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR( 9,Color9)
0243     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR(12,grey12)
0244     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR(13,grey13)
0245     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR(14,grey14)
0246     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR(15,grey15)
0247     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR(16,grey16)
0248     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR(17,grey17)
0249     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR(18,grey18)
0250     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR(19,grey19)
0251     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR(50,Color50)
0252 
0253 #undef TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR
0254 
0255     // Initialize the Pretty Palette Spectrum Violet->Red
0256     //   The color model used here is based on the HLS model which
0257     //   is much more suitable for creating palettes than RGB.
0258     //   Fixing the saturation and lightness we can scan through the
0259     //   spectrum of visible light by using "hue" alone.
0260     //   In Root hue takes values from 0 to 360.
0261    {float saturation = 1;
0262     float lightness = 0.5;
0263     float MaxHue = 280;
0264     float MinHue = 0;
0265     unsigned int MaxPretty = 50;
0266 
0267     // from index 51 to 100.
0268     float r,g,b,hue;
0269     std::string head("Color");
0270     for(unsigned int i=0 ; i<MaxPretty ; i++) {
0271       hue = MaxHue-(i+1)*((MaxHue-MinHue)/MaxPretty);
0272       hls_to_rgb(hue, lightness, saturation, r, g, b);
0273       new_TColor(i+51, r, g, b,head,i+51);
0274     }}
0275 
0276     double h,l,s,r,g,b;
0277 
0278     // dark colors (index 101 to 150) :
0279     // NOTE : 100 = "dark black" would overlap with "pretty 49" !
0280     //        then start to 1+100.
0281    {for(unsigned int i=1 ; i<=50 ; i++) {
0282       map_t::const_iterator it = find(i);
0283       //if(it==end()) {}
0284       const std::string& nam = (*it).second.first;
0285       const colorf& col = (*it).second.second;
0286       rgb_to_hls<double>(col.r(),col.g(),col.b(),h,l,s);
0287       hls_to_rgb<double>(h,0.7*l,s, r, g, b);
0288       new_TColor(i+100, r, g, b, nam+"_dark");
0289     }}
0290 
0291     // bright colors (index 151 to 200) :
0292     // NOTE : 150 = "bright black" would overlap with "dark 50" !
0293     //        then start to 1+150.
0294    {for(unsigned int i=1 ; i<=50 ; i++) {
0295       map_t::const_iterator it = find(i);
0296       //if(it==end()) {}
0297       const std::string& nam = (*it).second.first;
0298       const colorf& col = (*it).second.second;
0299       rgb_to_hls<double>(col.r(),col.g(),col.b(),h,l,s);
0300       hls_to_rgb<double>(h,1.2*l,s, r, g, b);
0301       new_TColor(i+150, r, g, b, nam+"_bright");
0302     }}
0303 
0304     // Initialize special colors for x3d
0305     // from 201 to 228=200+4*7 : 7*4 = 28.
0306    {std::string head("Color");
0307     unsigned int index;
0308     for(unsigned int i = 1; i <= 7; i++) {
0309       map_t::const_iterator it = find(i);
0310       //if(it==end()) {}
0311       const colorf& col = (*it).second.second;
0312       r = col.r();
0313       g = col.r();
0314       b = col.r();
0315       if (i == 1) { r = 0.6; g = 0.6; b = 0.6; }
0316 
0317       if (r == 1) r = 0.9;
0318       if (r == 0) r = 0.1;
0319 
0320       if (g == 1) g = 0.9;
0321       if (g == 0) g = 0.1;
0322 
0323       if (b == 1) b = 0.9;
0324       if (b == 0) b = 0.1;
0325 
0326       rgb_to_hls(r,g,b,h,l,s);
0327 
0328       hls_to_rgb(h,0.6*l,s,r,g,b);
0329       index = 200+4*i-3;
0330       new_TColor(index,r,g,b,head,index);
0331 
0332       hls_to_rgb(h,0.8*l,s,r,g,b);
0333       index = 200+4*i-2;
0334       new_TColor(index,r,g,b,head,index);
0335 
0336       hls_to_rgb(h,1.2*l,s,r,g,b);
0337       index = 200+4*i-1;
0338       new_TColor(index,r,g,b,head,index);
0339 
0340       hls_to_rgb(h,1.4*l,s,r,g,b);
0341       index = 200+4*i;
0342       new_TColor(index,r,g,b,head,index);
0343     }}
0344 
0345     create_color_wheel();
0346   }
0347 
0348 protected:
0349   void new_TColor(unsigned int a_i,
0350                   double a_r,double a_g,double a_b,
0351                   const std::string& a_n) {
0352     (*this)[a_i] = style_color(a_n,float(a_r),float(a_g),float(a_b));
0353   }
0354   void new_TColor(unsigned int a_i,
0355                   double a_r,double a_g,double a_b,
0356                   const std::string& a_head,unsigned int a_index) {
0357     std::string stmp;
0358     if(!num2s(a_index,stmp)) {}
0359     new_TColor(a_i,a_r,a_g,a_b,a_head+stmp);
0360   }
0361   void new_TColor(unsigned int a_i,const colorf& a_color,const std::string& a_n) {
0362     (*this)[a_i] = style_color(a_n,a_color.r(),a_color.g(),a_color.b());
0363   }
0364 
0365   void create_colors_circle(unsigned int a_offset,
0366                             const std::string& a_name,
0367                             unsigned char a_rgb[]) {
0368     // Create the "circle" colors in the Color Wheel
0369     for(unsigned int n=0;n<15;n++) {
0370       int colorn = a_offset+n-10;
0371       if(colorn<0) continue;
0372       if(n>10) {
0373         new_TColor(colorn,a_rgb[3*n]/255.,a_rgb[3*n+1]/255.,a_rgb[3*n+2]/255.,a_name+"+",n-10);
0374       } else if (n<10) {
0375         new_TColor(colorn,a_rgb[3*n]/255.,a_rgb[3*n+1]/255.,a_rgb[3*n+2]/255.,a_name+"-",10-n);
0376       } else {
0377         new_TColor(colorn,a_rgb[3*n]/255.,a_rgb[3*n+1]/255.,a_rgb[3*n+2]/255.,a_name);
0378       }
0379     }
0380   }
0381 
0382   void create_colors_rectangle(unsigned int a_offset,
0383                                const std::string& a_name,
0384                                unsigned char a_rgb[]) {
0385     // Create the "rectangular" colors in the Color Wheel
0386     for (unsigned int n=0;n<20;n++) {
0387       int colorn = a_offset+n-9;
0388       if(colorn<0) continue;
0389       if(n>9) {
0390         new_TColor(colorn,a_rgb[3*n]/255.,a_rgb[3*n+1]/255.,a_rgb[3*n+2]/255.,a_name+"+",n-9);
0391       } else if(n<9) {
0392         new_TColor(colorn,a_rgb[3*n]/255.,a_rgb[3*n+1]/255.,a_rgb[3*n+2]/255.,a_name+"-",9-n);
0393       } else {
0394         new_TColor(colorn,a_rgb[3*n]/255.,a_rgb[3*n+1]/255.,a_rgb[3*n+2]/255.,a_name);
0395       }
0396     }
0397   }
0398 
0399   void create_color_wheel() {
0400     // Static function steering the creation of all colors
0401     // in the ROOT Color Wheel
0402     typedef unsigned char UChar_t;
0403     UChar_t magenta[46]= {255,204,255
0404             ,255,153,255, 204,153,204
0405             ,255,102,255, 204,102,204, 153,102,153
0406             ,255, 51,255, 204, 51,204, 153, 51,153, 102, 51,102
0407             ,255,  0,255, 204,  0,204, 153,  0,153, 102,  0,102,  51,  0, 51};
0408 
0409     UChar_t red[46]    = {255,204,204
0410             ,255,153,153, 204,153,153
0411             ,255,102,102, 204,102,102, 153,102,102
0412             ,255, 51, 51, 204, 51, 51, 153, 51, 51, 102, 51, 51
0413             ,255,  0,  0, 204,  0,  0, 153,  0,  0, 102,  0,  0,  51,  0,  0};
0414 
0415     UChar_t yellow[46] = {255,255,204
0416             ,255,255,153, 204,204,153
0417             ,255,255,102, 204,204,102, 153,153,102
0418             ,255,255, 51, 204,204, 51, 153,153, 51, 102,102, 51
0419             ,255,255,  0, 204,204,  0, 153,153,  0, 102,102,  0,  51, 51,  0};
0420 
0421     UChar_t green[46]  = {204,255,204
0422             ,153,255,153, 153,204,153
0423             ,102,255,102, 102,204,102, 102,153,102
0424             , 51,255, 51,  51,204, 51,  51,153, 51,  51,102, 51
0425             ,  0,255,  0,   0,204,  0,   0,153,  0,   0,102,  0,  0, 51,  0};
0426 
0427     UChar_t cyan[46]   = {204,255,255
0428             ,153,255,255, 153,204,204
0429             ,102,255,255, 102,204,204, 102,153,153
0430             , 51,255,255,  51,204,204,  51,153,153,  51,102,102
0431             ,  0,255,255,   0,204,204,   0,153,153,   0,102,102,   0, 51,  51};
0432 
0433     UChar_t blue[46]   = {204,204,255
0434             ,153,153,255, 153,153,204
0435             ,102,102,255, 102,102,204, 102,102,153
0436             , 51, 51,255,  51, 51,204,  51, 51,153,  51, 51,102
0437             ,  0,  0,255,   0,  0,204,   0,  0,153,   0,  0,102,   0,  0,  51};
0438 
0439     UChar_t pink[60] = {
0440         255, 51,153,  204,  0,102,  102,  0, 51,  153,  0, 51,  204, 51,102
0441         ,255,102,153,  255,  0,102,  255, 51,102,  204,  0, 51,  255,  0, 51
0442         ,255,153,204,  204,102,153,  153, 51,102,  153,  0,102,  204, 51,153
0443         ,255,102,204,  255,  0,153,  204,  0,153,  255, 51,204,  255,  0,153};
0444 
0445     UChar_t orange[60]={
0446         255,204,153,  204,153,102,  153,102, 51,  153,102,  0,  204,153, 51
0447         ,255,204,102,  255,153,  0,  255,204, 51,  204,153,  0,  255,204,  0
0448         ,255,153, 51,  204,102,  0,  102, 51,  0,  153, 51,  0,  204,102, 51
0449         ,255,153,102,  255,102,  0,  255,102, 51,  204, 51,  0,  255, 51,  0};
0450 
0451     UChar_t spring[60]={
0452         153,255, 51,  102,204,  0,   51,102,  0,   51,153,  0,  102,204, 51
0453         ,153,255,102,  102,255,  0,  102,255, 51,   51,204,  0,   51,255, 0
0454         ,204,255,153,  153,204,102,  102,153, 51,  102,153,  0,  153,204, 51
0455         ,204,255,102,  153,255,  0,  204,255, 51,  153,204,  0,  204,255,  0};
0456 
0457     UChar_t teal[60] = {
0458         153,255,204,  102,204,153,   51,153,102,    0,153,102,   51,204,153
0459         ,102,255,204,    0,255,102,   51,255,204,    0,204,153,    0,255,204
0460         , 51,255,153,    0,204,102,    0,102, 51,    0,153, 51,   51,204,102
0461         ,102,255,153,    0,255,153,   51,255,102,    0,204, 51,    0,255, 51};
0462 
0463     UChar_t azure[60] ={
0464         153,204,255,  102,153,204,   51,102,153,    0, 51,153,   51,102,204
0465         ,102,153,255,    0,102,255,   51,102,255,    0, 51,204,    0, 51,255
0466         , 51,153,255,    0,102,204,    0, 51,102,    0,102,153,   51,153,204
0467         ,102,204,255,    0,153,255,   51,204,255,    0,153,204,    0,204,255};
0468 
0469     UChar_t violet[60]={
0470         204,153,255,  153,102,204,  102, 51,153,  102,  0,153,  153, 51,204
0471         ,204,102,255,  153,  0,255,  204, 51,255,  153,  0,204,  204,  0,255
0472         ,153, 51,255,  102,  0,204,   51,  0,102,   51,  0,153,  102, 51,204
0473         ,153,102,255,  102,  0,255,  102, 51,255,   51,  0,204,   51,  0,255};
0474 
0475     create_colors_circle(kMagenta,"kMagenta",magenta);
0476     create_colors_circle(kRed,    "kRed",    red);
0477     create_colors_circle(kYellow, "kYellow", yellow);
0478     create_colors_circle(kGreen,  "kGreen",  green);
0479     create_colors_circle(kCyan,   "kCyan",   cyan);
0480     create_colors_circle(kBlue,   "kBlue",   blue);
0481 
0482     create_colors_rectangle(kPink,  "kPink",  pink);
0483     create_colors_rectangle(kOrange,"kOrange",orange);
0484     create_colors_rectangle(kSpring,"kSpring",spring);
0485     create_colors_rectangle(kTeal,  "kTeal",  teal);
0486     create_colors_rectangle(kAzure, "kAzure", azure);
0487     create_colors_rectangle(kViolet,"kViolet",violet);
0488 
0489     // Create the Gray scale colors in the Color Wheel
0490     new_TColor(kGray  ,204./255.,204./255.,204./255.,"kGray");
0491     new_TColor(kGray+1,153./255.,153./255.,153./255.,"kGray+1");
0492     new_TColor(kGray+2,102./255.,102./255.,102./255.,"kGray+2");
0493     new_TColor(kGray+3, 51./255., 51./255., 51./255.,"kGray+3");
0494   }
0495 
0496 };
0497 
0498 class style_povama_colormap : public style_colormap {
0499 public:
0500   style_povama_colormap() {
0501     add(style_color("White",colorf(1.00f, 1.00f, 1.00f)));
0502     add(style_color("Black",colorf(0.00f, 0.00f, 0.00f)));
0503     add(style_color("PeachPuff",colorf(1.00f, 0.85f, 0.70f)));
0504     add(style_color("Peach",colorf(0.90f, 0.50f, 0.30f)));
0505     add(style_color("SlateGrey",colorf(0.44f, 0.50f, 0.56f)));
0506     add(style_color("CornflowerBlue",colorf(0.39f, 0.58f, 0.93f)));
0507     add(style_color("Aquamarine",colorf(0.50f, 0.50f, 0.83f)));
0508     add(style_color("LawnGreen",colorf(0.49f, 0.92f, 0.00f)));
0509     add(style_color("DarkKhaki",colorf(0.74f, 0.71f, 0.42f)));
0510     add(style_color("Gold",colorf(1.00f, 0.84f, 0.00f)));
0511     add(style_color("IndianRed",colorf(0.80f, 0.36f, 0.36f)));
0512     add(style_color("SaddleBrown",colorf(0.55f, 0.27f, 0.07f)));
0513     add(style_color("DeepPink",colorf(1.00f, 0.08f, 0.56f)));
0514   }
0515 };
0516 
0517 }}
0518 
0519 
0520 #include "../tokenize"
0521 
0522 namespace tools {
0523 namespace sg {
0524 
0525 typedef std::map<std::string,style_colormap> cmaps_t;
0526 
0527 inline bool to_ulong(const std::string& a_s,unsigned long& a_v){
0528   a_v = 0L;
0529   if(::sscanf(a_s.c_str(),"%lx",&a_v)!=1) {
0530     if(::sscanf(a_s.c_str(),"%lu",&a_v)!=1) {
0531       a_v = 0L;
0532       return false;
0533     }
0534   }
0535   return true;
0536 }
0537 
0538 inline bool find_color(const cmaps_t& a_cmaps,const std::string& a_s,colorf& a_col){
0539   //NOTE : if ret false, we do not set a_col to something.
0540 
0541   std::string::size_type pos_slash = a_s.rfind('/');
0542   if(pos_slash!=std::string::npos) { //<cmap>/<color name>
0543     std::string cmap = a_s.substr(0,pos_slash);
0544     std::string cnam = a_s.substr(pos_slash+1,a_s.size()-(pos_slash+1));
0545     cmaps_t::const_iterator it = a_cmaps.find(cmap);
0546     if(it==a_cmaps.end()) return false;
0547     return (*it).second.get_color(cnam,a_col);
0548 
0549   } else {
0550 
0551     if( (a_s.size()==7) && (a_s[0]=='#') ) {
0552       // #RRGGBB format :
0553       //  1 3 5
0554       unsigned long rr,gg,bb;
0555 
0556      {std::string _s("0x");
0557       _s += a_s.substr(1,2);
0558       if(!to_ulong(_s,rr)) return false;}
0559 
0560      {std::string _s("0x");
0561       _s += a_s.substr(3,2);
0562       if(!to_ulong(_s,gg)) return false;}
0563 
0564      {std::string _s("0x");
0565       _s += a_s.substr(5,2);
0566       if(!to_ulong(_s,bb)) return false;}
0567 
0568       a_col = colorf(((float)rr)/255,((float)gg)/255,((float)bb)/255);
0569       return true;
0570     }
0571 
0572     //a_s of the form : <real:r> <real:g> <real:b>
0573     //a_s of the form : <real:r> <real:g> <real:b> <real:a>
0574 
0575    {std::vector<std::string> ws;
0576     words(a_s," ",false,ws);
0577     if(ws.size()==3) {
0578       float r,g,b;
0579       if( to<float>(ws[0],r) && ((0<=r)&&(r<=1)) &&
0580           to<float>(ws[1],g) && ((0<=g)&&(g<=1)) &&
0581           to<float>(ws[2],b) && ((0<=b)&&(b<=1)) ){
0582         a_col = colorf(r,g,b);
0583         return true;
0584       }
0585 
0586     } else if(ws.size()==4) {
0587       float r,g,b,a;
0588       if( to<float>(ws[0],r) && ((0<=r)&&(r<=1)) &&
0589           to<float>(ws[1],g) && ((0<=g)&&(g<=1)) &&
0590           to<float>(ws[2],b) && ((0<=b)&&(b<=1)) &&
0591           to<float>(ws[3],a) && ((0<=a)&&(a<=1)) ){
0592         a_col = colorf(r,g,b,a);
0593         return true;
0594       }
0595 
0596     }}
0597 
0598     // search in default colormap :
0599    {cmaps_t::const_iterator it = a_cmaps.find(style_default_colormap::s_default());
0600     if(it!=a_cmaps.end()) {
0601       if((*it).second.get_color(a_s,a_col)) return true;
0602     }}
0603 
0604   }
0605 
0606   return false;
0607 }
0608 
0609 }}
0610 
0611 #endif
0612 
0613 
0614