Logo ROOT   6.10/09
Reference Guide
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
20 A generic, speed-optimised mapping from value to RGBA color
21 supporting different wrapping and range truncation modes.
22 
23 Flag 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(0)
53 {
54  SetLimits(0, 1024);
55  SetMinMax(0, 512);
56 
57  SetDefaultColor(0);
58  SetUnderColor(1);
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 
75  fInterpolate (interp),
76  fShowDefValue (showdef),
77  fFixColorRange (fixcolrng),
80 
81  fDefaultColor(-1),
82  fUnderColor (-1),
83  fOverColor (-1),
84 
85  fNBins(0), fCAMin(0), fCAMax(0), fColorArray(0)
86 {
87  SetLimits(min, max);
88  SetMinMax(min, max);
89 
90  SetDefaultColor(0);
91  SetUnderColor(1);
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);
110  Int_t nCol = gStyle->GetNumberOfColors();
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];
144  UChar_t* p = fColorArray;
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 = 0;
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 
175  ClearColorArray();
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 
191  ClearColorArray();
192 }
193 
194 ////////////////////////////////////////////////////////////////////////////////
195 /// Set current min value.
196 
198 {
199  fMinVal = TMath::Min(min, fMaxVal);
200  ClearColorArray();
201 }
202 
203 ////////////////////////////////////////////////////////////////////////////////
204 /// Set current max value.
205 
207 {
208  fMaxVal = TMath::Max(max, fMinVal);
209  ClearColorArray();
210 }
211 
212 ////////////////////////////////////////////////////////////////////////////////
213 /// Set current min/max values.
214 
216 {
217  fMinVal = min;
218  fMaxVal = max;
219  ClearColorArray();
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;
244  ClearColorArray();
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 {
254  fFixColorRange = v;
255  ClearColorArray();
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 {
338  fOverColor = Color_t(TColor::GetColor(r, g, b));
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 }
void SetUnderColor(Color_t ci)
Set underflow color.
A generic, speed-optimised mapping from value to RGBA color supporting different wrapping and range t...
float Float_t
Definition: RtypesCore.h:53
void SetUnderColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255)
Set underflow color.
R__EXTERN TStyle * gStyle
Definition: TStyle.h:402
This is the ROOT implementation of the Qt object communication mechanism (see also http://www...
Definition: TQObject.h:49
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:168
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
void SetOverColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255)
Set overflow color.
void ClearColorArray()
Clear internal color array.
void SetFixColorRange(Bool_t v)
Set flag specifying how the palette is mapped to signal values: true - LowLimit -> HighLimit false - ...
ULong_t Pixel_t
Definition: GuiTypes.h:39
UChar_t fOverRGBA[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.
Int_t GetColorPalette(Int_t i) const
Return color number i in current palette.
Definition: TStyle.cxx:735
short Color_t
Definition: RtypesCore.h:79
void SetupColorArray() const
Construct internal color array that maps signal value to RGBA color.
void SetDefaultColor(Color_t ci)
Set default color.
void SetMin(Int_t min)
Set current min value.
TRandom2 r(17)
UChar_t * fColorArray
SVector< double, 2 > v
Definition: Dict.h:5
void SetMinMax(Int_t min, Int_t max)
Set current min/max values.
Double_t Nint(Double_t x)
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:1707
Base-class for reference-counted objects.
Definition: TEveUtil.h:163
void SetMax(Int_t max)
Set current max value.
void SetOverColor(Color_t ci)
Set overflow color.
Int_t GetNumberOfColors() const
Return number of colors in the color palette.
Definition: TStyle.cxx:801
const Bool_t kFALSE
Definition: RtypesCore.h:92
#define ClassImp(name)
Definition: Rtypes.h:336
double f(double x)
double Double_t
Definition: RtypesCore.h:55
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...
Mother of all ROOT objects.
Definition: TObject.h:37
void SetInterpolate(Bool_t b)
Set interpolation flag.
TEveRGBAPalette()
Constructor.
void SetDefaultColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255)
Set default color.
void SetLimits(Int_t low, Int_t high)
Set low/high limits on signal value.
UChar_t fUnderRGBA[4]
double f2(const double *x)
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:192
void SetupColor(Int_t val, UChar_t *pix) const
Set RGBA color &#39;pixel&#39; for signal-value &#39;val&#39;.
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:200
void MinMaxValChanged()
Emit the "MinMaxValChanged()" signal.
TF1 * f1
Definition: legend1.C:11
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
unsigned char UChar_t
Definition: RtypesCore.h:34
UChar_t fDefaultRGBA[4]
void SetOverColorPixel(Pixel_t pix)
Set overflow color.
const Bool_t kTRUE
Definition: RtypesCore.h:91
Int_t Nint(T x)
Definition: TMath.h:607
virtual ~TEveRGBAPalette()
Destructor.
void SetUnderColorPixel(Pixel_t pix)
Set underflow color.