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