Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/externals/g4tools/include/tools/sg/style_colormap

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.
  3 
  4 #ifndef tools_sg_style_colormap
  5 #define tools_sg_style_colormap
  6 
  7 #include "style_color"
  8 
  9 #include "../hls"
 10 #include "../sto"
 11 #include "../num2s"
 12 #include "../S_STRING"
 13 #include "../forit"
 14 
 15 #include <map>
 16 
 17 namespace tools {
 18 namespace sg {
 19 
 20 class style_colormap : public std::map<unsigned int,style_color> {
 21   typedef std::map<unsigned int,style_color> parent;
 22 protected:
 23   typedef std::map<unsigned int,style_color> map_t;
 24 public:
 25   TOOLS_SCLASS(tools::sg::style_colormap)
 26 public:
 27   style_colormap():parent(){
 28 #ifdef TOOLS_MEM
 29     mem::increment(s_class().c_str());
 30 #endif
 31   }
 32   virtual ~style_colormap(){
 33 #ifdef TOOLS_MEM
 34     mem::decrement(s_class().c_str());
 35 #endif
 36   }
 37 public:
 38   style_colormap(const style_colormap& a_from):parent(a_from){
 39 #ifdef TOOLS_MEM
 40     mem::increment(s_class().c_str());
 41 #endif
 42   }
 43   style_colormap& operator=(const style_colormap& a_from){
 44     parent::operator=(a_from);
 45     return *this;
 46   }
 47 public:
 48   bool get_color(unsigned int a_index,colorf& a_col) const {
 49     map_t::const_iterator it = find(a_index);
 50     if(it==end()) {
 51       a_col.set_value(0.5F,0.5F,0.5F,1);
 52       return false;
 53     }
 54     a_col = (*it).second.second;
 55     return true;
 56   }
 57   bool get_color(const std::string& a_s,colorf& a_col) const {
 58     tools_mforcit(unsigned int,style_color,*this,it) {
 59       if((*it).second.first==a_s) {
 60         a_col = (*it).second.second;
 61         return true;
 62       }
 63     }
 64     //we do not set a_col to something.
 65     return false;
 66   }
 67   bool get_string_color(unsigned int a_index,std::string& a_s) const{
 68     map_t::const_iterator it = find(a_index);
 69     if(it==end()) {a_s.clear();return false;}
 70     colorf c = (*it).second.second;
 71 
 72     char ss[192]; //3*64 = 192
 73     snpf(ss,sizeof(ss),"%g %g %g",c[0],c[1],c[2]);
 74     a_s = std::string(ss);
 75     return true;
 76   }
 77 public:
 78   void add(const style_color& a_color) {
 79     (*this)[uint32((*this).size())] = a_color;
 80   }
 81 };
 82 
 83 }}
 84 
 85 #include "../colors"
 86 
 87 namespace tools {
 88 namespace sg {
 89 
 90 class style_default_colormap : public style_colormap {
 91 public:
 92   TOOLS_CLASS_STRING(default)
 93 public:
 94 #define STYLE_COLORMAP_ADD(a__name) \
 95     tmp.set_name(#a__name);\
 96     set_color_##a__name(tmp);\
 97     add(tmp);
 98 
 99   style_default_colormap() {
100     style_color tmp;
101     STYLE_COLORMAP_ADD(aquamarine)
102     STYLE_COLORMAP_ADD(mediumaquamarine)
103     STYLE_COLORMAP_ADD(black)
104     STYLE_COLORMAP_ADD(blue)
105     STYLE_COLORMAP_ADD(cadetblue)
106     STYLE_COLORMAP_ADD(cornflowerblue)
107     STYLE_COLORMAP_ADD(darkslateblue)
108     STYLE_COLORMAP_ADD(lightblue)
109     STYLE_COLORMAP_ADD(lightsteelblue)
110     STYLE_COLORMAP_ADD(mediumblue)
111 
112     STYLE_COLORMAP_ADD(mediumslateblue)
113     STYLE_COLORMAP_ADD(midnightblue)
114     STYLE_COLORMAP_ADD(navyblue)
115     STYLE_COLORMAP_ADD(navy)
116     STYLE_COLORMAP_ADD(skyblue)
117     STYLE_COLORMAP_ADD(slateblue)
118     STYLE_COLORMAP_ADD(steelblue)
119     STYLE_COLORMAP_ADD(coral)
120     STYLE_COLORMAP_ADD(cyan)
121     STYLE_COLORMAP_ADD(firebrick)
122 
123     STYLE_COLORMAP_ADD(brown)
124     STYLE_COLORMAP_ADD(gold)
125     STYLE_COLORMAP_ADD(goldenrod)
126     STYLE_COLORMAP_ADD(green)
127     STYLE_COLORMAP_ADD(darkgreen)
128     STYLE_COLORMAP_ADD(darkolivegreen)
129     STYLE_COLORMAP_ADD(forestgreen)
130     STYLE_COLORMAP_ADD(limegreen)
131     STYLE_COLORMAP_ADD(mediumseagreen)
132     STYLE_COLORMAP_ADD(mediumspringgreen)
133 
134     STYLE_COLORMAP_ADD(palegreen)
135     STYLE_COLORMAP_ADD(seagreen)
136     STYLE_COLORMAP_ADD(springgreen)
137     STYLE_COLORMAP_ADD(yellowgreen)
138     STYLE_COLORMAP_ADD(darkslategrey)
139     STYLE_COLORMAP_ADD(dimgrey)
140     STYLE_COLORMAP_ADD(lightgrey)
141     STYLE_COLORMAP_ADD(grey)
142     STYLE_COLORMAP_ADD(khaki)
143     STYLE_COLORMAP_ADD(magenta)
144 
145     STYLE_COLORMAP_ADD(maroon)
146     STYLE_COLORMAP_ADD(orange)
147     STYLE_COLORMAP_ADD(orchid)
148     STYLE_COLORMAP_ADD(darkorchid)
149     STYLE_COLORMAP_ADD(mediumorchid)
150     STYLE_COLORMAP_ADD(pink)
151     STYLE_COLORMAP_ADD(plum)
152     STYLE_COLORMAP_ADD(red)
153     STYLE_COLORMAP_ADD(indianred)
154     STYLE_COLORMAP_ADD(mediumvioletred)
155 
156     STYLE_COLORMAP_ADD(orangered)
157     STYLE_COLORMAP_ADD(violetred)
158     STYLE_COLORMAP_ADD(salmon)
159     STYLE_COLORMAP_ADD(sienna)
160     STYLE_COLORMAP_ADD(tan)
161     STYLE_COLORMAP_ADD(thistle)
162     STYLE_COLORMAP_ADD(turquoise)
163     STYLE_COLORMAP_ADD(darkturquoise)
164     STYLE_COLORMAP_ADD(mediumturquoise)
165     STYLE_COLORMAP_ADD(violet)
166 
167     STYLE_COLORMAP_ADD(blueviolet)
168     STYLE_COLORMAP_ADD(wheat)
169     STYLE_COLORMAP_ADD(white)
170     STYLE_COLORMAP_ADD(yellow)
171     STYLE_COLORMAP_ADD(greenyellow)
172   }
173 #undef STYLE_COLORMAP_ADD
174 };
175 
176 class style_ROOT_colormap : public style_colormap {
177   //enum EColor {kWhite,kBlack,kRed,kGreen,kBlue,kYellow,kMagenta,kCyan};
178                //0    1      2    3      4     5       6        7
179 
180 
181   // ROOT-5.24.00b/Rtypes.h
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};
185 
186 public:
187   style_ROOT_colormap() {
188     // ROOT-4.00.08/TApplication.cxx/InitializeColors
189     // ROOT-5.18.00d/TColor.cxx/InitializeColors
190     //resize(51+50+50+50); //201
191 
192     // from index 0   to 50  : default colors.
193     // from index 51  to 100 : pretty.
194     // from index 101 to 150 : dark version of default colors.
195     // from index 151 to 200 : bright version of default colors.
196 
197     //base/inc/Gtypes.h
198 
199     new_TColor(kWhite,1,1,1,"background");
200     new_TColor(kBlack,0,0,0,"black");
201     new_TColor(2,1,0,0,"red");
202     new_TColor(3,0,1,0,"green");
203     new_TColor(4,0,0,1,"blue");
204     new_TColor(5,1,1,0,"yellow");
205     new_TColor(6,1,0,1,"magenta");
206     new_TColor(7,0,1,1,"cyan");
207     new_TColor(10,0.999,0.999,0.999,"white");
208     new_TColor(11,0.754,0.715,0.676,"editcol");
209 
210     // The color white above is defined as being nearly white.
211     // Sets the associated dark color also to white.
212     //new_TColor(110,0.999,0.999,.999,"Color110");
213 
214     // Initialize Custom colors
215     new_TColor(20,0.8,0.78,0.67,"Color20");
216     new_TColor(31,0.54,0.66,0.63,"Color31");
217     new_TColor(41,0.83,0.81,0.53,"Color41");
218     new_TColor(30,0.52,0.76,0.64,"Color30");
219     new_TColor(32,0.51,0.62,0.55,"Color32");
220     new_TColor(24,0.70,0.65,0.59,"Color24");
221     new_TColor(21,0.8,0.78,0.67,"Color21");
222     new_TColor(47,0.67,0.56,0.58,"Color47");
223     new_TColor(35,0.46,0.54,0.57,"Color35");
224     new_TColor(33,0.68,0.74,0.78,"Color33");
225     new_TColor(39,0.5,0.5,0.61,"Color39");
226     new_TColor(37,0.43,0.48,0.52,"Color37");
227     new_TColor(38,0.49,0.6,0.82,"Color38");
228     new_TColor(36,0.41,0.51,0.59,"Color36");
229     new_TColor(49,0.58,0.41,0.44,"Color49");
230     new_TColor(43,0.74,0.62,0.51,"Color43");
231     new_TColor(22,0.76,0.75,0.66,"Color22");
232     new_TColor(45,0.75,0.51,0.47,"Color45");
233     new_TColor(44,0.78,0.6,0.49,"Color44");
234     new_TColor(26,0.68,0.6,0.55,"Color26");
235     new_TColor(28,0.53,0.4,0.34,"Color28");
236     new_TColor(25,0.72,0.64,0.61,"Color25");
237     new_TColor(27,0.61,0.56,0.51,"Color27");
238     new_TColor(23,0.73,0.71,0.64,"Color23");
239     new_TColor(42,0.87,0.73,0.53,"Color42");
240     new_TColor(46,0.81,0.37,0.38,"Color46");
241     new_TColor(48,0.65,0.47,0.48,"Color48");
242     new_TColor(34,0.48,0.56,0.6,"Color34");
243     new_TColor(40,0.67,0.65,0.75,"Color40");
244     new_TColor(29,0.69,0.81,0.78,"Color29");
245 
246     // Initialize some additional greyish non saturated colors
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);
249 
250     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR( 8,Color8)
251     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR( 9,Color9)
252     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR(12,grey12)
253     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR(13,grey13)
254     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR(14,grey14)
255     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR(15,grey15)
256     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR(16,grey16)
257     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR(17,grey17)
258     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR(18,grey18)
259     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR(19,grey19)
260     TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR(50,Color50)
261 
262 #undef TOOLS_SG_STYLE_COLORMAP_ADD_TCOLOR
263 
264     // Initialize the Pretty Palette Spectrum Violet->Red
265     //   The color model used here is based on the HLS model which
266     //   is much more suitable for creating palettes than RGB.
267     //   Fixing the saturation and lightness we can scan through the
268     //   spectrum of visible light by using "hue" alone.
269     //   In Root hue takes values from 0 to 360.
270    {float saturation = 1;
271     float lightness = 0.5;
272     float MaxHue = 280;
273     float MinHue = 0;
274     unsigned int MaxPretty = 50;
275 
276     // from index 51 to 100.
277     float r,g,b,hue;
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);
282       new_TColor(i+51, r, g, b,head,i+51);
283     }}
284 
285     double h,l,s,r,g,b;
286 
287     // dark colors (index 101 to 150) :
288     // NOTE : 100 = "dark black" would overlap with "pretty 49" !
289     //        then start to 1+100.
290    {for(unsigned int i=1 ; i<=50 ; i++) {
291       map_t::const_iterator it = find(i);
292       //if(it==end()) {}
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);
297       new_TColor(i+100, r, g, b, nam+"_dark");
298     }}
299 
300     // bright colors (index 151 to 200) :
301     // NOTE : 150 = "bright black" would overlap with "dark 50" !
302     //        then start to 1+150.
303    {for(unsigned int i=1 ; i<=50 ; i++) {
304       map_t::const_iterator it = find(i);
305       //if(it==end()) {}
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);
310       new_TColor(i+150, r, g, b, nam+"_bright");
311     }}
312 
313     // Initialize special colors for x3d
314     // from 201 to 228=200+4*7 : 7*4 = 28.
315    {std::string head("Color");
316     unsigned int index;
317     for(unsigned int i = 1; i <= 7; i++) {
318       map_t::const_iterator it = find(i);
319       //if(it==end()) {}
320       const colorf& col = (*it).second.second;
321       r = col.r();
322       g = col.r();
323       b = col.r();
324       if (i == 1) { r = 0.6; g = 0.6; b = 0.6; }
325 
326       if (r == 1) r = 0.9;
327       if (r == 0) r = 0.1;
328 
329       if (g == 1) g = 0.9;
330       if (g == 0) g = 0.1;
331 
332       if (b == 1) b = 0.9;
333       if (b == 0) b = 0.1;
334 
335       rgb_to_hls(r,g,b,h,l,s);
336 
337       hls_to_rgb(h,0.6*l,s,r,g,b);
338       index = 200+4*i-3;
339       new_TColor(index,r,g,b,head,index);
340 
341       hls_to_rgb(h,0.8*l,s,r,g,b);
342       index = 200+4*i-2;
343       new_TColor(index,r,g,b,head,index);
344 
345       hls_to_rgb(h,1.2*l,s,r,g,b);
346       index = 200+4*i-1;
347       new_TColor(index,r,g,b,head,index);
348 
349       hls_to_rgb(h,1.4*l,s,r,g,b);
350       index = 200+4*i;
351       new_TColor(index,r,g,b,head,index);
352     }}
353 
354     create_color_wheel();
355   }
356 
357 protected:
358   void new_TColor(unsigned int a_i,
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));
362   }
363   void new_TColor(unsigned int a_i,
364                   double a_r,double a_g,double a_b,
365                   const std::string& a_head,unsigned int a_index) {
366     std::string stmp;
367     if(!num2s(a_index,stmp)) {}
368     new_TColor(a_i,a_r,a_g,a_b,a_head+stmp);
369   }
370   void new_TColor(unsigned int a_i,const colorf& a_color,const std::string& a_n) {
371     (*this)[a_i] = style_color(a_n,a_color.r(),a_color.g(),a_color.b());
372   }
373 
374   void create_colors_circle(unsigned int a_offset,
375                             const std::string& a_name,
376                             unsigned char a_rgb[]) {
377     // Create the "circle" colors in the Color Wheel
378     for(unsigned int n=0;n<15;n++) {
379       int colorn = a_offset+n-10;
380       if(colorn<0) continue;
381       if(n>10) {
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);
383       } else if (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);
385       } else {
386         new_TColor(colorn,a_rgb[3*n]/255.,a_rgb[3*n+1]/255.,a_rgb[3*n+2]/255.,a_name);
387       }
388       //color->SetTitle(color->AsHexString());
389     }
390   }
391 
392   void create_colors_rectangle(unsigned int a_offset,
393                                const std::string& a_name,
394                                unsigned char a_rgb[]) {
395     // Create the "rectangular" colors in the Color Wheel
396     for (unsigned int n=0;n<20;n++) {
397       int colorn = a_offset+n-9;
398       if(colorn<0) continue;
399       if(n>9) {
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);
401       } else if(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);
403       } else {
404         new_TColor(colorn,a_rgb[3*n]/255.,a_rgb[3*n+1]/255.,a_rgb[3*n+2]/255.,a_name);
405       }
406       //color->SetTitle(color->AsHexString());
407     }
408   }
409 
410   void create_color_wheel() {
411     // Static function steering the creation of all colors
412     // in the ROOT Color Wheel
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};
419 
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};
425 
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};
431 
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};
437 
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};
443 
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};
449 
450     UChar_t pink[60] = {
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};
455 
456     UChar_t orange[60]={
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};
461 
462     UChar_t spring[60]={
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};
467 
468     UChar_t teal[60] = {
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};
473 
474     UChar_t azure[60] ={
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};
479 
480     UChar_t violet[60]={
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};
485 
486     create_colors_circle(kMagenta,"kMagenta",magenta);
487     create_colors_circle(kRed,    "kRed",    red);
488     create_colors_circle(kYellow, "kYellow", yellow);
489     create_colors_circle(kGreen,  "kGreen",  green);
490     create_colors_circle(kCyan,   "kCyan",   cyan);
491     create_colors_circle(kBlue,   "kBlue",   blue);
492 
493     create_colors_rectangle(kPink,  "kPink",  pink);
494     create_colors_rectangle(kOrange,"kOrange",orange);
495     create_colors_rectangle(kSpring,"kSpring",spring);
496     create_colors_rectangle(kTeal,  "kTeal",  teal);
497     create_colors_rectangle(kAzure, "kAzure", azure);
498     create_colors_rectangle(kViolet,"kViolet",violet);
499 
500     // Create the Gray scale colors in the Color Wheel
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");
505   }
506 
507 };
508 
509 class style_povama_colormap : public style_colormap {
510 public:
511   style_povama_colormap() {
512     add(style_color("White",colorf(1.00f, 1.00f, 1.00f)));
513     add(style_color("Black",colorf(0.00f, 0.00f, 0.00f)));
514     add(style_color("PeachPuff",colorf(1.00f, 0.85f, 0.70f)));
515     add(style_color("Peach",colorf(0.90f, 0.50f, 0.30f)));
516     add(style_color("SlateGrey",colorf(0.44f, 0.50f, 0.56f)));
517     add(style_color("CornflowerBlue",colorf(0.39f, 0.58f, 0.93f)));
518     add(style_color("Aquamarine",colorf(0.50f, 0.50f, 0.83f)));
519     add(style_color("LawnGreen",colorf(0.49f, 0.92f, 0.00f)));
520     add(style_color("DarkKhaki",colorf(0.74f, 0.71f, 0.42f)));
521     add(style_color("Gold",colorf(1.00f, 0.84f, 0.00f)));
522     add(style_color("IndianRed",colorf(0.80f, 0.36f, 0.36f)));
523     add(style_color("SaddleBrown",colorf(0.55f, 0.27f, 0.07f)));
524     add(style_color("DeepPink",colorf(1.00f, 0.08f, 0.56f)));
525   }
526 };
527 
528 }}
529 
530 
531 #include "../words"
532 
533 namespace tools {
534 namespace sg {
535 
536 typedef std::map<std::string,style_colormap> cmaps_t;
537 
538 inline bool to_ulong(const std::string& a_s,unsigned long& a_v){
539   a_v = 0L;
540   if(::sscanf(a_s.c_str(),"%lx",&a_v)!=1) {
541     if(::sscanf(a_s.c_str(),"%lu",&a_v)!=1) {
542       a_v = 0L;
543       return false;
544     }
545   }
546   return true;
547 }
548 
549 inline bool find_color(const cmaps_t& a_cmaps,const std::string& a_s,colorf& a_col){
550   //NOTE : if ret false, we do not set a_col to something.
551 
552   std::string::size_type pos_slash = a_s.rfind('/');
553   if(pos_slash!=std::string::npos) { //<cmap>/<color name>
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);
559 
560   } else {
561 
562     if( (a_s.size()==7) && (a_s[0]=='#') ) {
563       // #RRGGBB format :
564       //  1 3 5
565       unsigned long rr,gg,bb;
566 
567      {std::string _s("0x");
568       _s += a_s.substr(1,2);
569       if(!to_ulong(_s,rr)) return false;}
570 
571      {std::string _s("0x");
572       _s += a_s.substr(3,2);
573       if(!to_ulong(_s,gg)) return false;}
574 
575      {std::string _s("0x");
576       _s += a_s.substr(5,2);
577       if(!to_ulong(_s,bb)) return false;}
578 
579       a_col = colorf(((float)rr)/255,((float)gg)/255,((float)bb)/255);
580       return true;
581     }
582 
583     //a_s of the form : <real:r> <real:g> <real:b>
584     //a_s of the form : <real:r> <real:g> <real:b> <real:a>
585 
586    {std::vector<std::string> ws;
587     words(a_s," ",false,ws);
588     if(ws.size()==3) {
589       float r,g,b;
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)) ){
593         a_col = colorf(r,g,b);
594         return true;
595       }
596 
597     } else if(ws.size()==4) {
598       float r,g,b,a;
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)) ){
603         a_col = colorf(r,g,b,a);
604         return true;
605       }
606 
607     }}
608 
609     // search in default colormap :
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;
613     }}
614 
615   }
616 
617   return false;
618 }
619 
620 }}
621 
622 #endif
623 
624 
625