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#include <nlohmann/json.hpp>
18
19
20using namespace ROOT::Experimental;
21
22/** \class REveRGBAPalette
23\ingroup REve
24A generic, speed-optimised mapping from value to RGBA color
25supporting different wrapping and range truncation modes.
26
27Flag fFixColorRange: specifies how the palette is mapped to signal values:
28 - true - LowLimit -> HighLimit
29 - false - MinValue -> MaxValue
30*/
31
33
34////////////////////////////////////////////////////////////////////////////////
35/// Constructor.
36
37REveRGBAPalette::REveRGBAPalette() :
38 REveElement("RGBAPalette", "Palette"),
39 REveRefCnt(),
40
41 fUIf(1), fUIc(0),
42
43 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0),
44
45 fUIDoubleRep (kFALSE),
46 fInterpolate (kTRUE),
47 fShowDefValue (kTRUE),
48 fFixColorRange (kFALSE),
49 fUnderflowAction (kLA_Cut),
50 fOverflowAction (kLA_Clip),
51
52 fDefaultColor(-1),
53 fUnderColor (-1),
54 fOverColor (-1),
55
56 fNBins(0), fCAMin(0), fCAMax(0), fColorArray(nullptr)
57{
58 SetLimits(0, 1024);
59 SetMinMax(0, 512);
60
63 SetOverColor(2);
64}
65
66////////////////////////////////////////////////////////////////////////////////
67/// Constructor.
68
70 Bool_t showdef, Bool_t fixcolrng) :
71 REveElement("RGBAPalette", "Palette"),
72 REveRefCnt(),
73
74 fUIf(1), fUIc(0),
75
76 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0),
77
78 fUIDoubleRep (kFALSE),
79 fInterpolate (interp),
80 fShowDefValue (showdef),
81 fFixColorRange (fixcolrng),
82 fUnderflowAction (kLA_Cut),
83 fOverflowAction (kLA_Clip),
84
85 fDefaultColor(-1),
86 fUnderColor (-1),
87 fOverColor (-1),
88
89 fNBins(0), fCAMin(0), fCAMax(0), fColorArray(nullptr)
90{
91 SetLimits(min, max);
92 SetMinMax(min, max);
93
96 SetOverColor(2);
97}
98
99////////////////////////////////////////////////////////////////////////////////
100/// Destructor.
101
103{
104 delete [] fColorArray;
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// Set RGBA color 'pixel' for signal-value 'val'.
109
111{
112 using namespace TMath;
113 Float_t div = Max(1, fCAMax - fCAMin);
115
116 Float_t f;
117 if (val >= fCAMax) f = nCol - 1;
118 else if (val <= fCAMin) f = 0;
119 else f = (val - fCAMin)/div*(nCol - 1);
120
121 if (fInterpolate) {
122 Int_t bin = (Int_t) f;
123 Float_t f2 = f - bin, f1 = 1.0f - f2;
125 f2, gStyle->GetColorPalette(Min(bin + 1, nCol - 1)),
126 pixel);
127 } else {
129 }
130}
131
132////////////////////////////////////////////////////////////////////////////////
133/// Construct internal color array that maps signal value to RGBA color.
134
136{
137 if (fColorArray)
138 delete [] fColorArray;
139
140 if (fFixColorRange) {
142 } else {
144 }
145 fNBins = fCAMax - fCAMin + 1;
146
147 fColorArray = new UChar_t [4 * fNBins];
149 for(Int_t v = fCAMin; v <= fCAMax; ++v, p+=4)
150 SetupColor(v, p);
151}
152
153////////////////////////////////////////////////////////////////////////////////
154/// Clear internal color array.
155
157{
158 if (fColorArray) {
159 delete [] fColorArray;
160 fColorArray = nullptr;
161 fNBins = fCAMin = fCAMax = 0;
162 }
163
164 StampNieces();
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// Set low/high limits on signal value. Current min/max values are
169/// clamped into the new limits.
170
172{
173 fLowLimit = low;
174 fHighLimit = high;
175
180
182}
183
184////////////////////////////////////////////////////////////////////////////////
185/// Set low/high limits and rescale current min/max values.
186
188{
189 Float_t rng_old = fHighLimit - fLowLimit;
190 Float_t rng_new = high - low;
191
192 fMinVal = TMath::Nint(low + (fMinVal - fLowLimit)*rng_new/rng_old);
193 fMaxVal = TMath::Nint(low + (fMaxVal - fLowLimit)*rng_new/rng_old);
194 fLowLimit = low;
195 fHighLimit = high;
196
198}
199
200////////////////////////////////////////////////////////////////////////////////
201/// Set current min value.
202
204{
205 fMinVal = TMath::Min(min, fMaxVal);
207}
208
209////////////////////////////////////////////////////////////////////////////////
210/// Set current max value.
211
213{
214 fMaxVal = TMath::Max(max, fMinVal);
216}
217
218////////////////////////////////////////////////////////////////////////////////
219/// Set current min/max values.
220
222{
223 fMinVal = min;
224 fMaxVal = max;
226}
227
228////////////////////////////////////////////////////////////////////////////////
229/// Set flag determining whether GUI editor and overlays should show limits
230/// and axis values as real values with mapping from integer value i to real
231/// value d as: d = f*i + fc
232
234{
235 fUIDoubleRep = b;
236 if (fUIDoubleRep) {
237 fUIf = f; fUIc = c;
238 } else {
239 fUIf = 1; fUIc = 0;
240 }
241}
242
243////////////////////////////////////////////////////////////////////////////////
244/// Set interpolation flag. This determines how colors from ROOT's
245/// palette are mapped into RGBA values for given signal.
246
248{
249 fInterpolate = b;
251}
252
253////////////////////////////////////////////////////////////////////////////////
254/// Set flag specifying how the palette is mapped to signal values:
255/// true - LowLimit -> HighLimit
256/// false - MinValue -> MaxValue
257
259{
262}
263
264////////////////////////////////////////////////////////////////////////////////
265/// Set default color.
266
268{
269 fDefaultColor = ci;
271}
272
273////////////////////////////////////////////////////////////////////////////////
274/// Set default color.
275
277{
279}
280
281////////////////////////////////////////////////////////////////////////////////
282/// Set default color.
283
285{
287 fDefaultRGBA[0] = r;
288 fDefaultRGBA[1] = g;
289 fDefaultRGBA[2] = b;
290 fDefaultRGBA[3] = a;
291}
292
293////////////////////////////////////////////////////////////////////////////////
294/// Set underflow color.
295
297{
298 fUnderColor = ci;
300}
301
302////////////////////////////////////////////////////////////////////////////////
303/// Set underflow color.
304
306{
308}
309
310////////////////////////////////////////////////////////////////////////////////
311/// Set underflow color.
312
314{
316 fUnderRGBA[0] = r;
317 fUnderRGBA[1] = g;
318 fUnderRGBA[2] = b;
319 fUnderRGBA[3] = a;
320 StampNieces();
322}
323
324////////////////////////////////////////////////////////////////////////////////
325/// Set overflow color.
326
328{
329 fOverColor = ci;
331}
332
333////////////////////////////////////////////////////////////////////////////////
334/// Set overflow color.
335
337{
339}
340
341////////////////////////////////////////////////////////////////////////////////
342/// Set overflow color.
343
345{
347 fOverRGBA[0] = r;
348 fOverRGBA[1] = g;
349 fOverRGBA[2] = b;
350 fOverRGBA[3] = a;
351 StampNieces();
353}
354
355
356////////////////////////////////////////////////////////////////////////////////
357// Prepare streaming information
358//
359Int_t REveRGBAPalette::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
360{
361 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
362 j["oAction"] = fOverflowAction;
363 j["uAction"] = fUnderflowAction;
364 j["oColor"] = fOverColor;
365 j["uColor"] = fUnderColor;
366 j["fixRng"] = fFixColorRange;
367 j["lowLimit"] = fLowLimit;
368 j["highLimit"] = fHighLimit;
369 j["interpolate"] = fInterpolate;
370 j["min"] = fMinVal;
371 j["max"] = fMaxVal;
372 return ret;
373}
374
375
376////////////////////////////////////////////////////////////////////////////////
377// Notifiy dependent
378//
380{
381 for (auto &c : fNieces)
382 {
383 c->AddStamp(REveElement::kCBObjProps);
384 }
385}
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:85
unsigned char UChar_t
Definition RtypesCore.h:38
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
#define ClassImp(name)
Definition Rtypes.h:382
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:436
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
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 - ...
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Write core json.
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:106
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:138
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:1920
Int_t GetColorPalette(Int_t i) const
Return color number i in current palette.
Definition TStyle.cxx:1101
Int_t GetNumberOfColors() const
Return number of colors in the color palette.
Definition TStyle.cxx:1175
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