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
32
33////////////////////////////////////////////////////////////////////////////////
34/// Constructor.
35
36REveRGBAPalette::REveRGBAPalette() :
37 REveElement("RGBAPalette", "Palette"),
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(nullptr)
56{
57 SetLimits(0, 1024);
58 SetMinMax(0, 512);
59
62 SetOverColor(2);
63}
64
65////////////////////////////////////////////////////////////////////////////////
66/// Constructor.
67
70 REveElement("RGBAPalette", "Palette"),
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(nullptr)
89{
90 SetLimits(min, max);
91 SetMinMax(min, max);
92
95 SetOverColor(2);
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// Destructor.
100
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];
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 = nullptr;
160 fNBins = fCAMin = fCAMax = 0;
161 }
162
163 StampNieces();
164}
165
166////////////////////////////////////////////////////////////////////////////////
167/// Set low/high limits on signal value. Current min/max values are
168/// clamped into the new limits.
169
171{
172 fLowLimit = low;
173 fHighLimit = high;
174
179
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// Set low/high limits and rescale current min/max values.
185
198
199////////////////////////////////////////////////////////////////////////////////
200/// Set current min value.
201
207
208////////////////////////////////////////////////////////////////////////////////
209/// Set current max value.
210
216
217////////////////////////////////////////////////////////////////////////////////
218/// Set current min/max values.
219
221{
222 fMinVal = min;
223 fMaxVal = max;
225}
226
227////////////////////////////////////////////////////////////////////////////////
228/// Set flag determining whether GUI editor and overlays should show limits
229/// and axis values as real values with mapping from integer value i to real
230/// value d as: d = f*i + fc
231
233{
234 fUIDoubleRep = b;
235 if (fUIDoubleRep) {
236 fUIf = f; fUIc = c;
237 } else {
238 fUIf = 1; fUIc = 0;
239 }
240}
241
242////////////////////////////////////////////////////////////////////////////////
243/// Set interpolation flag. This determines how colors from ROOT's
244/// palette are mapped into RGBA values for given signal.
245
251
252////////////////////////////////////////////////////////////////////////////////
253/// Set flag specifying how the palette is mapped to signal values:
254/// true - LowLimit -> HighLimit
255/// false - MinValue -> MaxValue
256
262
263////////////////////////////////////////////////////////////////////////////////
264/// Set default color.
265
271
272////////////////////////////////////////////////////////////////////////////////
273/// Set default color.
274
279
280////////////////////////////////////////////////////////////////////////////////
281/// Set default color.
282
291
292////////////////////////////////////////////////////////////////////////////////
293/// Set underflow color.
294
300
301////////////////////////////////////////////////////////////////////////////////
302/// Set underflow color.
303
308
309////////////////////////////////////////////////////////////////////////////////
310/// Set underflow color.
311
322
323////////////////////////////////////////////////////////////////////////////////
324/// Set overflow color.
325
331
332////////////////////////////////////////////////////////////////////////////////
333/// Set overflow color.
334
339
340////////////////////////////////////////////////////////////////////////////////
341/// Set overflow color.
342
353
354
355////////////////////////////////////////////////////////////////////////////////
356// Prepare streaming information
357//
359{
361 j["oAction"] = fOverflowAction;
362 j["uAction"] = fUnderflowAction;
363 j["oColor"] = fOverColor;
364 j["uColor"] = fUnderColor;
365 j["fixRng"] = fFixColorRange;
366 j["lowLimit"] = fLowLimit;
367 j["highLimit"] = fHighLimit;
368 j["interpolate"] = fInterpolate;
369 j["min"] = fMinVal;
370 j["max"] = fMaxVal;
371 return ret;
372}
373
374
375////////////////////////////////////////////////////////////////////////////////
376// Notifiy dependent
377//
379{
380 for (auto &c : fNieces)
381 {
382 c->AddStamp(REveElement::kCBObjProps);
383 }
384}
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
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
short Color_t
Color number (short)
Definition RtypesCore.h:99
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char)
Definition RtypesCore.h:52
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:442
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:1926
Int_t GetColorPalette(Int_t i) const
Return color number i in current palette.
Definition TStyle.cxx:1102
Int_t GetNumberOfColors() const
Return number of colors in the color palette.
Definition TStyle.cxx:1176
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:251
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:199