Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Colour Class Reference

#include <G4Colour.hh>

Public Member Functions

 G4Colour (G4double r=1., G4double gr=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 &rhs)
G4double GetRed () const
G4double GetGreen () const
G4double GetBlue () const
G4double GetAlpha () const
void SetRed (G4double)
void SetGreen (G4double)
void SetBlue (G4double)
void SetAlpha (G4double)
G4bool operator< (const G4Colour &rhs) 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 G4bool GetColour (const G4String &key, G4Colour &result)
static G4bool GetColor (const G4String &key, G4Colour &result)
static void AddToMap (const G4String &key, const G4Colour &colour)
static void InitialiseColourMap ()
static const std::map< G4String, G4Colour > & GetMap ()

Friends

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

Detailed Description

Definition at line 88 of file G4Colour.hh.

Constructor & Destructor Documentation

◆ G4Colour() [1/2]

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

Definition at line 42 of file G4Colour.cc.

42 :
43red(clamp(r)), green(clamp(gr)), blue(clamp(b)), alpha(clamp(a))
44{}
T clamp(T value, T lo, T hi)

Referenced by AddToMap(), Black(), Blue(), Brown(), Cyan(), GetColor(), GetColour(), Gray(), Green(), Grey(), Magenta(), operator!=(), operator+=(), operator<(), operator<<, operator==(), Red(), White(), and Yellow().

◆ G4Colour() [2/2]

G4Colour::G4Colour ( G4ThreeVector v)

Definition at line 46 of file G4Colour.cc.

46 :
47red(clamp(v.x())), green(clamp(v.y())), blue(clamp(v.z())), alpha (1.)
48{}
double z() const
double x() const
double y() const

Member Function Documentation

◆ AddToMap()

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

Definition at line 86 of file G4Colour.cc.

87{
88 // Allow only master thread to populate the map
90 static G4bool first = true;
91 if (first) {
92 first = false;
94 ("G4Colour::AddToMap(const G4String& key, const G4Colour& colour)",
95 "greps0002", JustWarning,
96 "Attempt to add to colour map from non-master thread.");
97 }
98 return;
99 }
100
101 // Add standard colours to map
102 InitialiseColourMap(); // Initialises if not already initialised
103
104 // Convert to lower case since colour map is case insensitive
105 G4String myKey = G4StrUtil::to_lower_copy(key);
106
107 if (fColourMap.find(myKey) == fColourMap.end()) fColourMap[myKey] = colour;
108 else {
110 ed << "G4Colour with key " << myKey << " already exists." << G4endl;
112 ("G4Colour::AddToMap(const G4String& key, const G4Colour& colour)",
113 "greps0001", JustWarning, ed,
114 "Colour key exists");
115 }
116}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
bool G4bool
Definition G4Types.hh:86
#define G4endl
Definition G4ios.hh:67
static void InitialiseColourMap()
Definition G4Colour.cc:118
G4String to_lower_copy(G4String str)
Return lowercased copy of string.
G4bool IsMasterThread()

Referenced by InitialiseColourMap().

◆ Black()

G4Colour G4Colour::Black ( )
inlinestatic

Definition at line 178 of file G4Colour.hh.

178{return G4Colour(0.0, 0.0, 0.0);}
G4Colour(G4double r=1., G4double gr=1., G4double b=1., G4double a=1.)
Definition G4Colour.cc:42

Referenced by InitialiseColourMap(), and G4VVisCommand::Twinkle().

◆ Blue()

G4Colour G4Colour::Blue ( )
inlinestatic

◆ Brown()

G4Colour G4Colour::Brown ( )
inlinestatic

Definition at line 179 of file G4Colour.hh.

179{return G4Colour(0.45,0.25,0.0);}

Referenced by InitialiseColourMap().

◆ Cyan()

G4Colour G4Colour::Cyan ( )
inlinestatic

Definition at line 183 of file G4Colour.hh.

183{return G4Colour(0.0, 1.0, 1.0);}

Referenced by InitialiseColourMap().

◆ GetAlpha()

◆ GetBlue()

G4double G4Colour::GetBlue ( ) const
inline

◆ GetColor()

G4bool G4Colour::GetColor ( const G4String & key,
G4Colour & result )
inlinestatic

Definition at line 188 of file G4Colour.hh.

189{return G4Colour::GetColour(key, result);}
static G4bool GetColour(const G4String &key, G4Colour &result)
Definition G4Colour.cc:140

◆ GetColour()

G4bool G4Colour::GetColour ( const G4String & key,
G4Colour & result )
static

Definition at line 140 of file G4Colour.cc.

145{
146 // Add standard colours to map
147 InitialiseColourMap(); // Initialises if not already initialised
148
149 G4String myKey = G4StrUtil::to_lower_copy(key);
150
151 // NOLINTNEXTLINE(modernize-use-auto): Explicitly want a const_iterator
152 std::map<G4String, G4Colour>::const_iterator iter = fColourMap.find(myKey);
153
154 // Don't modify "result" if colour was not found in map
155 if (iter == fColourMap.cend()) {
157 ed << "Colour \"" << key << "\" not found. No action taken.";
158 G4Exception("G4Colour::GetColour", "greps0003", JustWarning, ed);
159 return false;
160 }
161
162 result = iter->second;
163
164 return true;
165}

Referenced by G4ViewParameters::CameraAndLightingCommands(), G4AxesModel::Construct(), G4VVisCommand::ConvertToColour(), GetColor(), G4ModelColourMap< T >::Set(), G4TrajectoryDrawByEncounteredVolume::SetDefault(), G4TrajectoryDrawByOriginVolume::SetDefault(), G4TrajectoryDrawByParticleID::SetDefault(), G4ModelCmdApplyColour< M >::SetNewValue(), and G4ModelCmdApplyStringColour< M >::SetNewValue().

◆ GetGreen()

G4double G4Colour::GetGreen ( ) const
inline

◆ GetMap()

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

Definition at line 167 of file G4Colour.cc.

168{
169 // Add standard colours to map
170 InitialiseColourMap(); // Initialises if not already initialised
171
172 return fColourMap;
173}

Referenced by operator<<.

◆ GetRed()

G4double G4Colour::GetRed ( ) const
inline

◆ Gray()

G4Colour G4Colour::Gray ( )
inlinestatic

Definition at line 176 of file G4Colour.hh.

176{return G4Colour(0.5, 0.5, 0.5);}

Referenced by InitialiseColourMap().

◆ Green()

G4Colour G4Colour::Green ( )
inlinestatic

◆ Grey()

G4Colour G4Colour::Grey ( )
inlinestatic

Definition at line 177 of file G4Colour.hh.

177{return G4Colour(0.5, 0.5, 0.5);}

Referenced by InitialiseColourMap().

◆ InitialiseColourMap()

void G4Colour::InitialiseColourMap ( )
static

Definition at line 118 of file G4Colour.cc.

119{
120 if (fInitColourMap) return;
121
122 fInitColourMap = true;
123
124 // clang-format off
125 // Standard colours
126 AddToMap("white", G4Colour::White());
127 AddToMap("grey", G4Colour::Grey());
128 AddToMap("gray", G4Colour::Gray());
129 AddToMap("black", G4Colour::Black());
130 AddToMap("brown", G4Colour::Brown());
131 AddToMap("red", G4Colour::Red());
132 AddToMap("green", G4Colour::Green());
133 AddToMap("blue", G4Colour::Blue());
134 AddToMap("cyan", G4Colour::Cyan());
135 AddToMap("magenta", G4Colour::Magenta());
136 AddToMap("yellow", G4Colour::Yellow());
137 // clang-format off
138}
static G4Colour White()
Definition G4Colour.hh:175
static G4Colour Yellow()
Definition G4Colour.hh:185
static G4Colour Green()
Definition G4Colour.hh:181
static void AddToMap(const G4String &key, const G4Colour &colour)
Definition G4Colour.cc:86
static G4Colour Red()
Definition G4Colour.hh:180
static G4Colour Brown()
Definition G4Colour.hh:179
static G4Colour Grey()
Definition G4Colour.hh:177
static G4Colour Black()
Definition G4Colour.hh:178
static G4Colour Magenta()
Definition G4Colour.hh:184
static G4Colour Blue()
Definition G4Colour.hh:182
static G4Colour Gray()
Definition G4Colour.hh:176
static G4Colour Cyan()
Definition G4Colour.hh:183

Referenced by AddToMap(), GetColour(), and GetMap().

◆ Magenta()

G4Colour G4Colour::Magenta ( )
inlinestatic

Definition at line 184 of file G4Colour.hh.

184{return G4Colour(1.0, 0.0, 1.0);}

Referenced by InitialiseColourMap().

◆ operator G4ThreeVector()

G4Colour::operator G4ThreeVector ( )

Definition at line 56 of file G4Colour.cc.

56 {
57 return G4ThreeVector(red,green,blue);
58}
CLHEP::Hep3Vector G4ThreeVector

◆ operator!=()

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

Definition at line 76 of file G4Colour.cc.

76 {
77 return (red != c.red) ||
78 (green != c.green) ||
79 (blue != c.blue) ||
80 (alpha != c.alpha);
81}

Referenced by operator==().

◆ operator+=()

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

Definition at line 106 of file G4Colour.hh.

106{*this = rhs; return *this;}

◆ operator<()

G4bool G4Colour::operator< ( const G4Colour & rhs) const

Definition at line 175 of file G4Colour.cc.

176{
177 if (red < rhs.red) return true;
178 if (red == rhs.red) {
179 if (green < rhs.green) return true;
180 if (green == rhs.green) {
181 if (blue < rhs.blue) return true;
182 if (blue == rhs.blue) {
183 if (alpha < rhs.alpha) return true;
184 }
185 }
186 }
187 return false;
188}

◆ operator==()

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

Definition at line 104 of file G4Colour.hh.

104{return !(operator != (c));}
G4bool operator!=(const G4Colour &c) const
Definition G4Colour.cc:76

◆ Red()

◆ SetAlpha()

void G4Colour::SetAlpha ( G4double a)

Definition at line 53 of file G4Colour.cc.

53{alpha = clamp(a);}

Referenced by G4VVisCommand::ConvertToColour(), and G4PhysicalVolumeModel::DescribeAndDescend().

◆ SetBlue()

void G4Colour::SetBlue ( G4double b)

Definition at line 52 of file G4Colour.cc.

52{blue = clamp(b);}

◆ SetGreen()

void G4Colour::SetGreen ( G4double gr)

Definition at line 51 of file G4Colour.cc.

51{green = clamp(gr);}

◆ SetRed()

void G4Colour::SetRed ( G4double r)

Definition at line 50 of file G4Colour.cc.

50{red = clamp(r);}

◆ White()

G4Colour G4Colour::White ( )
inlinestatic

Definition at line 175 of file G4Colour.hh.

175{return G4Colour(1.0, 1.0, 1.0);}

Referenced by InitialiseColourMap(), G4TrajectoryDrawByParticleID::SetDefault(), and G4VVisCommand::Twinkle().

◆ Yellow()

G4Colour G4Colour::Yellow ( )
inlinestatic

Definition at line 185 of file G4Colour.hh.

185{return G4Colour(1.0, 1.0, 0.0);}

Referenced by InitialiseColourMap().

◆ operator<<

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

Definition at line 60 of file G4Colour.cc.

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

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