forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TEveRGBAPalette.cxx
354 lines (280 loc) · 9.58 KB
/
TEveRGBAPalette.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
// @(#)root/eve:$Id$
// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
/*************************************************************************
* Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#include "TEveRGBAPalette.h"
#include "TColor.h"
#include "TStyle.h"
#include "TMath.h"
/** \class TEveRGBAPalette
\ingroup TEve
A generic, speed-optimised mapping from value to RGBA color
supporting different wrapping and range truncation modes.
Flag fFixColorRange: specifies how the palette is mapped to signal values:
- true - LowLimit -> HighLimit
- false - MinValue -> MaxValue
*/
ClassImp(TEveRGBAPalette);
////////////////////////////////////////////////////////////////////////////////
/// Constructor.
TEveRGBAPalette::TEveRGBAPalette() :
TObject(), TQObject(),
TEveRefCnt(),
fUIf(1), fUIc(0),
fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0),
fUIDoubleRep (kFALSE),
fInterpolate (kTRUE),
fShowDefValue (kTRUE),
fFixColorRange (kFALSE),
fUnderflowAction (kLA_Cut),
fOverflowAction (kLA_Clip),
fDefaultColor(-1),
fUnderColor (-1),
fOverColor (-1),
fNBins(0), fCAMin(0), fCAMax(0), fColorArray(nullptr)
{
SetLimits(0, 1024);
SetMinMax(0, 512);
SetDefaultColor(0);
SetUnderColor(1);
SetOverColor(2);
}
////////////////////////////////////////////////////////////////////////////////
/// Constructor.
TEveRGBAPalette::TEveRGBAPalette(Int_t min, Int_t max, Bool_t interp,
Bool_t showdef, Bool_t fixcolrng) :
TObject(), TQObject(),
TEveRefCnt(),
fUIf(1), fUIc(0),
fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0),
fUIDoubleRep (kFALSE),
fInterpolate (interp),
fShowDefValue (showdef),
fFixColorRange (fixcolrng),
fUnderflowAction (kLA_Cut),
fOverflowAction (kLA_Clip),
fDefaultColor(-1),
fUnderColor (-1),
fOverColor (-1),
fNBins(0), fCAMin(0), fCAMax(0), fColorArray(nullptr)
{
SetLimits(min, max);
SetMinMax(min, max);
SetDefaultColor(0);
SetUnderColor(1);
SetOverColor(2);
}
////////////////////////////////////////////////////////////////////////////////
/// Destructor.
TEveRGBAPalette::~TEveRGBAPalette()
{
delete [] fColorArray;
}
////////////////////////////////////////////////////////////////////////////////
/// Set RGBA color 'pixel' for signal-value 'val'.
void TEveRGBAPalette::SetupColor(Int_t val, UChar_t* pixel) const
{
using namespace TMath;
Float_t div = Max(1, fCAMax - fCAMin);
Int_t nCol = gStyle->GetNumberOfColors();
Float_t f;
if (val >= fCAMax) f = nCol - 1;
else if (val <= fCAMin) f = 0;
else f = (val - fCAMin)/div*(nCol - 1);
if (fInterpolate) {
Int_t bin = (Int_t) f;
Float_t f2 = f - bin, f1 = 1.0f - f2;
TEveUtil::ColorFromIdx(f1, gStyle->GetColorPalette(bin),
f2, gStyle->GetColorPalette(Min(bin + 1, nCol - 1)),
pixel);
} else {
TEveUtil::ColorFromIdx(gStyle->GetColorPalette((Int_t) Nint(f)), pixel);
}
}
////////////////////////////////////////////////////////////////////////////////
/// Construct internal color array that maps signal value to RGBA color.
void TEveRGBAPalette::SetupColorArray() const
{
if (fColorArray)
delete [] fColorArray;
if (fFixColorRange) {
fCAMin = fLowLimit; fCAMax = fHighLimit;
} else {
fCAMin = fMinVal; fCAMax = fMaxVal;
}
fNBins = fCAMax - fCAMin + 1;
fColorArray = new UChar_t [4 * fNBins];
UChar_t* p = fColorArray;
for(Int_t v = fCAMin; v <= fCAMax; ++v, p+=4)
SetupColor(v, p);
}
////////////////////////////////////////////////////////////////////////////////
/// Clear internal color array.
void TEveRGBAPalette::ClearColorArray()
{
if (fColorArray) {
delete [] fColorArray;
fColorArray = nullptr;
fNBins = fCAMin = fCAMax = 0;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Set low/high limits on signal value. Current min/max values are
/// clamped into the new limits.
void TEveRGBAPalette::SetLimits(Int_t low, Int_t high)
{
fLowLimit = low;
fHighLimit = high;
if (fMaxVal < fLowLimit) SetMax(fLowLimit);
if (fMinVal < fLowLimit) SetMin(fLowLimit);
if (fMinVal > fHighLimit) SetMin(fHighLimit);
if (fMaxVal > fHighLimit) SetMax(fHighLimit);
ClearColorArray();
}
////////////////////////////////////////////////////////////////////////////////
/// Set low/high limits and rescale current min/max values.
void TEveRGBAPalette::SetLimitsScaleMinMax(Int_t low, Int_t high)
{
Float_t rng_old = fHighLimit - fLowLimit;
Float_t rng_new = high - low;
fMinVal = TMath::Nint(low + (fMinVal - fLowLimit)*rng_new/rng_old);
fMaxVal = TMath::Nint(low + (fMaxVal - fLowLimit)*rng_new/rng_old);
fLowLimit = low;
fHighLimit = high;
ClearColorArray();
}
////////////////////////////////////////////////////////////////////////////////
/// Set current min value.
void TEveRGBAPalette::SetMin(Int_t min)
{
fMinVal = TMath::Min(min, fMaxVal);
ClearColorArray();
}
////////////////////////////////////////////////////////////////////////////////
/// Set current max value.
void TEveRGBAPalette::SetMax(Int_t max)
{
fMaxVal = TMath::Max(max, fMinVal);
ClearColorArray();
}
////////////////////////////////////////////////////////////////////////////////
/// Set current min/max values.
void TEveRGBAPalette::SetMinMax(Int_t min, Int_t max)
{
fMinVal = min;
fMaxVal = max;
ClearColorArray();
}
////////////////////////////////////////////////////////////////////////////////
/// Set flag determining whether GUI editor and overlays should show limits
/// and axis values as real values with mapping from integer value i to real
/// value d as: d = f*i + fc
void TEveRGBAPalette::SetUIDoubleRep(Bool_t b, Double_t f, Double_t c)
{
fUIDoubleRep = b;
if (fUIDoubleRep) {
fUIf = f; fUIc = c;
} else {
fUIf = 1; fUIc = 0;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Set interpolation flag. This determines how colors from ROOT's
/// palette are mapped into RGBA values for given signal.
void TEveRGBAPalette::SetInterpolate(Bool_t b)
{
fInterpolate = b;
ClearColorArray();
}
////////////////////////////////////////////////////////////////////////////////
/// Set flag specifying how the palette is mapped to signal values:
/// true - LowLimit -> HighLimit
/// false - MinValue -> MaxValue
void TEveRGBAPalette::SetFixColorRange(Bool_t v)
{
fFixColorRange = v;
ClearColorArray();
}
////////////////////////////////////////////////////////////////////////////////
/// Set default color.
void TEveRGBAPalette::SetDefaultColor(Color_t ci)
{
fDefaultColor = ci;
TEveUtil::ColorFromIdx(ci, fDefaultRGBA, kTRUE);
}
////////////////////////////////////////////////////////////////////////////////
/// Set default color.
void TEveRGBAPalette::SetDefaultColorPixel(Pixel_t pix)
{
SetDefaultColor(Color_t(TColor::GetColor(pix)));
}
////////////////////////////////////////////////////////////////////////////////
/// Set default color.
void TEveRGBAPalette::SetDefaultColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
{
fDefaultColor = Color_t(TColor::GetColor(r, g, b));
fDefaultRGBA[0] = r;
fDefaultRGBA[1] = g;
fDefaultRGBA[2] = b;
fDefaultRGBA[3] = a;
}
////////////////////////////////////////////////////////////////////////////////
/// Set underflow color.
void TEveRGBAPalette::SetUnderColor(Color_t ci)
{
fUnderColor = ci;
TEveUtil::ColorFromIdx(ci, fUnderRGBA, kTRUE);
}
////////////////////////////////////////////////////////////////////////////////
/// Set underflow color.
void TEveRGBAPalette::SetUnderColorPixel(Pixel_t pix)
{
SetUnderColor(Color_t(TColor::GetColor(pix)));
}
////////////////////////////////////////////////////////////////////////////////
/// Set underflow color.
void TEveRGBAPalette::SetUnderColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
{
fUnderColor = Color_t(TColor::GetColor(r, g, b));
fUnderRGBA[0] = r;
fUnderRGBA[1] = g;
fUnderRGBA[2] = b;
fUnderRGBA[3] = a;
}
////////////////////////////////////////////////////////////////////////////////
/// Set overflow color.
void TEveRGBAPalette::SetOverColor(Color_t ci)
{
fOverColor = ci;
TEveUtil::ColorFromIdx(ci, fOverRGBA, kTRUE);
}
////////////////////////////////////////////////////////////////////////////////
/// Set overflow color.
void TEveRGBAPalette::SetOverColorPixel(Pixel_t pix)
{
SetOverColor(Color_t(TColor::GetColor(pix)));
}
////////////////////////////////////////////////////////////////////////////////
/// Set overflow color.
void TEveRGBAPalette::SetOverColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
{
fOverColor = Color_t(TColor::GetColor(r, g, b));
fOverRGBA[0] = r;
fOverRGBA[1] = g;
fOverRGBA[2] = b;
fOverRGBA[3] = a;
}
////////////////////////////////////////////////////////////////////////////////
/// Emit the "MinMaxValChanged()" signal.
/// This is NOT called automatically from SetMin/Max functions but
/// it IS called from TEveRGBAPaletteEditor after it changes the
/// min/max values.
void TEveRGBAPalette::MinMaxValChanged()
{
Emit("MinMaxValChanged()");
}