Warning, /include/Geant4/tools/colorf 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_colorf
0005 #define tools_colorf
0006
0007 #include "lina/vec4f"
0008
0009 namespace tools {
0010
0011 class colorf : public vec4f {
0012 typedef vec4f parent;
0013 public: //for SWIG
0014 typedef unsigned char uchar;
0015 public:
0016 TOOLS_SCLASS(tools::colorf) //for stype()
0017 public:
0018 colorf():parent(0,0,0,1){}
0019 #ifdef TOOLS_MEM
0020 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){}
0021 #else
0022 colorf(float a_r,float a_g,float a_b,float a_a = 1):parent(a_r,a_g,a_b,a_a){}
0023 #endif
0024 virtual ~colorf() {}
0025 public:
0026 colorf(const colorf& a_from):parent(a_from){}
0027 colorf& operator=(const colorf& a_from){
0028 parent::operator=(a_from);
0029 return *this;
0030 }
0031 public:
0032 colorf& operator*=(const colorf& a_v) {
0033 m_data[0] *= a_v.m_data[0];
0034 m_data[1] *= a_v.m_data[1];
0035 m_data[2] *= a_v.m_data[2];
0036 m_data[3] *= a_v.m_data[3];
0037 return *this;
0038 }
0039 colorf& operator*=(float a_v) {
0040 m_data[0] *= a_v;
0041 m_data[1] *= a_v;
0042 m_data[2] *= a_v;
0043 m_data[3] *= a_v;
0044 return *this;
0045 }
0046 public:
0047 void clamp(float a_min = 0,float a_max = 1) {
0048 if(m_data[0]<a_min) m_data[0] = a_min;
0049 if(m_data[1]<a_min) m_data[1] = a_min;
0050 if(m_data[2]<a_min) m_data[2] = a_min;
0051 if(m_data[3]<a_min) m_data[3] = a_min;
0052
0053 if(a_max<m_data[0]) m_data[0] = a_max;
0054 if(a_max<m_data[1]) m_data[1] = a_max;
0055 if(a_max<m_data[2]) m_data[2] = a_max;
0056 if(a_max<m_data[3]) m_data[3] = a_max;
0057 }
0058 float r() const {return v0();}
0059 float g() const {return v1();}
0060 float b() const {return v2();}
0061 float a() const {return v3();}
0062
0063 void set_r(float a_v) {m_data[0] = a_v;}
0064 void set_g(float a_v) {m_data[1] = a_v;}
0065 void set_b(float a_v) {m_data[2] = a_v;}
0066 void set_a(float a_v) {m_data[3] = a_v;}
0067
0068 uchar ruchar() const {return uchar(255.0f*m_data[0]);}
0069 uchar guchar() const {return uchar(255.0f*m_data[1]);}
0070 uchar buchar() const {return uchar(255.0f*m_data[2]);}
0071 uchar auchar() const {return uchar(255.0f*m_data[3]);}
0072
0073 #ifdef tools_colorf
0074 // deprecated, use the upper ones.
0075 uchar rchar() const {return uchar(255.0f*m_data[0]);}
0076 uchar gchar() const {return uchar(255.0f*m_data[1]);}
0077 uchar bchar() const {return uchar(255.0f*m_data[2]);}
0078 #endif
0079
0080 public:
0081 //#define tools_stat_colorfs
0082 #ifdef tools_stat_colorfs
0083 //NOTE : the below are deprecated, use functions in tools/colorfs.
0084 // colorf::white() replaced by colorf_white()
0085
0086 // our forever 65 named colors taken long time ago from X11.
0087
0088 //NOTE : don't handle a static object because of mem balance.
0089 //0-9
0090 static colorf aquamarine() {return colorf(0.496101F,0.996109F,0.828138F);}
0091 static colorf mediumaquamarine() {return colorf(0.398444F,0.800793F,0.664073F);}
0092 static colorf black() {return colorf(0,0,0);}
0093 static colorf blue() {return colorf(0,0,1);}
0094 static colorf cadetblue() {return colorf(0.371099F,0.617197F,0.62501F);}
0095 static colorf cornflowerblue() {return colorf(0.390631F,0.58204F,0.925795F);}
0096 static colorf darkslateblue() {return colorf(0.281254F,0.238285F,0.542977F);}
0097 static colorf lightblue() {return colorf(0.675792F,0.843763F,0.898451F);}
0098 static colorf lightsteelblue() {return colorf(0.68751F,0.765637F,0.867201F);}
0099 static colorf mediumblue() {return colorf(0,0,0.800793F);}
0100
0101 //10-19
0102 static colorf mediumslateblue() {return colorf(0.480476F,0.406256F,0.929702F);}
0103 static colorf midnightblue() {return colorf(0.0976577F,0.0976577F,0.437507F);}
0104 static colorf navyblue() {return colorf(0,0,0.500008F);}
0105 static colorf navy() {return colorf(0,0,0.500008F);}
0106 static colorf skyblue() {return colorf(0.527352F,0.8047F,0.917983F);}
0107 static colorf slateblue() {return colorf(0.414069F,0.351568F,0.800793F);}
0108 static colorf steelblue() {return colorf(0.273442F,0.50782F,0.703136F);}
0109 static colorf coral() {return colorf(0.996109F,0.496101F,0.312505F);}
0110 static colorf cyan() {return colorf(0,1,1);}
0111 static colorf firebrick() {return colorf(0.695323F,0.132815F,0.132815F);}
0112
0113 //20-29
0114 static colorf brown() {return colorf(0.644541F,0.164065F,0.164065F);}
0115 static colorf gold() {return colorf(0.996109F,0.839857F,0);}
0116 static colorf goldenrod() {return colorf(0.851575F,0.644541F,0.125002F);}
0117 static colorf green() {return colorf(0,1,0);}
0118 static colorf darkgreen() {return colorf(0,0.390631F,0);}
0119 static colorf darkolivegreen() {return colorf(0.332036F,0.417975F,0.183597F);}
0120 static colorf forestgreen() {return colorf(0.132815F,0.542977F,0.132815F);}
0121 static colorf limegreen() {return colorf(0.195315F,0.800793F,0.195315F);}
0122 static colorf mediumseagreen() {return colorf(0.234379F,0.699229F,0.441413F);}
0123 static colorf mediumspringgreen() {return colorf(0,0.976577F,0.601572F);}
0124
0125 //30-39
0126 static colorf palegreen() {return colorf(0.593759F,0.980484F,0.593759F);}
0127 static colorf seagreen() {return colorf(0.17969F,0.542977F,0.339849F);}
0128 static colorf springgreen() {return colorf(0,0.996109F,0.496101F);}
0129 static colorf yellowgreen() {return colorf(0.601572F,0.800793F,0.195315F);}
0130 static colorf darkslategrey() {return colorf(0.183597F,0.308598F,0.308598F);}
0131 static colorf dimgrey() {return colorf(0.410163F,0.410163F,0.410163F);}
0132 static colorf lightgrey() {return colorf(0.824231F,0.824231F,0.824231F);}
0133 static colorf grey() {return colorf(0.750011F,0.750011F,0.750011F);}
0134 static colorf khaki() {return colorf(0.937514F,0.898451F,0.546883F);}
0135 static colorf magenta() {return colorf(1,0,1);}
0136
0137 //40-49
0138 static colorf maroon() {return colorf(0.68751F,0.187503F,0.375006F);}
0139 static colorf orange() {return colorf(0.996109F,0.644541F,0);}
0140 static colorf orchid() {return colorf(0.851575F,0.437507F,0.83595F);}
0141 static colorf darkorchid() {return colorf(0.597665F,0.195315F,0.796887F);}
0142 static colorf mediumorchid() {return colorf(0.726574F,0.332036F,0.824231F);}
0143 static colorf pink() {return colorf(0.996109F,0.750011F,0.792981F);}
0144 static colorf plum() {return colorf(0.863294F,0.62501F,0.863294F);}
0145 static colorf red() {return colorf(1,0,0);}
0146 static colorf indianred() {return colorf(0.800793F,0.35938F,0.35938F);}
0147 static colorf mediumvioletred() {return colorf(0.777356F,0.0820325F,0.519539F);}
0148
0149 //50-59
0150 static colorf orangered() {return colorf(0.996109F,0.269535F,0);}
0151 static colorf violetred() {return colorf(0.812512F,0.125002F,0.562509F);}
0152 static colorf salmon() {return colorf(0.976577F,0.500008F,0.445319F);}
0153 static colorf sienna() {return colorf(0.62501F,0.320317F,0.175784F);}
0154 static colorf tan() {return colorf(0.820325F,0.703136F,0.546883F);}
0155 static colorf thistle() {return colorf(0.843763F,0.746105F,0.843763F);}
0156 static colorf turquoise() {return colorf(0.250004F,0.875013F,0.812512F);}
0157 static colorf darkturquoise() {return colorf(0,0.8047F,0.816419F);}
0158 static colorf mediumturquoise() {return colorf(0.281254F,0.816419F,0.796887F);}
0159 static colorf violet() {return colorf(0.929702F,0.50782F,0.929702F);}
0160
0161 //60-64
0162 static colorf blueviolet() {return colorf(0.539071F,0.167971F,0.882826F);}
0163 static colorf wheat() {return colorf(0.957046F,0.867201F,0.699229F);}
0164 static colorf white() {return colorf(1,1,1);}
0165 static colorf yellow() {return colorf(1,1,0);}
0166 static colorf greenyellow() {return colorf(0.675792F,0.996109F,0.18359F);}
0167 #endif
0168 };
0169
0170 struct cmp_colorf {
0171 bool operator()(const colorf& a_a,const colorf& a_b) const {
0172 // x :
0173 if(a_a.v0()<a_b.v0()) return true;
0174 if(a_a.v0()>a_b.v0()) return false;
0175 // y :
0176 if(a_a.v1()<a_b.v1()) return true;
0177 if(a_a.v1()>a_b.v1()) return false;
0178 // z :
0179 if(a_a.v2()<a_b.v2()) return true;
0180 return false;
0181 }
0182 };
0183
0184 //default color is lightgrey:
0185 #if defined(TOOLS_MEM) && !defined(TOOLS_MEM_ATEXIT)
0186 inline const colorf& colorf_default() {static const colorf s_v(0.824231F,0.824231F,0.824231F,1,false);return s_v;}
0187 #else
0188 inline const colorf& colorf_default() {static const colorf s_v(0.824231F,0.824231F,0.824231F,1);return s_v;}
0189 #endif
0190
0191 }
0192
0193 #endif