Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4Colour.cc
이 파일의 문서화 페이지로 가기
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4Colour.cc 106385 2017-10-09 09:36:33Z gcosmo $
28 //
29 //
30 // John Allison 20th October 1996
31 
32 #include "G4Colour.hh"
33 
34 #include "G4Threading.hh"
35 
37 red (r), green (gr), blue (b), alpha (a)
38 {
39  if( red > 1.0 ){red = 1.0;} if( red < 0.0 ){red = 0.0;}
40  if( green > 1.0 ){green = 1.0;} if( green < 0.0 ){green = 0.0;}
41  if( blue > 1.0 ){blue = 1.0;} if( blue < 0.0 ){blue = 0.0;}
42  if( alpha > 1.0 ){alpha = 1.0;} if( alpha < 0.0 ){alpha = 0.0;}
43 }
44 
46 red (v.x()), green (v.y()), blue (v.z()), alpha (1.)
47 {
48  if( red > 1.0 ){red = 1.0;} if( red < 0.0 ){red = 0.0;}
49  if( green > 1.0 ){green = 1.0;} if( green < 0.0 ){green = 0.0;}
50  if( blue > 1.0 ){blue = 1.0;} if( blue < 0.0 ){blue = 0.0;}
51 }
52 
54 {
55  red = r;
56  if( red > 1.0 ){red = 1.0;} if( red < 0.0 ){red = 0.0;}
57 }
58 
60 {
61  green = gr;
62  if( green > 1.0 ){green = 1.0;} if( green < 0.0 ){green = 0.0;}
63 }
64 
66 {
67  blue = b;
68  if( blue > 1.0 ){blue = 1.0;} if( blue < 0.0 ){blue = 0.0;}
69 }
70 
72 {
73  alpha = a;
74  if( alpha > 1.0 ){alpha = 1.0;} if( alpha < 0.0 ){alpha = 0.0;}
75 }
76 
77 G4Colour::operator G4ThreeVector() {
78  return G4ThreeVector(red,green,blue);
79 }
80 
81 std::ostream& operator << (std::ostream& os, const G4Colour& c) {
82  os << '(' << c.red << ',' << c.green << ',' << c.blue
83  << ',' << c.alpha << ')';
84  const std::map<G4String, G4Colour>& colourMap = G4Colour::GetMap();
85  // Reverse iterator to pick up English spelling of grey!! :)
86  std::map<G4String, G4Colour>::const_reverse_iterator ri;
87  for (ri = colourMap.rbegin(); ri != colourMap.rend(); ++ri) {
88  if (c == ri->second) {
89  os << " (" << ri->first << ')';
90  break;
91  }
92  }
93 
94  return os;
95 }
96 
98  if (
99  (red != c.red) ||
100  (green != c.green) ||
101  (blue != c.blue) ||
102  (alpha != c.alpha)
103  )
104  return true;
105  return false;
106 }
107 
108 std::map<G4String, G4Colour> G4Colour::fColourMap;
110 
111 void G4Colour::AddToMap(const G4String& key, const G4Colour& colour)
112 {
113  // Allow only master thread to populate the map
115  static G4bool first = true;
116  if (first) {
117  first = false;
119  ("G4Colour::AddToMap(const G4String& key, const G4Colour& colour)",
120  "greps0002", JustWarning,
121  "Attempt to add to colour map from non-master thread.");
122  }
123  return;
124  }
125 
126  // Convert to lower case since colour map is case insensitive
127  G4String myKey(key);
128  myKey.toLower();
129 
130  std::map<G4String, G4Colour>::iterator iter = fColourMap.find(myKey);
131 
132  if (iter == fColourMap.end()) fColourMap[myKey] = colour;
133  else {
135  ed << "G4Colour with key " << myKey << " already exists." << G4endl;
137  ("G4Colour::AddToMap(const G4String& key, const G4Colour& colour)",
138  "greps0001", JustWarning, ed,
139  "Colour key exists");
140  }
141 }
142 
144 {
145  if (fInitColourMap) return;
146 
147  fInitColourMap = true;
148 
149  // Standard colours
150  AddToMap("white", G4Colour::White());
151  AddToMap("grey", G4Colour::Grey());
152  AddToMap("gray", G4Colour::Gray());
153  AddToMap("black", G4Colour::Black());
154  AddToMap("brown", G4Colour::Brown());
155  AddToMap("red", G4Colour::Red());
156  AddToMap("green", G4Colour::Green());
157  AddToMap("blue", G4Colour::Blue());
158  AddToMap("cyan", G4Colour::Cyan());
159  AddToMap("magenta", G4Colour::Magenta());
160  AddToMap("yellow", G4Colour::Yellow());
161 }
162 
164 {
165  // Add standard colours to map
166  InitialiseColourMap(); // Initialises if not already initialised
167 
168  G4String myKey(key);
169  myKey.toLower();
170 
171  std::map<G4String, G4Colour>::iterator iter = fColourMap.find(myKey);
172 
173  // Don't modify "result" if colour was not found in map
174  if (iter == fColourMap.end()) return false;
175 
176  result = iter->second;
177 
178  return true;
179 }
180 
181 const std::map<G4String, G4Colour>& G4Colour::GetMap()
182 {
183  // Add standard colours to map
184  InitialiseColourMap(); // Initialises if not already initialised
185 
186  return fColourMap;
187 }
Float_t x
Definition: compare.C:6
CLHEP::Hep3Vector G4ThreeVector
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
static std::map< G4String, G4Colour > fColourMap
Definition: G4Colour.hh:146
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
void SetRed(G4double)
Definition: G4Colour.cc:53
void SetGreen(G4double)
Definition: G4Colour.cc:59
G4double green
Definition: G4Colour.hh:144
Definition: test07.cc:36
std::ostream & operator<<(std::ostream &, const BasicVector3D< float > &)
static G4bool fInitColourMap
Definition: G4Colour.hh:147
#define G4endl
Definition: G4ios.hh:61
Float_t y
Definition: compare.C:6
static G4Colour Black()
Definition: G4Colour.hh:158
Double_t z
static G4Colour Gray()
Definition: G4Colour.hh:156
G4bool IsMasterThread()
Definition: G4Threading.cc:130
G4double blue
Definition: G4Colour.hh:144
Definition: test07.cc:36
void SetBlue(G4double)
Definition: G4Colour.cc:65
static void AddToMap(const G4String &key, const G4Colour &colour)
Definition: G4Colour.cc:111
void toLower()
G4Colour(G4double r=1., G4double g=1., G4double b=1., G4double a=1.)
Definition: G4Colour.cc:36
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
static G4Colour Yellow()
Definition: G4Colour.hh:165
static void InitialiseColourMap()
Definition: G4Colour.cc:143
static G4Colour Blue()
Definition: G4Colour.hh:162
static const G4double alpha
static G4Colour Cyan()
Definition: G4Colour.hh:163
G4double G4ParticleHPJENDLHEData::G4double result
static G4Colour Magenta()
Definition: G4Colour.hh:164
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
static G4Colour Brown()
Definition: G4Colour.hh:159
static G4Colour Red()
Definition: G4Colour.hh:160
G4double alpha
Definition: G4Colour.hh:144
static const std::map< G4String, G4Colour > & GetMap()
Definition: G4Colour.cc:181
void SetAlpha(G4double)
Definition: G4Colour.cc:71
static G4Colour Green()
Definition: G4Colour.hh:161
static G4Colour White()
Definition: G4Colour.hh:155
G4bool operator!=(const G4Colour &c) const
Definition: G4Colour.cc:97
G4double red
Definition: G4Colour.hh:144
static G4bool GetColour(const G4String &key, G4Colour &result)
Definition: G4Colour.cc:163
static G4Colour Grey()
Definition: G4Colour.hh:157