]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/RGBAPalette.cxx
Fix effc++ warnings.
[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
8 using namespace Reve;
9
10 //______________________________________________________________________
11 // RGBAPalette
12 //
13
14 ClassImp(RGBAPalette)
15
16 RGBAPalette::RGBAPalette() :
17   TObject(),
18   Reve::ReferenceCount(),
19
20   fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0), fNBins(0),
21
22   fCutLow      (kTRUE),
23   fCutHigh     (kFALSE),
24   fInterpolate (kFALSE),
25   fWrap        (kFALSE),
26   fDefaultColor(0),
27   fColorArray  (0)
28 {
29   SetLimits(0, 1000);
30   SetMinMax(0, 100);
31 }
32
33 RGBAPalette::RGBAPalette(Int_t min, Int_t max) :
34   TObject(),
35   Reve::ReferenceCount(),
36
37   fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0), fNBins(0),
38
39   fCutLow      (kTRUE),
40   fCutHigh     (kFALSE),
41   fInterpolate (kFALSE),
42   fWrap        (kFALSE),
43   fDefaultColor(0),
44   fColorArray  (0)
45 {
46   SetLimits(0, 1000);
47   SetMinMax(min, max);
48 }
49
50 RGBAPalette::RGBAPalette(Int_t min, Int_t max, Bool_t interp, Bool_t wrap) :
51   TObject(),
52   Reve::ReferenceCount(),
53
54   fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0), fNBins(0),
55
56   fCutLow      (kTRUE),
57   fCutHigh     (kFALSE),
58   fInterpolate (interp),
59   fWrap        (wrap),
60   fDefaultColor(0),
61   fColorArray  (0)
62 {
63   SetLimits(0, 1023);
64   SetMinMax(min, max);
65 }
66
67 RGBAPalette::~RGBAPalette()
68 {
69   delete [] fColorArray;
70 }
71
72 /**************************************************************************/
73
74 void RGBAPalette::SetupColor(Int_t val, UChar_t* pixel) const
75 {
76   using namespace TMath;
77   Float_t div  = Max(1, fMaxVal - fMinVal);
78   Int_t   nCol = gStyle->GetNumberOfColors();
79
80   Float_t f;
81   if      (val >= fMaxVal) f = nCol - 1;
82   else if (val <= fMinVal) f = 0;
83   else                     f = (val - fMinVal)/div*(nCol - 1);
84
85   if (fInterpolate) {
86     Int_t  bin = (Int_t) f;
87     Float_t f1 = f - bin, f2 = 1.0f - f1;
88     ColorFromIdx(f1, gStyle->GetColorPalette(bin),
89                  f2, gStyle->GetColorPalette(Min(bin + 1, nCol - 1)),
90                  pixel);
91   } else {
92     ColorFromIdx(gStyle->GetColorPalette((Int_t) Nint(f)), pixel);    
93   }
94 }
95
96 void RGBAPalette::SetupColorArray() const
97 {
98   if(fColorArray) // !!!! should reinit anyway, maybe palette in gstyle changed
99     return;
100
101   // !!!! probably should store original palette for editing ...
102
103   fColorArray = new UChar_t [4 * fNBins];
104   UChar_t* p = fColorArray;
105   for(Int_t v=fMinVal; v<=fMaxVal; ++v, p+=4)
106     SetupColor(v, p);
107 }
108
109 void RGBAPalette::ClearColorArray()
110 {
111   if(fColorArray) {
112     delete [] fColorArray;
113     fColorArray = 0;
114   }
115 }
116
117 /**************************************************************************/
118
119 void RGBAPalette::SetLimits(Int_t low, Int_t high)
120 {
121   fLowLimit  = low;
122   fHighLimit = high;
123   if (fMaxVal < fLowLimit)  SetMax(fLowLimit);
124   if (fMinVal < fLowLimit)  SetMin(fLowLimit);
125   if (fMinVal > fHighLimit) SetMin(fHighLimit);
126   if (fMaxVal > fHighLimit) SetMax(fHighLimit);
127     
128 }
129
130 void RGBAPalette::SetMin(Int_t min)
131 {
132   fMinVal = TMath::Min(min, fMaxVal);
133   fNBins  = fMaxVal - fMinVal + 1;
134   ClearColorArray();
135 }
136
137 void RGBAPalette::SetMax(Int_t max)
138 {
139   fMaxVal = TMath::Max(max, fMinVal);
140   fNBins  = fMaxVal - fMinVal + 1;
141   ClearColorArray();
142 }
143
144 void RGBAPalette::SetMinMax(Int_t min, Int_t max)
145 {
146   fMinVal = min;
147   fMaxVal = max;
148   fNBins  = fMaxVal - fMinVal + 1;
149   ClearColorArray();
150 }
151
152 void RGBAPalette::SetInterpolate(Bool_t b)
153 {
154   fInterpolate = b;
155   ClearColorArray();
156 }
157
158 void RGBAPalette::SetWrap(Bool_t b)
159 {
160   fWrap = b;
161 }
162
163 /**************************************************************************/
164
165 void RGBAPalette::SetDefaultColor(Color_t ci)
166 {
167   fDefaultColor = ci;
168   ColorFromIdx(ci, fDefaultRGBA, kTRUE);
169 }
170
171 void RGBAPalette::SetDefaultColor(Pixel_t pix)
172 {
173   SetDefaultColor(Color_t(TColor::GetColor(pix)));
174 }
175
176 void RGBAPalette::SetDefaultColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
177 {
178   fDefaultColor = Color_t(TColor::GetColor(r, g, b));
179   fDefaultRGBA[0] = r;
180   fDefaultRGBA[1] = g;
181   fDefaultRGBA[2] = b;
182   fDefaultRGBA[3] = a;
183 }