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10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /graphics_reps/src/G4Colour.cc (Version 11.3.0) and /graphics_reps/src/G4Colour.cc (Version 8.0)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                    <<   3 // * DISCLAIMER                                                       *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th <<   5 // * The following disclaimer summarizes all the specific disclaimers *
  6 // * the Geant4 Collaboration.  It is provided <<   6 // * of contributors to this software. The specific disclaimers,which *
  7 // * conditions of the Geant4 Software License <<   7 // * govern, are listed with their locations in:                      *
  8 // * LICENSE and available at  http://cern.ch/ <<   8 // *   http://cern.ch/geant4/license                                  *
  9 // * include a list of copyright holders.      << 
 10 // *                                                9 // *                                                                  *
 11 // * Neither the authors of this software syst     10 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     11 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     12 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     13 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  <<  14 // * use.                                                             *
 16 // * for the full disclaimer and the limitatio << 
 17 // *                                               15 // *                                                                  *
 18 // * This  code  implementation is the result  <<  16 // * This  code  implementation is the  intellectual property  of the *
 19 // * technical work of the GEANT4 collaboratio <<  17 // * GEANT4 collaboration.                                            *
 20 // * By using,  copying,  modifying or  distri <<  18 // * By copying,  distributing  or modifying the Program (or any work *
 21 // * any work based  on the software)  you  ag <<  19 // * based  on  the Program)  you indicate  your  acceptance of  this *
 22 // * use  in  resulting  scientific  publicati <<  20 // * statement, and all its terms.                                    *
 23 // * acceptance of all terms of the Geant4 Sof << 
 24 // *******************************************     21 // ********************************************************************
 25 //                                                 22 //
 26 //                                                 23 //
                                                   >>  24 // $Id: G4Colour.cc,v 1.9 2005/11/10 20:34:45 tinslay Exp $
                                                   >>  25 // GEANT4 tag $Name: geant4-08-00 $
 27 //                                                 26 //
 28 //                                                 27 // 
 29 // John Allison 20th October 1996                  28 // John Allison 20th October 1996
 30                                                    29 
 31 #include "G4Colour.hh"                             30 #include "G4Colour.hh"
 32                                                    31 
 33 #include "G4Threading.hh"                      <<  32 #include <sstream>
 34                                                    33 
 35 G4Colour::G4Colour (G4double r, G4double gr, G <<  34 G4Colour::G4Colour (G4double r, G4double g, G4double b, G4double a):
 36 red (r), green (gr), blue (b), alpha (a)       <<  35 red (r), green (g), blue (b), alpha (a)
 37 {                                                  36 {
 38   if( red   > 1.0 ){red   = 1.0;} if( red   <      37   if( red   > 1.0 ){red   = 1.0;} if( red   < 0.0 ){red   = 0.0;}
 39   if( green > 1.0 ){green = 1.0;} if( green <      38   if( green > 1.0 ){green = 1.0;} if( green < 0.0 ){green = 0.0;}
 40   if( blue  > 1.0 ){blue  = 1.0;} if( blue  <      39   if( blue  > 1.0 ){blue  = 1.0;} if( blue  < 0.0 ){blue  = 0.0;}
 41   if( alpha > 1.0 ){alpha = 1.0;} if( alpha <      40   if( alpha > 1.0 ){alpha = 1.0;} if( alpha < 0.0 ){alpha = 0.0;}
 42 }                                                  41 }
 43                                                    42 
 44 G4Colour::G4Colour (G4ThreeVector v):              43 G4Colour::G4Colour (G4ThreeVector v):
 45 red (v.x()), green (v.y()), blue (v.z()), alph     44 red (v.x()), green (v.y()), blue (v.z()), alpha (1.)
 46 {                                                  45 {
 47   if( red   > 1.0 ){red   = 1.0;} if( red   <      46   if( red   > 1.0 ){red   = 1.0;} if( red   < 0.0 ){red   = 0.0;}
 48   if( green > 1.0 ){green = 1.0;} if( green <      47   if( green > 1.0 ){green = 1.0;} if( green < 0.0 ){green = 0.0;}
 49   if( blue  > 1.0 ){blue  = 1.0;} if( blue  <      48   if( blue  > 1.0 ){blue  = 1.0;} if( blue  < 0.0 ){blue  = 0.0;}
 50 }                                                  49 }
 51                                                    50 
 52 void G4Colour::SetRed (G4double r)             << 
 53 {                                              << 
 54   red = r;                                     << 
 55   if( red   > 1.0 ){red   = 1.0;} if( red   <  << 
 56 }                                              << 
 57                                                << 
 58 void G4Colour::SetGreen (G4double gr)          << 
 59 {                                              << 
 60   green = gr;                                  << 
 61   if( green > 1.0 ){green = 1.0;} if( green <  << 
 62 }                                              << 
 63                                                << 
 64 void G4Colour::SetBlue (G4double b)            << 
 65 {                                              << 
 66   blue = b;                                    << 
 67   if( blue  > 1.0 ){blue  = 1.0;} if( blue  <  << 
 68 }                                              << 
 69                                                << 
 70 void G4Colour::SetAlpha (G4double a)           << 
 71 {                                              << 
 72   alpha = a;                                   << 
 73   if( alpha > 1.0 ){alpha = 1.0;} if( alpha <  << 
 74 }                                              << 
 75                                                << 
 76 G4Colour::operator G4ThreeVector() {               51 G4Colour::operator G4ThreeVector() {
 77   return G4ThreeVector(red,green,blue);            52   return G4ThreeVector(red,green,blue);
 78 }                                                  53 }
 79                                                    54 
 80 std::ostream& operator << (std::ostream& os, c     55 std::ostream& operator << (std::ostream& os, const G4Colour& c) {
 81   os << '(' << c.red << ',' << c.green << ','  <<  56   return os << '(' << c.red << ',' << c.green << ',' << c.blue
 82             << ',' << c.alpha << ')';          <<  57       << ',' << c.alpha << ')';
 83   const std::map<G4String, G4Colour>& colourMa << 
 84   // Reverse iterator to pick up English spell << 
 85   std::map<G4String, G4Colour>::const_reverse_ << 
 86   for (ri = colourMap.rbegin(); ri != colourMa << 
 87     if (c == ri->second) {                     << 
 88       os << " (" << ri->first << ')';          << 
 89       break;                                   << 
 90     }                                          << 
 91   }                                            << 
 92                                                << 
 93   return os;                                   << 
 94 }                                                  58 }
 95                                                    59 
 96 G4bool G4Colour::operator != (const G4Colour&      60 G4bool G4Colour::operator != (const G4Colour& c) const {
 97   return (red   != c.red)   ||                 <<  61   if (
                                                   >>  62       (red   != c.red)   ||
 98       (green != c.green) ||                        63       (green != c.green) ||
 99       (blue  != c.blue)  ||                        64       (blue  != c.blue)  ||
100       (alpha != c.alpha);                      <<  65       (alpha != c.alpha)
                                                   >>  66       )
                                                   >>  67     return true;
                                                   >>  68   return false;
101 }                                                  69 }
102                                                    70 
103 std::map<G4String, G4Colour> G4Colour::fColour <<  71 const G4Colour G4Colour::fWhite   = G4Colour(1.0, 1.0, 1.0);   
104 G4bool G4Colour::fInitColourMap = false;       <<  72 const G4Colour G4Colour::fGray    = G4Colour(0.5, 0.5, 0.5);  
                                                   >>  73 const G4Colour G4Colour::fGrey    = G4Colour::fGray;  
                                                   >>  74 const G4Colour G4Colour::fBlack   = G4Colour(0.0, 0.0, 0.0); 
                                                   >>  75 const G4Colour G4Colour::fRed     = G4Colour(1.0, 0.0, 0.0); 
                                                   >>  76 const G4Colour G4Colour::fGreen   = G4Colour(0.0, 1.0, 0.0); 
                                                   >>  77 const G4Colour G4Colour::fBlue    = G4Colour(0.0, 0.0, 1.0); 
                                                   >>  78 const G4Colour G4Colour::fCyan    = G4Colour(0.0, 1.0, 1.0); 
                                                   >>  79 const G4Colour G4Colour::fMagenta = G4Colour(1.0, 0.0, 1.0);  
                                                   >>  80 const G4Colour G4Colour::fYellow  = G4Colour(1.0, 1.0, 0.0);
                                                   >>  81 
                                                   >>  82 map<G4String, G4Colour> G4Colour::fColourMap;
                                                   >>  83 bool G4Colour::fInitColourMap = false;
                                                   >>  84 
                                                   >>  85 const G4Colour& G4Colour::White()   {return fWhite;}
                                                   >>  86 const G4Colour& G4Colour::Gray()    {return fGray;}
                                                   >>  87 const G4Colour& G4Colour::Grey()    {return fGrey;} 
                                                   >>  88 const G4Colour& G4Colour::Black()   {return fBlack;}  
                                                   >>  89 const G4Colour& G4Colour::Red()     {return fRed;}
                                                   >>  90 const G4Colour& G4Colour::Green()   {return fGreen;}  
                                                   >>  91 const G4Colour& G4Colour::Blue()    {return fBlue;}
                                                   >>  92 const G4Colour& G4Colour::Cyan()    {return fCyan;} 
                                                   >>  93 const G4Colour& G4Colour::Magenta() {return fMagenta;}
                                                   >>  94 const G4Colour& G4Colour::Yellow()  {return fYellow;}
105                                                    95 
106 void G4Colour::AddToMap(const G4String& key, c <<  96 void
                                                   >>  97 G4Colour::AddToMap(const G4String& key, const G4Colour& colour) 
107 {                                                  98 {
108   // Allow only master thread to populate the  << 
109   if (!G4Threading::IsMasterThread()) {        << 
110     static G4bool first = true;                << 
111     if (first) {                               << 
112       first = false;                           << 
113       G4Exception                              << 
114       ("G4Colour::AddToMap(const G4String& key << 
115        "greps0002", JustWarning,               << 
116        "Attempt to add to colour map from non- << 
117     }                                          << 
118     return;                                    << 
119   }                                            << 
120                                                << 
121   // Add standard colours to map               << 
122   InitialiseColourMap();  // Initialises if no << 
123                                                << 
124   // Convert to lower case since colour map is     99   // Convert to lower case since colour map is case insensitive
125   G4String myKey = G4StrUtil::to_lower_copy(ke << 100   G4String myKey(key);
                                                   >> 101   myKey.toLower();
                                                   >> 102 
                                                   >> 103   map<G4String, G4Colour>::iterator iter = fColourMap.find(myKey);
126                                                   104   
127   if (fColourMap.find(myKey) == fColourMap.end << 105   if (iter == fColourMap.end()) fColourMap[myKey] = colour;  
128   else {                                          106   else {
129     G4ExceptionDescription ed;                 << 107     std::ostringstream o; 
130     ed << "G4Colour with key " << myKey << " a << 108     o << "G4Colour with key "<<myKey<<" already exists ";
131     G4Exception                                   109     G4Exception
132       ("G4Colour::AddToMap(const G4String& key    110       ("G4Colour::AddToMap(const G4String& key, const G4Colour& colour)",
133        "greps0001", JustWarning, ed,           << 111        "ColourKeyExists", JustWarning, o.str().c_str());
134        "Colour key exists");                   << 
135   }                                               112   }
136 }                                                 113 }
137                                                   114 
138 void G4Colour::InitialiseColourMap()           << 115 void
                                                   >> 116 G4Colour::InitialiseColourMap() 
139 {                                                 117 {
140   if (fInitColourMap) return;                  << 
141                                                << 
142   fInitColourMap = true;                       << 
143                                                << 
144   // Standard colours                             118   // Standard colours
145   AddToMap("white",   G4Colour::White());      << 119   AddToMap("white",   G4Colour::fWhite);
146   AddToMap("grey",    G4Colour::Grey());       << 120   AddToMap("gray",    G4Colour::fGray);
147   AddToMap("gray",    G4Colour::Gray());       << 121   AddToMap("grey",    G4Colour::fGrey);
148   AddToMap("black",   G4Colour::Black());      << 122   AddToMap("black",   G4Colour::fBlack);
149   AddToMap("brown",   G4Colour::Brown());      << 123   AddToMap("red",     G4Colour::fRed);
150   AddToMap("red",     G4Colour::Red());        << 124   AddToMap("green",   G4Colour::fGreen);
151   AddToMap("green",   G4Colour::Green());      << 125   AddToMap("blue",    G4Colour::fBlue);
152   AddToMap("blue",    G4Colour::Blue());       << 126   AddToMap("cyan",    G4Colour::fCyan);
153   AddToMap("cyan",    G4Colour::Cyan());       << 127   AddToMap("magenta", G4Colour::fMagenta);
154   AddToMap("magenta", G4Colour::Magenta());    << 128   AddToMap("yellow",  G4Colour::fYellow);
155   AddToMap("yellow",  G4Colour::Yellow());     << 129 }
156 }                                              << 130 
157                                                << 131 bool
158 G4bool G4Colour::GetColour(const G4String& key << 132 G4Colour::GetColour(const G4String& key, G4Colour& result) 
159 // Get colour for given key, placing it in res << 133 {
160 // The key is usually the name of the colour.  << 134   if (false == fInitColourMap) {
161 // The key is case insensitive.                << 135     fInitColourMap = true;
162 // Returns false if key doesn't exist, leaving << 136     // Add standard colours to map
163 {                                              << 137     InitialiseColourMap();
164   // Add standard colours to map               << 
165   InitialiseColourMap();  // Initialises if no << 
166                                                << 
167   G4String myKey = G4StrUtil::to_lower_copy(ke << 
168                                                << 
169   // NOLINTNEXTLINE(modernize-use-auto): Expli << 
170   std::map<G4String, G4Colour>::const_iterator << 
171                                                << 
172   // Don't modify "result" if colour was not f << 
173   if (iter == fColourMap.cend()) {             << 
174     G4ExceptionDescription ed;                 << 
175     ed << "Colour \"" << key << "\" not found. << 
176     G4Exception("G4Colour::GetColour", "greps0 << 
177     return false;                              << 
178   }                                               138   }
                                                   >> 139  
                                                   >> 140   G4String myKey(key);
                                                   >> 141   myKey.toLower();
                                                   >> 142  
                                                   >> 143   map<G4String, G4Colour>::iterator iter = fColourMap.find(myKey);
179                                                   144 
                                                   >> 145   // Don't modify "result" if colour was not found in map
                                                   >> 146   if (iter == fColourMap.end()) return false;
                                                   >> 147   
180   result = iter->second;                          148   result = iter->second;
181                                                   149 
182   return true;                                    150   return true;
183 }                                              << 
184                                                << 
185 const std::map<G4String, G4Colour>& G4Colour:: << 
186 {                                              << 
187   // Add standard colours to map               << 
188   InitialiseColourMap();  // Initialises if no << 
189                                                << 
190   return fColourMap;                           << 
191 }                                              << 
192                                                << 
193 G4bool G4Colour::operator< (const G4Colour& rh << 
194 {                                              << 
195   if (red < rhs.red) return true;              << 
196   if (red == rhs.red) {                        << 
197     if (green < rhs.green) return true;        << 
198     if (green == rhs.green) {                  << 
199       if (blue < rhs.blue) return true;        << 
200       if (blue == rhs.blue) {                  << 
201         if (alpha < rhs.alpha) return true;    << 
202       }                                        << 
203     }                                          << 
204   }                                            << 
205   return false;                                << 
206 }                                                 151 }
207                                                   152