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