]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/RGBAPalette.h
New files: a generic color palette with value to color mapping; to be used by most...
[u/mrichter/AliRoot.git] / EVE / Reve / RGBAPalette.h
1 // $Header$
2
3 #ifndef REVE_RGBAPalette_H
4 #define REVE_RGBAPalette_H
5
6 #include <Reve/Reve.h>
7
8 #include <TObject.h>
9
10 namespace Reve {
11
12 class RGBAPalette : public TObject, public ReferenceCount
13 {
14   friend class RGBAPaletteEditor;
15   friend class RGBAPaletteSubEditor;
16
17 private:
18   RGBAPalette(const RGBAPalette&);            // Not implemented
19   RGBAPalette& operator=(const RGBAPalette&); // Not implemented
20
21 protected:
22   Int_t     fLowLimit;  // Low  limit for Min/Max values (used by editor)
23   Int_t     fHighLimit; // High limit for Min/Max values (used by editor)
24   Int_t     fMinVal;
25   Int_t     fMaxVal;
26   Int_t     fNBins;
27   Bool_t    fCutLow;    // Instruct renderer not to display quoads below fMinVal
28   Bool_t    fCutHigh;   // Instruct renderer not to display quoads above fMaxVal
29   Bool_t    fInterpolate;
30   Bool_t    fWrap;
31   Color_t   fDefaultColor;
32   UChar_t   fDefaultRGBA[4];
33
34   mutable UChar_t* fColorArray; //[4*fNBins]
35
36   void SetupColor(Int_t val, UChar_t* pix) const;
37
38   static RGBAPalette* fgDefaultPalette;
39
40 public:
41   RGBAPalette();
42   RGBAPalette(Int_t min, Int_t max);
43   RGBAPalette(Int_t min, Int_t max, Bool_t interp, Bool_t wrap);
44   virtual ~RGBAPalette();
45
46   void SetupColorArray() const;
47   void ClearColorArray();
48
49   UChar_t* ColorFromArray(Int_t val) const;
50   void     ColorFromArray(Int_t val, UChar_t* pix, Bool_t alpha=kTRUE) const;
51
52   Bool_t   WithinVisibleRange(Int_t val) const;
53
54   Int_t  GetMinVal() const      { return fMinVal; }
55   Int_t  GetMaxVal() const      { return fMaxVal; }
56   Bool_t GetInterpolate() const { return fInterpolate; }
57   Bool_t GetWrap() const        { return fWrap; }
58
59   void   SetLimits(Int_t low, Int_t high);
60   void   SetMinMax(Int_t min, Int_t max);
61   void   SetMin(Int_t min);
62   void   SetMax(Int_t max);
63   void   SetInterpolate(Bool_t b);
64   void   SetWrap(Bool_t b);
65
66   Color_t  GetDefaultColor() const { return fDefaultColor; }
67   Color_t* PtrDefaultColor() { return &fDefaultColor; }
68   UChar_t* GetDefaultRGBA()  { return fDefaultRGBA;  }
69   const UChar_t* GetDefaultRGBA() const { return fDefaultRGBA;  }
70
71   void   SetDefaultColor(Color_t ci);
72   void   SetDefaultColor(Pixel_t pix);
73   void   SetDefaultColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
74
75   // ?? Should we emit some *SIGNALS* ??
76   // ?? Should we have a RendererTimeStamp ??
77
78   ClassDef(RGBAPalette, 1);
79 }; // endclass RGBAPalette
80
81
82 inline UChar_t* RGBAPalette::ColorFromArray(Int_t val) const
83 {
84   if(!fColorArray)  SetupColorArray();
85   if(val < fMinVal) val = fWrap ? ((val+1-fMinVal)%fNBins + fMaxVal) : fMinVal;
86   if(val > fMaxVal) val = fWrap ? ((val-1-fMaxVal)%fNBins + fMinVal) : fMaxVal;
87   return fColorArray + 4 * (val - fMinVal);
88 }
89
90 inline void RGBAPalette::ColorFromArray(Int_t val, UChar_t* pix, Bool_t alpha) const
91 {
92   UChar_t* c = ColorFromArray(val);
93   pix[0] = c[0]; pix[1] = c[1]; pix[2] = c[2];
94   if (alpha) pix[3] = c[3];
95 }
96
97 inline Bool_t RGBAPalette::WithinVisibleRange(Int_t val) const
98 {
99   if ((val < fMinVal && fCutLow) || (val > fMaxVal && fCutHigh))
100     return kFALSE;
101   else
102     return kTRUE;
103 }
104
105 }
106
107 #endif