]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/RGBAPalette.cxx
Dummy methods DefineParticle required by the interface added.
[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,  512);
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(min, max);
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::SetLimitsScaleMinMax(Int_t low, Int_t high)
123 {
124   Float_t rng_old = fHighLimit - fLowLimit;
125   Float_t rng_new = high - low;
126
127   fMinVal = TMath::Nint(low + (fMinVal - fLowLimit)*rng_new/rng_old);
128   fMaxVal = TMath::Nint(low + (fMaxVal - fLowLimit)*rng_new/rng_old);
129   fLowLimit  = low;
130   fHighLimit = high;
131
132   fNBins  = fMaxVal - fMinVal + 1;
133   ClearColorArray();
134 }
135
136 void RGBAPalette::SetMin(Int_t min)
137 {
138   fMinVal = TMath::Min(min, fMaxVal);
139   fNBins  = fMaxVal - fMinVal + 1;
140   ClearColorArray();
141 }
142
143 void RGBAPalette::SetMax(Int_t max)
144 {
145   fMaxVal = TMath::Max(max, fMinVal);
146   fNBins  = fMaxVal - fMinVal + 1;
147   ClearColorArray();
148 }
149
150 void RGBAPalette::SetMinMax(Int_t min, Int_t max)
151 {
152   fMinVal = min;
153   fMaxVal = max;
154   fNBins  = fMaxVal - fMinVal + 1;
155   ClearColorArray();
156 }
157
158 /**************************************************************************/
159 /**************************************************************************/
160
161 void RGBAPalette::SetInterpolate(Bool_t b)
162 {
163   fInterpolate = b;
164   ClearColorArray();
165 }
166
167 /**************************************************************************/
168 /**************************************************************************/
169
170 void RGBAPalette::SetDefaultColor(Color_t ci)
171 {
172   fDefaultColor = ci;
173   ColorFromIdx(ci, fDefaultRGBA, kTRUE);
174 }
175
176 void RGBAPalette::SetDefaultColor(Pixel_t pix)
177 {
178   SetDefaultColor(Color_t(TColor::GetColor(pix)));
179 }
180
181 void RGBAPalette::SetDefaultColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
182 {
183   fDefaultColor = Color_t(TColor::GetColor(r, g, b));
184   fDefaultRGBA[0] = r;
185   fDefaultRGBA[1] = g;
186   fDefaultRGBA[2] = b;
187   fDefaultRGBA[3] = a;
188 }
189
190 /**************************************************************************/
191
192 void RGBAPalette::SetUnderColor(Color_t ci)
193 {
194   fUnderColor = ci;
195   ColorFromIdx(ci, fUnderRGBA, kTRUE);
196 }
197
198 void RGBAPalette::SetUnderColor(Pixel_t pix)
199 {
200   SetUnderColor(Color_t(TColor::GetColor(pix)));
201 }
202
203 void RGBAPalette::SetUnderColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
204 {
205   fUnderColor = Color_t(TColor::GetColor(r, g, b));
206   fUnderRGBA[0] = r;
207   fUnderRGBA[1] = g;
208   fUnderRGBA[2] = b;
209   fUnderRGBA[3] = a;
210 }
211
212 /**************************************************************************/
213
214 void RGBAPalette::SetOverColor(Color_t ci)
215 {
216   fOverColor = ci;
217   ColorFromIdx(ci, fOverRGBA, kTRUE);
218 }
219
220 void RGBAPalette::SetOverColor(Pixel_t pix)
221 {
222   SetOverColor(Color_t(TColor::GetColor(pix)));
223 }
224
225 void RGBAPalette::SetOverColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
226 {
227   fOverColor = Color_t(TColor::GetColor(r, g, b));
228   fOverRGBA[0] = r;
229   fOverRGBA[1] = g;
230   fOverRGBA[2] = b;
231   fOverRGBA[3] = a;
232 }
233
234 /**************************************************************************/
235 /**************************************************************************/