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_sg_style_colormap 00005 #define inlib_sg_style_colormap 00006 00007 #include <vector> 00008 #include "../colorf" 00009 00010 namespace inlib { 00011 namespace sg { 00012 00013 class style_color : public std::pair<std::string,colorf> { 00014 public: 00015 style_color(): std::pair<std::string,colorf>("",colorf()){} 00016 style_color(const std::string& a_name,const colorf& a_color) 00017 :std::pair<std::string,colorf>(a_name,a_color) 00018 {} 00019 style_color(const std::string& a_name,float a_r,float a_g,float a_b) 00020 :std::pair<std::string,colorf>(a_name,colorf(a_r,a_g,a_b)) 00021 {} 00022 virtual ~style_color(){} 00023 public: 00024 style_color(const style_color& a_from) 00025 :std::pair<std::string,colorf>(a_from.first,a_from.second) 00026 {} 00027 style_color& operator=(const style_color& a_from){ 00028 first = a_from.first; 00029 second = a_from.second; 00030 return *this; 00031 } 00032 }; 00033 00034 class style_colormap : public std::vector<style_color> { 00035 public: 00036 bool get_color(unsigned int a_index,colorf& a_col) const { 00037 if(a_index>=size()) { 00038 a_col.set_value(0.5F,0.5F,0.5F); 00039 return false; 00040 } 00041 a_col = (*this)[a_index].second; 00042 return true; 00043 } 00044 bool get_color(const std::string& a_s,colorf& a_col) const { 00045 std::vector<style_color>::const_iterator it; 00046 for(it=begin();it!=end();++it) { 00047 if((*it).first==a_s) { 00048 a_col = (*it).second; 00049 return true; 00050 } 00051 } 00052 //we do not set a_col to something. 00053 return false; 00054 } 00055 bool get_string_color(unsigned int a_index,std::string& a_s) const{ 00056 if(a_index>=size()) {a_s.clear();return false;} 00057 colorf c = (*this)[a_index].second; 00058 char ss[192]; //3*64 = 192 00059 #ifdef WIN32 00060 _snprintf(ss,sizeof(ss),"%g %g %g",c[0],c[1],c[2]); 00061 #else 00062 ::snprintf(ss,sizeof(ss),"%g %g %g",c[0],c[1],c[2]); 00063 #endif 00064 a_s = std::string(ss); 00065 return true; 00066 } 00067 }; 00068 00069 class style_default_colormap : public style_colormap { 00070 public: 00071 style_default_colormap() { 00072 push_back(style_color("aquamarine",colorf::aquamarine())); 00073 push_back(style_color("mediumaquamarine",colorf::mediumaquamarine())); 00074 push_back(style_color("black",colorf::black())); 00075 push_back(style_color("blue",colorf::blue())); 00076 push_back(style_color("cadetblue",colorf::cadetblue())); 00077 push_back(style_color("cornflowerblue",colorf::cornflowerblue())); 00078 push_back(style_color("darkslateblue",colorf::darkslateblue())); 00079 push_back(style_color("lightblue",colorf::lightblue())); 00080 push_back(style_color("lightsteelblue",colorf::lightsteelblue())); 00081 push_back(style_color("mediumblue",colorf::mediumblue())); 00082 00083 push_back(style_color("mediumslateblue",colorf::mediumslateblue())); 00084 push_back(style_color("midnightblue",colorf::midnightblue())); 00085 push_back(style_color("navyblue",colorf::navyblue())); 00086 push_back(style_color("navy",colorf::navy())); 00087 push_back(style_color("skyblue",colorf::skyblue())); 00088 push_back(style_color("slateblue",colorf::slateblue())); 00089 push_back(style_color("steelblue",colorf::steelblue())); 00090 push_back(style_color("coral",colorf::coral())); 00091 push_back(style_color("cyan",colorf::cyan())); 00092 push_back(style_color("firebrick",colorf::firebrick())); 00093 00094 push_back(style_color("brown",colorf::brown())); 00095 push_back(style_color("gold",colorf::gold())); 00096 push_back(style_color("goldenrod",colorf::goldenrod())); 00097 push_back(style_color("green",colorf::green())); 00098 push_back(style_color("darkgreen",colorf::darkgreen())); 00099 push_back(style_color("darkolivegreen",colorf::darkolivegreen())); 00100 push_back(style_color("forestgreen",colorf::forestgreen())); 00101 push_back(style_color("limegreen",colorf::limegreen())); 00102 push_back(style_color("mediumseagreen",colorf::mediumseagreen())); 00103 push_back(style_color("mediumspringgreen",colorf::mediumspringgreen())); 00104 00105 push_back(style_color("palegreen",colorf::palegreen())); 00106 push_back(style_color("seagreen",colorf::seagreen())); 00107 push_back(style_color("springgreen",colorf::springgreen())); 00108 push_back(style_color("yellowgreen",colorf::yellowgreen())); 00109 push_back(style_color("darkslategrey",colorf::darkslategrey())); 00110 push_back(style_color("dimgrey",colorf::dimgrey())); 00111 push_back(style_color("lightgrey",colorf::lightgrey())); 00112 push_back(style_color("grey",colorf::grey())); 00113 push_back(style_color("khaki",colorf::khaki())); 00114 push_back(style_color("magenta",colorf::magenta())); 00115 00116 push_back(style_color("maroon",colorf::maroon())); 00117 push_back(style_color("orange",colorf::orange())); 00118 push_back(style_color("orchid",colorf::orchid())); 00119 push_back(style_color("darkorchid",colorf::darkorchid())); 00120 push_back(style_color("mediumorchid",colorf::mediumorchid())); 00121 push_back(style_color("pink",colorf::pink())); 00122 push_back(style_color("plum",colorf::plum())); 00123 push_back(style_color("red",colorf::red())); 00124 push_back(style_color("indianred",colorf::indianred())); 00125 push_back(style_color("mediumvioletred",colorf::mediumvioletred())); 00126 00127 push_back(style_color("orangered",colorf::orangered())); 00128 push_back(style_color("violetred",colorf::violetred())); 00129 push_back(style_color("salmon",colorf::salmon())); 00130 push_back(style_color("sienna",colorf::sienna())); 00131 push_back(style_color("tan",colorf::tan())); 00132 push_back(style_color("thistle",colorf::thistle())); 00133 push_back(style_color("turquoise",colorf::turquoise())); 00134 push_back(style_color("darkturquoise",colorf::darkturquoise())); 00135 push_back(style_color("mediumturquoise",colorf::mediumturquoise())); 00136 push_back(style_color("violet",colorf::violet())); 00137 00138 push_back(style_color("blueviolet",colorf::blueviolet())); 00139 push_back(style_color("wheat",colorf::wheat())); 00140 push_back(style_color("white",colorf::white())); 00141 push_back(style_color("yellow",colorf::yellow())); 00142 push_back(style_color("greenyellow",colorf::greenyellow())); 00143 } 00144 }; 00145 00146 class style_ROOT_colormap : public style_colormap { 00147 public: 00148 enum EColor {kWhite,kBlack,kRed,kGreen,kBlue,kYellow,kMagenta,kCyan}; 00149 //0 1 2 3 4 5 6 7 00150 style_ROOT_colormap() { 00151 // ROOT-4.00.08/TApplication.cxx/InitializeColors 00152 resize(51); 00153 00154 //base/inc/Gtypes.h 00155 00156 new_TColor(kWhite,1,1,1,"background"); 00157 new_TColor(kBlack,0,0,0,"black"); 00158 new_TColor(kRed,1,0,0,"red"); 00159 new_TColor(kGreen,0,1,0,"green"); 00160 new_TColor(kBlue,0,0,1,"blue"); 00161 new_TColor(kYellow,1,1,0,"yellow"); 00162 new_TColor(kMagenta,1,0,1,"magenta"); 00163 new_TColor(kCyan,0,1,1,"cyan"); 00164 new_TColor(10,0.999,0.999,0.999,"white"); 00165 new_TColor(11,0.754,0.715,0.676,"editcol"); 00166 00167 // The color white above is defined as being nearly white. 00168 // Sets the associated dark color also to white. 00169 //new_TColor(110,0.999,0.999,.999,"Color110"); 00170 00171 // Initialize Custom colors 00172 new_TColor(20,0.8,0.78,0.67,"Color20"); 00173 new_TColor(31,0.54,0.66,0.63,"Color31"); 00174 new_TColor(41,0.83,0.81,0.53,"Color41"); 00175 new_TColor(30,0.52,0.76,0.64,"Color30"); 00176 new_TColor(32,0.51,0.62,0.55,"Color32"); 00177 new_TColor(24,0.70,0.65,0.59,"Color24"); 00178 new_TColor(21,0.8,0.78,0.67,"Color21"); 00179 new_TColor(47,0.67,0.56,0.58,"Color47"); 00180 new_TColor(35,0.46,0.54,0.57,"Color35"); 00181 new_TColor(33,0.68,0.74,0.78,"Color33"); 00182 new_TColor(39,0.5,0.5,0.61,"Color39"); 00183 new_TColor(37,0.43,0.48,0.52,"Color37"); 00184 new_TColor(38,0.49,0.6,0.82,"Color38"); 00185 new_TColor(36,0.41,0.51,0.59,"Color36"); 00186 new_TColor(49,0.58,0.41,0.44,"Color49"); 00187 new_TColor(43,0.74,0.62,0.51,"Color43"); 00188 new_TColor(22,0.76,0.75,0.66,"Color22"); 00189 new_TColor(45,0.75,0.51,0.47,"Color45"); 00190 new_TColor(44,0.78,0.6,0.49,"Color44"); 00191 new_TColor(26,0.68,0.6,0.55,"Color26"); 00192 new_TColor(28,0.53,0.4,0.34,"Color28"); 00193 new_TColor(25,0.72,0.64,0.61,"Color25"); 00194 new_TColor(27,0.61,0.56,0.51,"Color27"); 00195 new_TColor(23,0.73,0.71,0.64,"Color23"); 00196 new_TColor(42,0.87,0.73,0.53,"Color42"); 00197 new_TColor(46,0.81,0.37,0.38,"Color46"); 00198 new_TColor(48,0.65,0.47,0.48,"Color48"); 00199 new_TColor(34,0.48,0.56,0.6,"Color34"); 00200 new_TColor(40,0.67,0.65,0.75,"Color40"); 00201 new_TColor(29,0.69,0.81,0.78,"Color29"); 00202 00203 // Initialize some additional greyish non saturated colors 00204 new_TColor(8, 0.35,0.83,0.33,"Color8"); 00205 new_TColor(9, 0.35,0.33,0.85,"Color9"); 00206 new_TColor(12,.3,.3,.3,"grey12"); 00207 new_TColor(13,.4,.4,.4,"grey13"); 00208 new_TColor(14,.5,.5,.5,"grey14"); 00209 new_TColor(15,.6,.6,.6,"grey15"); 00210 new_TColor(16,.7,.7,.7,"grey16"); 00211 new_TColor(17,.8,.8,.8,"grey17"); 00212 new_TColor(18,.9,.9,.9,"grey18"); 00213 new_TColor(19,.95,.95,.95,"grey19"); 00214 new_TColor(50, 0.83,0.35,0.33,"Color50"); 00215 00216 // Initialize the Pretty Palette Spectrum Violet->Red 00217 // The color model used here is based on the HLS model which 00218 // is much more suitable for creating palettes than RGB. 00219 // Fixing the saturation and lightness we can scan through the 00220 // spectrum of visible light by using "hue" alone. 00221 // In Root hue takes values from 0 to 360. 00222 /*FIXME 00223 float saturation = 1; 00224 float lightness = 0.5; 00225 float MaxHue = 280; 00226 float MinHue = 0; 00227 Int_t MaxPretty = 50; 00228 float hue; 00229 00230 for (i=0 ; i<MaxPretty ; i++) { 00231 hue = MaxHue-(i+1)*((MaxHue-MinHue)/MaxPretty); 00232 TColor::HLStoRGB(hue, lightness, saturation, r, g, b); 00233 new_TColor(i+51, r, g, b); 00234 }*/ 00235 00236 // Initialize the Pretty Palette Spectrum Violet->Red 00237 // The color model used here is based on the HLS model which 00238 // is much more suitable for creating palettes than RGB. 00239 // Fixing the saturation and lightness we can scan through the 00240 // spectrum of visible light by using "hue" alone. 00241 // In Root hue takes values from 0 to 360. 00242 /*FIXME 00243 float saturation = 1; 00244 float lightness = 0.5; 00245 float MaxHue = 280; 00246 float MinHue = 0; 00247 Int_t MaxPretty = 50; 00248 float hue; 00249 00250 for (i=0 ; i<MaxPretty ; i++) { 00251 hue = MaxHue-(i+1)*((MaxHue-MinHue)/MaxPretty); 00252 TColor::HLStoRGB(hue, lightness, saturation, r, g, b); 00253 new_TColor(i+51, r, g, b); 00254 }*/ 00255 00256 } 00257 private: 00258 void new_TColor(unsigned int i, 00259 double r,double g,double b, 00260 const std::string& n) { 00261 //it assumes that the vector has the correct size. 00262 (*this)[i] = style_color(n,float(r),float(g),float(b)); 00263 } 00264 }; 00265 00266 }} 00267 00268 00269 #include <map> 00270 namespace inlib { 00271 namespace sg { 00272 typedef std::map<std::string,inlib::sg::style_colormap> cmaps_t; 00273 }} 00274 00275 #endif 00276 00277 00278