G4Colour.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // 
00030 // John Allison 20th October 1996
00031 
00032 // Class Description:
00033 // Class G4Colour has 4 fields, which represent the RGBA (red, green, blue, 
00034 // and alpha) components of colour. Each component takes a value between 
00035 // 0 and 1. If an irrelevant value, i.e., a value less than 0 or greater 
00036 // than 1, is given as an argument of the constructor, such a value is 
00037 // automatically clipped to 0 or 1. Alpha is opacity (1 = opaque).
00038 // 
00039 // A G4Colour object is instantiated by giving red, green, and blue 
00040 // components to its constructor, i.e., 
00041 // 
00042 //      G4Colour::G4Colour ( G4double r = 1.0, 
00043 //                           G4double g = 1.0, 
00044 //                           G4double b = 1.0, 
00045 //                           G4double a = 1.0);
00046 //                                   // 0<=red, green, blue <= 1.0 
00047 // 
00048 // The default value of each component is 1.0. That is to say, the default 
00049 // colour is "white".  For example, colours which are often used can be 
00050 // instantiated as follows: 
00051 // 
00052 //      G4Colour  white   ()              ;  // white
00053 //      G4Colour  white   (1.0, 1.0, 1.0) ;  // white
00054 //      G4Colour  gray    (0.5, 0.5, 0.5) ;  // gray
00055 //      G4Colour  black   (0.0, 0.0, 0.0) ;  // black
00056 //      G4Colour  brown   (0.45,0.25,0.0) ;  // G4 logo brown
00057 //      G4Colour  red     (1.0, 0.0, 0.0) ;  // red
00058 //      G4Colour  green   (0.0, 1.0, 0.0) ;  // green
00059 //      G4Colour  blue    (0.0, 0.0, 1.0) ;  // blue
00060 //      G4Colour  cyan    (0.0, 1.0, 1.0) ;  // cyan
00061 //      G4Colour  magenta (1.0, 0.0, 1.0) ;  // magenta 
00062 //      G4Colour  yellow  (1.0, 1.0, 0.0) ;  // yellow
00063 // 
00064 // For convenience, static member functions are also defined for the above colours. 
00065 //
00066 // After instantiation of a G4Colour object, you can access to its components 
00067 // with the following access functions: 
00068 // 
00069 //      G4double G4Colour::GetRed   () const ; // Get the red   component. 
00070 //      G4double G4Colour::GetGreen () const ; // Get the green component.
00071 //      G4double G4Colour::GetBlue  () const ; // Get the blue  component.
00072 //
00073 // Class Description - End:
00074 
00075 #ifndef G4COLOUR_HH
00076 #define G4COLOUR_HH
00077 
00078 #include "globals.hh"
00079 #include "G4ThreeVector.hh"
00080 #include <iostream>
00081 #include <map>
00082 
00083 class G4Colour {
00084 
00085   friend std::ostream& operator << (std::ostream&, const G4Colour&);
00086 
00087 public: // With description
00088 
00089   G4Colour (G4double r = 1., G4double g = 1., G4double b = 1.,
00090             G4double a = 1.);
00091 
00092   G4Colour (G4ThreeVector);
00093   // Converts the components of the 3-vector into red, green, blue.
00094   // The opacity, alpha = 1.
00095 
00096   operator G4ThreeVector();
00097   // Converts red, green, blue into the components of a 3-vector.
00098 
00099   G4bool operator != (const G4Colour& c) const;
00100   G4bool operator == (const G4Colour& c) const {return !(operator != (c));}
00101   G4double GetRed   () const;
00102   G4double GetGreen () const;
00103   G4double GetBlue  () const;
00104   G4double GetAlpha () const;  // alpha = opacity = 1. - transparency.
00105 
00106   static G4Colour White();
00107   static G4Colour Gray();
00108   static G4Colour Grey();
00109   static G4Colour Black();
00110   static G4Colour Brown();  // G4 logo brown
00111   static G4Colour Red();
00112   static G4Colour Green();
00113   static G4Colour Blue(); 
00114   static G4Colour Cyan();
00115   static G4Colour Magenta();
00116   static G4Colour Yellow();
00117 
00118   static void AddToMap(const G4String& key, const G4Colour& colour);
00119   // Add user defined colour to colour map with given key. Standard
00120   // colours are added to map by default.
00121 
00122   static G4bool GetColour(const G4String& key, G4Colour& result);
00123   // Get colour for given key. Returns false if key doesn't exist 
00124   // in colour map, leaving result unchanged. Colour map
00125   // is not sensitive to key case.
00126 
00127   static const std::map<G4String, G4Colour>& GetMap();
00128   
00129 private:
00130   G4double red, green, blue, alpha;
00131 
00132   static std::map<G4String, G4Colour> fColourMap;
00133   static G4bool fInitColourMap;
00134   static void InitialiseColourMap();
00135     
00136 };
00137 
00138 inline G4double G4Colour::GetRed   () const {return red;}
00139 inline G4double G4Colour::GetGreen () const {return green;}
00140 inline G4double G4Colour::GetBlue  () const {return blue;}
00141 inline G4double G4Colour::GetAlpha () const {return alpha;}
00142 inline G4Colour G4Colour::White()   {return G4Colour(1.0, 1.0, 1.0);}
00143 inline G4Colour G4Colour::Gray()    {return G4Colour(0.5, 0.5, 0.5);}
00144 inline G4Colour G4Colour::Grey()    {return G4Colour(0.5, 0.5, 0.5);}
00145 inline G4Colour G4Colour::Black()   {return G4Colour(0.0, 0.0, 0.0);}
00146 inline G4Colour G4Colour::Brown()   {return G4Colour(0.45,0.25,0.0);}
00147 inline G4Colour G4Colour::Red()     {return G4Colour(1.0, 0.0, 0.0);}
00148 inline G4Colour G4Colour::Green()   {return G4Colour(0.0, 1.0, 0.0);}
00149 inline G4Colour G4Colour::Blue()    {return G4Colour(0.0, 0.0, 1.0);} 
00150 inline G4Colour G4Colour::Cyan()    {return G4Colour(0.0, 1.0, 1.0);}
00151 inline G4Colour G4Colour::Magenta() {return G4Colour(1.0, 0.0, 1.0);}
00152 inline G4Colour G4Colour::Yellow()  {return G4Colour(1.0, 1.0, 0.0);}
00153 
00154 #endif

Generated on Mon May 27 17:47:56 2013 for Geant4 by  doxygen 1.4.7