Logo ROOT   6.08/07
Reference Guide
TGLObject.cxx
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Matevz Tadel 7/4/2006
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2006, 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 
13 #include "TGLObject.h"
14 #include "TGLRnrCtx.h"
15 #include "TObject.h"
16 #include "TClass.h"
17 #include "TBaseClass.h"
18 #include "TList.h"
19 #include "TString.h"
20 
21 /** \class TGLObject
22 \ingroup opengl
23 Base-class for direct OpenGL renderers.
24 This allows classes to circumvent passing of TBuffer3D and
25 use user-provided OpenGL code.
26 By convention, if you want class TFoo : public TObject to have direct rendering
27 you should also provide TFooGL : public TGLObject and implement
28 abstract functions SetModel() and SetBBox().
29 TAttBBox can be used to facilitate calculation of bounding-boxes.
30 See TPointSet3D and TPointSet3DGL.
31 */
32 
34 
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// Decide if display-list should be used for this pass rendering,
39 /// as determined by rnrCtx.
40 
42 {
43  if (!fDLCache ||
44  !fScene ||
45  (rnrCtx.SecSelection() && SupportsSecondarySelect()) ||
46  (fMultiColor && (rnrCtx.Highlight() || rnrCtx.IsDrawPassOutlineLine())) ||
47  (AlwaysSecondarySelect() && rnrCtx.Highlight()))
48  {
49  return kFALSE;
50  }
51 
52  return kTRUE;
53 }
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 /// Update bounding box from external source.
57 /// We call abstract SetBBox() and propagate the change to all
58 /// attached physicals.
59 
61 {
62  SetBBox();
64 }
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// Checks if obj is of proper class and sets the model.
68 /// Protected helper for subclasses.
69 /// Most sub-classes use exception-throwing SetModelDynCast() instead.
70 
72 {
73  if(obj->InheritsFrom(cls) == kFALSE) {
74  Warning("TGLObject::SetModelCheckClass", "object of wrong class passed.");
75  return kFALSE;
76  }
77  fExternalObj = obj;
78 
79  return kTRUE;
80 }
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Set axis-aligned bounding-box.
84 /// Protected helper for subclasses.
85 
88  Float_t zmin, Float_t zmax)
89 {
90  fBoundingBox.SetAligned(TGLVertex3(xmin, ymin, zmin),
91  TGLVertex3(xmax, ymax, zmax));
92 }
93 
94 ////////////////////////////////////////////////////////////////////////////////
95 /// Set axis-aligned bounding-box.
96 /// Protected helper for subclasses.
97 
99 {
100  SetAxisAlignedBBox(p[0], p[1], p[2], p[3], p[4], p[5]);
101 }
102 
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Recursively search cls and its base classes for a GL-renderer
106 /// class.
107 
109 {
110  TString rnr( cls->GetName() );
111  rnr += "GL";
112  TClass* c = TClass::GetClass(rnr);
113  if (c != 0)
114  return c;
115 
116  TList* bases = cls->GetListOfBases();
117  if (bases == 0 || bases->IsEmpty())
118  return 0;
119 
120  TIter next_base(bases);
121  TBaseClass* bc;
122  while ((bc = (TBaseClass*) next_base()) != 0) {
123  cls = bc->GetClassPointer();
124  if ((c = SearchGLRenderer(cls)) != 0) {
125  return c;
126  }
127  }
128  return 0;
129 }
130 
131 ////////////////////////////////////////////////////////////////////////////////
132 /// Return direct-rendering GL class for class isa.
133 /// Zero is a valid response.
134 
136 {
137  TPair* p = (TPair*) fgGLClassMap.FindObject(isa);
138  TClass* cls;
139  if (p != 0) {
140  cls = (TClass*) p->Value();
141  } else {
142  cls = SearchGLRenderer(isa);
143  fgGLClassMap.Add(isa, cls);
144  }
145  return cls;
146 }
void SetAligned(const TGLVertex3 &lowVertex, const TGLVertex3 &highVertex)
Set ALIGNED box from two low/high vertices.
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
Bool_t Highlight() const
Definition: TGLRnrCtx.h:218
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition: TGLRnrCtx.h:40
TList * GetListOfBases()
Return list containing the TBaseClass(es) of a class.
Definition: TClass.cxx:3460
Bool_t SecSelection() const
Definition: TGLRnrCtx.h:224
float xmin
Definition: THbookFile.cxx:93
float Float_t
Definition: RtypesCore.h:53
virtual void UpdateBoundingBox()
Update bounding box from external source.
Definition: TGLObject.cxx:60
return c
float ymin
Definition: THbookFile.cxx:93
static TMap fgGLClassMap
Definition: TGLObject.h:24
void UpdateBoundingBoxesOfPhysicals()
Update bounding-boxed of all dependent physicals.
TClass * GetClassPointer(Bool_t load=kTRUE)
Get pointer to the base class TClass.
Definition: TBaseClass.cxx:63
void Add(TObject *obj)
This function may not be used (but we need to provide it since it is a pure virtual in TCollection)...
Definition: TMap.cxx:53
void SetAxisAlignedBBox(Float_t xmin, Float_t xmax, Float_t ymin, Float_t ymax, Float_t zmin, Float_t zmax)
Set axis-aligned bounding-box.
Definition: TGLObject.cxx:86
Basic string class.
Definition: TString.h:137
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Bool_t IsDrawPassOutlineLine() const
Definition: TGLRnrCtx.h:207
virtual Bool_t SupportsSecondarySelect() const
TGLScene * fScene
Shape's bounding box.
3 component (x/y/z) vertex class.
Definition: TGLUtil.h:86
Base-class for direct OpenGL renderers.
Definition: TGLObject.h:21
TObject * Value() const
Definition: TMap.h:125
TObject * fExternalObj
first replica
A doubly linked list.
Definition: TList.h:47
Bool_t SetModelCheckClass(TObject *obj, TClass *cls)
Checks if obj is of proper class and sets the model.
Definition: TGLObject.cxx:71
float ymax
Definition: THbookFile.cxx:93
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:488
static TClass * GetGLRenderer(TClass *isa)
Return direct-rendering GL class for class isa.
Definition: TGLObject.cxx:135
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
float xmax
Definition: THbookFile.cxx:93
void Warning(const char *location, const char *msgfmt,...)
Each class (see TClass) has a linked list of its base class(es).
Definition: TBaseClass.h:35
Class used by TMap to store (key,value) pairs.
Definition: TMap.h:106
virtual Bool_t IsEmpty() const
Definition: TCollection.h:99
virtual Bool_t ShouldDLCache(const TGLRnrCtx &rnrCtx) const
Decide if display-list should be used for this pass rendering, as determined by rnrCtx.
Definition: TGLObject.cxx:41
#define ClassImp(name)
Definition: Rtypes.h:279
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Definition: TMap.h:44
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition: TClass.cxx:2893
Bool_t fMultiColor
Definition: TGLObject.h:28
static TClass * SearchGLRenderer(TClass *cls)
Recursively search cls and its base classes for a GL-renderer class.
Definition: TGLObject.cxx:108
Mother of all ROOT objects.
Definition: TObject.h:37
TObject * FindObject(const char *keyname) const
Check if a (key,value) pair exists with keyname as name of the key.
Definition: TMap.cxx:214
virtual void SetBBox()=0
TGLBoundingBox fBoundingBox
Also plays the role of ID.
Bool_t fDLCache
display-list validity bit-field
virtual Bool_t AlwaysSecondarySelect() const
const Bool_t kTRUE
Definition: Rtypes.h:91