Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 3 4 #ifndef tools_colorf 5 #define tools_colorf 6 7 #include "lina/vec4f" 8 9 namespace tools { 10 11 class colorf : public vec4f { 12 typedef vec4f parent; 13 public: //for SWIG 14 typedef unsigned char uchar; 15 public: 16 TOOLS_SCLASS(tools::colorf) //for stype() 17 public: 18 colorf():parent(0,0,0,1){} 19 #ifdef TOOLS_MEM 20 colorf(float a_r,float a_g,float a_b,float a_a = 1,bool a_inc = true):parent(a_r,a_g,a_b,a_a,a_inc){} 21 #else 22 colorf(float a_r,float a_g,float a_b,float a_a = 1):parent(a_r,a_g,a_b,a_a){} 23 #endif 24 virtual ~colorf() {} 25 public: 26 colorf(const colorf& a_from):parent(a_from){} 27 colorf& operator=(const colorf& a_from){ 28 parent::operator=(a_from); 29 return *this; 30 } 31 public: 32 colorf& operator*=(const colorf& a_v) { 33 m_data[0] *= a_v.m_data[0]; 34 m_data[1] *= a_v.m_data[1]; 35 m_data[2] *= a_v.m_data[2]; 36 m_data[3] *= a_v.m_data[3]; 37 return *this; 38 } 39 colorf& operator*=(float a_v) { 40 m_data[0] *= a_v; 41 m_data[1] *= a_v; 42 m_data[2] *= a_v; 43 m_data[3] *= a_v; 44 return *this; 45 } 46 public: 47 void clamp(float a_min = 0,float a_max = 1) { 48 if(m_data[0]<a_min) m_data[0] = a_min; 49 if(m_data[1]<a_min) m_data[1] = a_min; 50 if(m_data[2]<a_min) m_data[2] = a_min; 51 if(m_data[3]<a_min) m_data[3] = a_min; 52 53 if(a_max<m_data[0]) m_data[0] = a_max; 54 if(a_max<m_data[1]) m_data[1] = a_max; 55 if(a_max<m_data[2]) m_data[2] = a_max; 56 if(a_max<m_data[3]) m_data[3] = a_max; 57 } 58 float r() const {return v0();} 59 float g() const {return v1();} 60 float b() const {return v2();} 61 float a() const {return v3();} 62 63 void set_r(float a_v) {m_data[0] = a_v;} 64 void set_g(float a_v) {m_data[1] = a_v;} 65 void set_b(float a_v) {m_data[2] = a_v;} 66 void set_a(float a_v) {m_data[3] = a_v;} 67 68 uchar ruchar() const {return uchar(255.0f*m_data[0]);} 69 uchar guchar() const {return uchar(255.0f*m_data[1]);} 70 uchar buchar() const {return uchar(255.0f*m_data[2]);} 71 uchar auchar() const {return uchar(255.0f*m_data[3]);} 72 73 #ifdef tools_colorf 74 // deprecated, use the upper ones. 75 uchar rchar() const {return uchar(255.0f*m_data[0]);} 76 uchar gchar() const {return uchar(255.0f*m_data[1]);} 77 uchar bchar() const {return uchar(255.0f*m_data[2]);} 78 #endif 79 80 public: 81 //#define tools_stat_colorfs 82 #ifdef tools_stat_colorfs 83 //NOTE : the below are deprecated, use functions in tools/colorfs. 84 // colorf::white() replaced by colorf_white() 85 86 // our forever 65 named colors taken long time ago from X11. 87 88 //NOTE : don't handle a static object because of mem balance. 89 //0-9 90 static colorf aquamarine() {return colorf(0.496101F,0.996109F,0.828138F);} 91 static colorf mediumaquamarine() {return colorf(0.398444F,0.800793F,0.664073F);} 92 static colorf black() {return colorf(0,0,0);} 93 static colorf blue() {return colorf(0,0,1);} 94 static colorf cadetblue() {return colorf(0.371099F,0.617197F,0.62501F);} 95 static colorf cornflowerblue() {return colorf(0.390631F,0.58204F,0.925795F);} 96 static colorf darkslateblue() {return colorf(0.281254F,0.238285F,0.542977F);} 97 static colorf lightblue() {return colorf(0.675792F,0.843763F,0.898451F);} 98 static colorf lightsteelblue() {return colorf(0.68751F,0.765637F,0.867201F);} 99 static colorf mediumblue() {return colorf(0,0,0.800793F);} 100 101 //10-19 102 static colorf mediumslateblue() {return colorf(0.480476F,0.406256F,0.929702F);} 103 static colorf midnightblue() {return colorf(0.0976577F,0.0976577F,0.437507F);} 104 static colorf navyblue() {return colorf(0,0,0.500008F);} 105 static colorf navy() {return colorf(0,0,0.500008F);} 106 static colorf skyblue() {return colorf(0.527352F,0.8047F,0.917983F);} 107 static colorf slateblue() {return colorf(0.414069F,0.351568F,0.800793F);} 108 static colorf steelblue() {return colorf(0.273442F,0.50782F,0.703136F);} 109 static colorf coral() {return colorf(0.996109F,0.496101F,0.312505F);} 110 static colorf cyan() {return colorf(0,1,1);} 111 static colorf firebrick() {return colorf(0.695323F,0.132815F,0.132815F);} 112 113 //20-29 114 static colorf brown() {return colorf(0.644541F,0.164065F,0.164065F);} 115 static colorf gold() {return colorf(0.996109F,0.839857F,0);} 116 static colorf goldenrod() {return colorf(0.851575F,0.644541F,0.125002F);} 117 static colorf green() {return colorf(0,1,0);} 118 static colorf darkgreen() {return colorf(0,0.390631F,0);} 119 static colorf darkolivegreen() {return colorf(0.332036F,0.417975F,0.183597F);} 120 static colorf forestgreen() {return colorf(0.132815F,0.542977F,0.132815F);} 121 static colorf limegreen() {return colorf(0.195315F,0.800793F,0.195315F);} 122 static colorf mediumseagreen() {return colorf(0.234379F,0.699229F,0.441413F);} 123 static colorf mediumspringgreen() {return colorf(0,0.976577F,0.601572F);} 124 125 //30-39 126 static colorf palegreen() {return colorf(0.593759F,0.980484F,0.593759F);} 127 static colorf seagreen() {return colorf(0.17969F,0.542977F,0.339849F);} 128 static colorf springgreen() {return colorf(0,0.996109F,0.496101F);} 129 static colorf yellowgreen() {return colorf(0.601572F,0.800793F,0.195315F);} 130 static colorf darkslategrey() {return colorf(0.183597F,0.308598F,0.308598F);} 131 static colorf dimgrey() {return colorf(0.410163F,0.410163F,0.410163F);} 132 static colorf lightgrey() {return colorf(0.824231F,0.824231F,0.824231F);} 133 static colorf grey() {return colorf(0.750011F,0.750011F,0.750011F);} 134 static colorf khaki() {return colorf(0.937514F,0.898451F,0.546883F);} 135 static colorf magenta() {return colorf(1,0,1);} 136 137 //40-49 138 static colorf maroon() {return colorf(0.68751F,0.187503F,0.375006F);} 139 static colorf orange() {return colorf(0.996109F,0.644541F,0);} 140 static colorf orchid() {return colorf(0.851575F,0.437507F,0.83595F);} 141 static colorf darkorchid() {return colorf(0.597665F,0.195315F,0.796887F);} 142 static colorf mediumorchid() {return colorf(0.726574F,0.332036F,0.824231F);} 143 static colorf pink() {return colorf(0.996109F,0.750011F,0.792981F);} 144 static colorf plum() {return colorf(0.863294F,0.62501F,0.863294F);} 145 static colorf red() {return colorf(1,0,0);} 146 static colorf indianred() {return colorf(0.800793F,0.35938F,0.35938F);} 147 static colorf mediumvioletred() {return colorf(0.777356F,0.0820325F,0.519539F);} 148 149 //50-59 150 static colorf orangered() {return colorf(0.996109F,0.269535F,0);} 151 static colorf violetred() {return colorf(0.812512F,0.125002F,0.562509F);} 152 static colorf salmon() {return colorf(0.976577F,0.500008F,0.445319F);} 153 static colorf sienna() {return colorf(0.62501F,0.320317F,0.175784F);} 154 static colorf tan() {return colorf(0.820325F,0.703136F,0.546883F);} 155 static colorf thistle() {return colorf(0.843763F,0.746105F,0.843763F);} 156 static colorf turquoise() {return colorf(0.250004F,0.875013F,0.812512F);} 157 static colorf darkturquoise() {return colorf(0,0.8047F,0.816419F);} 158 static colorf mediumturquoise() {return colorf(0.281254F,0.816419F,0.796887F);} 159 static colorf violet() {return colorf(0.929702F,0.50782F,0.929702F);} 160 161 //60-64 162 static colorf blueviolet() {return colorf(0.539071F,0.167971F,0.882826F);} 163 static colorf wheat() {return colorf(0.957046F,0.867201F,0.699229F);} 164 static colorf white() {return colorf(1,1,1);} 165 static colorf yellow() {return colorf(1,1,0);} 166 static colorf greenyellow() {return colorf(0.675792F,0.996109F,0.18359F);} 167 #endif 168 }; 169 170 struct cmp_colorf { 171 bool operator()(const colorf& a_a,const colorf& a_b) const { 172 // x : 173 if(a_a.v0()<a_b.v0()) return true; 174 if(a_a.v0()>a_b.v0()) return false; 175 // y : 176 if(a_a.v1()<a_b.v1()) return true; 177 if(a_a.v1()>a_b.v1()) return false; 178 // z : 179 if(a_a.v2()<a_b.v2()) return true; 180 return false; 181 } 182 }; 183 184 //default color is lightgrey: 185 #if defined(TOOLS_MEM) && !defined(TOOLS_MEM_ATEXIT) 186 inline const colorf& colorf_default() {static const colorf s_v(0.824231F,0.824231F,0.824231F,1,false);return s_v;} 187 #else 188 inline const colorf& colorf_default() {static const colorf s_v(0.824231F,0.824231F,0.824231F,1);return s_v;} 189 #endif 190 191 } 192 193 #endif