Logo ROOT   6.14/05
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 &#39;shape1&#39; and &#39;shape2&#39; bounding box volumes - return kTRUE if &#39;shape1&#39; bigger than &#39;shape2&#39;...
Definition: TGLScene.cxx:356
virtual void EndUpdate(Bool_t minorChange=kTRUE, Bool_t sceneChanged=kTRUE, Bool_t updateViewers=kTRUE)
Exit scene update mode.
Definition: TGLScene.cxx:1265
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:1352
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
TGLLogicalShape * FindLogicalSmartRefresh(TObject *ID) const
Find and return logical shape identified by unique &#39;ID&#39; in refresh-cache.
Definition: TGLScene.cxx:1455
virtual ~TGLScene()
Destroy scene objects.
Definition: TGLScene.cxx:292
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:623
static Bool_t ComparePhysicalDiagonals(const TGLPhysicalShape *shape1, const TGLPhysicalShape *shape2)
Compare &#39;shape1&#39; and &#39;shape2&#39; bounding box volumes - return kTRUE if &#39;shape1&#39; bigger than &#39;shape2&#39;...
Definition: TGLScene.cxx:366
Identifier of a shared GL-context.
Definition: TGLContext.h:80
virtual void RenderSelOpaqueForHighlight(TGLRnrCtx &rnrCtx)
Render selected opaque elements for highlight.
Definition: TGLScene.cxx:653
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:1283
virtual void RenderOpaque(TGLRnrCtx &rnrCtx)
Render opaque elements.
Definition: TGLScene.cxx:613
PhysicalShapeMap_t::const_iterator PhysicalShapeMapCIt_t
Definition: TGLScene.h:52
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:1231
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:950
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:663
virtual TSceneInfo * CreateSceneInfo(TGLViewerBase *view)
Create a scene-info instance appropriate for this scene class.
Definition: TGLScene.cxx:347
virtual TGLLogicalShape * FindLogical(TObject *logid) const
Find and return logical shape identified by unique logid.
Definition: TGLScene.cxx:1107
virtual void AdoptPhysical(TGLPhysicalShape &shape)
Adopt dynamically created physical &#39;shape&#39; - add to internal map and take responsibility for deleting...
Definition: TGLScene.cxx:1129
#define ClassDef(name, id)
Definition: Rtypes.h:320
virtual void CalcBoundingBox() const
Encapsulates all physical shapes bounding box with axes aligned box.
Definition: TGLScene.cxx:977
virtual void UpdatePhysical(UInt_t phid, Double_t *trans, UChar_t *col)
Reposition/recolor physical shape.
Definition: TGLScene.cxx:1304
UInt_t BeginSmartRefresh()
Moves logicals that support smart-refresh to intermediate cache.
Definition: TGLScene.cxx:1416
std::map< UInt_t, TGLPhysicalShape * > PhysicalShapeMap_t
Definition: TGLScene.h:49
void DumpMapSizes() const
Print sizes of logical and physical-shape maps.
Definition: TGLScene.cxx:1523
Base-class for direct OpenGL renderers.
Definition: TGLObject.h:21
std::map< TClass *, UInt_t > fByShapeCnt
Definition: TGLScene.h:117
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 &#39;ID&#39;.
Definition: TGLScene.cxx:1036
DrawElementPtrVec_t fSelTranspElements
Definition: TGLScene.h:98
short Color_t
Definition: RtypesCore.h:79
virtual TGLPhysicalShape * FindPhysical(UInt_t phid) const
Find and return physical shape identified by unique &#39;ID&#39;.
Definition: TGLScene.cxx:1221
Standard selection record including information about containing scene and details ob out selected ob...
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual Bool_t DestroyPhysical(UInt_t phid)
Destroy physical shape defined by unique &#39;ID&#39;.
Definition: TGLScene.cxx:1159
std::vector< DrawElement_t * > DrawElementPtrVec_t
Definition: TGLScene.h:70
TGLContextIdentity * GetGLCtxIdentity() const
Definition: TGLScene.h:232
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:672
Abstract logical shape - a GL &#39;drawable&#39; - base for all shapes - faceset sphere etc.
friend class TSceneInfo
Definition: TGLScene.h:123
void EndSmartRefresh()
Wipes logicals in refresh-cache.
Definition: TGLScene.cxx:1439
Float_t fLastPointSizeScale
Definition: TGLScene.h:141
std::vector< TGLPlane > TGLPlaneSet_t
Definition: TGLUtil.h:570
virtual Int_t DestroyPhysicals()
Destroy physical shapes.
Definition: TGLScene.cxx:1183
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:893
UInt_t SizeOfScene() const
Return memory cost of scene.
Definition: TGLScene.cxx:1491
virtual void DestroyPhysicalInternal(PhysicalShapeMapIt_t pit)
Virtual function to destroy a physical.
Definition: TGLScene.cxx:1149
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:633
virtual void PostDraw(TGLRnrCtx &rnrCtx)
Called after the rendering is finished.
Definition: TGLScene.cxx:707
TGLScene & operator=(const TGLScene &)
virtual void RenderSelTransp(TGLRnrCtx &rnrCtx)
Render selected transparent elements.
Definition: TGLScene.cxx:643
Mother of all ROOT objects.
Definition: TObject.h:37
virtual void RebuildSceneInfo(TGLRnrCtx &rnrCtx)
Major change in scene, need to rebuild all-element draw-vector and sort it.
Definition: TGLScene.cxx:382
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:311
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:1543
DrawElementPtrVec_t fOpaqueElements
Definition: TGLScene.h:95
TGLScene provides management and rendering of ROOT&#39;s default 3D /object representation as logical and...
Definition: TGLScene.h:30
Bool_t fInSmartRefresh
Definition: TGLScene.h:137
virtual void RenderAllPasses(TGLRnrCtx &rnrCtx, DrawElementPtrVec_t &elVec, Bool_t check_timeout)
Do full rendering of scene.
Definition: TGLScene.cxx:725
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:426
virtual Bool_t BeginUpdate()
Put scene in update mode, return true if lock acquired.
Definition: TGLScene.cxx:1245
unsigned char UChar_t
Definition: RtypesCore.h:34
virtual void AdoptLogical(TGLLogicalShape &shape)
Adopt dynamically created logical &#39;shape&#39; - add to internal map and take responsibility for deleting...
Definition: TGLScene.cxx:1018
std::vector< DrawElement_t >::iterator DrawElementVec_i
Definition: TGLScene.h:68
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:1532
DrawElementVec_t fVisibleElements
Definition: TGLScene.h:92
const Bool_t kTRUE
Definition: RtypesCore.h:87
std::vector< DrawElement_t * >::iterator DrawElementPtrVec_i
Definition: TGLScene.h:71
virtual Int_t DestroyLogicals()
Destroy all logical shapes in scene.
Definition: TGLScene.cxx:1073
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:544
virtual void PreDraw(TGLRnrCtx &rnrCtx)
Initialize rendering.
Definition: TGLScene.cxx:568
ShapeVec_t fShapesOfInterest
Definition: TGLScene.h:90