]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/RGBAPalette.h
989e75357490eb327e91ae4114e4c1dd0d5a95f6
[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 public:
18   enum LimitAction_e { LA_Cut, LA_Mark, LA_Clip, LA_Wrap };
19
20 private:
21   RGBAPalette(const RGBAPalette&);            // Not implemented
22   RGBAPalette& operator=(const RGBAPalette&); // Not implemented
23
24 protected:
25   Int_t     fLowLimit;  // Low  limit for Min/Max values (used by editor)
26   Int_t     fHighLimit; // High limit for Min/Max values (used by editor)
27   Int_t     fMinVal;
28   Int_t     fMaxVal;
29   Int_t     fNBins;
30
31   Bool_t        fInterpolate;
32   Bool_t        fShowDefValue;
33   Int_t fUndershootAction;
34   Int_t fOvershootAction;
35
36   Color_t   fDefaultColor;   // Color for when value is not specified
37   UChar_t   fDefaultRGBA[4];
38   Color_t   fUnderColor;     // Undershoot color
39   UChar_t   fUnderRGBA[4];
40   Color_t   fOverColor;      // Overshoot color
41   UChar_t   fOverRGBA[4];
42
43   mutable UChar_t* fColorArray; //[4*fNBins]
44
45   void SetupColor(Int_t val, UChar_t* pix) const;
46
47   static RGBAPalette* fgDefaultPalette;
48
49 public:
50   RGBAPalette();
51   RGBAPalette(Int_t min, Int_t max);
52   RGBAPalette(Int_t min, Int_t max, Bool_t interp, Bool_t showdef=kTRUE);
53   virtual ~RGBAPalette();
54
55   void SetupColorArray() const;
56   void ClearColorArray();
57
58   Bool_t   WithinVisibleRange(Int_t val) const;
59   const UChar_t* ColorFromValue(Int_t val) const;
60   void     ColorFromValue(Int_t val, UChar_t* pix, Bool_t alpha=kTRUE) const;
61   Bool_t   ColorFromValue(Int_t val, Int_t defVal, UChar_t* pix, Bool_t alpha=kTRUE) const;
62
63   Int_t  GetMinVal() const { return fMinVal; }
64   Int_t  GetMaxVal() const { return fMaxVal; }
65
66   void   SetLimits(Int_t low, Int_t high);
67   void   SetMinMax(Int_t min, Int_t max);
68   void   SetMin(Int_t min);
69   void   SetMax(Int_t max);
70
71   // ================================================================
72
73   Bool_t GetInterpolate() const { return fInterpolate; }
74   void   SetInterpolate(Bool_t b);
75
76   Bool_t GetShowDefValue() const { return fShowDefValue; }
77   void   SetShowDefValue(Bool_t v) { fShowDefValue = v; }
78
79   Int_t GetUndershootAction() const  { return fUndershootAction; }
80   Int_t GetOvershootAction()  const  { return fOvershootAction;  }
81   void  SetUndershootAction(Int_t a) { fUndershootAction = a;    }
82   void  SetOvershootAction(Int_t a)  { fOvershootAction  = a;    }
83
84   // ================================================================
85
86   Color_t  GetDefaultColor() const { return fDefaultColor; }
87   Color_t* PtrDefaultColor() { return &fDefaultColor; }
88   UChar_t* GetDefaultRGBA()  { return fDefaultRGBA;  }
89   const UChar_t* GetDefaultRGBA() const { return fDefaultRGBA;  }
90
91   void   SetDefaultColor(Color_t ci);
92   void   SetDefaultColor(Pixel_t pix);
93   void   SetDefaultColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
94
95   // ----------------------------------------------------------------
96
97   Color_t  GetUnderColor() const { return fUnderColor; }
98   Color_t* PtrUnderColor() { return &fUnderColor; }
99   UChar_t* GetUnderRGBA()  { return fUnderRGBA;  }
100   const UChar_t* GetUnderRGBA() const { return fUnderRGBA;  }
101
102   void   SetUnderColor(Color_t ci);
103   void   SetUnderColor(Pixel_t pix);
104   void   SetUnderColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
105
106   // ----------------------------------------------------------------
107
108   Color_t  GetOverColor() const { return fOverColor; }
109   Color_t* PtrOverColor() { return &fOverColor; }
110   UChar_t* GetOverRGBA()  { return fOverRGBA;  }
111   const UChar_t* GetOverRGBA() const { return fOverRGBA;  }
112
113   void   SetOverColor(Color_t ci);
114   void   SetOverColor(Pixel_t pix);
115   void   SetOverColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
116
117   // ================================================================
118
119   // ?? Should we emit some *SIGNALS* ??
120   // ?? Should we have a RendererTimeStamp ??
121
122   ClassDef(RGBAPalette, 1);
123 }; // endclass RGBAPalette
124
125
126 /**************************************************************************/
127 // Inlines for RGBAPalette
128 /**************************************************************************/
129
130 inline Bool_t RGBAPalette::WithinVisibleRange(Int_t val) const
131 {
132   if ((val < fMinVal && fUndershootAction == LA_Cut) ||
133       (val > fMaxVal && fOvershootAction  == LA_Cut))
134     return kFALSE;
135   else
136     return kTRUE;
137 }
138
139 inline const UChar_t* RGBAPalette::ColorFromValue(Int_t val) const
140 {
141   // Here we expect that LA_Cut has been checked; we further check
142   // for LA_Wrap and LA_Clip otherwise we proceed as for LA_Mark.
143
144   if (!fColorArray)  SetupColorArray();
145   if (val < fMinVal) {
146     if (fUndershootAction == LA_Wrap)
147       val = (val+1-fMinVal)%fNBins + fMaxVal;
148     else if (fUndershootAction == LA_Clip)
149       val = fMinVal;
150     else
151       return fUnderRGBA;
152   }
153   else if(val > fMaxVal) {
154     if (fOvershootAction == LA_Wrap)
155       val = (val-1-fMaxVal)%fNBins + fMinVal;
156     else if (fOvershootAction == LA_Clip)
157       val = fMaxVal;
158     else
159       return fOverRGBA;
160   }
161   return fColorArray + 4 * (val - fMinVal);
162 }
163
164 inline void RGBAPalette::ColorFromValue(Int_t val, UChar_t* pix, Bool_t alpha) const
165 {
166   const UChar_t* c = ColorFromValue(val);
167   pix[0] = c[0]; pix[1] = c[1]; pix[2] = c[2];
168   if (alpha) pix[3] = c[3];
169 }
170
171 inline Bool_t RGBAPalette::ColorFromValue(Int_t val, Int_t defVal, UChar_t* pix, Bool_t alpha) const
172 {
173   if (val == defVal) {
174     if (fShowDefValue) {
175       pix[0] = fDefaultRGBA[0];
176       pix[1] = fDefaultRGBA[1];
177       pix[2] = fDefaultRGBA[2];
178       if (alpha) pix[3] = fDefaultRGBA[3]; 
179       return kTRUE;
180     } else {
181       return kFALSE;
182     }
183   }
184
185   if (WithinVisibleRange(val)) {
186     ColorFromValue(val, pix, alpha);
187     return kTRUE;
188   } else {
189     return kFALSE;
190   }
191 }
192
193 }
194
195 #endif