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 (0),
96 fLastIdx (-1),
97
98 fColor (kWhite),
99 fFrame (0),
100 fPalette (0),
101 fRenderMode (kRM_AsIs),
102 fSelectViaFrame (kFALSE),
103 fHighlightFrame (kFALSE),
104 fDisableLighting(kTRUE),
105 fHistoButtons (kTRUE),
106 fEmitSignals (kFALSE),
107 fCallbackFoo (0),
108 fTooltipCBFoo (0)
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(0);
125 SetPalette(0);
127 ReleaseIds();
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// Protected method called whenever a new digit is added.
132
134{
135 fLastIdx = fPlex.Size();
137 return fLastDigit;
138}
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
162{
164}
165
166////////////////////////////////////////////////////////////////////////////////
167/// Override from REveElement, forward to Frame.
168
170{
171 if (fSingleColor)
172 {
174 }
175 else if (fFrame)
176 {
177 fFrame->SetFrameColor(color);
179 }
180}
181
182/*
183////////////////////////////////////////////////////////////////////////////////
184/// Virtual function called when both fSelected is false and
185/// fImpliedSelected is 0.
186
187void REveDigitSet::UnSelected()
188{
189 fSelectedSet.clear();
190 REveElement::UnSelected();
191}
192
193////////////////////////////////////////////////////////////////////////////////
194/// Virtual function called when both fHighlighted is false and
195/// fImpliedHighlighted is 0.
196
197void REveDigitSet::UnHighlighted()
198{
199 fHighlightedSet.clear();
200 REveElement::UnHighlighted();
201}
202
203*/
204////////////////////////////////////////////////////////////////////////////////
205/// Return tooltip for highlighted element if always-sec-select is set.
206/// Otherwise return the tooltip for this element.
207
208std::string REveDigitSet::GetHighlightTooltip(const std::set<int>& secondary_idcs) const
209{
210 if (GetAlwaysSecSelect())
211 {
212 if (fTooltipCBFoo)
213 {
214 return (fTooltipCBFoo)(this, *secondary_idcs.begin());
215 }
216 else if (fDigitIds)
217 {
218 TObject *o = GetId(*secondary_idcs.begin());
219 if (o)
220 return o->GetName();
221 }
222 return TString::Format("%s; idx=%d", GetCName(), *secondary_idcs.begin()).Data();
223 }
224 else
225 {
226 return REveElement::GetHighlightTooltip(secondary_idcs);
227 }
228}
229////////////////////////////////////////////////////////////////////////////////
230/// Instruct underlying memory allocator to regroup itself into a
231/// contiguous memory chunk.
232
234{
235 fPlex.Refit();
236}
237
238////////////////////////////////////////////////////////////////////////////////
239/// Iterate over the digits and determine min and max signal values.
240
242{
243 if (fValueIsColor || fPlex.Size() == 0)
244 {
245 min = max = 0;
246 return;
247 }
248
249 min = kMaxInt;
250 max = kMinInt;
251 for (Int_t c=0; c<fPlex.VecSize(); ++c)
252 {
253 Char_t* a = fPlex.Chunk(c);
254 Int_t n = fPlex.NAtoms(c);
255 while (n--)
256 {
257 Int_t v = ((DigitBase_t*)a)->fValue;
258 if (v < min) min = v;
259 if (v > max) max = v;
260 a += fPlex.S();
261 }
262 }
263 if (min == max)
264 --min;
265}
266
267////////////////////////////////////////////////////////////////////////////////
268/// Set current digit -- the one that will receive calls to
269/// DigitValue/Color/Id/UserData() functions.
270/// Note that various AddXyzz() functions set the current digit to the newly
271/// added one.
272
274{
275 fLastIdx = idx;
276 fLastDigit = GetDigit(idx);
277}
278
279////////////////////////////////////////////////////////////////////////////////
280/// Set signal value for the last digit added.
281
283{
285}
286
287////////////////////////////////////////////////////////////////////////////////
288/// Set color for the last digit added.
289
291{
293}
294
295////////////////////////////////////////////////////////////////////////////////
296/// Set color for the last digit added.
297
299{
300 REveUtil::ColorFromIdx(ci, (UChar_t*) & fLastDigit->fValue, transparency);
301}
302
303////////////////////////////////////////////////////////////////////////////////
304/// Set color for the last digit added.
305
307{
309 x[0] = r; x[1] = g; x[2] = b; x[3] = a;
310}
311
312////////////////////////////////////////////////////////////////////////////////
313/// Set color for the last digit added.
314
316{
318 x[0] = rgba[0]; x[1] = rgba[1]; x[2] = rgba[2]; x[3] = rgba[3];
319}
320
321////////////////////////////////////////////////////////////////////////////////
322/// Set external object reference for the last digit added.
323
325{
326 DigitId(fLastIdx, id);
327}
328
329////////////////////////////////////////////////////////////////////////////////
330/// Set external id for the last added digit.
331
333{
334 if (!fDigitIds)
335 fDigitIds = new TRefArray;
336
337 if (fOwnIds && n < fDigitIds->GetSize() && fDigitIds->At(n))
338 delete fDigitIds->At(n);
339
341}
342
343////////////////////////////////////////////////////////////////////////////////
344/// Set external object reference for digit n.
345
347{
348 return fDigitIds ? fDigitIds->At(n) : 0;
349}
350
351/*
352////////////////////////////////////////////////////////////////////////////////
353/// Paint this object. Only direct rendering is supported.
354
355void REveDigitSet::Paint(Option_t*)
356{
357 PaintStandard(this);
358}
359
360////////////////////////////////////////////////////////////////////////////////
361/// Called from renderer when a digit with index idx is selected.
362/// This is by-passed when always-secondary-select is active.
363
364void REveDigitSet::DigitSelected(Int_t idx)
365{
366 DigitBase_t *qb = GetDigit(idx);
367 TObject *obj = GetId(idx);
368
369 if (fCallbackFoo) {
370 (fCallbackFoo)(this, idx, obj);
371 }
372 if (fEmitSignals) {
373 SecSelected(this, idx);
374 } else {
375 printf("REveDigitSet::DigitSelected idx=%d, value=%d, obj=0x%lx\n",
376 idx, qb->fValue, (ULong_t)obj);
377 if (obj)
378 obj->Print();
379 }
380}
381
382////////////////////////////////////////////////////////////////////////////////
383/// Emit a SecSelected signal.
384/// This is by-passed when always-secondary-select is active.
385
386void REveDigitSet::SecSelected(REveDigitSet* qs, Int_t idx)
387{
388 Longptr_t args[2];
389 args[0] = (Longptr_t) qs;
390 args[1] = (Longptr_t) idx;
391
392 // Emit("SecSelected(REveDigitSet*, Int_t)", args);
393}
394
395*/
396////////////////////////////////////////////////////////////////////////////////
397/// Set REveFrameBox pointer.
398
400{
401 if (fFrame == b) return;
402 if (fFrame) fFrame->DecRefCount(this);
403 fFrame = b;
404 if (fFrame) {
405 fFrame->IncRefCount(this);
406 if (!fSingleColor) {
408 }
409 } else {
411 }
412}
413
414////////////////////////////////////////////////////////////////////////////////
415/// Set REveRGBAPalette pointer.
416
418{
419 if (fPalette == p) return;
421 fPalette = p;
423}
424
425////////////////////////////////////////////////////////////////////////////////
426/// Make sure the REveRGBAPalette pointer is not null.
427/// If it is not set, a new one is instantiated and the range is set
428/// to current min/max signal values.
429
431{
432 if (fPalette == 0) {
434 if (!fValueIsColor) {
435 Int_t min, max;
436 ScanMinMaxValues(min, max);
437 fPalette->SetLimits(min, max);
438 fPalette->SetMinMax(min, max);
439 }
440 }
441 return fPalette;
442}
443
444////////////////////////////////////////////////////////////////////////////////
445/// Utility function for maping digit idx with visible shape idx
447{
448 if (fSingleColor) {
449 return true;
450 } else if (fValueIsColor) {
451 return d->fValue ? true : false;
452 } else {
453 if (fPalette)
454 return d->fValue > fPalette->GetMinVal() && d->fValue < fPalette->GetMaxVal();
455 else {
456 printf("Error REveDigitSet::IsDigitVisible() unhadled case\n");
457 return true;
458 }
459 }
460}
461
462////////////////////////////////////////////////////////////////////////////////
463/// Utility function for maping digit idx with visible shape idx
465{
466 int atomIdx = 0;
467 int shapeIdx = 0;
468 for (Int_t c = 0; c < fPlex.VecSize(); ++c) {
469 Char_t *a = fPlex.Chunk(c);
470 Int_t n = fPlex.NAtoms(c);
471 while (n--) {
472 if (IsDigitVisible((DigitBase_t *)a)) {
473 if (shapeIdx == iShapeIdx)
474 return atomIdx;
475 shapeIdx++;
476 }
477 atomIdx++;
478 a += fPlex.S();
479 }
480 }
481
482 printf("REveDigitSet::GetAtomIdxFromShapeIdx Error locating atom idx from shape idx %d\n", iShapeIdx);
483 return -1;
484}
485
486////////////////////////////////////////////////////////////////////////////////
487/// Utility function for maping shape idx to digit idx
489{
490 int atomIdx = 0;
491 int shapeIdx = 0;
492 for (Int_t c = 0; c < fPlex.VecSize(); ++c) {
493 Char_t *a = fPlex.Chunk(c);
494 Int_t n = fPlex.NAtoms(c);
495 while (n--) {
496 if (IsDigitVisible((DigitBase_t *)a)) {
497 if (atomIdx == iAtomIdx) {
498 return shapeIdx;
499 }
500 shapeIdx++;
501 }
502 atomIdx++;
503 a += fPlex.S();
504 }
505 }
506
507 printf("REveDigitSet::GetShapeIdxFromAtomIdx:: Atom with idx %d does not have a visible shape \n", iAtomIdx);
508 return -1;
509}
510
511
512////////////////////////////////////////////////////////////////////////////////
513// Direct callback from EveElemenControl, function elementSelected/elementHighligted controll
514//
515void REveDigitSet::NewShapePicked(int shapeIdx, Int_t selectionId, bool multi)
516{
517 int digitId = GetAtomIdxFromShapeIdx(shapeIdx);
518 auto digit = GetDigit(digitId);
519 if (gDebug) printf("REveDigitSet::NewShapePicked elementId %d shape ID = %d, atom ID = %d, value = %d\n", GetElementId(), shapeIdx, digitId, digit->fValue);
520
521 REveSelection *selection = dynamic_cast<REveSelection *>(ROOT::Experimental::gEve->FindElementById(selectionId));
522 std::set<int> sset = {digitId};
523
524 RefSelectedSet() = sset;
525 selection->NewElementPicked(GetElementId(), multi, true, sset);
526}
527
528////////////////////////////////////////////////////////////////////////////////
529// called from REveSelection to stream specific selection data
530void REveDigitSet::FillExtraSelectionData(nlohmann::json &j, const std::set<int> &secondary_idcs) const
531{
532 j["shape_idcs"] = nlohmann::json::array();
533 for (auto &i : secondary_idcs) {
534 int shapeIdx = GetShapeIdxFromAtomIdx(i);
535 if (shapeIdx >= 0)
536 j["shape_idcs"].push_back(GetShapeIdxFromAtomIdx(i));
537 }
538}
539
540////////////////////////////////////////////////////////////////////////////////
541/// Fill core part of JSON representation.
542
543Int_t REveDigitSet::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
544{
545 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
546
547 j["fSingleColor"] = fSingleColor;
548 j["fAntiFlick"] = GetAntiFlick();
549 j["fSecondarySelect"] = fAlwaysSecSelect;
550 j["fDetIdsAsSecondaryIndices"] = fDetIdsAsSecondaryIndices;
551
552 return ret;
553}
#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
Definition RtypesCore.h:92
constexpr Int_t kMaxInt
Definition RtypesCore.h:112
unsigned char UChar_t
Definition RtypesCore.h:38
char Char_t
Definition RtypesCore.h:37
constexpr Int_t kMinInt
Definition RtypesCore.h:113
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
@ kWhite
Definition Rtypes.h:65
#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
Definition TROOT.cxx:597
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.
void DigitId(TObject *id)
Set external object reference for the last digit added.
void NewShapePicked(int shapeId, Int_t selectionId, bool multi)
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.
virtual ~REveDigitSet()
Destructor.
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:397
virtual void DecRefCount(REveElement *re)
Decrease reference count and remove re from the list of back-references.
Definition REveUtil.cxx:406
virtual void StampBackPtrElements(UChar_t stamps)
Add given stamps to elements in the list of reverse references.
Definition REveUtil.cxx:421
REveSelection Container for selected and highlighted elements.
void NewElementPicked(ElementId_t id, bool multi, bool secondary, const std::set< int > &secondary_idcs={})
Called from GUI when user picks or un-picks an element.
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:118
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:439
An array of references to TObjects.
Definition TRefArray.h:33
TObject * At(Int_t idx) const override
Definition TRefArray.h:178
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.
const char * Data() const
Definition TString.h:380
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:2356
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
R__EXTERN REveManager * gEve