RootPalette.h
Go to the documentation of this file.
1 // RootPalette.h
2 //
3 // Class to define color palettes for Root.
4 //
5 // Example of use:
6 // RootPalette oldPalette; // Save the old palette
7 // RootPalette::set(1026);
8 // TCanvas* pcan = new TCanvas;
9 // ph2->Draw("colz");
10 // pcan->Print();
11 // oldPalette.setRootPalette(); // Restore the old palette
12 //
13 // Palette indices:
14 // < 1000 uses the Root definitions (e.g. kRainBow or kBird).
15 // See the Root doc page for TColor for some of the permitted values.
16 // K+10 - yellow to red to black. For zmin = 0.
17 // K+11 - Same as 1010 with first 0.5% of colors set white
18 // K+12 - Same as 1010 with first 1% of colors set white
19 // K+13 - Same as 1010 with first 2% of colors set white
20 // K+14 - Same as 1010 with first 3% of colors set white
21 // K+15 - Same as 1010 with first 4% of colors set white
22 // K+16 - Same as 1010 with first 5% of colors set white
23 // K+17 - Same as 1010 with first 10% of colors set white
24 // K+18 - Same as 1010 with first 15% of colors set white
25 // K+19 - Same as 1010 with first 20% of colors set white
26 // K+20 - dark to light blue, yellow to red to black. For zmin = -zmax.
27 // K+21 - Same as 1020 with central 0.5% of colors set white
28 // K+22 - Same as 1020 with central 1% of colors set white
29 // K+23 - Same as 1020 with central 2% of colors set white
30 // K+24 - Same as 1020 with central 3% of colors set white
31 // K+25 - Same as 1020 with central 4% of colors set white
32 // K+26 - Same as 1020 with central 5% of colors set white
33 // K+27 - Same as 1020 with central 10% of colors set white
34 // K+28 - Same as 1020 with central 15% of colors set white
35 // K+29 - Same as 1020 with central 20% of colors set white
36 // K = 1000 - Original palette
37 // 2000 - Palette added Dec 2019
38 
39 #ifndef RootPalette_H
40 #define RootPalette_H
41 
42 #include <vector>
43 
44 class TStyle;
45 
46 class RootPalette {
47 
48 public:
49 
50  // Default Root palette.
51  // This is created when the first object of this type is created.
52  static const RootPalette* defaultPalette();
53 
54  // Return a palette by index.
55  // 0 - default Root palette.
56  // 1-999 - Root definitions
57  // 1001 - ADC blue-red-black
58  static const RootPalette* find(unsigned int ipal);
59 
60  // Set palette index to |ipal| (see above).
61  // If ipal < 0, the color map is inverted.
62  // Returns true if the palette was set successfully.
63  static bool set(int ipal);
64 
65  // Ctor from the current style.
66  // Copies the current color map.
67  RootPalette();
68 
69  // Ctor from a given style.
70  RootPalette(TStyle* pstyle);
71 
72  // Ctor from a Root palette index.
73  RootPalette(int ipal);
74 
75  // Getters.
76  int rootPaletteIndex() const { return m_rootPalette; }
77  unsigned int ncol() const { return m_cols.size(); }
78  const int* colorArray() const { return ncol() ? &m_cols[0] : nullptr; }
79  const std::vector<int>& colorVector() const { return m_cols; }
80 
81  // Fetch the Root palette from the current or specified style.
82  int getRootPalette();
83  int getRootPalette(TStyle* pstyle);
84 
85  // Set the Root palette for the current or specified style.
86  // Returns 0 for success.
87  int setRootPalette() const;
88  int setRootPalette(TStyle* pstyle) const;
89 
90  // Return the color map mutable.
91  // With this, user may change any of the colors.
92  std::vector<int>& mutableColorVector() { return m_cols; }
93 
94  // Set the first ncol entries in the color map to color icol.
95  void setFirstColors(unsigned int ncol, unsigned int icol =0);
96 
97  // Set the ncol entries above and below the center of the color map to color icol.
98  void setCentralColors(unsigned int ncol, unsigned int icol =0);
99 
100 private:
101 
102  // If this is nonzero, the palette is one of the Root defaults.
104 
105  // Otherwise, the palette is this color map.
106  std::vector<int> m_cols;
107 
108 };
109 
110 #endif
std::vector< int > & mutableColorVector()
Definition: RootPalette.h:92
static const RootPalette * defaultPalette()
Definition: RootPalette.cxx:23
unsigned int ncol() const
Definition: RootPalette.h:77
int m_rootPalette
Definition: RootPalette.h:103
int getRootPalette()
void setCentralColors(unsigned int ncol, unsigned int icol=0)
std::vector< int > m_cols
Definition: RootPalette.h:106
int setRootPalette() const
const std::vector< int > & colorVector() const
Definition: RootPalette.h:79
void setFirstColors(unsigned int ncol, unsigned int icol=0)
const int * colorArray() const
Definition: RootPalette.h:78
static const RootPalette * find(unsigned int ipal)
Definition: RootPalette.cxx:34
int rootPaletteIndex() const
Definition: RootPalette.h:76