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