]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/Reve/RGBAPalette.cxx
Use new color-query function from RGBAPalette; validity of digit value was not honour...
[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>
7
8using namespace Reve;
9
10//______________________________________________________________________
11// RGBAPalette
12//
13
14ClassImp(RGBAPalette)
15
16RGBAPalette::RGBAPalette() :
17 TObject(),
18 Reve::ReferenceCount(),
3c67f72c 19
20 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0), fNBins(0),
21
8373e543 22 fCutLow (kTRUE),
23 fCutHigh (kFALSE),
24 fInterpolate (kFALSE),
25 fWrap (kFALSE),
3c67f72c 26 fDefaultColor(0),
8373e543 27 fColorArray (0)
28{
29 SetLimits(0, 1000);
30 SetMinMax(0, 100);
31}
32
33RGBAPalette::RGBAPalette(Int_t min, Int_t max) :
34 TObject(),
35 Reve::ReferenceCount(),
3c67f72c 36
37 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0), fNBins(0),
38
8373e543 39 fCutLow (kTRUE),
40 fCutHigh (kFALSE),
41 fInterpolate (kFALSE),
42 fWrap (kFALSE),
3c67f72c 43 fDefaultColor(0),
8373e543 44 fColorArray (0)
45{
46 SetLimits(0, 1000);
47 SetMinMax(min, max);
48}
49
50RGBAPalette::RGBAPalette(Int_t min, Int_t max, Bool_t interp, Bool_t wrap) :
51 TObject(),
52 Reve::ReferenceCount(),
3c67f72c 53
54 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0), fNBins(0),
55
56 fCutLow (kTRUE),
57 fCutHigh (kFALSE),
8373e543 58 fInterpolate (interp),
59 fWrap (wrap),
3c67f72c 60 fDefaultColor(0),
8373e543 61 fColorArray (0)
62{
63 SetLimits(0, 1023);
64 SetMinMax(min, max);
65}
66
67RGBAPalette::~RGBAPalette()
68{
69 delete [] fColorArray;
70}
71
72/**************************************************************************/
73
74void 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
96void 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
109void RGBAPalette::ClearColorArray()
110{
111 if(fColorArray) {
112 delete [] fColorArray;
113 fColorArray = 0;
114 }
115}
116
117/**************************************************************************/
118
119void 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
130void RGBAPalette::SetMin(Int_t min)
131{
132 fMinVal = TMath::Min(min, fMaxVal);
133 fNBins = fMaxVal - fMinVal + 1;
134 ClearColorArray();
135}
136
137void RGBAPalette::SetMax(Int_t max)
138{
139 fMaxVal = TMath::Max(max, fMinVal);
140 fNBins = fMaxVal - fMinVal + 1;
141 ClearColorArray();
142}
143
144void RGBAPalette::SetMinMax(Int_t min, Int_t max)
145{
146 fMinVal = min;
147 fMaxVal = max;
148 fNBins = fMaxVal - fMinVal + 1;
149 ClearColorArray();
150}
151
152void RGBAPalette::SetInterpolate(Bool_t b)
153{
154 fInterpolate = b;
155 ClearColorArray();
156}
157
158void RGBAPalette::SetWrap(Bool_t b)
159{
160 fWrap = b;
161}
162
163/**************************************************************************/
164
165void RGBAPalette::SetDefaultColor(Color_t ci)
166{
167 fDefaultColor = ci;
168 ColorFromIdx(ci, fDefaultRGBA, kTRUE);
169}
170
171void RGBAPalette::SetDefaultColor(Pixel_t pix)
172{
173 SetDefaultColor(Color_t(TColor::GetColor(pix)));
174}
175
176void 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}