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