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"
16
17#include "TRefArray.h"
18
19#include <nlohmann/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 fDefaultValue (kMinInt),
90 fValueIsColor (kFALSE),
91 fSingleColor (kFALSE),
92 fAntiFlick (kTRUE),
93 fDetIdsAsSecondaryIndices (kFALSE),
94 fPlex (),
95 fLastDigit (nullptr),
96 fLastIdx (-1),
97
98 fColor (kWhite),
99 fFrame (nullptr),
100 fPalette (nullptr),
101 fRenderMode (kRM_AsIs),
102 fSelectViaFrame (kFALSE),
103 fHighlightFrame (kFALSE),
104 fDisableLighting(kTRUE),
105 fHistoButtons (kTRUE),
106 fEmitSignals (kFALSE),
107 fCallbackFoo (nullptr),
108 fTooltipCBFoo (nullptr)
109{
110 // Constructor.
111
115}
116
117////////////////////////////////////////////////////////////////////////////////
118/// Destructor.
119/// Unreference frame and palette. Destroy referenced objects if they
120/// are owned by the REveDigitSet.
121
123{
124 SetFrame(nullptr);
125 SetPalette(nullptr);
127 ReleaseIds();
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// Protected method called whenever a new digit is added.
132
139
140////////////////////////////////////////////////////////////////////////////////
141/// Protected method. Release and delete the referenced objects, the
142/// ownership is *NOT* checked.
143
145{
146 if (fDigitIds)
147 {
148 const Int_t N = fDigitIds->GetSize();
149
150 for (Int_t i = 0; i < N; ++i)
151 delete fDigitIds->At(i);
152
153 fDigitIds->Expand(0);
154 }
155}
156
157////////////////////////////////////////////////////////////////////////////////
158/// Instruct digit-set to use single color for its digits.
159/// Call SetMainColor/Transparency to initialize it.
160
165
166////////////////////////////////////////////////////////////////////////////////
167/// Override from REveElement, forward to Frame.
168
170{
171 if (fSingleColor)
172 {
175 }
176 else if (fFrame)
177 {
178 fFrame->SetFrameColor(color);
180 }
181}
182
183/*
184////////////////////////////////////////////////////////////////////////////////
185/// Virtual function called when both fSelected is false and
186/// fImpliedSelected is 0.
187
188void REveDigitSet::UnSelected()
189{
190 fSelectedSet.clear();
191 REveElement::UnSelected();
192}
193
194////////////////////////////////////////////////////////////////////////////////
195/// Virtual function called when both fHighlighted is false and
196/// fImpliedHighlighted is 0.
197
198void REveDigitSet::UnHighlighted()
199{
200 fHighlightedSet.clear();
201 REveElement::UnHighlighted();
202}
203
204*/
205////////////////////////////////////////////////////////////////////////////////
206/// Return tooltip for highlighted element if always-sec-select is set.
207/// Otherwise return the tooltip for this element.
208
209std::string REveDigitSet::GetHighlightTooltip(const std::set<int>& secondary_idcs) const
210{
211 if (GetAlwaysSecSelect())
212 {
213 if (fTooltipCBFoo)
214 {
215 return (fTooltipCBFoo)(this, *secondary_idcs.begin());
216 }
217 else if (fDigitIds)
218 {
220 if (o)
221 return o->GetName();
222 }
223 return TString::Format("%s; idx=%d", GetCName(), *secondary_idcs.begin()).Data();
224 }
225 else
226 {
228 }
229}
230////////////////////////////////////////////////////////////////////////////////
231/// Instruct underlying memory allocator to regroup itself into a
232/// contiguous memory chunk.
233
235{
236 fPlex.Refit();
237}
238
239////////////////////////////////////////////////////////////////////////////////
240/// Iterate over the digits and determine min and max signal values.
241
243{
244 if (fValueIsColor || fPlex.Size() == 0)
245 {
246 min = max = 0;
247 return;
248 }
249
250 min = kMaxInt;
251 max = kMinInt;
252 for (Int_t c=0; c<fPlex.VecSize(); ++c)
253 {
254 Char_t* a = fPlex.Chunk(c);
255 Int_t n = fPlex.NAtoms(c);
256 while (n--)
257 {
258 Int_t v = ((DigitBase_t*)a)->fValue;
259 if (v < min) min = v;
260 if (v > max) max = v;
261 a += fPlex.S();
262 }
263 }
264 if (min == max)
265 --min;
266}
267
268////////////////////////////////////////////////////////////////////////////////
269/// Set current digit -- the one that will receive calls to
270/// DigitValue/Color/Id/UserData() functions.
271/// Note that various AddXyzz() functions set the current digit to the newly
272/// added one.
273
275{
276 fLastIdx = idx;
277 fLastDigit = GetDigit(idx);
278}
279
280////////////////////////////////////////////////////////////////////////////////
281/// Set signal value for the last digit added.
282
287
288////////////////////////////////////////////////////////////////////////////////
289/// Set color for the last digit added.
290
295
296////////////////////////////////////////////////////////////////////////////////
297/// Set color for the last digit added.
298
303
304////////////////////////////////////////////////////////////////////////////////
305/// Set color for the last digit added.
306
308{
310 x[0] = r; x[1] = g; x[2] = b; x[3] = a;
311}
312
313////////////////////////////////////////////////////////////////////////////////
314/// Set color for the last digit added.
315
317{
319 x[0] = rgba[0]; x[1] = rgba[1]; x[2] = rgba[2]; x[3] = rgba[3];
320}
321
322////////////////////////////////////////////////////////////////////////////////
323/// Set external object reference for the last digit added.
324
326{
327 DigitId(fLastIdx, id);
328}
329
330////////////////////////////////////////////////////////////////////////////////
331/// Set external id for the last added digit.
332
334{
335 if (!fDigitIds)
336 fDigitIds = new TRefArray;
337
338 if (fOwnIds && n < fDigitIds->GetSize() && fDigitIds->At(n))
339 delete fDigitIds->At(n);
340
342}
343
344////////////////////////////////////////////////////////////////////////////////
345/// Set external object reference for digit n.
346
348{
349 return fDigitIds ? fDigitIds->At(n) : nullptr;
350}
351
352/*
353////////////////////////////////////////////////////////////////////////////////
354/// Paint this object. Only direct rendering is supported.
355
356void REveDigitSet::Paint(Option_t*)
357{
358 PaintStandard(this);
359}
360
361////////////////////////////////////////////////////////////////////////////////
362/// Called from renderer when a digit with index idx is selected.
363/// This is by-passed when always-secondary-select is active.
364
365void REveDigitSet::DigitSelected(Int_t idx)
366{
367 DigitBase_t *qb = GetDigit(idx);
368 TObject *obj = GetId(idx);
369
370 if (fCallbackFoo) {
371 (fCallbackFoo)(this, idx, obj);
372 }
373 if (fEmitSignals) {
374 SecSelected(this, idx);
375 } else {
376 printf("REveDigitSet::DigitSelected idx=%d, value=%d, obj=0x%lx\n",
377 idx, qb->fValue, (ULong_t)obj);
378 if (obj)
379 obj->Print();
380 }
381}
382
383////////////////////////////////////////////////////////////////////////////////
384/// Emit a SecSelected signal.
385/// This is by-passed when always-secondary-select is active.
386
387void REveDigitSet::SecSelected(REveDigitSet* qs, Int_t idx)
388{
389 Longptr_t args[2];
390 args[0] = (Longptr_t) qs;
391 args[1] = (Longptr_t) idx;
392
393 // Emit("SecSelected(REveDigitSet*, Int_t)", args);
394}
395
396*/
397////////////////////////////////////////////////////////////////////////////////
398/// Set REveFrameBox pointer.
399
401{
402 if (fFrame == b) return;
403 if (fFrame) fFrame->DecRefCount(this);
404 fFrame = b;
405 if (fFrame) {
406 fFrame->IncRefCount(this);
407 if (!fSingleColor) {
409 }
410 } else {
412 }
413}
414
415////////////////////////////////////////////////////////////////////////////////
416/// Set REveRGBAPalette pointer.
417
419{
420 if (fPalette == p) return;
421 if (fPalette)
422 {
424 fPalette->RemoveNiece(this);
425 }
426 fPalette = p;
427 if (fPalette)
428 {
430 fPalette->AddNiece(this);
431 }
432}
433
434////////////////////////////////////////////////////////////////////////////////
435/// Make sure the REveRGBAPalette pointer is not null.
436/// If it is not set, a new one is instantiated and the range is set
437/// to current min/max signal values.
438
440{
441 if (fPalette == nullptr) {
443 if (!fValueIsColor) {
444 Int_t min, max;
445 ScanMinMaxValues(min, max);
446 fPalette->SetLimits(min, max);
447 fPalette->SetMinMax(min, max);
448 }
449 }
450 return fPalette;
451}
452
453////////////////////////////////////////////////////////////////////////////////
454/// Utility function for maping digit idx with visible shape idx
456{
457 if (fSingleColor) {
458 return true;
459 } else if (fValueIsColor) {
460 return d->fValue ? true : false;
461 } else {
462 if (fPalette)
463 {
464 if (d->fValue <= fPalette->GetMinVal())
465 {
467 }
468 else if (d->fValue >= fPalette->GetMaxVal())
469 {
471 }
472 else {
473 return (d->fValue > fPalette->GetMinVal() && d->fValue < fPalette->GetMaxVal());
474 }
475 }
476 else {
477 printf("Error REveDigitSet::IsDigitVisible() unhadled case\n");
478 return true;
479 }
480 }
481}
482
483////////////////////////////////////////////////////////////////////////////////
484/// Utility function for maping digit idx with visible shape idx
486{
487 int atomIdx = 0;
488 int shapeIdx = 0;
489 for (Int_t c = 0; c < fPlex.VecSize(); ++c) {
490 Char_t *a = fPlex.Chunk(c);
491 Int_t n = fPlex.NAtoms(c);
492 while (n--) {
493 if (IsDigitVisible((DigitBase_t *)a)) {
494 if (shapeIdx == iShapeIdx)
495 return atomIdx;
496 shapeIdx++;
497 }
498 atomIdx++;
499 a += fPlex.S();
500 }
501 }
502
503 printf("REveDigitSet::GetAtomIdxFromShapeIdx Error locating atom idx from shape idx %d\n", iShapeIdx);
504 return -1;
505}
506
507////////////////////////////////////////////////////////////////////////////////
508/// Utility function for maping shape idx to digit idx
510{
511 int atomIdx = 0;
512 int shapeIdx = 0;
513 for (Int_t c = 0; c < fPlex.VecSize(); ++c) {
514 Char_t *a = fPlex.Chunk(c);
515 Int_t n = fPlex.NAtoms(c);
516 while (n--) {
517 if (IsDigitVisible((DigitBase_t *)a)) {
518 if (atomIdx == iAtomIdx) {
519 return shapeIdx;
520 }
521 shapeIdx++;
522 }
523 atomIdx++;
524 a += fPlex.S();
525 }
526 }
527
528 printf("REveDigitSet::GetShapeIdxFromAtomIdx:: Atom with idx %d does not have a visible shape \n", iAtomIdx);
529 return -1;
530}
531
532
533////////////////////////////////////////////////////////////////////////////////
534// Direct callback from EveElemenControl, function elementSelected/elementHighligted controll
535//
537{
539 auto digit = GetDigit(digitId);
540 if (gDebug) printf("REveDigitSet::NewShapePicked elementId %d shape ID = %d, atom ID = %d, value = %d\n", GetElementId(), shapeIdx, digitId, digit->fValue);
541
543 std::set<int> sset = {digitId};
544
546 selection->NewElementPicked(GetElementId(), multi, true, sset);
547}
548
549////////////////////////////////////////////////////////////////////////////////
550// called from REveSelection to stream specific selection data
551void REveDigitSet::FillExtraSelectionData(nlohmann::json &j, const std::set<int> &secondary_idcs) const
552{
553 j["shape_idcs"] = nlohmann::json::array();
554 for (auto &i : secondary_idcs) {
556 if (shapeIdx >= 0)
557 j["shape_idcs"].push_back(GetShapeIdxFromAtomIdx(i));
558 }
559}
560
561////////////////////////////////////////////////////////////////////////////////
562/// Fill core part of JSON representation.
563
565{
567
568 j["fSingleColor"] = fSingleColor;
569 j["fAntiFlick"] = GetAntiFlick();
570 j["fSecondarySelect"] = fAlwaysSecSelect;
571 j["fDetIdsAsSecondaryIndices"] = fDetIdsAsSecondaryIndices;
572
573 return ret;
574}
#define d(i)
Definition RSha256.hxx:102
#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
short Color_t
Color number (short)
Definition RtypesCore.h:99
constexpr Int_t kMaxInt
Definition RtypesCore.h:119
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char)
Definition RtypesCore.h:52
char Char_t
Character 1 byte (char)
Definition RtypesCore.h:51
constexpr Int_t kMinInt
Definition RtypesCore.h:120
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
@ kWhite
Definition Rtypes.h:66
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define N
winID h TVirtualViewer3D TVirtualGLPainter p
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:627
virtual void AddNiece(REveElement *el)
virtual void RemoveNiece(REveElement *el)
void Refit()
Refit the container so that all current data fits into a single chunk.
void SetMainColor(Color_t color) override
Override from REveElement, forward to Frame.
void DigitId(TObject *id)
Set external object reference for the last digit added.
void NewShapePicked(int shapeId, Int_t selectionId, bool multi)
~REveDigitSet() override
Destructor.
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Fill core part of JSON representation.
void SetPalette(REveRGBAPalette *p)
Set REveRGBAPalette pointer.
void FillExtraSelectionData(nlohmann::json &j, const std::set< int > &secondary_idcs) const override
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.
int GetAtomIdxFromShapeIdx(int) const
Utility function for maping digit idx with visible shape idx.
bool IsDigitVisible(const DigitBase_t *) const
Utility function for maping digit idx with visible shape idx.
std::string GetHighlightTooltip(const std::set< int > &secondary_idcs) const override
Return tooltip for highlighted element if always-sec-select is set.
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.
void RefitPlex()
Instruct underlying memory allocator to regroup itself into a contiguous memory chunk.
DigitBase_t * GetDigit(Int_t n) const
Int_t fLastIdx
The last / current digit added to collection.
void ReleaseIds()
Protected method.
int GetShapeIdxFromAtomIdx(int) const
Utility function for maping shape idx to digit idx.
void DigitValue(Int_t value)
Set signal value for the last digit added.
void SetFrame(REveFrameBox *b)
Set REveFrameBox pointer.
TooltipCB_foo fTooltipCBFoo
Additional function to call on secondary-select.
TObject * GetId(Int_t n) const
Set external object reference for digit n.
void SetMainColorPtr(Color_t *colptr)
virtual std::string GetHighlightTooltip(const std::set< int > &) const
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
const char * GetCName() const
virtual void InitMainTrans(Bool_t can_edit=kTRUE)
Initialize the main transformation to identity matrix.
ElementId_t GetElementId() const
virtual void SetMainColor(Color_t color)
Set main color of the element.
void SetFrameColor(Color_t ci)
Set color of the frame.
REveElement * FindElementById(ElementId_t id) const
Lookup ElementId in element map and return corresponding REveElement*.
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:417
virtual void DecRefCount(REveElement *re)
Decrease reference count and remove re from the list of back-references.
Definition REveUtil.cxx:426
virtual void StampBackPtrElements(UChar_t stamps)
Add given stamps to elements in the list of reverse references.
Definition REveUtil.cxx:441
REveSelection Container for selected and highlighted elements.
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
const_iterator begin() const
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Mother of all ROOT objects.
Definition TObject.h:42
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:458
An array of references to TObjects.
Definition TRefArray.h:33
TObject * At(Int_t idx) const override
Definition TRefArray.h:184
virtual void Expand(Int_t newSize)
Expand or shrink the array to newSize elements.
virtual void AddAtAndExpand(TObject *obj, Int_t idx)
Add object at position idx.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2384
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
R__EXTERN REveManager * gEve