Geant4-11
Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes | Friends
G4Colour Class Reference

#include <G4Colour.hh>

Public Member Functions

 G4Colour (G4double r_=1., G4double g_=1., G4double b_=1., G4double a_=1.)
 
 G4Colour (G4ThreeVector)
 
G4double GetAlpha () const
 
G4double GetBlue () const
 
G4double GetGreen () const
 
G4double GetRed () const
 
 operator G4ThreeVector ()
 
G4bool operator!= (const G4Colour &c) const
 
G4Colouroperator+= (const G4Colour &rhs)
 
G4bool operator< (const G4Colour &rhs) const
 
G4bool operator== (const G4Colour &c) const
 
void SetAlpha (G4double)
 
void SetBlue (G4double)
 
void SetGreen (G4double)
 
void SetRed (G4double)
 

Static Public Member Functions

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

Private Attributes

G4double alpha
 
G4double blue
 
G4double green
 
G4double red
 

Static Private Attributes

static std::map< G4String, G4ColourfColourMap
 
static G4bool fInitColourMap = false
 

Friends

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

Detailed Description

Definition at line 82 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 35 of file G4Colour.cc.

35 :
36red (r), green (gr), blue (b), alpha (a)
37{
38 if( red > 1.0 ){red = 1.0;} if( red < 0.0 ){red = 0.0;}
39 if( green > 1.0 ){green = 1.0;} if( green < 0.0 ){green = 0.0;}
40 if( blue > 1.0 ){blue = 1.0;} if( blue < 0.0 ){blue = 0.0;}
41 if( alpha > 1.0 ){alpha = 1.0;} if( alpha < 0.0 ){alpha = 0.0;}
42}
G4double alpha
Definition: G4Colour.hh:145
G4double green
Definition: G4Colour.hh:145
G4double red
Definition: G4Colour.hh:145
G4double blue
Definition: G4Colour.hh:145

References alpha, blue, green, and red.

Referenced by Black(), Blue(), Brown(), Cyan(), Gray(), Green(), Grey(), Magenta(), Red(), White(), and Yellow().

◆ G4Colour() [2/2]

G4Colour::G4Colour ( G4ThreeVector  v)

Definition at line 44 of file G4Colour.cc.

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

References blue, green, and red.

Member Function Documentation

◆ AddToMap()

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

Definition at line 110 of file G4Colour.cc.

111{
112 // Allow only master thread to populate the map
114 static G4bool first = true;
115 if (first) {
116 first = false;
118 ("G4Colour::AddToMap(const G4String& key, const G4Colour& colour)",
119 "greps0002", JustWarning,
120 "Attempt to add to colour map from non-master thread.");
121 }
122 return;
123 }
124
125 // Convert to lower case since colour map is case insensitive
127
128 std::map<G4String, G4Colour>::iterator iter = fColourMap.find(myKey);
129
130 if (iter == fColourMap.end()) fColourMap[myKey] = colour;
131 else {
133 ed << "G4Colour with key " << myKey << " already exists." << G4endl;
135 ("G4Colour::AddToMap(const G4String& key, const G4Colour& colour)",
136 "greps0001", JustWarning, ed,
137 "Colour key exists");
138 }
139}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
bool G4bool
Definition: G4Types.hh:86
#define G4endl
Definition: G4ios.hh:57
static std::map< G4String, G4Colour > fColourMap
Definition: G4Colour.hh:147
G4String to_lower_copy(G4String str)
Return lowercased copy of string.
G4bool IsMasterThread()
Definition: G4Threading.cc:124

References fColourMap, G4endl, G4Exception(), G4Threading::IsMasterThread(), JustWarning, and G4StrUtil::to_lower_copy().

Referenced by InitialiseColourMap().

◆ Black()

G4Colour G4Colour::Black ( )
inlinestatic

Definition at line 159 of file G4Colour.hh.

159{return G4Colour(0.0, 0.0, 0.0);}
G4Colour(G4double r_=1., G4double g_=1., G4double b_=1., G4double a_=1.)
Definition: G4Colour.cc:35

References G4Colour().

Referenced by InitialiseColourMap().

◆ Blue()

G4Colour G4Colour::Blue ( )
inlinestatic

◆ Brown()

G4Colour G4Colour::Brown ( )
inlinestatic

Definition at line 160 of file G4Colour.hh.

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

References G4Colour().

Referenced by InitialiseColourMap(), and G4VisCommandSceneAddLogo2D::Logo2D::operator()().

◆ Cyan()

G4Colour G4Colour::Cyan ( )
inlinestatic

Definition at line 164 of file G4Colour.hh.

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

References G4Colour().

Referenced by InitialiseColourMap().

◆ GetAlpha()

G4double G4Colour::GetAlpha ( ) const
inline

◆ GetBlue()

G4double G4Colour::GetBlue ( ) const
inline

Definition at line 154 of file G4Colour.hh.

154{return blue;}

References blue.

Referenced by G4VtkSceneHandler::AddCompound(), G4HepRepFileSceneHandler::AddCompound(), G4GMocrenFileSceneHandler::AddDetector(), G4HepRepFileSceneHandler::AddHepRepInstance(), G4VtkSceneHandler::AddPrimitive(), G4GMocrenFileSceneHandler::AddPrimitive(), G4HepRepFileSceneHandler::AddPrimitive(), G4OpenInventorSceneHandler::AddPrimitive(), G4OpenGLImmediateSceneHandler::AddPrimitivePreambleInternal(), G4OpenGLStoredSceneHandler::AddPrimitivePreambleInternal(), G4VtkSceneHandler::AddPrimitiveTensorGlyph(), G4OpenInventorSceneHandler::AddProperties(), G4RTRun::Attenuate(), G4TheRayTracer::Attenuate(), G4ViewParameters::CameraAndLightingCommands(), G4OpenGLQtViewer::changeDepthOnSceneTreeItem(), G4OpenGLViewer::ClearViewWithoutFlush(), G4Qt3DUtils::ConvertToQColor(), G4TheMTRayTracer::CreateBitMap(), G4TheRayTracer::CreateBitMap(), G4OpenGLXmViewer::CreateMainWindow(), G4OpenGLQtViewer::createTreeWidgetItem(), G4OpenGLStoredViewer::DrawDisplayLists(), G4OpenGLQtViewer::DrawText(), G4OpenGLXViewer::DrawText(), G4VtkViewer::DrawViewHUD(), G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::Export(), export_G4Colour(), G4OpenInventorSceneHandler::GeneratePrerequisites(), G4TheRayTracer::GetMixedColour(), G4RTRun::GetMixedColour(), G4RTRun::GetSurfaceColour(), G4TheRayTracer::GetSurfaceColour(), std::hash< G4VisAttributes >::operator()(), G4OpenGLQtViewer::parseAndInsertInSceneTree(), G4OpenInventorQtViewer::SetView(), G4OpenInventorWinViewer::SetView(), G4OpenInventorXtExtendedViewer::SetView(), G4OpenInventorXtViewer::SetView(), G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::SetView(), G4VtkViewer::SetView(), G4VtkViewer::ShowView(), G4ViewParameters::TouchableCommands(), G4VViewer::TouchableSetColour(), G4TheMTRayTracer::Trace(), and G4OpenGLQtViewer::updateViewerPropertiesTableWidget().

◆ GetColour()

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

Definition at line 161 of file G4Colour.cc.

162{
163 // Add standard colours to map
164 InitialiseColourMap(); // Initialises if not already initialised
165
167
168 std::map<G4String, G4Colour>::iterator iter = fColourMap.find(myKey);
169
170 // Don't modify "result" if colour was not found in map
171 if (iter == fColourMap.end()) return false;
172
173 result = iter->second;
174
175 return true;
176}
static void InitialiseColourMap()
Definition: G4Colour.cc:141

References fColourMap, InitialiseColourMap(), and G4StrUtil::to_lower_copy().

Referenced by G4OpenGLSceneHandler::AddCompound(), G4Qt3DSceneHandler::AddCompound(), G4VtkSceneHandler::AddCompound(), G4AxesModel::Construct(), G4VVisCommand::ConvertToColour(), G4ModelColourMap< T >::Set(), G4TrajectoryDrawByEncounteredVolume::SetDefault(), G4TrajectoryDrawByOriginVolume::SetDefault(), G4TrajectoryDrawByParticleID::SetDefault(), G4ModelCmdApplyStringColour< M >::SetNewValue(), and G4ModelCmdApplyColour< M >::SetNewValue().

◆ GetGreen()

G4double G4Colour::GetGreen ( ) const
inline

Definition at line 153 of file G4Colour.hh.

153{return green;}

References green.

Referenced by G4VtkSceneHandler::AddCompound(), G4HepRepFileSceneHandler::AddCompound(), G4GMocrenFileSceneHandler::AddDetector(), G4HepRepFileSceneHandler::AddHepRepInstance(), G4VtkSceneHandler::AddPrimitive(), G4GMocrenFileSceneHandler::AddPrimitive(), G4HepRepFileSceneHandler::AddPrimitive(), G4OpenInventorSceneHandler::AddPrimitive(), G4OpenGLImmediateSceneHandler::AddPrimitivePreambleInternal(), G4OpenGLStoredSceneHandler::AddPrimitivePreambleInternal(), G4VtkSceneHandler::AddPrimitiveTensorGlyph(), G4OpenInventorSceneHandler::AddProperties(), G4RTRun::Attenuate(), G4TheRayTracer::Attenuate(), G4ViewParameters::CameraAndLightingCommands(), G4OpenGLQtViewer::changeDepthOnSceneTreeItem(), G4OpenGLViewer::ClearViewWithoutFlush(), G4Qt3DUtils::ConvertToQColor(), G4TheMTRayTracer::CreateBitMap(), G4TheRayTracer::CreateBitMap(), G4OpenGLXmViewer::CreateMainWindow(), G4OpenGLQtViewer::createTreeWidgetItem(), G4OpenGLStoredViewer::DrawDisplayLists(), G4OpenGLQtViewer::DrawText(), G4OpenGLXViewer::DrawText(), G4VtkViewer::DrawViewHUD(), G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::Export(), export_G4Colour(), G4OpenInventorSceneHandler::GeneratePrerequisites(), G4TheRayTracer::GetMixedColour(), G4RTRun::GetMixedColour(), G4RTRun::GetSurfaceColour(), G4TheRayTracer::GetSurfaceColour(), std::hash< G4VisAttributes >::operator()(), G4OpenGLQtViewer::parseAndInsertInSceneTree(), G4OpenInventorQtViewer::SetView(), G4OpenInventorWinViewer::SetView(), G4OpenInventorXtExtendedViewer::SetView(), G4OpenInventorXtViewer::SetView(), G4VtkViewer::SetView(), G4VtkViewer::ShowView(), G4ViewParameters::TouchableCommands(), G4VViewer::TouchableSetColour(), G4TheMTRayTracer::Trace(), and G4OpenGLQtViewer::updateViewerPropertiesTableWidget().

◆ GetMap()

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

Definition at line 178 of file G4Colour.cc.

179{
180 // Add standard colours to map
181 InitialiseColourMap(); // Initialises if not already initialised
182
183 return fColourMap;
184}

References fColourMap, and InitialiseColourMap().

Referenced by G4VisManager::PrintAvailableColours().

◆ GetRed()

G4double G4Colour::GetRed ( ) const
inline

Definition at line 152 of file G4Colour.hh.

152{return red;}

References red.

Referenced by G4VtkSceneHandler::AddCompound(), G4HepRepFileSceneHandler::AddCompound(), G4GMocrenFileSceneHandler::AddDetector(), G4HepRepFileSceneHandler::AddHepRepInstance(), G4VtkSceneHandler::AddPrimitive(), G4GMocrenFileSceneHandler::AddPrimitive(), G4HepRepFileSceneHandler::AddPrimitive(), G4OpenInventorSceneHandler::AddPrimitive(), G4OpenGLImmediateSceneHandler::AddPrimitivePreambleInternal(), G4OpenGLStoredSceneHandler::AddPrimitivePreambleInternal(), G4VtkSceneHandler::AddPrimitiveTensorGlyph(), G4OpenInventorSceneHandler::AddProperties(), G4RTRun::Attenuate(), G4TheRayTracer::Attenuate(), G4ViewParameters::CameraAndLightingCommands(), G4OpenGLQtViewer::changeDepthOnSceneTreeItem(), G4OpenGLViewer::ClearViewWithoutFlush(), G4Qt3DUtils::ConvertToQColor(), G4TheMTRayTracer::CreateBitMap(), G4TheRayTracer::CreateBitMap(), G4OpenGLXmViewer::CreateMainWindow(), G4OpenGLQtViewer::createTreeWidgetItem(), G4OpenGLStoredViewer::DrawDisplayLists(), G4OpenGLQtViewer::DrawText(), G4OpenGLXViewer::DrawText(), G4VtkViewer::DrawViewHUD(), G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::Export(), export_G4Colour(), G4OpenInventorSceneHandler::GeneratePrerequisites(), G4TheRayTracer::GetMixedColour(), G4RTRun::GetMixedColour(), G4RTRun::GetSurfaceColour(), G4TheRayTracer::GetSurfaceColour(), std::hash< G4VisAttributes >::operator()(), G4OpenGLQtViewer::parseAndInsertInSceneTree(), G4OpenInventorQtViewer::SetView(), G4OpenInventorWinViewer::SetView(), G4OpenInventorXtExtendedViewer::SetView(), G4OpenInventorXtViewer::SetView(), G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::SetView(), G4VtkViewer::SetView(), G4VtkViewer::ShowView(), G4ViewParameters::TouchableCommands(), G4VViewer::TouchableSetColour(), G4TheMTRayTracer::Trace(), and G4OpenGLQtViewer::updateViewerPropertiesTableWidget().

◆ Gray()

G4Colour G4Colour::Gray ( )
inlinestatic

Definition at line 157 of file G4Colour.hh.

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

References G4Colour().

Referenced by InitialiseColourMap().

◆ Green()

G4Colour G4Colour::Green ( )
inlinestatic

◆ Grey()

G4Colour G4Colour::Grey ( )
inlinestatic

Definition at line 158 of file G4Colour.hh.

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

References G4Colour().

Referenced by InitialiseColourMap().

◆ InitialiseColourMap()

void G4Colour::InitialiseColourMap ( )
static

Definition at line 141 of file G4Colour.cc.

142{
143 if (fInitColourMap) return;
144
145 fInitColourMap = true;
146
147 // Standard colours
148 AddToMap("white", G4Colour::White());
149 AddToMap("grey", G4Colour::Grey());
150 AddToMap("gray", G4Colour::Gray());
151 AddToMap("black", G4Colour::Black());
152 AddToMap("brown", G4Colour::Brown());
153 AddToMap("red", G4Colour::Red());
154 AddToMap("green", G4Colour::Green());
155 AddToMap("blue", G4Colour::Blue());
156 AddToMap("cyan", G4Colour::Cyan());
157 AddToMap("magenta", G4Colour::Magenta());
158 AddToMap("yellow", G4Colour::Yellow());
159}
static G4Colour White()
Definition: G4Colour.hh:156
static G4Colour Yellow()
Definition: G4Colour.hh:166
static G4Colour Green()
Definition: G4Colour.hh:162
static void AddToMap(const G4String &key, const G4Colour &colour)
Definition: G4Colour.cc:110
static G4Colour Red()
Definition: G4Colour.hh:161
static G4Colour Brown()
Definition: G4Colour.hh:160
static G4bool fInitColourMap
Definition: G4Colour.hh:148
static G4Colour Grey()
Definition: G4Colour.hh:158
static G4Colour Black()
Definition: G4Colour.hh:159
static G4Colour Magenta()
Definition: G4Colour.hh:165
static G4Colour Blue()
Definition: G4Colour.hh:163
static G4Colour Gray()
Definition: G4Colour.hh:157
static G4Colour Cyan()
Definition: G4Colour.hh:164

References AddToMap(), Black(), Blue(), Brown(), Cyan(), fInitColourMap, Gray(), Green(), Grey(), Magenta(), Red(), White(), and Yellow().

Referenced by GetColour(), GetMap(), and G4VisManager::InitialiseG4ColourMap().

◆ Magenta()

G4Colour G4Colour::Magenta ( )
inlinestatic

Definition at line 165 of file G4Colour.hh.

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

References G4Colour().

Referenced by InitialiseColourMap().

◆ operator G4ThreeVector()

G4Colour::operator G4ThreeVector ( )

Definition at line 76 of file G4Colour.cc.

76 {
78}
CLHEP::Hep3Vector G4ThreeVector

◆ operator!=()

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

Definition at line 96 of file G4Colour.cc.

96 {
97 if (
98 (red != c.red) ||
99 (green != c.green) ||
100 (blue != c.blue) ||
101 (alpha != c.alpha)
102 )
103 return true;
104 return false;
105}

References alpha, blue, green, and red.

Referenced by operator==().

◆ operator+=()

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

Definition at line 101 of file G4Colour.hh.

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

◆ operator<()

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

Definition at line 186 of file G4Colour.cc.

187{
188 if (red < rhs.red) return true;
189 else if (red == rhs.red) {
190 if (green < rhs.green) return true;
191 else if (green == rhs.green) {
192 if (blue < rhs.blue) return true;
193 else if (blue == rhs.blue) {
194 if (alpha < rhs.alpha) return true;
195 }}}
196 return false;
197}

References alpha, blue, green, and red.

◆ operator==()

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

Definition at line 99 of file G4Colour.hh.

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

References operator!=().

◆ Red()

G4Colour G4Colour::Red ( )
inlinestatic

◆ SetAlpha()

void G4Colour::SetAlpha ( G4double  a)

Definition at line 70 of file G4Colour.cc.

71{
72 alpha = a;
73 if( alpha > 1.0 ){alpha = 1.0;} if( alpha < 0.0 ){alpha = 0.0;}
74}

References alpha.

Referenced by G4VVisCommand::ConvertToColour().

◆ SetBlue()

void G4Colour::SetBlue ( G4double  b)

Definition at line 64 of file G4Colour.cc.

65{
66 blue = b;
67 if( blue > 1.0 ){blue = 1.0;} if( blue < 0.0 ){blue = 0.0;}
68}

References blue.

◆ SetGreen()

void G4Colour::SetGreen ( G4double  gr)

Definition at line 58 of file G4Colour.cc.

59{
60 green = gr;
61 if( green > 1.0 ){green = 1.0;} if( green < 0.0 ){green = 0.0;}
62}

References green.

◆ SetRed()

void G4Colour::SetRed ( G4double  r)

Definition at line 52 of file G4Colour.cc.

53{
54 red = r;
55 if( red > 1.0 ){red = 1.0;} if( red < 0.0 ){red = 0.0;}
56}

References red.

◆ White()

G4Colour G4Colour::White ( )
inlinestatic

Definition at line 156 of file G4Colour.hh.

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

References G4Colour().

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

◆ Yellow()

G4Colour G4Colour::Yellow ( )
inlinestatic

Definition at line 166 of file G4Colour.hh.

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

References G4Colour().

Referenced by InitialiseColourMap().

Friends And Related Function Documentation

◆ operator<<

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

Definition at line 80 of file G4Colour.cc.

80 {
81 os << '(' << c.red << ',' << c.green << ',' << c.blue
82 << ',' << c.alpha << ')';
83 const std::map<G4String, G4Colour>& colourMap = G4Colour::GetMap();
84 // Reverse iterator to pick up English spelling of grey!! :)
85 std::map<G4String, G4Colour>::const_reverse_iterator ri;
86 for (ri = colourMap.rbegin(); ri != colourMap.rend(); ++ri) {
87 if (c == ri->second) {
88 os << " (" << ri->first << ')';
89 break;
90 }
91 }
92
93 return os;
94}
static const std::map< G4String, G4Colour > & GetMap()
Definition: G4Colour.cc:178

Field Documentation

◆ alpha

G4double G4Colour::alpha
private

Definition at line 145 of file G4Colour.hh.

Referenced by G4Colour(), GetAlpha(), operator!=(), operator<(), and SetAlpha().

◆ blue

G4double G4Colour::blue
private

Definition at line 145 of file G4Colour.hh.

Referenced by G4Colour(), GetBlue(), operator!=(), operator<(), and SetBlue().

◆ fColourMap

std::map< G4String, G4Colour > G4Colour::fColourMap
staticprivate

Definition at line 147 of file G4Colour.hh.

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

◆ fInitColourMap

G4bool G4Colour::fInitColourMap = false
staticprivate

Definition at line 148 of file G4Colour.hh.

Referenced by InitialiseColourMap().

◆ green

G4double G4Colour::green
private

Definition at line 145 of file G4Colour.hh.

Referenced by G4Colour(), GetGreen(), operator!=(), operator<(), and SetGreen().

◆ red

G4double G4Colour::red
private

Definition at line 145 of file G4Colour.hh.

Referenced by G4Colour(), GetRed(), operator!=(), operator<(), and SetRed().


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