ROOT  6.06/09
Reference Guide
TGLScene.h
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Matevz Tadel, Feb 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, 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 #ifndef ROOT_TGLScene_H
13 #define ROOT_TGLScene_H
14 
15 #include "TGLSceneBase.h"
16 #include "TGLSceneInfo.h"
17 
18 #include "Gtypes.h"
19 
20 #include <map>
21 #include <vector>
22 
23 class TGLObject;
24 class TGLCamera;
25 class TGLLogicalShape;
26 class TGLPhysicalShape;
27 
28 class TGLContextIdentity;
29 
30 class TGLScene : public TGLSceneBase
31 {
32 private:
33  TGLScene(const TGLScene&); // Not implemented
34  TGLScene& operator=(const TGLScene&); // Not implemented
35 
36  // Compare physical-shape volumes/diagonals -- for draw-vec sorting
37  static Bool_t ComparePhysicalVolumes(const TGLPhysicalShape* shape1,
38  const TGLPhysicalShape* shape2);
40  const TGLPhysicalShape* shape2);
41 public:
42  // Logical shapes
43  typedef std::map<TObject*, TGLLogicalShape*> LogicalShapeMap_t;
44  typedef LogicalShapeMap_t::value_type LogicalShapeMapValueType_t;
45  typedef LogicalShapeMap_t::iterator LogicalShapeMapIt_t;
46  typedef LogicalShapeMap_t::const_iterator LogicalShapeMapCIt_t;
47 
48  // Physical Shapes
49  typedef std::map<UInt_t, TGLPhysicalShape*> PhysicalShapeMap_t;
50  typedef PhysicalShapeMap_t::value_type PhysicalShapeMapValueType_t;
51  typedef PhysicalShapeMap_t::iterator PhysicalShapeMapIt_t;
52  typedef PhysicalShapeMap_t::const_iterator PhysicalShapeMapCIt_t;
53 
54 
56  {
57  const TGLPhysicalShape* fPhysical; // Physical shape.
58 
59  Float_t fPixelSize; // Size of largest lod-axis in pixels.
60  Short_t fPixelLOD; // Size in LOD units.
61  Short_t fFinalLOD; // Corrected with SceneLOD and quantized.
62 
64  fPhysical(pshp), fPixelSize(0), fPixelLOD(0), fFinalLOD(0) {}
65  };
66 
67  typedef std::vector<DrawElement_t> DrawElementVec_t;
68  typedef std::vector<DrawElement_t>::iterator DrawElementVec_i;
69 
70  typedef std::vector<DrawElement_t*> DrawElementPtrVec_t;
71  typedef std::vector<DrawElement_t*>::iterator DrawElementPtrVec_i;
72 
73  // List of physical shapes ordered by volume/diagonal
74  typedef std::vector<const TGLPhysicalShape*> ShapeVec_t;
75  typedef ShapeVec_t::iterator ShapeVec_i;
76 
77  // ----------------------------------------------------------------
78  // SceneInfo ... extended scene context
79 
80  class TSceneInfo : public TGLSceneInfo
81  {
82  private:
83  Bool_t CmpDrawElements(const DrawElement_t& de1, const DrawElement_t& de2);
84 
85  protected:
86  void ClearDrawElementVec(DrawElementVec_t& vec, Int_t maxSize);
87  void ClearDrawElementPtrVec(DrawElementPtrVec_t& vec, Int_t maxSize);
88 
89  public:
90  ShapeVec_t fShapesOfInterest;
91 
92  DrawElementVec_t fVisibleElements;
93 
95  DrawElementPtrVec_t fOpaqueElements;
96  DrawElementPtrVec_t fTranspElements;
97  DrawElementPtrVec_t fSelOpaqueElements;
98  DrawElementPtrVec_t fSelTranspElements;
99 
100  TSceneInfo(TGLViewerBase* view=0, TGLScene* scene=0);
101  virtual ~TSceneInfo();
102 
103  void ClearAfterRebuild();
104  void ClearAfterUpdate();
105 
106  void Lodify(TGLRnrCtx& ctx);
107 
108  void PreDraw();
109  void PostDraw();
110 
111  // ---------------
112  // Draw statistics
113 
117  std::map<TClass*, UInt_t> fByShapeCnt;
118 
119  void ResetDrawStats();
120  void UpdateDrawStats(const TGLPhysicalShape& shape, Short_t lod);
121  void DumpDrawStats(); // Debug
122  };
123  friend class TSceneInfo; // for solaris cc
124 
125 
126 protected:
127  LogicalShapeMap_t fLogicalShapes; //!
128  PhysicalShapeMap_t fPhysicalShapes; //!
129 
130  virtual void DestroyPhysicalInternal(PhysicalShapeMapIt_t pit);
131 
132  // GLcontext
134  void ReleaseGLCtxIdentity();
135 
136  // Smart Refresh -- will go in this version
138  mutable LogicalShapeMap_t fSmartRefreshCache; //!
139 
140  // State that requires recreation of display-lists
143 
144  // ----------------------------------------------------------------
145  // ----------------------------------------------------------------
146 
147 public:
148  TGLScene();
149  virtual ~TGLScene();
150 
151  virtual void CalcBoundingBox() const;
152 
153  virtual TSceneInfo* CreateSceneInfo(TGLViewerBase* view);
154  virtual void RebuildSceneInfo(TGLRnrCtx& rnrCtx);
155  virtual void UpdateSceneInfo(TGLRnrCtx& rnrCtx);
156  virtual void LodifySceneInfo(TGLRnrCtx& rnrCtx);
157 
158 
159  // Rendering
160  virtual void PreDraw (TGLRnrCtx& rnrCtx);
161  // virtual void PreRender (TGLRnrCtx& rnrCtx);
162  // virtual void Render (TGLRnrCtx& rnrCtx);
163  virtual void RenderOpaque (TGLRnrCtx& rnrCtx);
164  virtual void RenderTransp (TGLRnrCtx& rnrCtx);
165  virtual void RenderSelOpaque(TGLRnrCtx& rnrCtx);
166  virtual void RenderSelTransp(TGLRnrCtx& rnrCtx);
167  virtual void RenderSelOpaqueForHighlight(TGLRnrCtx& rnrCtx);
168  virtual void RenderSelTranspForHighlight(TGLRnrCtx& rnrCtx);
169 
170  virtual void RenderHighlight(TGLRnrCtx& rnrCtx,
171  DrawElementPtrVec_t& elVec);
172 
173  // virtual void PostRender(TGLRnrCtx& rnrCtx);
174  virtual void PostDraw (TGLRnrCtx& rnrCtx);
175 
176  virtual void RenderAllPasses(TGLRnrCtx& rnrCtx,
177  DrawElementPtrVec_t& elVec,
178  Bool_t check_timeout);
179 
180 
181  virtual void RenderElements (TGLRnrCtx& rnrCtx,
182  DrawElementPtrVec_t& elVec,
183  Bool_t check_timeout,
184  const TGLPlaneSet_t* clipPlanes = 0);
185 
186  // Selection
187  virtual Bool_t ResolveSelectRecord(TGLSelectRecord& rec, Int_t curIdx);
188 
189  // Basic logical shape management
190  virtual void AdoptLogical(TGLLogicalShape& shape);
191  virtual Bool_t DestroyLogical(TObject* logid, Bool_t mustFind=kTRUE);
192  virtual Int_t DestroyLogicals();
193  virtual TGLLogicalShape* FindLogical(TObject* logid) const;
194 
195  // Basic physical shape management
196  virtual void AdoptPhysical(TGLPhysicalShape& shape);
197  virtual Bool_t DestroyPhysical(UInt_t phid);
198  virtual Int_t DestroyPhysicals();
199  virtual TGLPhysicalShape* FindPhysical(UInt_t phid) const;
200 
201  virtual UInt_t GetMaxPhysicalID();
202 
203  // ----------------------------------------------------------------
204  // Updates / removals of logical and physical shapes
205 
206  virtual Bool_t BeginUpdate();
207  virtual void EndUpdate(Bool_t minorChange=kTRUE, Bool_t sceneChanged=kTRUE, Bool_t updateViewers=kTRUE);
208 
209  virtual void UpdateLogical(TObject* logid);
210 
211  virtual void UpdatePhysical(UInt_t phid, Double_t* trans, UChar_t* col);
212  virtual void UpdatePhysical(UInt_t phid, Double_t* trans, Color_t cidx=-1, UChar_t transp=0);
213 
214  virtual void UpdatePhysioLogical(TObject* logid, Double_t* trans, UChar_t* col);
215  virtual void UpdatePhysioLogical(TObject* logid, Double_t* trans, Color_t cidx, UChar_t transp);
216 
217  // Temporary export for setting selected-state of physical shapes.
218  LogicalShapeMap_t& RefLogicalShapes() { return fLogicalShapes; }
219 
220 
221  // ----------------------------------------------------------------
222  // SmartRefresh
223 
225  void EndSmartRefresh();
227 
228 
229  // ----------------------------------------------------------------
230  // GL-context holding display-list definitions
231 
233 
234 
235  // ----------------------------------------------------------------
236  // Helpers
237 
238  UInt_t SizeOfScene() const;
239  void DumpMapSizes() const;
240 
241  static void RGBAFromColorIdx(Float_t rgba[4], Color_t ci, Char_t transp=0);
242 
243  static Bool_t IsOutside(const TGLBoundingBox& box,
244  const TGLPlaneSet_t& planes);
245 
246  ClassDef(TGLScene, 0); // Standard ROOT OpenGL scene with logial/physical shapes.
247 };
248 
249 
250 #endif
DrawElementPtrVec_t fTranspElements
Definition: TGLScene.h:96
ShapeVec_t::iterator ShapeVec_i
Definition: TGLScene.h:75
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition: TGLRnrCtx.h:40
std::vector< DrawElement_t > DrawElementVec_t
Definition: TGLScene.h:67
static Bool_t ComparePhysicalVolumes(const TGLPhysicalShape *shape1, const TGLPhysicalShape *shape2)
Compare 'shape1' and 'shape2' bounding box volumes - return kTRUE if 'shape1' bigger than 'shape2'...
Definition: TGLScene.cxx:353
virtual void EndUpdate(Bool_t minorChange=kTRUE, Bool_t sceneChanged=kTRUE, Bool_t updateViewers=kTRUE)
Exit scene update mode.
Definition: TGLScene.cxx:1262
virtual void UpdatePhysioLogical(TObject *logid, Double_t *trans, UChar_t *col)
Reposition/recolor physical for given logical (assume TGLObject and a single physical).
Definition: TGLScene.cxx:1349
virtual TGLLogicalShape * FindLogical(TObject *logid) const
Find and return logical shape identified by unique logid.
Definition: TGLScene.cxx:1104
Abstract base camera class - concrete classes for orthographic and perspective cameras derive from it...
Definition: TGLCamera.h:43
std::map< TObject *, TGLLogicalShape * > LogicalShapeMap_t
Definition: TGLScene.h:43
virtual ~TGLScene()
Destroy scene objects.
Definition: TGLScene.cxx:289
LogicalShapeMap_t::iterator LogicalShapeMapIt_t
Definition: TGLScene.h:45
float Float_t
Definition: RtypesCore.h:53
PhysicalShapeMap_t::value_type PhysicalShapeMapValueType_t
Definition: TGLScene.h:50
virtual void RenderTransp(TGLRnrCtx &rnrCtx)
Render transparent elements.
Definition: TGLScene.cxx:620
void ClearDrawElementVec(DrawElementVec_t &vec, Int_t maxSize)
Clear given vec and if it grew too large compared to the size of shape-of-interest also resize it...
Definition: TGLScene.cxx:68
static Bool_t ComparePhysicalDiagonals(const TGLPhysicalShape *shape1, const TGLPhysicalShape *shape2)
Compare 'shape1' and 'shape2' bounding box volumes - return kTRUE if 'shape1' bigger than 'shape2'...
Definition: TGLScene.cxx:363
virtual ~TSceneInfo()
Destructor.
Definition: TGLScene.cxx:60
Identifier of a shared GL-context.
Definition: TGLContext.h:83
UInt_t SizeOfScene() const
Return memory cost of scene.
Definition: TGLScene.cxx:1488
virtual TGLPhysicalShape * FindPhysical(UInt_t phid) const
Find and return physical shape identified by unique 'ID'.
Definition: TGLScene.cxx:1218
virtual void RenderSelOpaqueForHighlight(TGLRnrCtx &rnrCtx)
Render selected opaque elements for highlight.
Definition: TGLScene.cxx:650
Scene base-class – provides basic interface expected by the TGLViewer or its sub-classes: ...
Definition: TGLSceneBase.h:32
virtual void UpdateLogical(TObject *logid)
Drop display-lists for the logical (assume TGLObject/direct rendering).
Definition: TGLScene.cxx:1280
virtual void RenderOpaque(TGLRnrCtx &rnrCtx)
Render opaque elements.
Definition: TGLScene.cxx:610
PhysicalShapeMap_t::const_iterator PhysicalShapeMapCIt_t
Definition: TGLScene.h:52
Bool_t CmpDrawElements(const DrawElement_t &de1, const DrawElement_t &de2)
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
LogicalShapeMap_t fSmartRefreshCache
Definition: TGLScene.h:138
LogicalShapeMap_t::value_type LogicalShapeMapValueType_t
Definition: TGLScene.h:44
virtual UInt_t GetMaxPhysicalID()
Returns the maximum used physical id.
Definition: TGLScene.cxx:1228
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
virtual Bool_t ResolveSelectRecord(TGLSelectRecord &rec, Int_t curIdx)
Process selection record rec.
Definition: TGLScene.cxx:947
void ClearAfterUpdate()
Clear DrawElementPtrVectors and optionally resize them so that they don't take more space then requir...
Definition: TGLScene.cxx:113
LogicalShapeMap_t fLogicalShapes
Definition: TGLScene.h:127
Base class for GL viewers.
Definition: TGLViewerBase.h:36
Concrete physical shape - a GL drawable.
PhysicalShapeMap_t::iterator PhysicalShapeMapIt_t
Definition: TGLScene.h:51
virtual void RenderSelTranspForHighlight(TGLRnrCtx &rnrCtx)
Render selected transparent elements for highlight.
Definition: TGLScene.cxx:660
virtual TSceneInfo * CreateSceneInfo(TGLViewerBase *view)
Create a scene-info instance appropriate for this scene class.
Definition: TGLScene.cxx:344
virtual void AdoptPhysical(TGLPhysicalShape &shape)
Adopt dynamically created physical 'shape' - add to internal map and take responsibility for deleting...
Definition: TGLScene.cxx:1126
virtual void UpdatePhysical(UInt_t phid, Double_t *trans, UChar_t *col)
Reposition/recolor physical shape.
Definition: TGLScene.cxx:1301
UInt_t BeginSmartRefresh()
Moves logicals that support smart-refresh to intermediate cache.
Definition: TGLScene.cxx:1413
void PostDraw()
Clean-up after drawing, nothing to be done here.
Definition: TGLScene.cxx:169
std::map< UInt_t, TGLPhysicalShape * > PhysicalShapeMap_t
Definition: TGLScene.h:49
Base-class for direct OpenGL renderers.
Definition: TGLObject.h:21
std::map< TClass *, UInt_t > fByShapeCnt
Definition: TGLScene.h:117
void UpdateDrawStats(const TGLPhysicalShape &shape, Short_t lod)
Update draw stats, for newly drawn 'shape'.
Definition: TGLScene.cxx:187
void DumpMapSizes() const
Print sizes of logical and physical-shape maps.
Definition: TGLScene.cxx:1520
Float_t fLastLineWidthScale
Definition: TGLScene.h:142
LogicalShapeMap_t & RefLogicalShapes()
Definition: TGLScene.h:218
PhysicalShapeMap_t fPhysicalShapes
Definition: TGLScene.h:128
TGLContextIdentity * fGLCtxIdentity
Definition: TGLScene.h:133
virtual Bool_t DestroyLogical(TObject *logid, Bool_t mustFind=kTRUE)
Destroy logical shape defined by unique 'ID'.
Definition: TGLScene.cxx:1033
void ClearAfterRebuild()
Clear DrawElementVector fVisibleElement and optionally resize it so that it doesn't take more space t...
Definition: TGLScene.cxx:101
void DumpDrawStats()
Output draw stats to Info stream.
Definition: TGLScene.cxx:218
DrawElementPtrVec_t fSelTranspElements
Definition: TGLScene.h:98
short Color_t
Definition: RtypesCore.h:79
TGLLogicalShape * FindLogicalSmartRefresh(TObject *ID) const
Find and return logical shape identified by unique 'ID' in refresh-cache.
Definition: TGLScene.cxx:1452
Standard selection record including information about containing scene and details ob out selected ob...
TGLContextIdentity * GetGLCtxIdentity() const
Definition: TGLScene.h:232
virtual void CalcBoundingBox() const
Encapsulates all physical shapes bounding box with axes aligned box.
Definition: TGLScene.cxx:974
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual Bool_t DestroyPhysical(UInt_t phid)
Destroy physical shape defined by unique 'ID'.
Definition: TGLScene.cxx:1156
std::vector< DrawElement_t * > DrawElementPtrVec_t
Definition: TGLScene.h:70
const TGLPhysicalShape * fPhysical
Definition: TGLScene.h:57
short Short_t
Definition: RtypesCore.h:35
virtual void RenderHighlight(TGLRnrCtx &rnrCtx, DrawElementPtrVec_t &elVec)
Definition: TGLScene.cxx:669
Abstract logical shape - a GL 'drawable' - base for all shapes - faceset sphere etc.
void Lodify(TGLRnrCtx &ctx)
Quantize LODs for given render-context.
Definition: TGLScene.cxx:128
void EndSmartRefresh()
Wipes logicals in refresh-cache.
Definition: TGLScene.cxx:1436
Float_t fLastPointSizeScale
Definition: TGLScene.h:141
std::vector< TGLPlane > TGLPlaneSet_t
Definition: TGLUtil.h:574
virtual Int_t DestroyPhysicals()
Destroy physical shapes.
Definition: TGLScene.cxx:1180
double Double_t
Definition: RtypesCore.h:55
virtual void RenderElements(TGLRnrCtx &rnrCtx, DrawElementPtrVec_t &elVec, Bool_t check_timeout, const TGLPlaneSet_t *clipPlanes=0)
Render DrawElements in elementVec with given timeout.
Definition: TGLScene.cxx:890
virtual void DestroyPhysicalInternal(PhysicalShapeMapIt_t pit)
Virtual function to destroy a physical.
Definition: TGLScene.cxx:1146
std::vector< const TGLPhysicalShape * > ShapeVec_t
Definition: TGLScene.h:74
DrawElement_t(const TGLPhysicalShape *pshp=0)
Definition: TGLScene.h:63
virtual void RenderSelOpaque(TGLRnrCtx &rnrCtx)
Render selected opaque elements.
Definition: TGLScene.cxx:630
virtual void PostDraw(TGLRnrCtx &rnrCtx)
Called after the rendering is finished.
Definition: TGLScene.cxx:704
TGLScene & operator=(const TGLScene &)
void PreDraw()
Prepare for drawing - fill DrawElementPtrVectors from the contents of fVisibleElements if there was s...
Definition: TGLScene.cxx:138
virtual void RenderSelTransp(TGLRnrCtx &rnrCtx)
Render selected transparent elements.
Definition: TGLScene.cxx:640
Mother of all ROOT objects.
Definition: TObject.h:58
virtual void RebuildSceneInfo(TGLRnrCtx &rnrCtx)
Major change in scene, need to rebuild all-element draw-vector and sort it.
Definition: TGLScene.cxx:379
Concrete class describing an orientated (free) or axis aligned box of 8 vertices. ...
void ReleaseGLCtxIdentity()
Release all GL resources for current context identity.
Definition: TGLScene.cxx:308
char Char_t
Definition: RtypesCore.h:29
static Bool_t IsOutside(const TGLBoundingBox &box, const TGLPlaneSet_t &planes)
Check if box is outside of all planes.
Definition: TGLScene.cxx:1540
DrawElementPtrVec_t fOpaqueElements
Definition: TGLScene.h:95
TGLScene provides management and rendering of ROOT's default 3D /object representation as logical and...
Definition: TGLScene.h:30
Bool_t fInSmartRefresh
Definition: TGLScene.h:137
ClassDef(TGLScene, 0)
virtual void RenderAllPasses(TGLRnrCtx &rnrCtx, DrawElementPtrVec_t &elVec, Bool_t check_timeout)
Do full rendering of scene.
Definition: TGLScene.cxx:722
void ClearDrawElementPtrVec(DrawElementPtrVec_t &vec, Int_t maxSize)
Clear given vec and if it grew too large compared to the size of shape-of-interest also resize it...
Definition: TGLScene.cxx:84
DrawElementPtrVec_t fSelOpaqueElements
Definition: TGLScene.h:97
Base class for extended scene context.
Definition: TGLSceneInfo.h:26
virtual void UpdateSceneInfo(TGLRnrCtx &rnrCtx)
Fill scene-info with information needed for rendering, take into account the render-context (viewer s...
Definition: TGLScene.cxx:423
virtual Bool_t BeginUpdate()
Put scene in update mode, return true if lock acquired.
Definition: TGLScene.cxx:1242
unsigned char UChar_t
Definition: RtypesCore.h:34
virtual void AdoptLogical(TGLLogicalShape &shape)
Adopt dynamically created logical 'shape' - add to internal map and take responsibility for deleting...
Definition: TGLScene.cxx:1015
std::vector< DrawElement_t >::iterator DrawElementVec_i
Definition: TGLScene.h:68
TSceneInfo(TGLViewerBase *view=0, TGLScene *scene=0)
Constructor.
Definition: TGLScene.cxx:48
static void RGBAFromColorIdx(Float_t rgba[4], Color_t ci, Char_t transp=0)
Fill rgba color from ROOT color-index ci and transparency (0->100).
Definition: TGLScene.cxx:1529
const Bool_t kTRUE
Definition: Rtypes.h:91
DrawElementVec_t fVisibleElements
Definition: TGLScene.h:92
std::vector< DrawElement_t * >::iterator DrawElementPtrVec_i
Definition: TGLScene.h:71
virtual Int_t DestroyLogicals()
Destroy all logical shapes in scene.
Definition: TGLScene.cxx:1070
LogicalShapeMap_t::const_iterator LogicalShapeMapCIt_t
Definition: TGLScene.h:46
virtual void LodifySceneInfo(TGLRnrCtx &rnrCtx)
Setup LOD-dependant values in scene-info.
Definition: TGLScene.cxx:541
void ResetDrawStats()
Reset draw statistics.
Definition: TGLScene.cxx:176
virtual void PreDraw(TGLRnrCtx &rnrCtx)
Initialize rendering.
Definition: TGLScene.cxx:565
ShapeVec_t fShapesOfInterest
Definition: TGLScene.h:90