]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/RGBAPalette.h
Dummy methods DefineParticle required by the interface added.
[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     fUnderflowAction;
34   Int_t     fOverflowAction;
35
36   Color_t   fDefaultColor;   // Color for when value is not specified
37   UChar_t   fDefaultRGBA[4];
38   Color_t   fUnderColor;     // Underflow color
39   UChar_t   fUnderRGBA[4];
40   Color_t   fOverColor;      // Overflow 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, Bool_t interp=kFALSE, Bool_t showdef=kTRUE);
52   virtual ~RGBAPalette();
53
54   void SetupColorArray() const;
55   void ClearColorArray();
56
57   Bool_t   WithinVisibleRange(Int_t val) const;
58   const UChar_t* ColorFromValue(Int_t val) const;
59   void     ColorFromValue(Int_t val, UChar_t* pix, Bool_t alpha=kTRUE) const;
60   Bool_t   ColorFromValue(Int_t val, Int_t defVal, UChar_t* pix, Bool_t alpha=kTRUE) const;
61
62   Int_t  GetMinVal() const { return fMinVal; }
63   Int_t  GetMaxVal() const { return fMaxVal; }
64
65   void   SetLimits(Int_t low, Int_t high);
66   void   SetLimitsScaleMinMax(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   Int_t  GetLowLimit()  const { return fLowLimit;  }
72   Int_t  GetHighLimit() const { return fHighLimit; }
73
74   // ================================================================
75
76   Bool_t GetInterpolate() const { return fInterpolate; }
77   void   SetInterpolate(Bool_t b);
78
79   Bool_t GetShowDefValue() const { return fShowDefValue; }
80   void   SetShowDefValue(Bool_t v) { fShowDefValue = v; }
81
82   Int_t GetUnderflowAction() const  { return fUnderflowAction; }
83   Int_t GetOverflowAction()  const  { return fOverflowAction;  }
84   void  SetUnderflowAction(Int_t a) { fUnderflowAction = a;    }
85   void  SetOverflowAction(Int_t a)  { fOverflowAction  = a;    }
86
87   // ================================================================
88
89   Color_t  GetDefaultColor() const { return fDefaultColor; }
90   Color_t* PtrDefaultColor() { return &fDefaultColor; }
91   UChar_t* GetDefaultRGBA()  { return fDefaultRGBA;  }
92   const UChar_t* GetDefaultRGBA() const { return fDefaultRGBA;  }
93
94   void   SetDefaultColor(Color_t ci);
95   void   SetDefaultColor(Pixel_t pix);
96   void   SetDefaultColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
97
98   // ----------------------------------------------------------------
99
100   Color_t  GetUnderColor() const { return fUnderColor; }
101   Color_t* PtrUnderColor() { return &fUnderColor; }
102   UChar_t* GetUnderRGBA()  { return fUnderRGBA;  }
103   const UChar_t* GetUnderRGBA() const { return fUnderRGBA;  }
104
105   void   SetUnderColor(Color_t ci);
106   void   SetUnderColor(Pixel_t pix);
107   void   SetUnderColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
108
109   // ----------------------------------------------------------------
110
111   Color_t  GetOverColor() const { return fOverColor; }
112   Color_t* PtrOverColor() { return &fOverColor; }
113   UChar_t* GetOverRGBA()  { return fOverRGBA;  }
114   const UChar_t* GetOverRGBA() const { return fOverRGBA;  }
115
116   void   SetOverColor(Color_t ci);
117   void   SetOverColor(Pixel_t pix);
118   void   SetOverColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
119
120   // ================================================================
121
122   // ?? Should we emit some *SIGNALS* ??
123   // ?? Should we have a RendererTimeStamp ??
124
125   ClassDef(RGBAPalette, 1); // A generic mapping from value to RGBA color.
126 }; // endclass RGBAPalette
127
128
129 /**************************************************************************/
130 // Inlines for RGBAPalette
131 /**************************************************************************/
132
133 inline Bool_t RGBAPalette::WithinVisibleRange(Int_t val) const
134 {
135   if ((val < fMinVal && fUnderflowAction == LA_Cut) ||
136       (val > fMaxVal && fOverflowAction  == LA_Cut))
137     return kFALSE;
138   else
139     return kTRUE;
140 }
141
142 inline const UChar_t* RGBAPalette::ColorFromValue(Int_t val) const
143 {
144   // Here we expect that LA_Cut has been checked; we further check
145   // for LA_Wrap and LA_Clip otherwise we proceed as for LA_Mark.
146
147   if (!fColorArray)  SetupColorArray();
148   if (val < fMinVal) {
149     if (fUnderflowAction == LA_Wrap)
150       val = (val+1-fMinVal)%fNBins + fMaxVal;
151     else if (fUnderflowAction == LA_Clip)
152       val = fMinVal;
153     else
154       return fUnderRGBA;
155   }
156   else if(val > fMaxVal) {
157     if (fOverflowAction == LA_Wrap)
158       val = (val-1-fMaxVal)%fNBins + fMinVal;
159     else if (fOverflowAction == LA_Clip)
160       val = fMaxVal;
161     else
162       return fOverRGBA;
163   }
164   return fColorArray + 4 * (val - fMinVal);
165 }
166
167 inline void RGBAPalette::ColorFromValue(Int_t val, UChar_t* pix, Bool_t alpha) const
168 {
169   const UChar_t* c = ColorFromValue(val);
170   pix[0] = c[0]; pix[1] = c[1]; pix[2] = c[2];
171   if (alpha) pix[3] = c[3];
172 }
173
174 inline Bool_t RGBAPalette::ColorFromValue(Int_t val, Int_t defVal, UChar_t* pix, Bool_t alpha) const
175 {
176   if (val == defVal) {
177     if (fShowDefValue) {
178       pix[0] = fDefaultRGBA[0];
179       pix[1] = fDefaultRGBA[1];
180       pix[2] = fDefaultRGBA[2];
181       if (alpha) pix[3] = fDefaultRGBA[3]; 
182       return kTRUE;
183     } else {
184       return kFALSE;
185     }
186   }
187
188   if (WithinVisibleRange(val)) {
189     ColorFromValue(val, pix, alpha);
190     return kTRUE;
191   } else {
192     return kFALSE;
193   }
194 }
195
196 }
197
198 #endif