Back to home page

EIC code displayed by LXR

 
 

    


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   colorf(float a_r,float a_g,float a_b,float a_a = 1):parent(a_r,a_g,a_b,a_a){}
0020   virtual ~colorf() {}
0021 public:
0022   colorf(const colorf& a_from):parent(a_from){}
0023   colorf& operator=(const colorf& a_from){
0024     parent::operator=(a_from);
0025     return *this;
0026   }
0027 public:
0028   colorf& operator*=(const colorf& a_v) {
0029     m_data[0] *= a_v.m_data[0];
0030     m_data[1] *= a_v.m_data[1];
0031     m_data[2] *= a_v.m_data[2];
0032     m_data[3] *= a_v.m_data[3];
0033     return *this;
0034   }
0035   colorf& operator*=(float a_v) {
0036     m_data[0] *= a_v;
0037     m_data[1] *= a_v;
0038     m_data[2] *= a_v;
0039     m_data[3] *= a_v;
0040     return *this;
0041   }
0042 public:
0043   void clamp(float a_min = 0,float a_max = 1) {
0044     if(m_data[0]<a_min) m_data[0] = a_min;
0045     if(m_data[1]<a_min) m_data[1] = a_min;
0046     if(m_data[2]<a_min) m_data[2] = a_min;
0047     if(m_data[3]<a_min) m_data[3] = a_min;
0048 
0049     if(a_max<m_data[0]) m_data[0] = a_max;
0050     if(a_max<m_data[1]) m_data[1] = a_max;
0051     if(a_max<m_data[2]) m_data[2] = a_max;
0052     if(a_max<m_data[3]) m_data[3] = a_max;
0053   }
0054   float r() const {return v0();}
0055   float g() const {return v1();}
0056   float b() const {return v2();}
0057   float a() const {return v3();}
0058 
0059   void set_r(float a_v) {m_data[0] = a_v;}
0060   void set_g(float a_v) {m_data[1] = a_v;}
0061   void set_b(float a_v) {m_data[2] = a_v;}
0062   void set_a(float a_v) {m_data[3] = a_v;}
0063 
0064   uchar ruchar() const {return uchar(255.0f*m_data[0]);}
0065   uchar guchar() const {return uchar(255.0f*m_data[1]);}
0066   uchar buchar() const {return uchar(255.0f*m_data[2]);}
0067   uchar auchar() const {return uchar(255.0f*m_data[3]);}
0068 };
0069 
0070 }
0071 
0072 #endif