Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TEveDigitSetGL.cxx
Go to the documentation of this file.
1 // @(#)root/eve:$Id$
2 // Author: Matevz Tadel 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 "TEveDigitSetGL.h"
13 #include "TEveFrameBoxGL.h"
14 
15 #include "TGLRnrCtx.h"
16 #include "TGLSelectRecord.h"
17 #include "TGLIncludes.h"
18 
19 /** \class TEveDigitSetGL
20 \ingroup TEve
21 OpenGL renderer class for TEveDigitSet.
22 */
23 
24 ClassImp(TEveDigitSetGL);
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 /// Constructor.
28 
29 TEveDigitSetGL::TEveDigitSetGL() :
30  TGLObject(), fHighlightSet(0)
31 {
32 }
33 
34 ////////////////////////////////////////////////////////////////////////////////
35 /// Set color for rendering of the specified digit.
36 
37 Bool_t TEveDigitSetGL::SetupColor(const TEveDigitSet::DigitBase_t& q) const
38 {
39  TEveDigitSet &DS = * (TEveDigitSet*) fExternalObj;
40 
41  if (DS.fSingleColor)
42  {
43  return kTRUE;
44  }
45  else if (DS.fValueIsColor)
46  {
47  if (q.fValue != 0)
48  {
49  TGLUtil::Color4ubv((UChar_t*) & q.fValue);
50  return kTRUE;
51  } else {
52  return kFALSE;
53  }
54  }
55  else
56  {
57  UChar_t c[4];
58  Bool_t visible = DS.fPalette->ColorFromValue(q.fValue, DS.fDefaultValue, c);
59  if (visible)
60  TGLUtil::Color3ubv(c);
61  return visible;
62  }
63 }
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 /// Make a decision if the frame should be drawn.
67 /// This depends on the render state (selection / highligt) and
68 /// on values of members fSelectViaFrame and fHighlightFrame.
69 
70 void TEveDigitSetGL::DrawFrameIfNeeded(TGLRnrCtx& rnrCtx) const
71 {
72  TEveDigitSet &DS = * (TEveDigitSet*)fExternalObj;
73 
74  if (DS.fFrame != 0 && ! rnrCtx.SecSelection() &&
75  ! (rnrCtx.Selection() && ! DS.fSelectViaFrame) &&
76  ! (rnrCtx.Highlight() && ! DS.fHighlightFrame))
77  {
78  TEveFrameBoxGL::Render(DS.fFrame);
79  }
80 }
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Set bounding box.
84 
85 void TEveDigitSetGL::SetBBox()
86 {
87  SetAxisAlignedBBox(((TEveDigitSet*)fExternalObj)->AssertBBox());
88 }
89 
90 ////////////////////////////////////////////////////////////////////////////////
91 /// Draw the quad-set in highlight mode.
92 /// Incoming lvl is ignored -- physical shape always calls it with -1.
93 
94 void TEveDigitSetGL::DrawHighlight(TGLRnrCtx& rnrCtx, const TGLPhysicalShape* pshp, Int_t /*lvl*/) const
95 {
96  TEveDigitSet &DS = * (TEveDigitSet*)fExternalObj;
97 
98  if (AlwaysSecondarySelect())
99  {
100  if ( ! DS.RefHighlightedSet().empty())
101  {
102  fHighlightSet = & DS.RefHighlightedSet();
103  TGLObject::DrawHighlight(rnrCtx, pshp, 3);
104  }
105  if ( ! DS.RefSelectedSet().empty())
106  {
107  fHighlightSet = & DS.RefSelectedSet();
108  TGLObject::DrawHighlight(rnrCtx, pshp, 1);
109  }
110  fHighlightSet = 0;
111  }
112  else
113  {
114  TGLObject::DrawHighlight(rnrCtx, pshp);
115  }
116 }
117 
118 ////////////////////////////////////////////////////////////////////////////////
119 /// Processes secondary selection from TGLViewer.
120 /// Calls DigitSelected(Int_t) in the model object with index of
121 /// selected point as the argument.
122 
123 void TEveDigitSetGL::ProcessSelection(TGLRnrCtx& /*rnrCtx*/, TGLSelectRecord& rec)
124 {
125  TEveDigitSet &DS = * (TEveDigitSet*)fExternalObj;
126 
127  if (AlwaysSecondarySelect())
128  {
129  DS.ProcessGLSelection(rec);
130  }
131  else
132  {
133  if (rec.GetN() < 2) return;
134  DS.DigitSelected(rec.GetItem(1));
135  }
136 }