]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/Reve/RGBAPalette.cxx
Add Getters and Setters in TrackRnrStyle and TrackList to define rendering of path...
[u/mrichter/AliRoot.git] / EVE / Reve / RGBAPalette.cxx
CommitLineData
8373e543 1// $Header$
2
3#include "RGBAPalette.h"
4
5#include <TColor.h>
6#include <TStyle.h>
0b28fd57 7#include <TMath.h>
8373e543 8
9using namespace Reve;
10
11//______________________________________________________________________
12// RGBAPalette
13//
14
15ClassImp(RGBAPalette)
16
17RGBAPalette::RGBAPalette() :
18 TObject(),
19 Reve::ReferenceCount(),
3c67f72c 20
21 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0), fNBins(0),
22
a290e33f 23 fInterpolate (kFALSE),
24 fShowDefValue (kTRUE),
25 fUnderflowAction (LA_Cut),
26 fOverflowAction (LA_Clip),
bc5158df 27
3c67f72c 28 fDefaultColor(0),
bc5158df 29 fUnderColor (1),
30 fOverColor (2),
8373e543 31 fColorArray (0)
32{
e0fa60e9 33 SetLimits(0, 1024);
8373e543 34 SetMinMax(0, 100);
35}
36
bc5158df 37RGBAPalette::RGBAPalette(Int_t min, Int_t max, Bool_t interp, Bool_t showdef) :
8373e543 38 TObject(),
39 Reve::ReferenceCount(),
3c67f72c 40
41 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0), fNBins(0),
42
a290e33f 43 fInterpolate (interp),
44 fShowDefValue (showdef),
45 fUnderflowAction (LA_Cut),
46 fOverflowAction (LA_Clip),
bc5158df 47
3c67f72c 48 fDefaultColor(0),
bc5158df 49 fUnderColor (1),
50 fOverColor (2),
8373e543 51 fColorArray (0)
52{
e0fa60e9 53 SetLimits(0, 1024);
8373e543 54 SetMinMax(min, max);
55}
56
57RGBAPalette::~RGBAPalette()
58{
59 delete [] fColorArray;
60}
61
62/**************************************************************************/
63
64void 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
86void 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
99void RGBAPalette::ClearColorArray()
100{
101 if(fColorArray) {
102 delete [] fColorArray;
103 fColorArray = 0;
104 }
105}
106
107/**************************************************************************/
108
109void RGBAPalette::SetLimits(Int_t low, Int_t high)
110{
111 fLowLimit = low;
112 fHighLimit = high;
bc5158df 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();
8373e543 120}
121
122void RGBAPalette::SetMin(Int_t min)
123{
124 fMinVal = TMath::Min(min, fMaxVal);
125 fNBins = fMaxVal - fMinVal + 1;
126 ClearColorArray();
127}
128
129void RGBAPalette::SetMax(Int_t max)
130{
131 fMaxVal = TMath::Max(max, fMinVal);
132 fNBins = fMaxVal - fMinVal + 1;
133 ClearColorArray();
134}
135
136void RGBAPalette::SetMinMax(Int_t min, Int_t max)
137{
138 fMinVal = min;
139 fMaxVal = max;
140 fNBins = fMaxVal - fMinVal + 1;
141 ClearColorArray();
142}
143
bc5158df 144/**************************************************************************/
145/**************************************************************************/
146
8373e543 147void RGBAPalette::SetInterpolate(Bool_t b)
148{
149 fInterpolate = b;
150 ClearColorArray();
151}
152
bc5158df 153/**************************************************************************/
8373e543 154/**************************************************************************/
155
156void RGBAPalette::SetDefaultColor(Color_t ci)
157{
158 fDefaultColor = ci;
159 ColorFromIdx(ci, fDefaultRGBA, kTRUE);
160}
161
162void RGBAPalette::SetDefaultColor(Pixel_t pix)
163{
164 SetDefaultColor(Color_t(TColor::GetColor(pix)));
165}
166
167void 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}
bc5158df 175
176/**************************************************************************/
177
178void RGBAPalette::SetUnderColor(Color_t ci)
179{
180 fUnderColor = ci;
181 ColorFromIdx(ci, fUnderRGBA, kTRUE);
182}
183
184void RGBAPalette::SetUnderColor(Pixel_t pix)
185{
186 SetUnderColor(Color_t(TColor::GetColor(pix)));
187}
188
189void 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
200void RGBAPalette::SetOverColor(Color_t ci)
201{
202 fOverColor = ci;
203 ColorFromIdx(ci, fOverRGBA, kTRUE);
204}
205
206void RGBAPalette::SetOverColor(Pixel_t pix)
207{
208 SetOverColor(Color_t(TColor::GetColor(pix)));
209}
210
211void 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/**************************************************************************/