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
81
82////////////////////////////////////////////////////////////////////////////////
83
84TEveDigitSet::TEveDigitSet(const char* n, const char* t) :
85 TEveElement (fColor),
86 TNamed (n, t),
87
88 fDigitIds (0),
89 fDefaultValue (kMinInt),
90 fValueIsColor (kFALSE),
91 fSingleColor (kFALSE),
92 fAntiFlick (kTRUE),
93 fOwnIds (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 TEveDigitSet.
121
123{
124 SetFrame(0);
125 SetPalette(0);
126 if (fOwnIds)
127 ReleaseIds();
128 delete fDigitIds;
129}
130
131////////////////////////////////////////////////////////////////////////////////
132/// Protected method called whenever a new digit is added.
133
135{
136 fLastIdx = fPlex.Size();
138 return fLastDigit;
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Protected method. Release and delete the referenced objects, the
143/// ownership is *NOT* checked.
144
146{
147 if (fDigitIds)
148 {
149 const Int_t N = fDigitIds->GetSize();
150
151 for (Int_t i = 0; i < N; ++i)
152 delete fDigitIds->At(i);
153
154 fDigitIds->Expand(0);
155 }
156}
157
158////////////////////////////////////////////////////////////////////////////////
159/// Instruct digit-set to use single color for its digits.
160/// Call SetMainColor/Transparency to initialize it.
161
163{
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// Override from TEveElement, forward to Frame.
169
171{
172 if (fSingleColor)
173 {
175 }
176 else if (fFrame)
177 {
178 fFrame->SetFrameColor(color);
180 }
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// Virtual function called when both fSelected is false and
185/// fImpliedSelected is 0.
186
188{
189 fSelectedSet.clear();
191}
192
193////////////////////////////////////////////////////////////////////////////////
194/// Virtual function called when both fHighlighted is false and
195/// fImpliedHighlighted is 0.
196
198{
199 fHighlightedSet.clear();
201}
202
203////////////////////////////////////////////////////////////////////////////////
204/// Return tooltip for highlighted element if always-sec-select is set.
205/// Otherwise return the tooltip for this element.
206
208{
209 if (fHighlightedSet.empty()) return "";
210
211 if (GetAlwaysSecSelect())
212 {
213 if (fTooltipCBFoo)
214 {
215 return (fTooltipCBFoo)(this, *fHighlightedSet.begin());
216 }
217 else if (fDigitIds)
218 {
219 TObject *o = GetId(*fHighlightedSet.begin());
220 if (o)
221 return TString(o->GetName());
222 }
223 return TString::Format("%s; idx=%d", GetElementName(), *fHighlightedSet.begin());
224 }
225 else
226 {
228 }
229}
230
231////////////////////////////////////////////////////////////////////////////////
232/// Instruct underlying memory allocator to regroup itself into a
233/// contiguous memory chunk.
234
236{
237 fPlex.Refit();
238}
239
240////////////////////////////////////////////////////////////////////////////////
241/// Iterate over the digits and determine min and max signal values.
242
244{
245 if (fValueIsColor || fPlex.Size() == 0)
246 {
247 min = max = 0;
248 return;
249 }
250
251 min = kMaxInt;
252 max = kMinInt;
253 for (Int_t c=0; c<fPlex.VecSize(); ++c)
254 {
255 Char_t* a = fPlex.Chunk(c);
256 Int_t n = fPlex.NAtoms(c);
257 while (n--)
258 {
259 Int_t v = ((DigitBase_t*)a)->fValue;
260 if (v < min) min = v;
261 if (v > max) max = v;
262 a += fPlex.S();
263 }
264 }
265 if (min == max)
266 --min;
267}
268
269////////////////////////////////////////////////////////////////////////////////
270/// Set current digit -- the one that will receive calls to
271/// DigitValue/Color/Id/UserData() functions.
272/// Note that various AddXyzz() functions set the current digit to the newly
273/// added one.
274
276{
277 fLastIdx = idx;
278 fLastDigit = GetDigit(idx);
279}
280
281////////////////////////////////////////////////////////////////////////////////
282/// Set signal value for the last digit added.
283
285{
287}
288
289////////////////////////////////////////////////////////////////////////////////
290/// Set color for the last digit added.
291
293{
295}
296
297////////////////////////////////////////////////////////////////////////////////
298/// Set color for the last digit added.
299
301{
302 TEveUtil::ColorFromIdx(ci, (UChar_t*) & fLastDigit->fValue, transparency);
303}
304
305////////////////////////////////////////////////////////////////////////////////
306/// Set color for the last digit added.
307
309{
311 x[0] = r; x[1] = g; x[2] = b; x[3] = a;
312}
313
314////////////////////////////////////////////////////////////////////////////////
315/// Set color for the last digit added.
316
318{
320 x[0] = rgba[0]; x[1] = rgba[1]; x[2] = rgba[2]; x[3] = rgba[3];
321}
322
323////////////////////////////////////////////////////////////////////////////////
324/// Set external object reference for the last digit added.
325
327{
328 DigitId(fLastIdx, id);
329}
330
331////////////////////////////////////////////////////////////////////////////////
332/// Set user-data for the last digit added.
333
335{
336 fLastDigit->fUserData = ud;
337}
338
339////////////////////////////////////////////////////////////////////////////////
340/// Set external object reference for digit n.
341
343{
344 if (!fDigitIds)
345 fDigitIds = new TRefArray;
346
347 if (fOwnIds && n < fDigitIds->GetSize() && fDigitIds->At(n))
348 delete fDigitIds->At(n);
349
351}
352
353////////////////////////////////////////////////////////////////////////////////
354/// Set user-data for digit n.
355
357{
358 GetDigit(n)->fUserData = ud;
359}
360
361////////////////////////////////////////////////////////////////////////////////
362/// Return external TObject associated with digit n.
363
365{
366 return fDigitIds ? fDigitIds->At(n) : 0;
367}
368
369////////////////////////////////////////////////////////////////////////////////
370/// Get user-data associated with digit n.
371
373{
374 return GetDigit(n)->fUserData;
375}
376
377////////////////////////////////////////////////////////////////////////////////
378/// Paint this object. Only direct rendering is supported.
379
381{
382 PaintStandard(this);
383}
384
385////////////////////////////////////////////////////////////////////////////////
386/// Called from renderer when a digit with index idx is selected.
387/// This is by-passed when always-secondary-select is active.
388
390{
391 DigitBase_t *qb = GetDigit(idx);
392 TObject *obj = GetId(idx);
393
394 if (fCallbackFoo) {
395 (fCallbackFoo)(this, idx, obj);
396 }
397 if (fEmitSignals) {
398 SecSelected(this, idx);
399 } else {
400 printf("TEveDigitSet::DigitSelected idx=%d, value=%d, obj=0x%zx\n",
401 idx, qb->fValue, (size_t)obj);
402 if (obj)
403 obj->Print();
404 }
405}
406
407////////////////////////////////////////////////////////////////////////////////
408/// Emit a SecSelected signal.
409/// This is by-passed when always-secondary-select is active.
410
412{
413 Longptr_t args[2];
414 args[0] = (Longptr_t) qs;
415 args[1] = (Longptr_t) idx;
416
417 Emit("SecSelected(TEveDigitSet*, Int_t)", args);
418}
419
420////////////////////////////////////////////////////////////////////////////////
421/// Set TEveFrameBox pointer.
422
424{
425 if (fFrame == b) return;
426 if (fFrame) fFrame->DecRefCount(this);
427 fFrame = b;
428 if (fFrame) {
429 fFrame->IncRefCount(this);
430 if (!fSingleColor) {
432 }
433 } else {
435 }
436}
437
438////////////////////////////////////////////////////////////////////////////////
439/// Set TEveRGBAPalette pointer.
440
442{
443 if (fPalette == p) return;
445 fPalette = p;
447}
448
449////////////////////////////////////////////////////////////////////////////////
450/// Make sure the TEveRGBAPalette pointer is not null.
451/// If it is not set, a new one is instantiated and the range is set
452/// to current min/max signal values.
453
455{
456 if (fPalette == 0) {
458 if (!fValueIsColor) {
459 Int_t min, max;
460 ScanMinMaxValues(min, max);
461 fPalette->SetLimits(min, max);
462 fPalette->SetMinMax(min, max);
463 }
464 }
465 return fPalette;
466}
#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
long Longptr_t
Definition RtypesCore.h:82
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
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
@ 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
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:604
virtual void IncRefCount(TEveElement *re)
Increase reference count and add re to the list of back-references.
Definition TEveUtil.cxx:577
virtual void DecRefCount(TEveElement *re)
Decrease reference count and remove re from the list of back-references.
Definition TEveUtil.cxx:586
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:188
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:439
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:139
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