Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGLViewerBase.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_TGLViewerBase
13 #define ROOT_TGLViewerBase
14 
15 #include <TObject.h>
16 
17 #include "TGLLockable.h"
18 #include <TGLBoundingBox.h>
19 #include "TGLOverlay.h"
20 
21 #include <list>
22 #include <vector>
23 
24 class TGLSceneBase;
25 class TGLSceneInfo;
26 class TGLCamera;
27 class TGLClip;
28 class TGLRnrCtx;
29 class TGLLogicalShape;
30 class TGLSelectRecord;
31 class TGLOvlSelectRecord;
32 class TGLOverlayElement;
33 
34 // Avoid TObject inheritance due to clash with TVirtualViewer3D.
35 
36 class TGLViewerBase : public TGLLockable // : public TObject
37 {
38 private:
39  TGLViewerBase(const TGLViewerBase&); // Not implemented
40  TGLViewerBase& operator=(const TGLViewerBase&); // Not implemented
41 
42 protected:
43  typedef std::list<TGLSceneInfo*> SceneInfoList_t;
44  typedef SceneInfoList_t::iterator SceneInfoList_i;
45 
46  typedef std::vector<TGLSceneInfo*> SceneInfoVec_t;
47  typedef SceneInfoVec_t::iterator SceneInfoVec_i;
48 
49  typedef std::vector<TGLOverlayElement*> OverlayElmVec_t;
50  typedef OverlayElmVec_t::iterator OverlayElmVec_i;
51 
52  SceneInfoList_i FindScene(TGLSceneBase* scene);
53 
54  typedef void (TGLSceneBase::* SubRender_foo) (TGLRnrCtx &);
55 
56  void SubRenderScenes(SubRender_foo render_foo);
57 
58  virtual void SetupClipObject();
59 
60  // Members
61 
62  TGLRnrCtx *fRnrCtx;
63 
64  TGLCamera *fCamera; // Camera for rendering.
65  TGLClip *fClip; // Viewer clipping-plane.
66  Short_t fLOD; // Viewer-lod for rendering.
67  Short_t fStyle; // Viewer-style for rendering.
68  Float_t fWFLineW; // Optional override of scene wire-frame line-width
69  Float_t fOLLineW; // Optional override of scene outline line-width
70 
71  Bool_t fResetSceneInfosOnRender; // Request rebuild of view-specific scene data.
72  Bool_t fChanged; // Change requiring redraw is pending.
73 
74  SceneInfoList_t fScenes; // Registered scenes.
75  SceneInfoVec_t fVisScenes; // Visible scenes.
76 
77  TGLBoundingBox fOverallBoundingBox; // Axis-aligned union of scene bboxes.
78 
79  OverlayElmVec_t fOverlay;
80 
81  // ================================================================
82 
83 public:
84 
85  TGLViewerBase();
86  virtual ~TGLViewerBase();
87 
88  virtual const char* LockIdStr() const;
89 
90  TGLSceneInfo* AddScene(TGLSceneBase* scene);
91  void RemoveScene(TGLSceneBase* scene);
92  void RemoveAllScenes();
93  void SceneDestructing(TGLSceneBase* scene);
94 
95  TGLSceneInfo* GetSceneInfo(TGLSceneBase* scene);
96 
97  TGLLogicalShape* FindLogicalInScenes(TObject* id);
98 
99  virtual void AddOverlayElement(TGLOverlayElement* el);
100  virtual void RemoveOverlayElement(TGLOverlayElement* el);
101  virtual void DeleteOverlayAnnotations();
102  virtual void DeleteOverlayElements(TGLOverlayElement::ERole r);
103 
104  TGLClip* Clip() const { return fClip; }
105  void SetClip(TGLClip *p) { fClip = p; }
106 
107  Short_t LOD() const { return fLOD; }
108  void SetLOD(Short_t lod) { fLOD = lod; }
109 
110  Short_t Style() const { return fStyle; }
111  void SetStyle(Short_t st) { fStyle = st; }
112 
113  Float_t WFLineW() const { return fWFLineW; }
114  void SetWFLineW(Float_t w) { fWFLineW = w; }
115  Float_t OLLineW() const { return fOLLineW; }
116  void SetOLLineW(Float_t w) { fOLLineW = w; }
117 
118  // ================================================================
119 
120  virtual void ResetSceneInfos();
121  virtual void Changed() { fChanged = kTRUE; }
122  virtual Bool_t IsChanged() const { return fChanged; }
123 
124  virtual void MergeSceneBBoxes(TGLBoundingBox& bbox);
125 
126  const TGLBoundingBox& RefOverallBoundingBox() const { return fOverallBoundingBox; }
127 
128  // ================================================================
129 
130  // Low-level methods
131  virtual void PreRender();
132  virtual void Render();
133  virtual void RenderNonSelected();
134  virtual void RenderSelected();
135  virtual void RenderSelectedForHighlight();
136  virtual void RenderOpaque(Bool_t rnr_non_selected=kTRUE, Bool_t rnr_selected=kTRUE);
137  virtual void RenderTransparent(Bool_t rnr_non_selected=kTRUE, Bool_t rnr_selected=kTRUE);
138  virtual void RenderOverlay(Int_t state, Bool_t selection);
139  virtual void PostRender();
140 
141  virtual void PreRenderOverlaySelection();
142  virtual void PostRenderOverlaySelection();
143 
144  // High-level methods
145  // virtual void Draw();
146  // virtual void Select();
147  // virtual void SelectOverlay();
148 
149  // Demangle select buffer
150  Bool_t ResolveSelectRecord(TGLSelectRecord& rec, Int_t recIdx);
151  // Slightly higher-level search in select-buffer
152  Bool_t FindClosestRecord (TGLSelectRecord& rec, Int_t& recIdx);
153  Bool_t FindClosestOpaqueRecord(TGLSelectRecord& rec, Int_t& recIdx);
154 
155  // Demangle overlay select buffer
156  Bool_t FindClosestOverlayRecord(TGLOvlSelectRecord& rec, Int_t& recIdx);
157 
158  TGLRnrCtx* GetRnrCtx() const { return fRnrCtx; }
159  TGLRnrCtx& RnrCtx() const { return *fRnrCtx; }
160 
161  ClassDef(TGLViewerBase, 0); // GL Viewer base-class.
162 };
163 
164 
165 #endif