|
|
|||
Warning, file /include/Geant4/G4Colour.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 // 0002 // ******************************************************************** 0003 // * License and Disclaimer * 0004 // * * 0005 // * The Geant4 software is copyright of the Copyright Holders of * 0006 // * the Geant4 Collaboration. It is provided under the terms and * 0007 // * conditions of the Geant4 Software License, included in the file * 0008 // * LICENSE and available at http://cern.ch/geant4/license . These * 0009 // * include a list of copyright holders. * 0010 // * * 0011 // * Neither the authors of this software system, nor their employing * 0012 // * institutes,nor the agencies providing financial support for this * 0013 // * work make any representation or warranty, express or implied, * 0014 // * regarding this software system or assume any liability for its * 0015 // * use. Please see the license in the file LICENSE and URL above * 0016 // * for the full disclaimer and the limitation of liability. * 0017 // * * 0018 // * This code implementation is the result of the scientific and * 0019 // * technical work of the GEANT4 collaboration. * 0020 // * By using, copying, modifying or distributing the software (or * 0021 // * any work based on the software) you agree to acknowledge its * 0022 // * use in resulting scientific publications, and indicate your * 0023 // * acceptance of all terms of the Geant4 Software license. * 0024 // ******************************************************************** 0025 // 0026 // 0027 // 0028 // 0029 // John Allison 20th October 1996 0030 0031 // Class Description: 0032 // Class G4Colour has 4 fields, which represent the RGBA (red, green, blue, 0033 // and alpha) components of colour. Each component takes a value between 0034 // 0 and 1. If an irrelevant value, i.e., a value less than 0 or greater 0035 // than 1, is given as an argument of the constructor, such a value is 0036 // automatically clipped to 0 or 1. Alpha is opacity (1 = opaque). 0037 // 0038 // A G4Colour object is instantiated by giving red, green, and blue 0039 // components to its constructor, i.e., 0040 // 0041 // G4Colour::G4Colour ( G4double r = 1.0, 0042 // G4double g = 1.0, 0043 // G4double b = 1.0, 0044 // G4double a = 1.0); 0045 // // 0<=red, green, blue <= 1.0 0046 // 0047 // The default value of each component is 1.0. That is to say, the default 0048 // colour is "white". For example, colours which are often used can be 0049 // instantiated as follows: 0050 // 0051 // G4Colour white () ; // white 0052 // G4Colour white (1.0, 1.0, 1.0) ; // white 0053 // G4Colour gray (0.5, 0.5, 0.5) ; // gray 0054 // G4Colour black (0.0, 0.0, 0.0) ; // black 0055 // G4Colour brown (0.45,0.25,0.0) ; // G4 logo brown 0056 // G4Colour red (1.0, 0.0, 0.0) ; // red 0057 // G4Colour green (0.0, 1.0, 0.0) ; // green 0058 // G4Colour blue (0.0, 0.0, 1.0) ; // blue 0059 // G4Colour cyan (0.0, 1.0, 1.0) ; // cyan 0060 // G4Colour magenta (1.0, 0.0, 1.0) ; // magenta 0061 // G4Colour yellow (1.0, 1.0, 0.0) ; // yellow 0062 // 0063 // For convenience, static member functions are also defined for the above colours. 0064 // 0065 // After instantiation of a G4Colour object, you can access to its components 0066 // with the following access functions: 0067 // 0068 // G4double G4Colour::GetRed () const ; // Get the red component. 0069 // G4double G4Colour::GetGreen () const ; // Get the green component. 0070 // G4double G4Colour::GetBlue () const ; // Get the blue component. 0071 // 0072 // You may add colours to a map. They can then be retrieved with a string. 0073 // Standard colours are added to map by default when static functions AddToMap, 0074 // GetMap or GetColour are called. The G4 Vis Manager adds a copious additional 0075 // set of colours on instantiation - see G4VisManager::InitialiseG4ColourMap. 0076 // (Issue "/vis/list" to see available colours.) 0077 // 0078 // Class Description - End: 0079 0080 #ifndef G4COLOUR_HH 0081 #define G4COLOUR_HH 0082 0083 #include "globals.hh" 0084 #include "G4ThreeVector.hh" 0085 #include <iostream> 0086 #include <map> 0087 0088 class G4Colour { 0089 0090 friend std::ostream& operator << (std::ostream&, const G4Colour&); 0091 0092 public: // With description 0093 0094 G4Colour (G4double r_ = 1., G4double g_ = 1., G4double b_ = 1., 0095 G4double a_ = 1.); 0096 0097 G4Colour (G4ThreeVector); 0098 // Converts the components of the 3-vector into red, green, blue. 0099 // The opacity, alpha = 1. 0100 0101 operator G4ThreeVector(); 0102 // Converts red, green, blue into the components of a 3-vector. 0103 0104 G4bool operator != (const G4Colour& c) const; 0105 G4bool operator == (const G4Colour& c) const {return !(operator != (c));} 0106 0107 G4Colour& operator += (const G4Colour& rhs) {*this = rhs; return *this;} 0108 // Note: This is required by RayTracer in its use of G4THitsMap. 0109 // Adding colours, without also taking brightness into account, does not make 0110 // sense, so let us make it synonymous with operator=, which is, I guess, 0111 // equivalent to covering the old colour with the new, like a coat of paint. 0112 0113 G4double GetRed () const; 0114 G4double GetGreen () const; 0115 G4double GetBlue () const; 0116 G4double GetAlpha () const; // alpha = opacity = 1. - transparency. 0117 0118 void SetRed (G4double); 0119 void SetGreen (G4double); 0120 void SetBlue (G4double); 0121 void SetAlpha (G4double); // alpha = opacity = 1. - transparency. 0122 0123 static G4Colour White(); 0124 static G4Colour Gray(); 0125 static G4Colour Grey(); 0126 static G4Colour Black(); 0127 static G4Colour Brown(); // G4 logo brown 0128 static G4Colour Red(); 0129 static G4Colour Green(); 0130 static G4Colour Blue(); 0131 static G4Colour Cyan(); 0132 static G4Colour Magenta(); 0133 static G4Colour Yellow(); 0134 0135 static G4bool GetColour(const G4String& key, G4Colour& result); 0136 static G4bool GetColor(const G4String& key, G4Colour& result); 0137 // Find colour in colour map, placing it in result. 0138 // The key is usually the name of the colour. 0139 // The key is case insensitive. 0140 // Returns false if key doesn't exist, leaving result unchanged. 0141 // Usage: 0142 // G4Colour c; // A successful GetColour will place the colour here 0143 // if (G4Colour::GetColour("pink", c)) { 0144 // logical->SetVisAttributes(c); 0145 // } else { 0146 // logical->SetVisAttributes(G4Colour::Green()); 0147 // } 0148 // or more simply: 0149 // G4Colour c(G4Colour::Green()); // Default if colour not found 0150 // G4Colour::GetColour("pink", c); 0151 // logical->SetVisAttributes(c); 0152 0153 static void AddToMap(const G4String& key, const G4Colour& colour); 0154 // Add user defined colour to colour map with given key. Standard 0155 // colours are added to map by default. The G4 Vis Manager adds more. 0156 0157 static void InitialiseColourMap(); 0158 static const std::map<G4String, G4Colour>& GetMap(); 0159 0160 G4bool operator< (const G4Colour& rhs) const; 0161 0162 private: 0163 G4double red, green, blue, alpha; 0164 0165 static std::map<G4String, G4Colour> fColourMap; 0166 static G4bool fInitColourMap; 0167 0168 }; 0169 0170 inline G4double G4Colour::GetRed () const {return red;} 0171 inline G4double G4Colour::GetGreen () const {return green;} 0172 inline G4double G4Colour::GetBlue () const {return blue;} 0173 inline G4double G4Colour::GetAlpha () const {return alpha;} 0174 inline G4Colour G4Colour::White() {return G4Colour(1.0, 1.0, 1.0);} 0175 inline G4Colour G4Colour::Gray() {return G4Colour(0.5, 0.5, 0.5);} 0176 inline G4Colour G4Colour::Grey() {return G4Colour(0.5, 0.5, 0.5);} 0177 inline G4Colour G4Colour::Black() {return G4Colour(0.0, 0.0, 0.0);} 0178 inline G4Colour G4Colour::Brown() {return G4Colour(0.45,0.25,0.0);} 0179 inline G4Colour G4Colour::Red() {return G4Colour(1.0, 0.0, 0.0);} 0180 inline G4Colour G4Colour::Green() {return G4Colour(0.0, 1.0, 0.0);} 0181 inline G4Colour G4Colour::Blue() {return G4Colour(0.0, 0.0, 1.0);} 0182 inline G4Colour G4Colour::Cyan() {return G4Colour(0.0, 1.0, 1.0);} 0183 inline G4Colour G4Colour::Magenta() {return G4Colour(1.0, 0.0, 1.0);} 0184 inline G4Colour G4Colour::Yellow() {return G4Colour(1.0, 1.0, 0.0);} 0185 0186 inline G4bool G4Colour::GetColor(const G4String& key, G4Colour& result) 0187 {return G4Colour::GetColour(key, result);} 0188 0189 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|