Geant4  10.02.p03
G4Colour Class Reference

#include <G4Colour.hh>

Collaboration diagram for G4Colour:

Public Member Functions

 G4Colour (G4double r=1., G4double g=1., G4double b=1., G4double a=1.)
 
 G4Colour (G4ThreeVector)
 
 operator G4ThreeVector ()
 
G4bool operator!= (const G4Colour &c) const
 
G4bool operator== (const G4Colour &c) const
 
G4Colouroperator+= (const G4Colour &)
 
G4double GetRed () const
 
G4double GetGreen () const
 
G4double GetBlue () const
 
G4double GetAlpha () const
 

Static Public Member Functions

static G4Colour White ()
 
static G4Colour Gray ()
 
static G4Colour Grey ()
 
static G4Colour Black ()
 
static G4Colour Brown ()
 
static G4Colour Red ()
 
static G4Colour Green ()
 
static G4Colour Blue ()
 
static G4Colour Cyan ()
 
static G4Colour Magenta ()
 
static G4Colour Yellow ()
 
static void AddToMap (const G4String &key, const G4Colour &colour)
 
static G4bool GetColour (const G4String &key, G4Colour &result)
 
static const std::map< G4String, G4Colour > & GetMap ()
 

Static Private Member Functions

static void InitialiseColourMap ()
 

Private Attributes

G4double red
 
G4double green
 
G4double blue
 
G4double alpha
 

Static Private Attributes

static G4ThreadLocal std::map< G4String, G4Colour > * fColourMap = 0
 
static G4ThreadLocal G4bool fInitColourMap = false
 

Friends

std::ostream & operator<< (std::ostream &, const G4Colour &)
 

Detailed Description

Definition at line 83 of file G4Colour.hh.

Constructor & Destructor Documentation

◆ G4Colour() [1/2]

G4Colour::G4Colour ( G4double  r = 1.,
G4double  g = 1.,
G4double  b = 1.,
G4double  a = 1. 
)

Definition at line 34 of file G4Colour.cc.

34  :
35 red (r), green (gr), blue (b), alpha (a)
36 {
37  if( red > 1.0 ){red = 1.0;} if( red < 0.0 ){red = 0.0;}
38  if( green > 1.0 ){green = 1.0;} if( green < 0.0 ){green = 0.0;}
39  if( blue > 1.0 ){blue = 1.0;} if( blue < 0.0 ){blue = 0.0;}
40  if( alpha > 1.0 ){alpha = 1.0;} if( alpha < 0.0 ){alpha = 0.0;}
41 }
G4double alpha
Definition: G4Colour.hh:131
G4double red
Definition: G4Colour.hh:131
G4double blue
Definition: G4Colour.hh:131
G4double green
Definition: G4Colour.hh:131
Here is the caller graph for this function:

◆ G4Colour() [2/2]

G4Colour::G4Colour ( G4ThreeVector  v)

Definition at line 43 of file G4Colour.cc.

43  :
44 red (v.x()), green (v.y()), blue (v.z()), alpha (1.)
45 {
46  if( red > 1.0 ){red = 1.0;} if( red < 0.0 ){red = 0.0;}
47  if( green > 1.0 ){green = 1.0;} if( green < 0.0 ){green = 0.0;}
48  if( blue > 1.0 ){blue = 1.0;} if( blue < 0.0 ){blue = 0.0;}
49 }
G4double alpha
Definition: G4Colour.hh:131
G4double red
Definition: G4Colour.hh:131
double x() const
G4double blue
Definition: G4Colour.hh:131
double y() const
double z() const
G4double green
Definition: G4Colour.hh:131

Member Function Documentation

◆ AddToMap()

void G4Colour::AddToMap ( const G4String key,
const G4Colour colour 
)
static

Definition at line 86 of file G4Colour.cc.

87 {
88  if (!fColourMap)
89  fColourMap = new std::map<G4String, G4Colour>;
90 
91  // Convert to lower case since colour map is case insensitive
92  G4String myKey(key);
93  myKey.toLower();
94 
95  std::map<G4String, G4Colour>::iterator iter = fColourMap->find(myKey);
96 
97  if (iter == fColourMap->end()) (*fColourMap)[myKey] = colour;
98  else {
100  ed << "G4Colour with key "<<myKey<<" already exists."<<G4endl;
102  ("G4Colour::AddToMap(const G4String& key, const G4Colour& colour)",
103  "greps0001", JustWarning, ed,
104  "Colour key exists");
105  }
106 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define G4endl
Definition: G4ios.hh:61
static G4ThreadLocal std::map< G4String, G4Colour > * fColourMap
Definition: G4Colour.hh:133
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Black()

G4Colour G4Colour::Black ( )
inlinestatic

Definition at line 146 of file G4Colour.hh.

146 {return G4Colour(0.0, 0.0, 0.0);}
G4Colour(G4double r=1., G4double g=1., G4double b=1., G4double a=1.)
Definition: G4Colour.cc:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Blue()

G4Colour G4Colour::Blue ( )
inlinestatic

Definition at line 150 of file G4Colour.hh.

150 {return G4Colour(0.0, 0.0, 1.0);}
G4Colour(G4double r=1., G4double g=1., G4double b=1., G4double a=1.)
Definition: G4Colour.cc:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Brown()

G4Colour G4Colour::Brown ( )
inlinestatic

Definition at line 147 of file G4Colour.hh.

147 {return G4Colour(0.45,0.25,0.0);}
G4Colour(G4double r=1., G4double g=1., G4double b=1., G4double a=1.)
Definition: G4Colour.cc:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Cyan()

G4Colour G4Colour::Cyan ( )
inlinestatic

Definition at line 151 of file G4Colour.hh.

151 {return G4Colour(0.0, 1.0, 1.0);}
G4Colour(G4double r=1., G4double g=1., G4double b=1., G4double a=1.)
Definition: G4Colour.cc:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetAlpha()

G4double G4Colour::GetAlpha ( ) const
inline

Definition at line 142 of file G4Colour.hh.

142 {return alpha;}
G4double alpha
Definition: G4Colour.hh:131
Here is the caller graph for this function:

◆ GetBlue()

G4double G4Colour::GetBlue ( ) const
inline

Definition at line 141 of file G4Colour.hh.

141 {return blue;}
G4double blue
Definition: G4Colour.hh:131
Here is the caller graph for this function:

◆ GetColour()

bool G4Colour::GetColour ( const G4String key,
G4Colour result 
)
static

Definition at line 126 of file G4Colour.cc.

127 {
128  if (false == fInitColourMap) {
129  fInitColourMap = true;
130  // Add standard colours to map
132  }
133 
134  G4String myKey(key);
135  myKey.toLower();
136 
137  std::map<G4String, G4Colour>::iterator iter = fColourMap->find(myKey);
138 
139  // Don't modify "result" if colour was not found in map
140  if (iter == fColourMap->end()) return false;
141 
142  result = iter->second;
143 
144  return true;
145 }
static void InitialiseColourMap()
Definition: G4Colour.cc:109
static G4ThreadLocal G4bool fInitColourMap
Definition: G4Colour.hh:134
static G4ThreadLocal std::map< G4String, G4Colour > * fColourMap
Definition: G4Colour.hh:133
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetGreen()

G4double G4Colour::GetGreen ( ) const
inline

Definition at line 140 of file G4Colour.hh.

140 {return green;}
G4double green
Definition: G4Colour.hh:131
Here is the caller graph for this function:

◆ GetMap()

const std::map< G4String, G4Colour > & G4Colour::GetMap ( )
static

Definition at line 147 of file G4Colour.cc.

148 {
149  if (false == fInitColourMap) {
150  fInitColourMap = true;
151  // Add standard colours to map
153  }
154 
155  return *fColourMap;
156 }
static void InitialiseColourMap()
Definition: G4Colour.cc:109
static G4ThreadLocal G4bool fInitColourMap
Definition: G4Colour.hh:134
static G4ThreadLocal std::map< G4String, G4Colour > * fColourMap
Definition: G4Colour.hh:133
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetRed()

G4double G4Colour::GetRed ( ) const
inline

Definition at line 139 of file G4Colour.hh.

139 {return red;}
G4double red
Definition: G4Colour.hh:131
Here is the caller graph for this function:

◆ Gray()

G4Colour G4Colour::Gray ( )
inlinestatic

Definition at line 144 of file G4Colour.hh.

144 {return G4Colour(0.5, 0.5, 0.5);}
G4Colour(G4double r=1., G4double g=1., G4double b=1., G4double a=1.)
Definition: G4Colour.cc:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Green()

G4Colour G4Colour::Green ( )
inlinestatic

Definition at line 149 of file G4Colour.hh.

149 {return G4Colour(0.0, 1.0, 0.0);}
G4Colour(G4double r=1., G4double g=1., G4double b=1., G4double a=1.)
Definition: G4Colour.cc:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Grey()

G4Colour G4Colour::Grey ( )
inlinestatic

Definition at line 145 of file G4Colour.hh.

145 {return G4Colour(0.5, 0.5, 0.5);}
G4Colour(G4double r=1., G4double g=1., G4double b=1., G4double a=1.)
Definition: G4Colour.cc:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitialiseColourMap()

void G4Colour::InitialiseColourMap ( )
staticprivate

Definition at line 109 of file G4Colour.cc.

110 {
111  // Standard colours
112  AddToMap("white", G4Colour::White());
113  AddToMap("grey", G4Colour::Grey());
114  AddToMap("gray", G4Colour::Gray());
115  AddToMap("black", G4Colour::Black());
116  AddToMap("brown", G4Colour::Brown());
117  AddToMap("red", G4Colour::Red());
118  AddToMap("green", G4Colour::Green());
119  AddToMap("blue", G4Colour::Blue());
120  AddToMap("cyan", G4Colour::Cyan());
121  AddToMap("magenta", G4Colour::Magenta());
122  AddToMap("yellow", G4Colour::Yellow());
123 }
static G4Colour Gray()
Definition: G4Colour.hh:144
static G4Colour Green()
Definition: G4Colour.hh:149
static G4Colour Magenta()
Definition: G4Colour.hh:152
static G4Colour Brown()
Definition: G4Colour.hh:147
static G4Colour Black()
Definition: G4Colour.hh:146
static G4Colour Grey()
Definition: G4Colour.hh:145
static void AddToMap(const G4String &key, const G4Colour &colour)
Definition: G4Colour.cc:86
static G4Colour Blue()
Definition: G4Colour.hh:150
static G4Colour Cyan()
Definition: G4Colour.hh:151
static G4Colour Red()
Definition: G4Colour.hh:148
static G4Colour Yellow()
Definition: G4Colour.hh:153
static G4Colour White()
Definition: G4Colour.hh:143
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Magenta()

G4Colour G4Colour::Magenta ( )
inlinestatic

Definition at line 152 of file G4Colour.hh.

152 {return G4Colour(1.0, 0.0, 1.0);}
G4Colour(G4double r=1., G4double g=1., G4double b=1., G4double a=1.)
Definition: G4Colour.cc:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator G4ThreeVector()

G4Colour::operator G4ThreeVector ( )

Definition at line 51 of file G4Colour.cc.

51  {
52  return G4ThreeVector(red,green,blue);
53 }
CLHEP::Hep3Vector G4ThreeVector
G4double red
Definition: G4Colour.hh:131
G4double blue
Definition: G4Colour.hh:131
G4double green
Definition: G4Colour.hh:131

◆ operator!=()

G4bool G4Colour::operator!= ( const G4Colour c) const

Definition at line 71 of file G4Colour.cc.

71  {
72  if (
73  (red != c.red) ||
74  (green != c.green) ||
75  (blue != c.blue) ||
76  (alpha != c.alpha)
77  )
78  return true;
79  return false;
80 }
G4double alpha
Definition: G4Colour.hh:131
G4double red
Definition: G4Colour.hh:131
G4double blue
Definition: G4Colour.hh:131
G4double green
Definition: G4Colour.hh:131
Here is the caller graph for this function:

◆ operator+=()

G4Colour& G4Colour::operator+= ( const G4Colour )
inline

Definition at line 101 of file G4Colour.hh.

101 {return *this;} // Dummy
Here is the call graph for this function:

◆ operator==()

G4bool G4Colour::operator== ( const G4Colour c) const
inline

Definition at line 100 of file G4Colour.hh.

100 {return !(operator != (c));}
G4bool operator!=(const G4Colour &c) const
Definition: G4Colour.cc:71
Here is the call graph for this function:

◆ Red()

G4Colour G4Colour::Red ( )
inlinestatic

Definition at line 148 of file G4Colour.hh.

148 {return G4Colour(1.0, 0.0, 0.0);}
G4Colour(G4double r=1., G4double g=1., G4double b=1., G4double a=1.)
Definition: G4Colour.cc:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ White()

G4Colour G4Colour::White ( )
inlinestatic

Definition at line 143 of file G4Colour.hh.

143 {return G4Colour(1.0, 1.0, 1.0);}
G4Colour(G4double r=1., G4double g=1., G4double b=1., G4double a=1.)
Definition: G4Colour.cc:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Yellow()

G4Colour G4Colour::Yellow ( )
inlinestatic

Definition at line 153 of file G4Colour.hh.

153 {return G4Colour(1.0, 1.0, 0.0);}
G4Colour(G4double r=1., G4double g=1., G4double b=1., G4double a=1.)
Definition: G4Colour.cc:34
Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const G4Colour c 
)
friend

Definition at line 55 of file G4Colour.cc.

55  {
56  os << '(' << c.red << ',' << c.green << ',' << c.blue
57  << ',' << c.alpha << ')';
58  const std::map<G4String, G4Colour>& colourMap = G4Colour::GetMap();
59  // Reverse iterator to pick up English spelling of grey!! :)
60  std::map<G4String, G4Colour>::const_reverse_iterator ri;
61  for (ri = colourMap.rbegin(); ri != colourMap.rend(); ++ri) {
62  if (c == ri->second) {
63  os << " (" << ri->first << ')';
64  break;
65  }
66  }
67 
68  return os;
69 }
G4double alpha
Definition: G4Colour.hh:131
G4double red
Definition: G4Colour.hh:131
G4double blue
Definition: G4Colour.hh:131
G4double green
Definition: G4Colour.hh:131
static const std::map< G4String, G4Colour > & GetMap()
Definition: G4Colour.cc:147

Member Data Documentation

◆ alpha

G4double G4Colour::alpha
private

Definition at line 131 of file G4Colour.hh.

◆ blue

G4double G4Colour::blue
private

Definition at line 131 of file G4Colour.hh.

◆ fColourMap

G4ThreadLocal std::map< G4String, G4Colour > * G4Colour::fColourMap = 0
staticprivate

Definition at line 133 of file G4Colour.hh.

◆ fInitColourMap

G4ThreadLocal bool G4Colour::fInitColourMap = false
staticprivate

Definition at line 134 of file G4Colour.hh.

◆ green

G4double G4Colour::green
private

Definition at line 131 of file G4Colour.hh.

◆ red

G4double G4Colour::red
private

Definition at line 131 of file G4Colour.hh.


The documentation for this class was generated from the following files: