Logo ROOT  
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 {
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 }
TPair
Class used by TMap to store (key,value) pairs.
Definition: TMap.h:102
c
#define c(i)
Definition: RSha256.hxx:101
TGLObject.h
ymax
float ymax
Definition: THbookFile.cxx:95
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:100
Warning
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition: TError.cxx:231
TGLObject::SetModelCheckClass
Bool_t SetModelCheckClass(TObject *obj, TClass *cls)
Checks if obj is of proper class and sets the model.
Definition: TGLObject.cxx:71
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TGLObject::ShouldDLCache
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
xmax
float xmax
Definition: THbookFile.cxx:95
TGLObject::UpdateBoundingBox
virtual void UpdateBoundingBox()
Update bounding box from external source.
Definition: TGLObject.cxx:60
TGLLogicalShape::fExternalObj
TObject * fExternalObj
first replica
Definition: TGLLogicalShape.h:49
TGLLogicalShape::UpdateBoundingBoxesOfPhysicals
void UpdateBoundingBoxesOfPhysicals()
Update bounding-boxed of all dependent physicals.
Definition: TGLLogicalShape.cxx:246
Float_t
float Float_t
Definition: RtypesCore.h:57
TBaseClass
Each class (see TClass) has a linked list of its base class(es).
Definition: TBaseClass.h:33
TGLRnrCtx::IsDrawPassOutlineLine
Bool_t IsDrawPassOutlineLine() const
Definition: TGLRnrCtx.h:207
TGLLogicalShape::fScene
TGLScene * fScene
Shape's bounding box.
Definition: TGLLogicalShape.h:51
TBaseClass.h
TClass.h
TList.h
TMap::Add
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:54
TBaseClass::GetClassPointer
TClass * GetClassPointer(Bool_t load=kTRUE)
Get pointer to the base class TClass.
Definition: TBaseClass.cxx:63
TString
Basic string class.
Definition: TString.h:136
TObject::InheritsFrom
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
TGLLogicalShape::SupportsSecondarySelect
virtual Bool_t SupportsSecondarySelect() const
Definition: TGLLogicalShape.h:110
TString.h
bool
TGLRnrCtx.h
TGLObject
Base-class for direct OpenGL renderers.
Definition: TGLObject.h:22
TGLObject::fgGLClassMap
static TMap fgGLClassMap
Definition: TGLObject.h:24
xmin
float xmin
Definition: THbookFile.cxx:95
TGLObject::SearchGLRenderer
static TClass * SearchGLRenderer(TClass *cls)
Recursively search cls and its base classes for a GL-renderer class.
Definition: TGLObject.cxx:108
TGLObject::SetBBox
virtual void SetBBox()=0
TClass::GetListOfBases
TList * GetListOfBases()
Return list containing the TBaseClass(es) of a class.
Definition: TClass.cxx:3629
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:101
TGLObject::GetGLRenderer
static TClass * GetGLRenderer(TClass *isa)
Return direct-rendering GL class for class isa.
Definition: TGLObject.cxx:135
TMap::FindObject
TObject * FindObject(const char *keyname) const
Check if a (key,value) pair exists with keyname as name of the key.
Definition: TMap.cxx:215
TGLLogicalShape::fBoundingBox
TGLBoundingBox fBoundingBox
Also plays the role of ID.
Definition: TGLLogicalShape.h:50
TPair::Value
TObject * Value() const
Definition: TMap.h:121
TClass::GetClass
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:2955
TGLLogicalShape::fDLCache
Bool_t fDLCache
display-list validity bit-field
Definition: TGLLogicalShape.h:55
TCollection::IsEmpty
virtual Bool_t IsEmpty() const
Definition: TCollection.h:186
ymin
float ymin
Definition: THbookFile.cxx:95
TGLObject::SetAxisAlignedBBox
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
TGLRnrCtx::Highlight
Bool_t Highlight() const
Definition: TGLRnrCtx.h:218
TGLRnrCtx::SecSelection
Bool_t SecSelection() const
Definition: TGLRnrCtx.h:224
TObject.h
TClass
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
TIter
Definition: TCollection.h:233
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
TGLBoundingBox::SetAligned
void SetAligned(const TGLVertex3 &lowVertex, const TGLVertex3 &highVertex)
Set ALIGNED box from two low/high vertices.
Definition: TGLBoundingBox.cxx:185
TGLObject::fMultiColor
Bool_t fMultiColor
Definition: TGLObject.h:28
TGLVertex3
3 component (x/y/z) vertex class.
Definition: TGLUtil.h:84
TList
A doubly linked list.
Definition: TList.h:44
TGLRnrCtx
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition: TGLRnrCtx.h:41
TGLLogicalShape::AlwaysSecondarySelect
virtual Bool_t AlwaysSecondarySelect() const
Definition: TGLLogicalShape.h:111
TMap
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Definition: TMap.h:40