00001 // @(#)root/gl:$Id: TGLViewerBase.h 34006 2010-06-21 10:36:05Z matevz $ 00002 // Author: Matevz Tadel, Feb 2007 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. * 00006 * All rights reserved. * 00007 * * 00008 * For the licensing terms see $ROOTSYS/LICENSE. * 00009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00010 *************************************************************************/ 00011 00012 #ifndef ROOT_TGLViewerBase 00013 #define ROOT_TGLViewerBase 00014 00015 #include <TObject.h> 00016 00017 #include "TGLLockable.h" 00018 #include <TGLBoundingBox.h> 00019 #include "TGLOverlay.h" 00020 00021 #include <list> 00022 #include <vector> 00023 00024 class TGLSceneBase; 00025 class TGLSceneInfo; 00026 class TGLCamera; 00027 class TGLClip; 00028 class TGLRnrCtx; 00029 class TGLLogicalShape; 00030 class TGLSelectRecord; 00031 class TGLOvlSelectRecord; 00032 class TGLOverlayElement; 00033 00034 // Avoid TObject inheritance due to clash with TVirtualViewer3D. 00035 00036 class TGLViewerBase : public TGLLockable // : public TObject 00037 { 00038 private: 00039 TGLViewerBase(const TGLViewerBase&); // Not implemented 00040 TGLViewerBase& operator=(const TGLViewerBase&); // Not implemented 00041 00042 protected: 00043 typedef std::list<TGLSceneInfo*> SceneInfoList_t; 00044 typedef SceneInfoList_t::iterator SceneInfoList_i; 00045 00046 typedef std::vector<TGLSceneInfo*> SceneInfoVec_t; 00047 typedef SceneInfoVec_t::iterator SceneInfoVec_i; 00048 00049 typedef std::vector<TGLOverlayElement*> OverlayElmVec_t; 00050 typedef OverlayElmVec_t::iterator OverlayElmVec_i; 00051 00052 SceneInfoList_i FindScene(TGLSceneBase* scene); 00053 00054 typedef void (TGLSceneBase::* SubRender_foo) (TGLRnrCtx &); 00055 00056 void SubRenderScenes(SubRender_foo render_foo); 00057 00058 virtual void SetupClipObject(); 00059 00060 // Members 00061 00062 TGLRnrCtx *fRnrCtx; 00063 00064 TGLCamera *fCamera; // Camera for rendering. 00065 TGLClip *fClip; // Viewer clipping-plane. 00066 Short_t fLOD; // Viewer-lod for rendering. 00067 Short_t fStyle; // Viewer-style for rendering. 00068 Float_t fWFLineW; // Optional override of scene wire-frame line-width 00069 Float_t fOLLineW; // Optional override of scene outline line-width 00070 00071 Bool_t fResetSceneInfosOnRender; // Request rebuild of view-specific scene data. 00072 Bool_t fChanged; // Change requiring redraw is pending. 00073 00074 SceneInfoList_t fScenes; // Registered scenes. 00075 SceneInfoVec_t fVisScenes; // Visible scenes. 00076 00077 TGLBoundingBox fOverallBoundingBox; // Axis-aligned union of scene bboxes. 00078 00079 OverlayElmVec_t fOverlay; 00080 00081 // ================================================================ 00082 00083 public: 00084 00085 TGLViewerBase(); 00086 virtual ~TGLViewerBase(); 00087 00088 virtual const char* LockIdStr() const; 00089 00090 TGLSceneInfo* AddScene(TGLSceneBase* scene); 00091 void RemoveScene(TGLSceneBase* scene); 00092 void RemoveAllScenes(); 00093 void SceneDestructing(TGLSceneBase* scene); 00094 00095 TGLSceneInfo* GetSceneInfo(TGLSceneBase* scene); 00096 00097 TGLLogicalShape* FindLogicalInScenes(TObject* id); 00098 00099 virtual void AddOverlayElement(TGLOverlayElement* el); 00100 virtual void RemoveOverlayElement(TGLOverlayElement* el); 00101 virtual void DeleteOverlayAnnotations(); 00102 virtual void DeleteOverlayElements(TGLOverlayElement::ERole r); 00103 00104 TGLClip* Clip() const { return fClip; } 00105 void SetClip(TGLClip *p) { fClip = p; } 00106 00107 Short_t LOD() const { return fLOD; } 00108 void SetLOD(Short_t lod) { fLOD = lod; } 00109 00110 Short_t Style() const { return fStyle; } 00111 void SetStyle(Short_t st) { fStyle = st; } 00112 00113 Float_t WFLineW() const { return fWFLineW; } 00114 void SetWFLineW(Float_t w) { fWFLineW = w; } 00115 Float_t OLLineW() const { return fOLLineW; } 00116 void SetOLLineW(Float_t w) { fOLLineW = w; } 00117 00118 // ================================================================ 00119 00120 virtual void ResetSceneInfos(); 00121 virtual void Changed() { fChanged = kTRUE; } 00122 virtual Bool_t IsChanged() const { return fChanged; } 00123 00124 virtual void MergeSceneBBoxes(TGLBoundingBox& bbox); 00125 00126 // ================================================================ 00127 00128 // Low-level methods 00129 virtual void PreRender(); 00130 virtual void Render(); 00131 virtual void RenderNonSelected(); 00132 virtual void RenderSelected(); 00133 virtual void RenderOverlay(Int_t state, Bool_t selection); 00134 virtual void PostRender(); 00135 00136 virtual void PreRenderOverlaySelection(); 00137 virtual void PostRenderOverlaySelection(); 00138 00139 // High-level methods 00140 // virtual void Draw(); 00141 // virtual void Select(); 00142 // virtual void SelectOverlay(); 00143 00144 // Demangle select buffer 00145 Bool_t ResolveSelectRecord(TGLSelectRecord& rec, Int_t recIdx); 00146 // Slightly higher-level search in select-buffer 00147 Bool_t FindClosestRecord (TGLSelectRecord& rec, Int_t& recIdx); 00148 Bool_t FindClosestOpaqueRecord(TGLSelectRecord& rec, Int_t& recIdx); 00149 00150 // Demangle overlay select buffer 00151 Bool_t FindClosestOverlayRecord(TGLOvlSelectRecord& rec, Int_t& recIdx); 00152 00153 TGLRnrCtx* GetRnrCtx() const { return fRnrCtx; } 00154 TGLRnrCtx& RnrCtx() const { return *fRnrCtx; } 00155 00156 ClassDef(TGLViewerBase, 0); // GL Viewer base-class. 00157 }; 00158 00159 00160 #endif