Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveRGBAPalette.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
13
14#include "TColor.h"
15#include "TStyle.h"
16#include "TMath.h"
17
18
19using namespace ROOT::Experimental;
20
21/** \class REveRGBAPalette
22\ingroup REve
23A generic, speed-optimised mapping from value to RGBA color
24supporting different wrapping and range truncation modes.
25
26Flag fFixColorRange: specifies how the palette is mapped to signal values:
27 - true - LowLimit -> HighLimit
28 - false - MinValue -> MaxValue
29*/
30
32
33////////////////////////////////////////////////////////////////////////////////
34/// Constructor.
35
36REveRGBAPalette::REveRGBAPalette() :
37 TObject(),
38 REveRefCnt(),
39
40 fUIf(1), fUIc(0),
41
42 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0),
43
44 fUIDoubleRep (kFALSE),
45 fInterpolate (kTRUE),
46 fShowDefValue (kTRUE),
47 fFixColorRange (kFALSE),
48 fUnderflowAction (kLA_Cut),
49 fOverflowAction (kLA_Clip),
50
51 fDefaultColor(-1),
52 fUnderColor (-1),
53 fOverColor (-1),
54
55 fNBins(0), fCAMin(0), fCAMax(0), fColorArray(0)
56{
57 SetLimits(0, 1024);
58 SetMinMax(0, 512);
59
62 SetOverColor(2);
63}
64
65////////////////////////////////////////////////////////////////////////////////
66/// Constructor.
67
69 Bool_t showdef, Bool_t fixcolrng) :
70 TObject(),
71 REveRefCnt(),
72
73 fUIf(1), fUIc(0),
74
75 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0),
76
77 fUIDoubleRep (kFALSE),
78 fInterpolate (interp),
79 fShowDefValue (showdef),
80 fFixColorRange (fixcolrng),
81 fUnderflowAction (kLA_Cut),
82 fOverflowAction (kLA_Clip),
83
84 fDefaultColor(-1),
85 fUnderColor (-1),
86 fOverColor (-1),
87
88 fNBins(0), fCAMin(0), fCAMax(0), fColorArray(0)
89{
90 SetLimits(min, max);
91 SetMinMax(min, max);
92
95 SetOverColor(2);
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// Destructor.
100
102{
103 delete [] fColorArray;
104}
105
106////////////////////////////////////////////////////////////////////////////////
107/// Set RGBA color 'pixel' for signal-value 'val'.
108
110{
111 using namespace TMath;
112 Float_t div = Max(1, fCAMax - fCAMin);
114
115 Float_t f;
116 if (val >= fCAMax) f = nCol - 1;
117 else if (val <= fCAMin) f = 0;
118 else f = (val - fCAMin)/div*(nCol - 1);
119
120 if (fInterpolate) {
121 Int_t bin = (Int_t) f;
122 Float_t f2 = f - bin, f1 = 1.0f - f2;
124 f2, gStyle->GetColorPalette(Min(bin + 1, nCol - 1)),
125 pixel);
126 } else {
128 }
129}
130
131////////////////////////////////////////////////////////////////////////////////
132/// Construct internal color array that maps signal value to RGBA color.
133
135{
136 if (fColorArray)
137 delete [] fColorArray;
138
139 if (fFixColorRange) {
141 } else {
143 }
144 fNBins = fCAMax - fCAMin + 1;
145
146 fColorArray = new UChar_t [4 * fNBins];
147 UChar_t* p = fColorArray;
148 for(Int_t v = fCAMin; v <= fCAMax; ++v, p+=4)
149 SetupColor(v, p);
150}
151
152////////////////////////////////////////////////////////////////////////////////
153/// Clear internal color array.
154
156{
157 if (fColorArray) {
158 delete [] fColorArray;
159 fColorArray = 0;
160 fNBins = fCAMin = fCAMax = 0;
161 }
162}
163
164////////////////////////////////////////////////////////////////////////////////
165/// Set low/high limits on signal value. Current min/max values are
166/// clamped into the new limits.
167
169{
170 fLowLimit = low;
171 fHighLimit = high;
172
177
179}
180
181////////////////////////////////////////////////////////////////////////////////
182/// Set low/high limits and rescale current min/max values.
183
185{
186 Float_t rng_old = fHighLimit - fLowLimit;
187 Float_t rng_new = high - low;
188
189 fMinVal = TMath::Nint(low + (fMinVal - fLowLimit)*rng_new/rng_old);
190 fMaxVal = TMath::Nint(low + (fMaxVal - fLowLimit)*rng_new/rng_old);
191 fLowLimit = low;
192 fHighLimit = high;
193
195}
196
197////////////////////////////////////////////////////////////////////////////////
198/// Set current min value.
199
201{
202 fMinVal = TMath::Min(min, fMaxVal);
204}
205
206////////////////////////////////////////////////////////////////////////////////
207/// Set current max value.
208
210{
211 fMaxVal = TMath::Max(max, fMinVal);
213}
214
215////////////////////////////////////////////////////////////////////////////////
216/// Set current min/max values.
217
219{
220 fMinVal = min;
221 fMaxVal = max;
223}
224
225////////////////////////////////////////////////////////////////////////////////
226/// Set flag determining whether GUI editor and overlays should show limits
227/// and axis values as real values with mapping from integer value i to real
228/// value d as: d = f*i + fc
229
231{
232 fUIDoubleRep = b;
233 if (fUIDoubleRep) {
234 fUIf = f; fUIc = c;
235 } else {
236 fUIf = 1; fUIc = 0;
237 }
238}
239
240////////////////////////////////////////////////////////////////////////////////
241/// Set interpolation flag. This determines how colors from ROOT's
242/// palette are mapped into RGBA values for given signal.
243
245{
246 fInterpolate = b;
248}
249
250////////////////////////////////////////////////////////////////////////////////
251/// Set flag specifying how the palette is mapped to signal values:
252/// true - LowLimit -> HighLimit
253/// false - MinValue -> MaxValue
254
256{
259}
260
261////////////////////////////////////////////////////////////////////////////////
262/// Set default color.
263
265{
266 fDefaultColor = ci;
268}
269
270////////////////////////////////////////////////////////////////////////////////
271/// Set default color.
272
274{
276}
277
278////////////////////////////////////////////////////////////////////////////////
279/// Set default color.
280
282{
284 fDefaultRGBA[0] = r;
285 fDefaultRGBA[1] = g;
286 fDefaultRGBA[2] = b;
287 fDefaultRGBA[3] = a;
288}
289
290////////////////////////////////////////////////////////////////////////////////
291/// Set underflow color.
292
294{
295 fUnderColor = ci;
297}
298
299////////////////////////////////////////////////////////////////////////////////
300/// Set underflow color.
301
303{
305}
306
307////////////////////////////////////////////////////////////////////////////////
308/// Set underflow color.
309
311{
313 fUnderRGBA[0] = r;
314 fUnderRGBA[1] = g;
315 fUnderRGBA[2] = b;
316 fUnderRGBA[3] = a;
317}
318
319////////////////////////////////////////////////////////////////////////////////
320/// Set overflow color.
321
323{
324 fOverColor = ci;
326}
327
328////////////////////////////////////////////////////////////////////////////////
329/// Set overflow color.
330
332{
334}
335
336////////////////////////////////////////////////////////////////////////////////
337/// Set overflow color.
338
340{
342 fOverRGBA[0] = r;
343 fOverRGBA[1] = g;
344 fOverRGBA[2] = b;
345 fOverRGBA[3] = a;
346}
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
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
Definition RtypesCore.h:45
unsigned char UChar_t
Definition RtypesCore.h:38
const Bool_t kFALSE
Definition RtypesCore.h:92
short Color_t
Definition RtypesCore.h:83
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassImp(name)
Definition Rtypes.h:364
R__EXTERN TStyle * gStyle
Definition TStyle.h:412
void SetMinMax(Int_t min, Int_t max)
Set current min/max values.
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...
void SetupColorArray() const
Construct internal color array that maps signal value to RGBA color.
void SetMin(Int_t min)
Set current min value.
void ClearColorArray()
Clear internal color array.
void SetDefaultColorPixel(Pixel_t pix)
Set default color.
void SetUnderColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255)
Set underflow color.
void SetDefaultColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255)
Set default color.
void SetLimitsScaleMinMax(Int_t low, Int_t high)
Set low/high limits and rescale current min/max values.
void SetMax(Int_t max)
Set current max value.
void SetLimits(Int_t low, Int_t high)
Set low/high limits on signal value.
void SetUnderColorPixel(Pixel_t pix)
Set underflow color.
void SetInterpolate(Bool_t b)
Set interpolation flag.
void SetOverColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255)
Set overflow color.
void SetFixColorRange(Bool_t v)
Set flag specifying how the palette is mapped to signal values: true - LowLimit -> HighLimit false - ...
void SetUnderColor(Color_t ci)
Set underflow color.
void SetDefaultColor(Color_t ci)
Set default color.
void SetupColor(Int_t val, UChar_t *pix) const
Set RGBA color 'pixel' for signal-value 'val'.
void SetOverColor(Color_t ci)
Set overflow color.
void SetOverColorPixel(Pixel_t pix)
Set overflow color.
REveRefCnt REveRefCnt base-class (interface)
Definition REveUtil.hxx:107
static void ColorFromIdx(Color_t ci, UChar_t col[4], Bool_t alpha=kTRUE)
Fill col with RGBA values corresponding to index ci.
Definition REveUtil.cxx:122
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:1769
Mother of all ROOT objects.
Definition TObject.h:37
Int_t GetColorPalette(Int_t i) const
Return color number i in current palette.
Definition TStyle.cxx:1056
Int_t GetNumberOfColors() const
Return number of colors in the color palette.
Definition TStyle.cxx:1122
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:713
Short_t Max(Short_t a, Short_t b)
Definition TMathBase.h:212
Short_t Min(Short_t a, Short_t b)
Definition TMathBase.h:180