Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveDigitSet.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 "ROOT/REveDigitSet.hxx"
13#include "ROOT/REveManager.hxx"
14#include "ROOT/REveTrans.hxx"
15
16#include "TRefArray.h"
17
18using namespace::ROOT::Experimental;
19
20/** \class REveDigitSet
21\ingroup REve
22Base-class for storage of digit collections; provides
23transformation matrix (REveTrans), signal to color mapping
24(REveRGBAPalette) and visual grouping (REveFrameBox).
25
26Base-class for displaying a digit collection.
27Provides common services for:
28 - specifying signal / color per digit;
29 - specifying object reference per digit;
30 - controlling palette and thresholds (external object REveRGBAPalette);
31 - showing a frame around the digits (external object REveFrameBox);
32 - specifying transformation matrix for the whole collection;
33 by data-member of class REveTrans.
34
35Use method DigitId(TObject* id) to assign additional identification
36to the last created digit. By calling SetOwnIds(kTRUE) tje
37digit-set becomes the owner of the assigned objects and deletes
38them on destruction.
39Note that TRef is used for referencing the objects and if you
40instantiate the objects just to pass them to digit-set you should
41also call TProcessID::Get/SetObjectCount() at the beginning / end
42of processing of an event. See documentation for class TRef, in
43particular section 'ObjectNumber'.
44
45If you use value-is-color mode and want to use transparency, set
46the transparency to non-zero value so that GL-renderer will be
47properly informed.
48
49If you want to use single color for all elements call:
50~~~ {.cpp}
51 UseSingleColor()
52~~~
53Palette controls will not work in this case.
54
55A pointer to a rectangle / box of class REveFrameBox can be set via
56~~~ {.cpp}
57 void SetFrame(REveFrameBox* b);
58~~~
59A single REveFrameBox can be shared among several digit-sets (it is
60reference-counted). The following flags affect how the frame-box will drawn
61and used for selection and highlight:
62~~~ {.cpp}
63 Bool_t fSelectViaFrame;
64 Bool_t fHighlightFrame;
65~~~
66REveDigitSet is sub-classed from REveSecondarySelectable -- this means
67individual digits can be selected. By calling:
68~~~ {.cpp}
69 REveSecondarySelectable::SetAlwaysSecSelect(kTRUE);
70~~~
71one can enforce immediate feedback (highlight, tooltip and select on normal
72left-mouse click) on given digit-set.
73
74See also:
75~~~ {.cpp}
76 REveQuadSet: rectangle, hexagon or line per digit
77 REveBoxSet a 3D box per digit
78~~~
79*/
80
81////////////////////////////////////////////////////////////////////////////////
82
83REveDigitSet::REveDigitSet(const char* n, const char* t) :
84 REveElement (n, t),
85
86 fDefaultValue (kMinInt),
87 fValueIsColor (kFALSE),
88 fSingleColor (kFALSE),
89 fAntiFlick (kTRUE),
90 fDetIdsAsSecondaryIndices (kFALSE),
91 fPlex (),
92 fLastDigit (0),
93 fLastIdx (-1),
94
95 fColor (kWhite),
96 fFrame (0),
97 fPalette (0),
98 fRenderMode (kRM_AsIs),
99 fSelectViaFrame (kFALSE),
100 fHighlightFrame (kFALSE),
101 fDisableLighting(kTRUE),
102 fHistoButtons (kTRUE),
103 fEmitSignals (kFALSE),
104 fCallbackFoo (0),
105 fTooltipCBFoo (0)
106{
107 // Constructor.
108
112}
113
114////////////////////////////////////////////////////////////////////////////////
115/// Destructor.
116/// Unreference frame and palette. Destroy referenced objects if they
117/// are owned by the REveDigitSet.
118
120{
121 SetFrame(0);
122 SetPalette(0);
124 ReleaseIds();
125}
126
127////////////////////////////////////////////////////////////////////////////////
128/// Protected method called whenever a new digit is added.
129
131{
132 fLastIdx = fPlex.Size();
134 return fLastDigit;
135}
136
137////////////////////////////////////////////////////////////////////////////////
138/// Protected method. Release and delete the referenced objects, the
139/// ownership is *NOT* checked.
140
142{
143 fDigitIds.clear();
144}
145
146////////////////////////////////////////////////////////////////////////////////
147/// Instruct digit-set to use single color for its digits.
148/// Call SetMainColor/Transparency to initialize it.
149
151{
153}
154
155////////////////////////////////////////////////////////////////////////////////
156/// Override from REveElement, forward to Frame.
157
159{
160 if (fSingleColor)
161 {
163 }
164 else if (fFrame)
165 {
166 fFrame->SetFrameColor(color);
168 }
169}
170
171/*
172////////////////////////////////////////////////////////////////////////////////
173/// Virtual function called when both fSelected is false and
174/// fImpliedSelected is 0.
175
176void REveDigitSet::UnSelected()
177{
178 fSelectedSet.clear();
179 REveElement::UnSelected();
180}
181
182////////////////////////////////////////////////////////////////////////////////
183/// Virtual function called when both fHighlighted is false and
184/// fImpliedHighlighted is 0.
185
186void REveDigitSet::UnHighlighted()
187{
188 fHighlightedSet.clear();
189 REveElement::UnHighlighted();
190}
191
192////////////////////////////////////////////////////////////////////////////////
193/// Return tooltip for highlighted element if always-sec-select is set.
194/// Otherwise return the tooltip for this element.
195
196TString REveDigitSet::GetHighlightTooltip()
197{
198 if (fHighlightedSet.empty()) return "";
199
200 if (GetAlwaysSecSelect())
201 {
202 if (fTooltipCBFoo)
203 {
204 return (fTooltipCBFoo)(this, *fHighlightedSet.begin());
205 }
206 else if (fDigitIds)
207 {
208 TObject *o = GetId(*fHighlightedSet.begin());
209 if (o)
210 return TString(o->GetName());
211 }
212 return TString::Format("%s; idx=%d", GetElementName(), *fHighlightedSet.begin());
213 }
214 else
215 {
216 return REveElement::GetHighlightTooltip();
217 }
218}
219*/
220////////////////////////////////////////////////////////////////////////////////
221/// Instruct underlying memory allocator to regroup itself into a
222/// contiguous memory chunk.
223
225{
226 fPlex.Refit();
227}
228
229////////////////////////////////////////////////////////////////////////////////
230/// Iterate over the digits and determine min and max signal values.
231
233{
234 if (fValueIsColor || fPlex.Size() == 0)
235 {
236 min = max = 0;
237 return;
238 }
239
240 min = kMaxInt;
241 max = kMinInt;
242 for (Int_t c=0; c<fPlex.VecSize(); ++c)
243 {
244 Char_t* a = fPlex.Chunk(c);
245 Int_t n = fPlex.NAtoms(c);
246 while (n--)
247 {
248 Int_t v = ((DigitBase_t*)a)->fValue;
249 if (v < min) min = v;
250 if (v > max) max = v;
251 a += fPlex.S();
252 }
253 }
254 if (min == max)
255 --min;
256}
257
258////////////////////////////////////////////////////////////////////////////////
259/// Set current digit -- the one that will receive calls to
260/// DigitValue/Color/Id/UserData() functions.
261/// Note that various AddXyzz() functions set the current digit to the newly
262/// added one.
263
265{
266 fLastIdx = idx;
267 fLastDigit = GetDigit(idx);
268}
269
270////////////////////////////////////////////////////////////////////////////////
271/// Set signal value for the last digit added.
272
274{
275 fLastDigit->fValue = value;
276}
277
278////////////////////////////////////////////////////////////////////////////////
279/// Set color for the last digit added.
280
282{
284}
285
286////////////////////////////////////////////////////////////////////////////////
287/// Set color for the last digit added.
288
290{
291 REveUtil::ColorFromIdx(ci, (UChar_t*) & fLastDigit->fValue, transparency);
292}
293
294////////////////////////////////////////////////////////////////////////////////
295/// Set color for the last digit added.
296
298{
300 x[0] = r; x[1] = g; x[2] = b; x[3] = a;
301}
302
303////////////////////////////////////////////////////////////////////////////////
304/// Set color for the last digit added.
305
307{
309 x[0] = rgba[0]; x[1] = rgba[1]; x[2] = rgba[2]; x[3] = rgba[3];
310}
311
312
313////////////////////////////////////////////////////////////////////////////////
314/// Set external id for the last added digit.
315
317{
318 fDigitIds.push_back(n);
319}
320
321////////////////////////////////////////////////////////////////////////////////
322/// Set external object reference for digit n.
323
325{
326 return fDigitIds[n];
327}
328
329/*
330////////////////////////////////////////////////////////////////////////////////
331/// Paint this object. Only direct rendering is supported.
332
333void REveDigitSet::Paint(Option_t*)
334{
335 PaintStandard(this);
336}
337
338////////////////////////////////////////////////////////////////////////////////
339/// Called from renderer when a digit with index idx is selected.
340/// This is by-passed when always-secondary-select is active.
341
342void REveDigitSet::DigitSelected(Int_t idx)
343{
344 DigitBase_t *qb = GetDigit(idx);
345 TObject *obj = GetId(idx);
346
347 if (fCallbackFoo) {
348 (fCallbackFoo)(this, idx, obj);
349 }
350 if (fEmitSignals) {
351 SecSelected(this, idx);
352 } else {
353 printf("REveDigitSet::DigitSelected idx=%d, value=%d, obj=0x%lx\n",
354 idx, qb->fValue, (ULong_t)obj);
355 if (obj)
356 obj->Print();
357 }
358}
359
360////////////////////////////////////////////////////////////////////////////////
361/// Emit a SecSelected signal.
362/// This is by-passed when always-secondary-select is active.
363
364void REveDigitSet::SecSelected(REveDigitSet* qs, Int_t idx)
365{
366 Long_t args[2];
367 args[0] = (Long_t) qs;
368 args[1] = (Long_t) idx;
369
370 // Emit("SecSelected(REveDigitSet*, Int_t)", args);
371}
372
373*/
374////////////////////////////////////////////////////////////////////////////////
375/// Set REveFrameBox pointer.
376
378{
379 if (fFrame == b) return;
380 if (fFrame) fFrame->DecRefCount(this);
381 fFrame = b;
382 if (fFrame) {
383 fFrame->IncRefCount(this);
384 if (!fSingleColor) {
386 }
387 } else {
389 }
390}
391
392////////////////////////////////////////////////////////////////////////////////
393/// Set REveRGBAPalette pointer.
394
396{
397 if (fPalette == p) return;
399 fPalette = p;
401}
402
403////////////////////////////////////////////////////////////////////////////////
404/// Make sure the REveRGBAPalette pointer is not null.
405/// If it is not set, a new one is instantiated and the range is set
406/// to current min/max signal values.
407
409{
410 if (fPalette == 0) {
412 if (!fValueIsColor) {
413 Int_t min, max;
414 ScanMinMaxValues(min, max);
415 fPalette->SetLimits(min, max);
416 fPalette->SetMinMax(min, max);
417 }
418 }
419 return fPalette;
420}
421
422////////////////////////////////////////////////////////////////////////////////
423/// Fill core part of JSON representation.
424
425Int_t REveDigitSet::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
426{
427 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
428
429 j["fSingleColor"] = fSingleColor;
430 j["fAntiFlick"] = GetAntiFlick();
431 j["fSecondarySelect"] = fAlwaysSecSelect;
432 j["fDetIdsAsSecondaryIndices"] = fDetIdsAsSecondaryIndices;
433
434 return ret;
435}
ROOT::R::TRInterface & r
Definition Object.C:4
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define g(i)
Definition RSha256.hxx:105
#define a(i)
Definition RSha256.hxx:99
const Int_t kMinInt
Definition RtypesCore.h:104
const Int_t kMaxInt
Definition RtypesCore.h:103
unsigned char UChar_t
Definition RtypesCore.h:38
char Char_t
Definition RtypesCore.h:37
const Bool_t kFALSE
Definition RtypesCore.h:92
short Color_t
Definition RtypesCore.h:83
const Bool_t kTRUE
Definition RtypesCore.h:91
@ kWhite
Definition Rtypes.h:65
void Refit()
Refit the container so that all current data fits into a single chunk.
virtual void SetMainColor(Color_t color) override
Override from REveElement, forward to Frame.
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Fill core part of JSON representation.
void DigitId(Int_t n)
Set external id for the last added digit.
void SetPalette(REveRGBAPalette *p)
Set REveRGBAPalette pointer.
REveRGBAPalette * AssertPalette()
Make sure the REveRGBAPalette pointer is not null.
Color_t fColor
The last / current idx added to collection.
DigitBase_t * NewDigit()
Function providing highlight tooltips when always-sec-select is active.
void DigitColor(Color_t ci)
Set color for the last digit added.
void SetCurrentDigit(Int_t idx)
Set current digit – the one that will receive calls to DigitValue/Color/Id/UserData() functions.
void ScanMinMaxValues(Int_t &min, Int_t &max)
Iterate over the digits and determine min and max signal values.
void UseSingleColor()
Instruct digit-set to use single color for its digits.
Int_t GetId(Int_t n) const
Set external object reference for digit n.
void RefitPlex()
Instruct underlying memory allocator to regroup itself into a contiguous memory chunk.
virtual ~REveDigitSet()
Destructor.
DigitBase_t * GetDigit(Int_t n) const
Int_t fLastIdx
The last / current digit added to collection.
void ReleaseIds()
Protected method.
void DigitValue(Int_t value)
Set signal value for the last digit added.
void SetFrame(REveFrameBox *b)
Set REveFrameBox pointer.
void SetMainColorPtr(Color_t *colptr)
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
virtual void InitMainTrans(Bool_t can_edit=kTRUE)
Initialize the main transformation to identity matrix.
virtual void SetMainColor(Color_t color)
Set main color of the element.
void SetFrameColor(Color_t ci)
Set color of the frame.
void SetMinMax(Int_t min, Int_t max)
Set current min/max values.
void SetLimits(Int_t low, Int_t high)
Set low/high limits on signal value.
virtual void IncRefCount(REveElement *re)
Increase reference count and add re to the list of back-references.
Definition REveUtil.cxx:430
virtual void DecRefCount(REveElement *re)
Decrease reference count and remove re from the list of back-references.
Definition REveUtil.cxx:439
virtual void StampBackPtrElements(UChar_t stamps)
Add given stamps to elements in the list of reverse references.
Definition REveUtil.cxx:454
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
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16