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
29
30////////////////////////////////////////////////////////////////////////////////
31/// Constructor.
32
34 TObject(), TQObject(),
35 TEveRefCnt(),
36
37 fUIf(1), fUIc(0),
38
39 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0),
40
41 fUIDoubleRep (kFALSE),
42 fInterpolate (kTRUE),
43 fShowDefValue (kTRUE),
44 fFixColorRange (kFALSE),
45 fUnderflowAction (kLA_Cut),
46 fOverflowAction (kLA_Clip),
47
48 fDefaultColor(-1),
49 fUnderColor (-1),
50 fOverColor (-1),
51
52 fNBins(0), fCAMin(0), fCAMax(0), fColorArray(nullptr)
53{
54 SetLimits(0, 1024);
55 SetMinMax(0, 512);
56
59 SetOverColor(2);
60}
61
62////////////////////////////////////////////////////////////////////////////////
63/// Constructor.
64
66 Bool_t showdef, Bool_t fixcolrng) :
67 TObject(), TQObject(),
68 TEveRefCnt(),
69
70 fUIf(1), fUIc(0),
71
72 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0),
73
74 fUIDoubleRep (kFALSE),
75 fInterpolate (interp),
76 fShowDefValue (showdef),
77 fFixColorRange (fixcolrng),
78 fUnderflowAction (kLA_Cut),
79 fOverflowAction (kLA_Clip),
80
81 fDefaultColor(-1),
82 fUnderColor (-1),
83 fOverColor (-1),
84
85 fNBins(0), fCAMin(0), fCAMax(0), fColorArray(nullptr)
86{
87 SetLimits(min, max);
88 SetMinMax(min, max);
89
92 SetOverColor(2);
93}
94
95////////////////////////////////////////////////////////////////////////////////
96/// Destructor.
97
99{
100 delete [] fColorArray;
101}
102
103////////////////////////////////////////////////////////////////////////////////
104/// Set RGBA color 'pixel' for signal-value 'val'.
105
107{
108 using namespace TMath;
109 Float_t div = Max(1, fCAMax - fCAMin);
111
112 Float_t f;
113 if (val >= fCAMax) f = nCol - 1;
114 else if (val <= fCAMin) f = 0;
115 else f = (val - fCAMin)/div*(nCol - 1);
116
117 if (fInterpolate) {
118 Int_t bin = (Int_t) f;
119 Float_t f2 = f - bin, f1 = 1.0f - f2;
121 f2, gStyle->GetColorPalette(Min(bin + 1, nCol - 1)),
122 pixel);
123 } else {
125 }
126}
127
128////////////////////////////////////////////////////////////////////////////////
129/// Construct internal color array that maps signal value to RGBA color.
130
132{
133 if (fColorArray)
134 delete [] fColorArray;
135
136 if (fFixColorRange) {
138 } else {
140 }
141 fNBins = fCAMax - fCAMin + 1;
142
143 fColorArray = new UChar_t [4 * fNBins];
145 for(Int_t v = fCAMin; v <= fCAMax; ++v, p+=4)
146 SetupColor(v, p);
147}
148
149////////////////////////////////////////////////////////////////////////////////
150/// Clear internal color array.
151
153{
154 if (fColorArray) {
155 delete [] fColorArray;
156 fColorArray = nullptr;
157 fNBins = fCAMin = fCAMax = 0;
158 }
159}
160
161////////////////////////////////////////////////////////////////////////////////
162/// Set low/high limits on signal value. Current min/max values are
163/// clamped into the new limits.
164
166{
167 fLowLimit = low;
168 fHighLimit = high;
169
174
176}
177
178////////////////////////////////////////////////////////////////////////////////
179/// Set low/high limits and rescale current min/max values.
180
182{
183 Float_t rng_old = fHighLimit - fLowLimit;
184 Float_t rng_new = high - low;
185
186 fMinVal = TMath::Nint(low + (fMinVal - fLowLimit)*rng_new/rng_old);
187 fMaxVal = TMath::Nint(low + (fMaxVal - fLowLimit)*rng_new/rng_old);
188 fLowLimit = low;
189 fHighLimit = high;
190
192}
193
194////////////////////////////////////////////////////////////////////////////////
195/// Set current min value.
196
198{
199 fMinVal = TMath::Min(min, fMaxVal);
201}
202
203////////////////////////////////////////////////////////////////////////////////
204/// Set current max value.
205
207{
208 fMaxVal = TMath::Max(max, fMinVal);
210}
211
212////////////////////////////////////////////////////////////////////////////////
213/// Set current min/max values.
214
216{
217 fMinVal = min;
218 fMaxVal = max;
220}
221
222////////////////////////////////////////////////////////////////////////////////
223/// Set flag determining whether GUI editor and overlays should show limits
224/// and axis values as real values with mapping from integer value i to real
225/// value d as: d = f*i + fc
226
228{
229 fUIDoubleRep = b;
230 if (fUIDoubleRep) {
231 fUIf = f; fUIc = c;
232 } else {
233 fUIf = 1; fUIc = 0;
234 }
235}
236
237////////////////////////////////////////////////////////////////////////////////
238/// Set interpolation flag. This determines how colors from ROOT's
239/// palette are mapped into RGBA values for given signal.
240
242{
243 fInterpolate = b;
245}
246
247////////////////////////////////////////////////////////////////////////////////
248/// Set flag specifying how the palette is mapped to signal values:
249/// true - LowLimit -> HighLimit
250/// false - MinValue -> MaxValue
251
253{
256}
257
258////////////////////////////////////////////////////////////////////////////////
259/// Set default color.
260
262{
263 fDefaultColor = ci;
265}
266
267////////////////////////////////////////////////////////////////////////////////
268/// Set default color.
269
271{
273}
274
275////////////////////////////////////////////////////////////////////////////////
276/// Set default color.
277
279{
281 fDefaultRGBA[0] = r;
282 fDefaultRGBA[1] = g;
283 fDefaultRGBA[2] = b;
284 fDefaultRGBA[3] = a;
285}
286
287////////////////////////////////////////////////////////////////////////////////
288/// Set underflow color.
289
291{
292 fUnderColor = ci;
294}
295
296////////////////////////////////////////////////////////////////////////////////
297/// Set underflow color.
298
300{
302}
303
304////////////////////////////////////////////////////////////////////////////////
305/// Set underflow color.
306
308{
310 fUnderRGBA[0] = r;
311 fUnderRGBA[1] = g;
312 fUnderRGBA[2] = b;
313 fUnderRGBA[3] = a;
314}
315
316////////////////////////////////////////////////////////////////////////////////
317/// Set overflow color.
318
320{
321 fOverColor = ci;
323}
324
325////////////////////////////////////////////////////////////////////////////////
326/// Set overflow color.
327
329{
331}
332
333////////////////////////////////////////////////////////////////////////////////
334/// Set overflow color.
335
337{
339 fOverRGBA[0] = r;
340 fOverRGBA[1] = g;
341 fOverRGBA[2] = b;
342 fOverRGBA[3] = a;
343}
344
345////////////////////////////////////////////////////////////////////////////////
346/// Emit the "MinMaxValChanged()" signal.
347/// This is NOT called automatically from SetMin/Max functions but
348/// it IS called from TEveRGBAPaletteEditor after it changes the
349/// min/max values.
350
352{
353 Emit("MinMaxValChanged()");
354}
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
#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
Definition RtypesCore.h:45
short Color_t
Definition RtypesCore.h:92
unsigned char UChar_t
Definition RtypesCore.h:38
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void pix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void pixel
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
R__EXTERN TStyle * gStyle
Definition TStyle.h:433
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
Definition TColor.cxx:1839
A generic, speed-optimised mapping from value to RGBA color supporting different wrapping and range t...
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...
Base-class for reference-counted objects.
Definition TEveUtil.h:163
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:188
Mother of all ROOT objects.
Definition TObject.h:41
This is the ROOT implementation of the Qt object communication mechanism (see also http://www....
Definition TQObject.h:48
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition TQObject.h:164
Int_t GetColorPalette(Int_t i) const
Return color number i in current palette.
Definition TStyle.cxx:1097
Int_t GetNumberOfColors() const
Return number of colors in the color palette.
Definition TStyle.cxx:1171
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:693
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:250
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:198