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