Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
TEveRGBAPalette.cxx
Go to the documentation of this file.
1// @(#)root/eve:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TEveRGBAPalette.h"
13
14#include "TColor.h"
15#include "TStyle.h"
16#include "TMath.h"
17
18/** \class TEveRGBAPalette
19\ingroup TEve
20A generic, speed-optimised mapping from value to RGBA color
21supporting different wrapping and range truncation modes.
22
23Flag fFixColorRange: specifies how the palette is mapped to signal values:
24 - true - LowLimit -> HighLimit
25 - false - MinValue -> MaxValue
26*/
27
28
29////////////////////////////////////////////////////////////////////////////////
30/// Constructor.
31
33 TObject(), TQObject(),
34 TEveRefCnt(),
35
36 fUIf(1), fUIc(0),
37
38 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0),
39
46
47 fDefaultColor(-1),
48 fUnderColor (-1),
49 fOverColor (-1),
50
51 fNBins(0), fCAMin(0), fCAMax(0), fColorArray(nullptr)
52{
53 SetLimits(0, 1024);
54 SetMinMax(0, 512);
55
58 SetOverColor(2);
59}
60
61////////////////////////////////////////////////////////////////////////////////
62/// Constructor.
63
65 Bool_t showdef, Bool_t fixcolrng) :
66 TObject(), TQObject(),
67 TEveRefCnt(),
68
69 fUIf(1), fUIc(0),
70
71 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0),
72
74 fInterpolate (interp),
75 fShowDefValue (showdef),
76 fFixColorRange (fixcolrng),
79
80 fDefaultColor(-1),
81 fUnderColor (-1),
82 fOverColor (-1),
83
84 fNBins(0), fCAMin(0), fCAMax(0), fColorArray(nullptr)
85{
86 SetLimits(min, max);
87 SetMinMax(min, max);
88
91 SetOverColor(2);
92}
93
94////////////////////////////////////////////////////////////////////////////////
95/// Destructor.
96
101
102////////////////////////////////////////////////////////////////////////////////
103/// Set RGBA color 'pixel' for signal-value 'val'.
104
106{
107 using namespace TMath;
108 Float_t div = Max(1, fCAMax - fCAMin);
109 Int_t nCol = gStyle->GetNumberOfColors();
110
111 Float_t f;
112 if (val >= fCAMax) f = nCol - 1;
113 else if (val <= fCAMin) f = 0;
114 else f = (val - fCAMin)/div*(nCol - 1);
115
116 if (fInterpolate) {
117 Int_t bin = (Int_t) f;
118 Float_t f2 = f - bin, f1 = 1.0f - f2;
119 TEveUtil::ColorFromIdx(f1, gStyle->GetColorPalette(bin),
120 f2, gStyle->GetColorPalette(Min(bin + 1, nCol - 1)),
121 pixel);
122 } else {
123 TEveUtil::ColorFromIdx(gStyle->GetColorPalette((Int_t) Nint(f)), pixel);
124 }
125}
126
127////////////////////////////////////////////////////////////////////////////////
128/// Construct internal color array that maps signal value to RGBA color.
129
131{
132 if (fColorArray)
133 delete [] fColorArray;
134
135 if (fFixColorRange) {
137 } else {
139 }
140 fNBins = fCAMax - fCAMin + 1;
141
142 fColorArray = new UChar_t [4 * fNBins];
143 UChar_t* p = fColorArray;
144 for(Int_t v = fCAMin; v <= fCAMax; ++v, p+=4)
145 SetupColor(v, p);
146}
147
148////////////////////////////////////////////////////////////////////////////////
149/// Clear internal color array.
150
152{
153 if (fColorArray) {
154 delete [] fColorArray;
155 fColorArray = nullptr;
156 fNBins = fCAMin = fCAMax = 0;
157 }
158}
159
160////////////////////////////////////////////////////////////////////////////////
161/// Set low/high limits on signal value. Current min/max values are
162/// clamped into the new limits.
163
165{
166 fLowLimit = low;
167 fHighLimit = high;
168
173
175}
176
177////////////////////////////////////////////////////////////////////////////////
178/// Set low/high limits and rescale current min/max values.
179
181{
182 Float_t rng_old = fHighLimit - fLowLimit;
183 Float_t rng_new = high - low;
184
185 fMinVal = TMath::Nint(low + (fMinVal - fLowLimit)*rng_new/rng_old);
186 fMaxVal = TMath::Nint(low + (fMaxVal - fLowLimit)*rng_new/rng_old);
187 fLowLimit = low;
188 fHighLimit = high;
189
191}
192
193////////////////////////////////////////////////////////////////////////////////
194/// Set current min value.
195
201
202////////////////////////////////////////////////////////////////////////////////
203/// Set current max value.
204
210
211////////////////////////////////////////////////////////////////////////////////
212/// Set current min/max values.
213
215{
216 fMinVal = min;
217 fMaxVal = max;
219}
220
221////////////////////////////////////////////////////////////////////////////////
222/// Set flag determining whether GUI editor and overlays should show limits
223/// and axis values as real values with mapping from integer value i to real
224/// value d as: d = f*i + fc
225
227{
228 fUIDoubleRep = b;
229 if (fUIDoubleRep) {
230 fUIf = f; fUIc = c;
231 } else {
232 fUIf = 1; fUIc = 0;
233 }
234}
235
236////////////////////////////////////////////////////////////////////////////////
237/// Set interpolation flag. This determines how colors from ROOT's
238/// palette are mapped into RGBA values for given signal.
239
245
246////////////////////////////////////////////////////////////////////////////////
247/// Set flag specifying how the palette is mapped to signal values:
248/// true - LowLimit -> HighLimit
249/// false - MinValue -> MaxValue
250
256
257////////////////////////////////////////////////////////////////////////////////
258/// Set default color.
259
265
266////////////////////////////////////////////////////////////////////////////////
267/// Set default color.
268
273
274////////////////////////////////////////////////////////////////////////////////
275/// Set default color.
276
285
286////////////////////////////////////////////////////////////////////////////////
287/// Set underflow color.
288
294
295////////////////////////////////////////////////////////////////////////////////
296/// Set underflow color.
297
302
303////////////////////////////////////////////////////////////////////////////////
304/// Set underflow color.
305
314
315////////////////////////////////////////////////////////////////////////////////
316/// Set overflow color.
317
323
324////////////////////////////////////////////////////////////////////////////////
325/// Set overflow color.
326
331
332////////////////////////////////////////////////////////////////////////////////
333/// Set overflow color.
334
343
344////////////////////////////////////////////////////////////////////////////////
345/// Emit the "MinMaxValChanged()" signal.
346/// This is NOT called automatically from SetMin/Max functions but
347/// it IS called from TEveRGBAPaletteEditor after it changes the
348/// min/max values.
349
351{
352 Emit("MinMaxValChanged()");
353}
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:41
ROOT::R::TRInterface & r
Definition Object.C:4
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define g(i)
Definition RSha256.hxx:105
#define a(i)
Definition RSha256.hxx:99
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char).
Definition RtypesCore.h:52
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
short Color_t
Color number (short).
Definition RtypesCore.h:99
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
externTStyle * gStyle
Definition TStyle.h:442
static Int_t GetColor(const char *hexcolor)
void SetMax(Int_t max)
Set current max value.
void SetOverColor(Color_t ci)
Set overflow color.
UChar_t fDefaultRGBA[4]
void SetUnderColorPixel(Pixel_t pix)
Set underflow color.
~TEveRGBAPalette() override
Destructor.
UChar_t fOverRGBA[4]
void SetMin(Int_t min)
Set current min value.
void SetupColorArray() const
Construct internal color array that maps signal value to RGBA color.
void SetDefaultColor(Color_t ci)
Set default color.
void SetInterpolate(Bool_t b)
Set interpolation flag.
UChar_t * fColorArray
void SetDefaultColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255)
Set default color.
UChar_t fUnderRGBA[4]
void SetLimitsScaleMinMax(Int_t low, Int_t high)
Set low/high limits and rescale current min/max values.
void SetDefaultColorPixel(Pixel_t pix)
Set default color.
void ClearColorArray()
Clear internal color array.
void SetUnderColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255)
Set underflow color.
void SetOverColorPixel(Pixel_t pix)
Set overflow color.
void SetFixColorRange(Bool_t v)
Set flag specifying how the palette is mapped to signal values: true - LowLimit -> HighLimit false - ...
void SetupColor(Int_t val, UChar_t *pix) const
Set RGBA color 'pixel' for signal-value 'val'.
void SetMinMax(Int_t min, Int_t max)
Set current min/max values.
void MinMaxValChanged()
Emit the "MinMaxValChanged()" signal.
void SetOverColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255)
Set overflow color.
void SetLimits(Int_t low, Int_t high)
Set low/high limits on signal value.
void SetUnderColor(Color_t ci)
Set underflow color.
TEveRGBAPalette()
Constructor.
void SetUIDoubleRep(Bool_t b, Double_t f=1, Double_t c=0)
Set flag determining whether GUI editor and overlays should show limits and axis values as real value...
static void ColorFromIdx(Color_t ci, UChar_t col[4], Bool_t alpha=kTRUE)
Fill col with RGBA values corresponding to index ci.
Definition TEveUtil.cxx:187
TObject()
TObject constructor.
Definition TObject.h:259
TQObject(const TQObject &)=delete
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition TQObject.h:164
TF1 * f1
Definition legend1.C:11
TMath.
Definition TMathBase.h:35
Int_t Nint(T x)
Round to nearest integer. Rounds half integers to the nearest even integer.
Definition TMath.h:704
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:249
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:197