Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
21 class TGLObject;
22 class TGLCamera;
23 class TGLLogicalShape;
24 class TGLPhysicalShape;
25 
26 class TGLContextIdentity;
27 
28 class TGLScene : public TGLSceneBase
29 {
30 private:
31  TGLScene(const TGLScene&); // Not implemented
32  TGLScene& operator=(const TGLScene&); // Not implemented
33 
34  // Compare physical-shape volumes/diagonals -- for draw-vec sorting
35  static Bool_t ComparePhysicalVolumes(const TGLPhysicalShape* shape1,
36  const TGLPhysicalShape* shape2);
37  static Bool_t ComparePhysicalDiagonals(const TGLPhysicalShape* shape1,
38  const TGLPhysicalShape* shape2);
39 public:
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 
53  struct DrawElement_t
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=0) :
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:
81  Bool_t CmpDrawElements(const DrawElement_t& de1, const DrawElement_t& de2);
82 
83  protected:
84  void ClearDrawElementVec(DrawElementVec_t& vec, Int_t maxSize);
85  void ClearDrawElementPtrVec(DrawElementPtrVec_t& vec, Int_t maxSize);
86 
87  public:
88  ShapeVec_t fShapesOfInterest;
89 
90  DrawElementVec_t fVisibleElements;
91 
92  UInt_t fMinorStamp;
93  DrawElementPtrVec_t fOpaqueElements;
94  DrawElementPtrVec_t fTranspElements;
95  DrawElementPtrVec_t fSelOpaqueElements;
96  DrawElementPtrVec_t fSelTranspElements;
97 
98  TSceneInfo(TGLViewerBase* view=0, TGLScene* scene=0);
99  virtual ~TSceneInfo();
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 
112  Int_t fOpaqueCnt;
113  Int_t fTranspCnt;
114  Int_t fAsPixelCnt;
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 
124 protected:
125  LogicalShapeMap_t fLogicalShapes; //!
126  PhysicalShapeMap_t fPhysicalShapes; //!
127 
128  virtual void DestroyPhysicalInternal(PhysicalShapeMapIt_t pit);
129 
130  // GLcontext
131  TGLContextIdentity * fGLCtxIdentity;
132  void ReleaseGLCtxIdentity();
133 
134  // Smart Refresh -- will go in this version
135  Bool_t fInSmartRefresh; //!
136  mutable LogicalShapeMap_t fSmartRefreshCache; //!
137 
138  // State that requires recreation of display-lists
139  Float_t fLastPointSizeScale;
140  Float_t fLastLineWidthScale;
141 
142  // ----------------------------------------------------------------
143  // ----------------------------------------------------------------
144 
145 public:
146  TGLScene();
147  virtual ~TGLScene();
148 
149  virtual void CalcBoundingBox() const;
150 
151  virtual TSceneInfo* CreateSceneInfo(TGLViewerBase* view);
152  virtual void RebuildSceneInfo(TGLRnrCtx& rnrCtx);
153  virtual void UpdateSceneInfo(TGLRnrCtx& rnrCtx);
154  virtual void LodifySceneInfo(TGLRnrCtx& rnrCtx);
155 
156 
157  // Rendering
158  virtual void PreDraw (TGLRnrCtx& rnrCtx);
159  // virtual void PreRender (TGLRnrCtx& rnrCtx);
160  // virtual void Render (TGLRnrCtx& rnrCtx);
161  virtual void RenderOpaque (TGLRnrCtx& rnrCtx);
162  virtual void RenderTransp (TGLRnrCtx& rnrCtx);
163  virtual void RenderSelOpaque(TGLRnrCtx& rnrCtx);
164  virtual void RenderSelTransp(TGLRnrCtx& rnrCtx);
165  virtual void RenderSelOpaqueForHighlight(TGLRnrCtx& rnrCtx);
166  virtual void RenderSelTranspForHighlight(TGLRnrCtx& rnrCtx);
167 
168  virtual void RenderHighlight(TGLRnrCtx& rnrCtx,
169  DrawElementPtrVec_t& elVec);
170 
171  // virtual void PostRender(TGLRnrCtx& rnrCtx);
172  virtual void PostDraw (TGLRnrCtx& rnrCtx);
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 = 0);
183 
184  // Selection
185  virtual Bool_t ResolveSelectRecord(TGLSelectRecord& rec, Int_t curIdx);
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  virtual TGLLogicalShape* FindLogical(TObject* logid) const;
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.
216  LogicalShapeMap_t& RefLogicalShapes() { return fLogicalShapes; }
217 
218 
219  // ----------------------------------------------------------------
220  // SmartRefresh
221 
222  UInt_t BeginSmartRefresh();
223  void EndSmartRefresh();
224  TGLLogicalShape* FindLogicalSmartRefresh(TObject* ID) const;
225 
226 
227  // ----------------------------------------------------------------
228  // GL-context holding display-list definitions
229 
230  TGLContextIdentity* GetGLCtxIdentity() const { return fGLCtxIdentity; }
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  ClassDef(TGLScene, 0); // Standard ROOT OpenGL scene with logial/physical shapes.
245 };
246 
247 
248 #endif