]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/RGBAPalette.cxx
Adding includes now needed by ROOT
[u/mrichter/AliRoot.git] / EVE / Reve / RGBAPalette.cxx
1 // $Header$
2
3 #include "RGBAPalette.h"
4
5 #include <TColor.h>
6 #include <TStyle.h>
7 #include <TMath.h>
8
9 using namespace Reve;
10
11 //______________________________________________________________________
12 // RGBAPalette
13 //
14
15 ClassImp(RGBAPalette)
16
17 RGBAPalette::RGBAPalette() :
18   TObject(),
19   Reve::ReferenceCount(),
20
21   fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0), fNBins(0),
22
23   fInterpolate     (kFALSE),
24   fShowDefValue    (kTRUE),
25   fUnderflowAction (LA_Cut),
26   fOverflowAction  (LA_Clip),
27
28   fDefaultColor(0),
29   fUnderColor  (1),
30   fOverColor   (2),
31   fColorArray  (0)
32 {
33   SetLimits(0, 1024);
34   SetMinMax(0, 100);
35 }
36
37 RGBAPalette::RGBAPalette(Int_t min, Int_t max, Bool_t interp, Bool_t showdef) :
38   TObject(),
39   Reve::ReferenceCount(),
40
41   fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0), fNBins(0),
42
43   fInterpolate     (interp),
44   fShowDefValue    (showdef),
45   fUnderflowAction (LA_Cut),
46   fOverflowAction  (LA_Clip),
47
48   fDefaultColor(0),
49   fUnderColor  (1),
50   fOverColor   (2),
51   fColorArray  (0)
52 {
53   SetLimits(0, 1024);
54   SetMinMax(min, max);
55 }
56
57 RGBAPalette::~RGBAPalette()
58 {
59   delete [] fColorArray;
60 }
61
62 /**************************************************************************/
63
64 void RGBAPalette::SetupColor(Int_t val, UChar_t* pixel) const
65 {
66   using namespace TMath;
67   Float_t div  = Max(1, fMaxVal - fMinVal);
68   Int_t   nCol = gStyle->GetNumberOfColors();
69
70   Float_t f;
71   if      (val >= fMaxVal) f = nCol - 1;
72   else if (val <= fMinVal) f = 0;
73   else                     f = (val - fMinVal)/div*(nCol - 1);
74
75   if (fInterpolate) {
76     Int_t  bin = (Int_t) f;
77     Float_t f1 = f - bin, f2 = 1.0f - f1;
78     ColorFromIdx(f1, gStyle->GetColorPalette(bin),
79                  f2, gStyle->GetColorPalette(Min(bin + 1, nCol - 1)),
80                  pixel);
81   } else {
82     ColorFromIdx(gStyle->GetColorPalette((Int_t) Nint(f)), pixel);    
83   }
84 }
85
86 void RGBAPalette::SetupColorArray() const
87 {
88   if(fColorArray) // !!!! should reinit anyway, maybe palette in gstyle changed
89     return;
90
91   // !!!! probably should store original palette for editing ...
92
93   fColorArray = new UChar_t [4 * fNBins];
94   UChar_t* p = fColorArray;
95   for(Int_t v=fMinVal; v<=fMaxVal; ++v, p+=4)
96     SetupColor(v, p);
97 }
98
99 void RGBAPalette::ClearColorArray()
100 {
101   if(fColorArray) {
102     delete [] fColorArray;
103     fColorArray = 0;
104   }
105 }
106
107 /**************************************************************************/
108
109 void RGBAPalette::SetLimits(Int_t low, Int_t high)
110 {
111   fLowLimit  = low;
112   fHighLimit = high;
113   Bool_t changed = kFALSE;
114   if (fMaxVal < fLowLimit)  { SetMax(fLowLimit);  changed = kTRUE; }
115   if (fMinVal < fLowLimit)  { SetMin(fLowLimit);  changed = kTRUE; }
116   if (fMinVal > fHighLimit) { SetMin(fHighLimit); changed = kTRUE; }
117   if (fMaxVal > fHighLimit) { SetMax(fHighLimit); changed = kTRUE; }
118   if (changed)
119     ClearColorArray();
120 }
121
122 void RGBAPalette::SetMin(Int_t min)
123 {
124   fMinVal = TMath::Min(min, fMaxVal);
125   fNBins  = fMaxVal - fMinVal + 1;
126   ClearColorArray();
127 }
128
129 void RGBAPalette::SetMax(Int_t max)
130 {
131   fMaxVal = TMath::Max(max, fMinVal);
132   fNBins  = fMaxVal - fMinVal + 1;
133   ClearColorArray();
134 }
135
136 void RGBAPalette::SetMinMax(Int_t min, Int_t max)
137 {
138   fMinVal = min;
139   fMaxVal = max;
140   fNBins  = fMaxVal - fMinVal + 1;
141   ClearColorArray();
142 }
143
144 /**************************************************************************/
145 /**************************************************************************/
146
147 void RGBAPalette::SetInterpolate(Bool_t b)
148 {
149   fInterpolate = b;
150   ClearColorArray();
151 }
152
153 /**************************************************************************/
154 /**************************************************************************/
155
156 void RGBAPalette::SetDefaultColor(Color_t ci)
157 {
158   fDefaultColor = ci;
159   ColorFromIdx(ci, fDefaultRGBA, kTRUE);
160 }
161
162 void RGBAPalette::SetDefaultColor(Pixel_t pix)
163 {
164   SetDefaultColor(Color_t(TColor::GetColor(pix)));
165 }
166
167 void RGBAPalette::SetDefaultColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
168 {
169   fDefaultColor = Color_t(TColor::GetColor(r, g, b));
170   fDefaultRGBA[0] = r;
171   fDefaultRGBA[1] = g;
172   fDefaultRGBA[2] = b;
173   fDefaultRGBA[3] = a;
174 }
175
176 /**************************************************************************/
177
178 void RGBAPalette::SetUnderColor(Color_t ci)
179 {
180   fUnderColor = ci;
181   ColorFromIdx(ci, fUnderRGBA, kTRUE);
182 }
183
184 void RGBAPalette::SetUnderColor(Pixel_t pix)
185 {
186   SetUnderColor(Color_t(TColor::GetColor(pix)));
187 }
188
189 void RGBAPalette::SetUnderColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
190 {
191   fUnderColor = Color_t(TColor::GetColor(r, g, b));
192   fUnderRGBA[0] = r;
193   fUnderRGBA[1] = g;
194   fUnderRGBA[2] = b;
195   fUnderRGBA[3] = a;
196 }
197
198 /**************************************************************************/
199
200 void RGBAPalette::SetOverColor(Color_t ci)
201 {
202   fOverColor = ci;
203   ColorFromIdx(ci, fOverRGBA, kTRUE);
204 }
205
206 void RGBAPalette::SetOverColor(Pixel_t pix)
207 {
208   SetOverColor(Color_t(TColor::GetColor(pix)));
209 }
210
211 void RGBAPalette::SetOverColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
212 {
213   fOverColor = Color_t(TColor::GetColor(r, g, b));
214   fOverRGBA[0] = r;
215   fOverRGBA[1] = g;
216   fOverRGBA[2] = b;
217   fOverRGBA[3] = a;
218 }
219
220 /**************************************************************************/
221 /**************************************************************************/