Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TEveDigitSet.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 "TEveDigitSet.h"
13#include "TEveManager.h"
14#include "TEveTrans.h"
15
16#include "TRefArray.h"
17
18
19/** \class TEveDigitSet
20\ingroup TEve
21Base-class for storage of digit collections; provides
22transformation matrix (TEveTrans), signal to color mapping
23(TEveRGBAPalette) and visual grouping (TEveFrameBox).
24
25Base-class for displaying a digit collection.
26Provides common services for:
27 - specifying signal / color per digit;
28 - specifying object reference per digit;
29 - controlling palette and thresholds (external object TEveRGBAPalette);
30 - showing a frame around the digits (external object TEveFrameBox);
31 - specifying transformation matrix for the whole collection;
32 by data-member of class TEveTrans.
33
34Use method DigitId(TObject* id) to assign additional identification
35to the last created digit. By calling SetOwnIds(kTRUE) tje
36digit-set becomes the owner of the assigned objects and deletes
37them on destruction.
38Note that TRef is used for referencing the objects and if you
39instantiate the objects just to pass them to digit-set you should
40also call TProcessID::Get/SetObjectCount() at the beginning / end
41of processing of an event. See documentation for class TRef, in
42particular section 'ObjectNumber'.
43
44If you use value-is-color mode and want to use transparency, set
45the transparency to non-zero value so that GL-renderer will be
46properly informed.
47
48If you want to use single color for all elements call:
49~~~ {.cpp}
50 UseSingleColor()
51~~~
52Palette controls will not work in this case.
53
54A pointer to a rectangle / box of class TEveFrameBox can be set via
55~~~ {.cpp}
56 void SetFrame(TEveFrameBox* b);
57~~~
58A single TEveFrameBox can be shared among several digit-sets (it is
59reference-counted). The following flags affect how the frame-box will drawn
60and used for selection and highlight:
61~~~ {.cpp}
62 Bool_t fSelectViaFrame;
63 Bool_t fHighlightFrame;
64~~~
65TEveDigitSet is sub-classed from TEveSecondarySelectable -- this means
66individual digits can be selected. By calling:
67~~~ {.cpp}
68 TEveSecondarySelectable::SetAlwaysSecSelect(kTRUE);
69~~~
70one can enforce immediate feedback (highlight, tooltip and select on normal
71left-mouse click) on given digit-set.
72
73See also:
74~~~ {.cpp}
75 TEveQuadSet: rectangle, hexagon or line per digit
76 TEveBoxSet a 3D box per digit
77~~~
78*/
79
80
81////////////////////////////////////////////////////////////////////////////////
82
83TEveDigitSet::TEveDigitSet(const char* n, const char* t) :
84 TEveElement (fColor),
85 TNamed (n, t),
86
87 fDigitIds (nullptr),
88 fDefaultValue (kMinInt),
89 fValueIsColor (kFALSE),
90 fSingleColor (kFALSE),
91 fAntiFlick (kTRUE),
92 fOwnIds (kFALSE),
93 fPlex (),
94 fLastDigit (nullptr),
95 fLastIdx (-1),
96
97 fColor (kWhite),
98 fFrame (nullptr),
99 fPalette (nullptr),
100 fRenderMode (kRM_AsIs),
101 fSelectViaFrame (kFALSE),
102 fHighlightFrame (kFALSE),
103 fDisableLighting(kTRUE),
104 fHistoButtons (kTRUE),
105 fEmitSignals (kFALSE),
106 fCallbackFoo (nullptr),
107 fTooltipCBFoo (nullptr)
108{
109 // Constructor.
110
114}
115
116////////////////////////////////////////////////////////////////////////////////
117/// Destructor.
118/// Unreference frame and palette. Destroy referenced objects if they
119/// are owned by the TEveDigitSet.
120
122{
123 SetFrame(nullptr);
124 SetPalette(nullptr);
125 if (fOwnIds)
126 ReleaseIds();
127 delete fDigitIds;
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 TEveElement, forward to Frame.
168
170{
171 if (fSingleColor)
172 {
174 }
175 else if (fFrame)
176 {
177 fFrame->SetFrameColor(color);
179 }
180}
181
182////////////////////////////////////////////////////////////////////////////////
183/// Virtual function called when both fSelected is false and
184/// fImpliedSelected is 0.
185
191
192////////////////////////////////////////////////////////////////////////////////
193/// Virtual function called when both fHighlighted is false and
194/// fImpliedHighlighted is 0.
195
201
202////////////////////////////////////////////////////////////////////////////////
203/// Return tooltip for highlighted element if always-sec-select is set.
204/// Otherwise return the tooltip for this element.
205
207{
208 if (fHighlightedSet.empty()) return "";
209
210 if (GetAlwaysSecSelect())
211 {
212 if (fTooltipCBFoo)
213 {
214 return (fTooltipCBFoo)(this, *fHighlightedSet.begin());
215 }
216 else if (fDigitIds)
217 {
218 TObject *o = GetId(*fHighlightedSet.begin());
219 if (o)
220 return TString(o->GetName());
221 }
222 return TString::Format("%s; idx=%d", GetElementName(), *fHighlightedSet.begin());
223 }
224 else
225 {
227 }
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 user-data for the last digit added.
332
337
338////////////////////////////////////////////////////////////////////////////////
339/// Set external object reference for digit n.
340
342{
343 if (!fDigitIds)
344 fDigitIds = new TRefArray;
345
346 if (fOwnIds && n < fDigitIds->GetSize() && fDigitIds->At(n))
347 delete fDigitIds->At(n);
348
350}
351
352////////////////////////////////////////////////////////////////////////////////
353/// Set user-data for digit n.
354
356{
358}
359
360////////////////////////////////////////////////////////////////////////////////
361/// Return external TObject associated with digit n.
362
364{
365 return fDigitIds ? fDigitIds->At(n) : nullptr;
366}
367
368////////////////////////////////////////////////////////////////////////////////
369/// Get user-data associated with digit n.
370
372{
373 return GetDigit(n)->fUserData;
374}
375
376////////////////////////////////////////////////////////////////////////////////
377/// Paint this object. Only direct rendering is supported.
378
380{
381 PaintStandard(this);
382}
383
384////////////////////////////////////////////////////////////////////////////////
385/// Called from renderer when a digit with index idx is selected.
386/// This is by-passed when always-secondary-select is active.
387
389{
390 DigitBase_t *qb = GetDigit(idx);
391 TObject *obj = GetId(idx);
392
393 if (fCallbackFoo) {
394 (fCallbackFoo)(this, idx, obj);
395 }
396 if (fEmitSignals) {
397 SecSelected(this, idx);
398 } else {
399 printf("TEveDigitSet::DigitSelected idx=%d, value=%d, obj=0x%zx\n",
400 idx, qb->fValue, (size_t)obj);
401 if (obj)
402 obj->Print();
403 }
404}
405
406////////////////////////////////////////////////////////////////////////////////
407/// Emit a SecSelected signal.
408/// This is by-passed when always-secondary-select is active.
409
411{
412 Longptr_t args[2];
413 args[0] = (Longptr_t) qs;
414 args[1] = (Longptr_t) idx;
415
416 Emit("SecSelected(TEveDigitSet*, Int_t)", args);
417}
418
419////////////////////////////////////////////////////////////////////////////////
420/// Set TEveFrameBox pointer.
421
423{
424 if (fFrame == b) return;
425 if (fFrame) fFrame->DecRefCount(this);
426 fFrame = b;
427 if (fFrame) {
428 fFrame->IncRefCount(this);
429 if (!fSingleColor) {
431 }
432 } else {
434 }
435}
436
437////////////////////////////////////////////////////////////////////////////////
438/// Set TEveRGBAPalette pointer.
439
441{
442 if (fPalette == p) return;
444 fPalette = p;
446}
447
448////////////////////////////////////////////////////////////////////////////////
449/// Make sure the TEveRGBAPalette pointer is not null.
450/// If it is not set, a new one is instantiated and the range is set
451/// to current min/max signal values.
452
454{
455 if (fPalette == nullptr) {
457 if (!fValueIsColor) {
458 Int_t min, max;
459 ScanMinMaxValues(min, max);
460 fPalette->SetLimits(min, max);
461 fPalette->SetMinMax(min, max);
462 }
463 }
464 return fPalette;
465}
#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
long Longptr_t
Integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:89
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
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
@ 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
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Char_t * Chunk(Int_t chk) const
Int_t NAtoms(Int_t chk) const
Int_t VecSize() const
void Refit()
Refit the container so that all current data fits into a single chunk.
Int_t Size() const
Base-class for storage of digit collections; provides transformation matrix (TEveTrans),...
TString GetHighlightTooltip() 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 SetCurrentDigit(Int_t idx)
Set current digit – the one that will receive calls to DigitValue/Color/Id/UserData() functions.
TooltipCB_foo fTooltipCBFoo
Additional function to call on secondary-select.
void UnSelected() override
Virtual function called when both fSelected is false and fImpliedSelected is 0.
Int_t fDefaultValue
TEveDigitSet(const TEveDigitSet &)
Bool_t fEmitSignals
TEveRGBAPalette * fPalette
TEveRGBAPalette * AssertPalette()
Make sure the TEveRGBAPalette pointer is not null.
Int_t fLastIdx
The last / current digit added to collection.
void UseSingleColor()
Instruct digit-set to use single color for its digits.
Bool_t fSingleColor
void DigitColor(Color_t ci)
Set color for the last digit added.
void DigitValue(Int_t value)
Set signal value for the last digit added.
void RefitPlex()
Instruct underlying memory allocator to regroup itself into a contiguous memory chunk.
void ReleaseIds()
Protected method.
Callback_foo fCallbackFoo
TObject * GetId(Int_t n) const
Return external TObject associated with digit n.
TEveChunkManager fPlex
void * GetUserData() const
void SetPalette(TEveRGBAPalette *p)
Set TEveRGBAPalette pointer.
void UnHighlighted() override
Virtual function called when both fHighlighted is false and fImpliedHighlighted is 0.
DigitBase_t * fLastDigit
virtual void DigitSelected(Int_t idx)
Called from renderer when a digit with index idx is selected.
void SetMainColor(Color_t color) override
Override from TEveElement, forward to Frame.
DigitBase_t * NewDigit()
Function providing highlight tooltips when always-sec-select is active.
void SetFrame(TEveFrameBox *b)
Set TEveFrameBox pointer.
virtual void SecSelected(TEveDigitSet *qs, Int_t idx)
Emit a SecSelected signal.
void DigitUserData(void *ud)
Set user-data for the last digit added.
void Paint(Option_t *option="") override
Paint this object. Only direct rendering is supported.
Color_t fColor
The last / current idx added to collection.
DigitBase_t * GetDigit(Int_t n) const
TEveFrameBox * fFrame
TRefArray * fDigitIds
void DigitId(TObject *id)
Set external object reference for the last digit added.
Bool_t fValueIsColor
~TEveDigitSet() override
Destructor.
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition TEveElement.h:36
virtual void InitMainTrans(Bool_t can_edit=kTRUE)
Initialize the main transformation to identity matrix.
virtual TString GetHighlightTooltip()
Bool_t fCanEditMainTransparency
Definition TEveElement.h:95
virtual void SetMainColor(Color_t color)
Set main color of the element.
virtual void UnHighlighted()
Virtual function called when both fHighlighted is false and fImpliedHighlighted is 0.
void SetMainColorPtr(Color_t *color)
virtual const char * GetElementName() const
Virtual function for retrieving name of the element.
Bool_t fCanEditMainColor
Definition TEveElement.h:94
virtual void PaintStandard(TObject *id)
Paint object – a generic implementation for EVE elements.
virtual void UnSelected()
Virtual function called when both fSelected is false and fImpliedSelected is 0.
Description of a 2D or 3D frame that can be used to visually group a set of objects.
void SetFrameColor(Color_t ci)
Set color of the frame.
Color_t * PtrFrameColor()
A generic, speed-optimised mapping from value to RGBA color supporting different wrapping and range t...
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 StampBackPtrElements(UChar_t stamps)
Add given stamps to elements in the list of reverse references.
Definition TEveUtil.cxx:598
virtual void IncRefCount(TEveElement *re)
Increase reference count and add re to the list of back-references.
Definition TEveUtil.cxx:571
virtual void DecRefCount(TEveElement *re)
Decrease reference count and remove re from the list of back-references.
Definition TEveUtil.cxx:580
void IncRefCount()
Definition TEveUtil.h:174
void DecRefCount()
Definition TEveUtil.h:175
static void ColorFromIdx(Color_t ci, UChar_t col[4], Bool_t alpha=kTRUE)
Fill col with RGBA values corresponding to index ci.
Definition TEveUtil.cxx:187
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:457
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition TQObject.h:164
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.
Basic string class.
Definition TString.h:138
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