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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 ]

  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 //
 28 // 
 29 // John Allison 20th October 1996
 30 
 31 // Class Description:
 32 // Class G4Colour has 4 fields, which represent the RGBA (red, green, blue, 
 33 // and alpha) components of colour. Each component takes a value between 
 34 // 0 and 1. If an irrelevant value, i.e., a value less than 0 or greater 
 35 // than 1, is given as an argument of the constructor, such a value is 
 36 // automatically clipped to 0 or 1. Alpha is opacity (1 = opaque).
 37 // 
 38 // A G4Colour object is instantiated by giving red, green, and blue 
 39 // components to its constructor, i.e., 
 40 // 
 41 //      G4Colour::G4Colour ( G4double r = 1.0, 
 42 //                           G4double g = 1.0, 
 43 //                           G4double b = 1.0, 
 44 //                           G4double a = 1.0);
 45 //                                   // 0<=red, green, blue <= 1.0 
 46 // 
 47 // The default value of each component is 1.0. That is to say, the default 
 48 // colour is "white".  For example, colours which are often used can be 
 49 // instantiated as follows: 
 50 // 
 51 //      G4Colour  white   ()              ;  // white
 52 //      G4Colour  white   (1.0, 1.0, 1.0) ;  // white
 53 //      G4Colour  gray    (0.5, 0.5, 0.5) ;  // gray
 54 //      G4Colour  black   (0.0, 0.0, 0.0) ;  // black
 55 //      G4Colour  brown   (0.45,0.25,0.0) ;  // G4 logo brown
 56 //      G4Colour  red     (1.0, 0.0, 0.0) ;  // red
 57 //      G4Colour  green   (0.0, 1.0, 0.0) ;  // green
 58 //      G4Colour  blue    (0.0, 0.0, 1.0) ;  // blue
 59 //      G4Colour  cyan    (0.0, 1.0, 1.0) ;  // cyan
 60 //      G4Colour  magenta (1.0, 0.0, 1.0) ;  // magenta 
 61 //      G4Colour  yellow  (1.0, 1.0, 0.0) ;  // yellow
 62 // 
 63 // For convenience, static member functions are also defined for the above colours. 
 64 //
 65 // After instantiation of a G4Colour object, you can access to its components 
 66 // with the following access functions: 
 67 // 
 68 //      G4double G4Colour::GetRed   () const ; // Get the red   component. 
 69 //      G4double G4Colour::GetGreen () const ; // Get the green component.
 70 //      G4double G4Colour::GetBlue  () const ; // Get the blue  component.
 71 //
 72 // You may add colours to a map. They can then be retrieved with a string.
 73 // Standard colours are added to map by default when static functions AddToMap,
 74 // GetMap or GetColour are called. The G4 Vis Manager adds a copious additional
 75 // set of colours on instantiation - see G4VisManager::InitialiseG4ColourMap.
 76 // (Issue "/vis/list" to see available colours.)
 77 //
 78 // Class Description - End:
 79 
 80 #ifndef G4COLOUR_HH
 81 #define G4COLOUR_HH
 82 
 83 #include "globals.hh"
 84 #include "G4ThreeVector.hh"
 85 #include <iostream>
 86 #include <map>
 87 
 88 class G4Colour {
 89 
 90   friend std::ostream& operator << (std::ostream&, const G4Colour&);
 91 
 92 public: // With description
 93 
 94   G4Colour (G4double r_ = 1., G4double g_ = 1., G4double b_ = 1.,
 95             G4double a_ = 1.);
 96 
 97   G4Colour (G4ThreeVector);
 98   // Converts the components of the 3-vector into red, green, blue.
 99   // The opacity, alpha = 1.
100 
101   operator G4ThreeVector();
102   // Converts red, green, blue into the components of a 3-vector.
103 
104   G4bool operator != (const G4Colour& c) const;
105   G4bool operator == (const G4Colour& c) const {return !(operator != (c));}
106 
107   G4Colour& operator += (const G4Colour& rhs) {*this = rhs; return *this;}
108   // Note: This is required by RayTracer in its use of G4THitsMap.
109   // Adding colours, without also taking brightness into account, does not make
110   // sense, so let us make it synonymous with operator=, which is, I guess,
111   // equivalent to covering the old colour with the new, like a coat of paint.
112 
113   G4double GetRed   () const;
114   G4double GetGreen () const;
115   G4double GetBlue  () const;
116   G4double GetAlpha () const;  // alpha = opacity = 1. - transparency.
117 
118   void SetRed   (G4double);
119   void SetGreen (G4double);
120   void SetBlue  (G4double);
121   void SetAlpha (G4double);  // alpha = opacity = 1. - transparency.
122 
123   static G4Colour White();
124   static G4Colour Gray();
125   static G4Colour Grey();
126   static G4Colour Black();
127   static G4Colour Brown();  // G4 logo brown
128   static G4Colour Red();
129   static G4Colour Green();
130   static G4Colour Blue(); 
131   static G4Colour Cyan();
132   static G4Colour Magenta();
133   static G4Colour Yellow();
134 
135   static G4bool GetColour(const G4String& key, G4Colour& result);
136   static G4bool GetColor(const G4String& key, G4Colour& result);
137   // Find colour in colour map, placing it in result.
138   // The key is usually the name of the colour.
139   // The key is case insensitive.
140   // Returns false if key doesn't exist, leaving result unchanged.
141   // Usage:
142   //   G4Colour c;  // A successful GetColour will place the colour here
143   //   if (G4Colour::GetColour("pink", c)) {
144   //     logical->SetVisAttributes(c);
145   //   } else {
146   //     logical->SetVisAttributes(G4Colour::Green());
147   //   }
148   // or more simply:
149   //   G4Colour c(G4Colour::Green());  // Default if colour not found
150   //   G4Colour::GetColour("pink", c);
151   //   logical->SetVisAttributes(c);
152 
153   static void AddToMap(const G4String& key, const G4Colour& colour);
154   // Add user defined colour to colour map with given key. Standard
155   // colours are added to map by default. The G4 Vis Manager adds more.
156 
157   static void InitialiseColourMap();
158   static const std::map<G4String, G4Colour>& GetMap();
159 
160   G4bool operator< (const G4Colour& rhs) const;
161 
162 private:
163   G4double red, green, blue, alpha;
164 
165   static std::map<G4String, G4Colour> fColourMap;
166   static G4bool fInitColourMap;
167 
168 };
169 
170 inline G4double G4Colour::GetRed   () const {return red;}
171 inline G4double G4Colour::GetGreen () const {return green;}
172 inline G4double G4Colour::GetBlue  () const {return blue;}
173 inline G4double G4Colour::GetAlpha () const {return alpha;}
174 inline G4Colour G4Colour::White()   {return G4Colour(1.0, 1.0, 1.0);}
175 inline G4Colour G4Colour::Gray()    {return G4Colour(0.5, 0.5, 0.5);}
176 inline G4Colour G4Colour::Grey()    {return G4Colour(0.5, 0.5, 0.5);}
177 inline G4Colour G4Colour::Black()   {return G4Colour(0.0, 0.0, 0.0);}
178 inline G4Colour G4Colour::Brown()   {return G4Colour(0.45,0.25,0.0);}
179 inline G4Colour G4Colour::Red()     {return G4Colour(1.0, 0.0, 0.0);}
180 inline G4Colour G4Colour::Green()   {return G4Colour(0.0, 1.0, 0.0);}
181 inline G4Colour G4Colour::Blue()    {return G4Colour(0.0, 0.0, 1.0);} 
182 inline G4Colour G4Colour::Cyan()    {return G4Colour(0.0, 1.0, 1.0);}
183 inline G4Colour G4Colour::Magenta() {return G4Colour(1.0, 0.0, 1.0);}
184 inline G4Colour G4Colour::Yellow()  {return G4Colour(1.0, 1.0, 0.0);}
185 
186 inline G4bool G4Colour::GetColor(const G4String& key, G4Colour& result)
187 {return G4Colour::GetColour(key, result);}
188 
189 #endif
190