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 REveRefCnt(),
38
39 fUIf(1), fUIc(0),
40
41 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0),
42
43 fUIDoubleRep (kFALSE),
44 fInterpolate (kTRUE),
45 fShowDefValue (kTRUE),
46 fFixColorRange (kFALSE),
47 fUnderflowAction (kLA_Cut),
48 fOverflowAction (kLA_Clip),
49
50 fDefaultColor(-1),
51 fUnderColor (-1),
52 fOverColor (-1),
53
54 fNBins(0), fCAMin(0), fCAMax(0), fColorArray(0)
55{
56 SetLimits(0, 1024);
57 SetMinMax(0, 512);
58
61 SetOverColor(2);
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// Constructor.
66
68 Bool_t showdef, Bool_t fixcolrng) :
69 REveRefCnt(),
70
71 fUIf(1), fUIc(0),
72
73 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0),
74
75 fUIDoubleRep (kFALSE),
76 fInterpolate (interp),
77 fShowDefValue (showdef),
78 fFixColorRange (fixcolrng),
79 fUnderflowAction (kLA_Cut),
80 fOverflowAction (kLA_Clip),
81
82 fDefaultColor(-1),
83 fUnderColor (-1),
84 fOverColor (-1),
85
86 fNBins(0), fCAMin(0), fCAMax(0), fColorArray(0)
87{
88 SetLimits(min, max);
89 SetMinMax(min, max);
90
93 SetOverColor(2);
94}
95
96////////////////////////////////////////////////////////////////////////////////
97/// Destructor.
98
100{
101 delete [] fColorArray;
102}
103
104////////////////////////////////////////////////////////////////////////////////
105/// Set RGBA color 'pixel' for signal-value 'val'.
106
108{
109 using namespace TMath;
110 Float_t div = Max(1, fCAMax - fCAMin);
112
113 Float_t f;
114 if (val >= fCAMax) f = nCol - 1;
115 else if (val <= fCAMin) f = 0;
116 else f = (val - fCAMin)/div*(nCol - 1);
117
118 if (fInterpolate) {
119 Int_t bin = (Int_t) f;
120 Float_t f2 = f - bin, f1 = 1.0f - f2;
122 f2, gStyle->GetColorPalette(Min(bin + 1, nCol - 1)),
123 pixel);
124 } else {
126 }
127}
128
129////////////////////////////////////////////////////////////////////////////////
130/// Construct internal color array that maps signal value to RGBA color.
131
133{
134 if (fColorArray)
135 delete [] fColorArray;
136
137 if (fFixColorRange) {
139 } else {
141 }
142 fNBins = fCAMax - fCAMin + 1;
143
144 fColorArray = new UChar_t [4 * fNBins];
146 for(Int_t v = fCAMin; v <= fCAMax; ++v, p+=4)
147 SetupColor(v, p);
148}
149
150////////////////////////////////////////////////////////////////////////////////
151/// Clear internal color array.
152
154{
155 if (fColorArray) {
156 delete [] fColorArray;
157 fColorArray = 0;
158 fNBins = fCAMin = fCAMax = 0;
159 }
160}
161
162////////////////////////////////////////////////////////////////////////////////
163/// Set low/high limits on signal value. Current min/max values are
164/// clamped into the new limits.
165
167{
168 fLowLimit = low;
169 fHighLimit = high;
170
175
177}
178
179////////////////////////////////////////////////////////////////////////////////
180/// Set low/high limits and rescale current min/max values.
181
183{
184 Float_t rng_old = fHighLimit - fLowLimit;
185 Float_t rng_new = high - low;
186
187 fMinVal = TMath::Nint(low + (fMinVal - fLowLimit)*rng_new/rng_old);
188 fMaxVal = TMath::Nint(low + (fMaxVal - fLowLimit)*rng_new/rng_old);
189 fLowLimit = low;
190 fHighLimit = high;
191
193}
194
195////////////////////////////////////////////////////////////////////////////////
196/// Set current min value.
197
199{
200 fMinVal = TMath::Min(min, fMaxVal);
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// Set current max value.
206
208{
209 fMaxVal = TMath::Max(max, fMinVal);
211}
212
213////////////////////////////////////////////////////////////////////////////////
214/// Set current min/max values.
215
217{
218 fMinVal = min;
219 fMaxVal = max;
221}
222
223////////////////////////////////////////////////////////////////////////////////
224/// Set flag determining whether GUI editor and overlays should show limits
225/// and axis values as real values with mapping from integer value i to real
226/// value d as: d = f*i + fc
227
229{
230 fUIDoubleRep = b;
231 if (fUIDoubleRep) {
232 fUIf = f; fUIc = c;
233 } else {
234 fUIf = 1; fUIc = 0;
235 }
236}
237
238////////////////////////////////////////////////////////////////////////////////
239/// Set interpolation flag. This determines how colors from ROOT's
240/// palette are mapped into RGBA values for given signal.
241
243{
244 fInterpolate = b;
246}
247
248////////////////////////////////////////////////////////////////////////////////
249/// Set flag specifying how the palette is mapped to signal values:
250/// true - LowLimit -> HighLimit
251/// false - MinValue -> MaxValue
252
254{
257}
258
259////////////////////////////////////////////////////////////////////////////////
260/// Set default color.
261
263{
264 fDefaultColor = ci;
266}
267
268////////////////////////////////////////////////////////////////////////////////
269/// Set default color.
270
272{
274}
275
276////////////////////////////////////////////////////////////////////////////////
277/// Set default color.
278
280{
282 fDefaultRGBA[0] = r;
283 fDefaultRGBA[1] = g;
284 fDefaultRGBA[2] = b;
285 fDefaultRGBA[3] = a;
286}
287
288////////////////////////////////////////////////////////////////////////////////
289/// Set underflow color.
290
292{
293 fUnderColor = ci;
295}
296
297////////////////////////////////////////////////////////////////////////////////
298/// Set underflow color.
299
301{
303}
304
305////////////////////////////////////////////////////////////////////////////////
306/// Set underflow color.
307
309{
311 fUnderRGBA[0] = r;
312 fUnderRGBA[1] = g;
313 fUnderRGBA[2] = b;
314 fUnderRGBA[3] = a;
315}
316
317////////////////////////////////////////////////////////////////////////////////
318/// Set overflow color.
319
321{
322 fOverColor = ci;
324}
325
326////////////////////////////////////////////////////////////////////////////////
327/// Set overflow color.
328
330{
332}
333
334////////////////////////////////////////////////////////////////////////////////
335/// Set overflow color.
336
338{
340 fOverRGBA[0] = r;
341 fOverRGBA[1] = g;
342 fOverRGBA[2] = b;
343 fOverRGBA[3] = a;
344}
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
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:414
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:103
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:118
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:1823
Int_t GetColorPalette(Int_t i) const
Return color number i in current palette.
Definition TStyle.cxx:1057
Int_t GetNumberOfColors() const
Return number of colors in the color palette.
Definition TStyle.cxx:1123
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:691
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