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