Geant4 11.2.2
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 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 &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 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 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}

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

Member Function Documentation

◆ AddToMap()

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

Definition at line 106 of file G4Colour.cc.

107{
108 // Allow only master thread to populate the map
110 static G4bool first = true;
111 if (first) {
112 first = false;
114 ("G4Colour::AddToMap(const G4String& key, const G4Colour& colour)",
115 "greps0002", JustWarning,
116 "Attempt to add to colour map from non-master thread.");
117 }
118 return;
119 }
120
121 // Convert to lower case since colour map is case insensitive
122 G4String myKey = G4StrUtil::to_lower_copy(key);
123
124 if (fColourMap.find(myKey) == fColourMap.end()) fColourMap[myKey] = colour;
125 else {
127 ed << "G4Colour with key " << myKey << " already exists." << G4endl;
129 ("G4Colour::AddToMap(const G4String& key, const G4Colour& colour)",
130 "greps0001", JustWarning, ed,
131 "Colour key exists");
132 }
133}
@ 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
G4bool IsMasterThread()

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

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

◆ 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);}

Referenced by InitialiseColourMap().

◆ Cyan()

G4Colour G4Colour::Cyan ( )
inlinestatic

Definition at line 164 of file G4Colour.hh.

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

Referenced by InitialiseColourMap().

◆ GetAlpha()

◆ GetBlue()

G4double G4Colour::GetBlue ( ) const
inline

Definition at line 154 of file G4Colour.hh.

154{return blue;}

Referenced by G4HepRepFileSceneHandler::AddCompound(), G4GMocrenFileSceneHandler::AddPrimitive(), G4HepRepFileSceneHandler::AddPrimitive(), G4OpenInventorSceneHandler::AddPrimitive(), G4VtkStore::AddPrimitiveSeparate(), G4VtkStore::AddPrimitiveTensorGlyph(), G4VtkStore::AddPrimitiveTransformBake(), G4VtkViewer::AddViewHUD(), G4TheRayTracer::Attenuate(), G4ViewParameters::CameraAndLightingCommands(), G4OpenGLViewer::ClearViewWithoutFlush(), G4Qt3DUtils::ConvertToQColor(), G4TheMTRayTracer::CreateBitMap(), G4TheRayTracer::CreateBitMap(), G4OpenGLXmViewer::CreateMainWindow(), G4OpenGLStoredViewer::DrawDisplayLists(), G4OpenGLQtViewer::DrawText(), G4OpenGLXViewer::DrawText(), G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::Export(), G4VtkPolydataPolygonPipeline::G4VtkPolydataPolygonPipeline(), G4VtkPolydataPolyline2DPipeline::G4VtkPolydataPolyline2DPipeline(), G4VtkPolydataPolylinePipeline::G4VtkPolydataPolylinePipeline(), G4VtkPolydataSpherePipeline::G4VtkPolydataSpherePipeline(), G4VtkText2DPipeline::G4VtkText2DPipeline(), G4VtkTextPipeline::G4VtkTextPipeline(), G4TheRayTracer::GetMixedColour(), G4TheRayTracer::GetSurfaceColour(), G4VtkSceneHandler::MakeDefaultVisContext(), G4VtkPolydataInstanceAppendPipeline::MakeHash(), MakeHash(), std::hash< G4VisAttributes >::operator()(), G4OpenInventorQtViewer::SetView(), G4OpenInventorWinViewer::SetView(), G4OpenInventorXtExtendedViewer::SetView(), G4OpenInventorXtViewer::SetView(), G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::SetView(), G4VtkViewer::SetView(), G4VtkViewer::ShowView(), G4ViewParameters::TouchableCommands(), G4TheMTRayTracer::Trace(), and G4OpenGLQtViewer::updateViewerPropertiesTableWidget().

◆ GetColour()

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

Definition at line 155 of file G4Colour.cc.

156{
157 // Add standard colours to map
158 InitialiseColourMap(); // Initialises if not already initialised
159
160 G4String myKey = G4StrUtil::to_lower_copy(key);
161
162 // NOLINTNEXTLINE(modernize-use-auto): Explicitly want a const_iterator
163 std::map<G4String, G4Colour>::const_iterator iter = fColourMap.find(myKey);
164
165 // Don't modify "result" if colour was not found in map
166 if (iter == fColourMap.cend()) return false;
167
168 result = iter->second;
169
170 return true;
171}
static void InitialiseColourMap()
Definition G4Colour.cc:135

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

◆ GetGreen()

G4double G4Colour::GetGreen ( ) const
inline

Definition at line 153 of file G4Colour.hh.

153{return green;}

Referenced by G4HepRepFileSceneHandler::AddCompound(), G4GMocrenFileSceneHandler::AddPrimitive(), G4HepRepFileSceneHandler::AddPrimitive(), G4OpenInventorSceneHandler::AddPrimitive(), G4VtkStore::AddPrimitiveSeparate(), G4VtkStore::AddPrimitiveTensorGlyph(), G4VtkStore::AddPrimitiveTransformBake(), G4VtkViewer::AddViewHUD(), G4TheRayTracer::Attenuate(), G4ViewParameters::CameraAndLightingCommands(), G4OpenGLViewer::ClearViewWithoutFlush(), G4Qt3DUtils::ConvertToQColor(), G4TheMTRayTracer::CreateBitMap(), G4TheRayTracer::CreateBitMap(), G4OpenGLXmViewer::CreateMainWindow(), G4OpenGLStoredViewer::DrawDisplayLists(), G4OpenGLQtViewer::DrawText(), G4OpenGLXViewer::DrawText(), G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::Export(), G4VtkPolydataPolygonPipeline::G4VtkPolydataPolygonPipeline(), G4VtkPolydataPolyline2DPipeline::G4VtkPolydataPolyline2DPipeline(), G4VtkPolydataPolylinePipeline::G4VtkPolydataPolylinePipeline(), G4VtkPolydataSpherePipeline::G4VtkPolydataSpherePipeline(), G4VtkText2DPipeline::G4VtkText2DPipeline(), G4VtkTextPipeline::G4VtkTextPipeline(), G4TheRayTracer::GetMixedColour(), G4TheRayTracer::GetSurfaceColour(), G4VtkSceneHandler::MakeDefaultVisContext(), G4VtkPolydataInstanceAppendPipeline::MakeHash(), MakeHash(), std::hash< G4VisAttributes >::operator()(), G4OpenInventorQtViewer::SetView(), G4OpenInventorWinViewer::SetView(), G4OpenInventorXtExtendedViewer::SetView(), G4OpenInventorXtViewer::SetView(), G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::SetView(), G4VtkViewer::SetView(), G4VtkViewer::ShowView(), G4ViewParameters::TouchableCommands(), G4TheMTRayTracer::Trace(), and G4OpenGLQtViewer::updateViewerPropertiesTableWidget().

◆ GetMap()

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

Definition at line 173 of file G4Colour.cc.

174{
175 // Add standard colours to map
176 InitialiseColourMap(); // Initialises if not already initialised
177
178 return fColourMap;
179}

◆ GetRed()

G4double G4Colour::GetRed ( ) const
inline

Definition at line 152 of file G4Colour.hh.

152{return red;}

Referenced by G4HepRepFileSceneHandler::AddCompound(), G4GMocrenFileSceneHandler::AddPrimitive(), G4HepRepFileSceneHandler::AddPrimitive(), G4OpenInventorSceneHandler::AddPrimitive(), G4VtkStore::AddPrimitiveSeparate(), G4VtkStore::AddPrimitiveTensorGlyph(), G4VtkStore::AddPrimitiveTransformBake(), G4VtkViewer::AddViewHUD(), G4TheRayTracer::Attenuate(), G4ViewParameters::CameraAndLightingCommands(), G4OpenGLViewer::ClearViewWithoutFlush(), G4Qt3DUtils::ConvertToQColor(), G4TheMTRayTracer::CreateBitMap(), G4TheRayTracer::CreateBitMap(), G4OpenGLXmViewer::CreateMainWindow(), G4OpenGLStoredViewer::DrawDisplayLists(), G4OpenGLQtViewer::DrawText(), G4OpenGLXViewer::DrawText(), G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::Export(), G4VtkPolydataPolygonPipeline::G4VtkPolydataPolygonPipeline(), G4VtkPolydataPolyline2DPipeline::G4VtkPolydataPolyline2DPipeline(), G4VtkPolydataPolylinePipeline::G4VtkPolydataPolylinePipeline(), G4VtkPolydataSpherePipeline::G4VtkPolydataSpherePipeline(), G4VtkText2DPipeline::G4VtkText2DPipeline(), G4VtkTextPipeline::G4VtkTextPipeline(), G4TheRayTracer::GetMixedColour(), G4TheRayTracer::GetSurfaceColour(), G4VtkSceneHandler::MakeDefaultVisContext(), G4VtkPolydataInstanceAppendPipeline::MakeHash(), MakeHash(), std::hash< G4VisAttributes >::operator()(), G4OpenInventorQtViewer::SetView(), G4OpenInventorWinViewer::SetView(), G4OpenInventorXtExtendedViewer::SetView(), G4OpenInventorXtViewer::SetView(), G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::SetView(), G4VtkViewer::SetView(), G4VtkViewer::ShowView(), G4ViewParameters::TouchableCommands(), 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);}

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);}

Referenced by InitialiseColourMap().

◆ InitialiseColourMap()

void G4Colour::InitialiseColourMap ( )
static

Definition at line 135 of file G4Colour.cc.

136{
137 if (fInitColourMap) return;
138
139 fInitColourMap = true;
140
141 // Standard colours
142 AddToMap("white", G4Colour::White());
143 AddToMap("grey", G4Colour::Grey());
144 AddToMap("gray", G4Colour::Gray());
145 AddToMap("black", G4Colour::Black());
146 AddToMap("brown", G4Colour::Brown());
147 AddToMap("red", G4Colour::Red());
148 AddToMap("green", G4Colour::Green());
149 AddToMap("blue", G4Colour::Blue());
150 AddToMap("cyan", G4Colour::Cyan());
151 AddToMap("magenta", G4Colour::Magenta());
152 AddToMap("yellow", G4Colour::Yellow());
153}
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:106
static G4Colour Red()
Definition G4Colour.hh:161
static G4Colour Brown()
Definition G4Colour.hh:160
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

Referenced by GetColour(), and GetMap().

◆ Magenta()

G4Colour G4Colour::Magenta ( )
inlinestatic

Definition at line 165 of file G4Colour.hh.

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

Referenced by InitialiseColourMap().

◆ operator G4ThreeVector()

G4Colour::operator G4ThreeVector ( )

Definition at line 76 of file G4Colour.cc.

76 {
77 return G4ThreeVector(red,green,blue);
78}
CLHEP::Hep3Vector G4ThreeVector

◆ operator!=()

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

Definition at line 96 of file G4Colour.cc.

96 {
97 return (red != c.red) ||
98 (green != c.green) ||
99 (blue != c.blue) ||
100 (alpha != c.alpha);
101}

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 181 of file G4Colour.cc.

182{
183 if (red < rhs.red) return true;
184 if (red == rhs.red) {
185 if (green < rhs.green) return true;
186 if (green == rhs.green) {
187 if (blue < rhs.blue) return true;
188 if (blue == rhs.blue) {
189 if (alpha < rhs.alpha) return true;
190 }
191 }
192 }
193 return false;
194}

◆ 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

◆ Red()

◆ 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}

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}

◆ 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}

◆ 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}

◆ White()

G4Colour G4Colour::White ( )
inlinestatic

Definition at line 156 of file G4Colour.hh.

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

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

◆ Yellow()

G4Colour G4Colour::Yellow ( )
inlinestatic

Definition at line 166 of file G4Colour.hh.

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

Referenced by InitialiseColourMap().

Friends And Related Symbol 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:173

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