#ifndef ROOT_TGLViewer
#define ROOT_TGLViewer
#include "TGLViewerBase.h"
#include "TGLRnrCtx.h"
#include "TGLSelectRecord.h"
#include "TVirtualViewer3D.h"
#include "TBuffer3D.h"
#include "TGLPerspectiveCamera.h"
#include "TGLOrthoCamera.h"
#include "TTimer.h"
#include "TPoint.h"
#include "TGEventHandler.h"
#include "GuiTypes.h"
#include "TQObject.h"
#include <vector>
class TGLSceneBase;
class TGLRedrawTimer;
class TGLViewerEditor;
class TGLWidget;
class TGLLightSet;
class TGLClipSet;
class TGLManipSet;
class TGLCameraOverlay;
class TGLContextIdentity;
class TTimer;
class TContextMenu;
class TGedEditor;
class TGLPShapeObj;
class TGLViewer : public TVirtualViewer3D,
public TGLViewerBase,
public TQObject
{
friend class TGLOutput;
friend class TGLEventHandler;
public:
enum ECameraType { kCameraPerspXOZ, kCameraPerspYOZ, kCameraPerspXOY,
kCameraOrthoXOY, kCameraOrthoXOZ, kCameraOrthoZOY,
kCameraOrthoXnOY, kCameraOrthoXnOZ, kCameraOrthoZnOY };
enum ESecSelType { kOnRequest, kOnKeyMod1 };
private:
TGLViewer(const TGLViewer &);
TGLViewer & operator=(const TGLViewer &);
void InitSecondaryObjects();
protected:
TVirtualPad *fPad;
TContextMenu *fContextMenu;
TGLPerspectiveCamera fPerspectiveCameraXOZ;
TGLPerspectiveCamera fPerspectiveCameraYOZ;
TGLPerspectiveCamera fPerspectiveCameraXOY;
TGLOrthoCamera fOrthoXOYCamera;
TGLOrthoCamera fOrthoXOZCamera;
TGLOrthoCamera fOrthoZOYCamera;
TGLOrthoCamera fOrthoXnOYCamera;
TGLOrthoCamera fOrthoXnOZCamera;
TGLOrthoCamera fOrthoZnOYCamera;
TGLCamera *fCurrentCamera;
Bool_t fStereo;
Float_t fStereoZeroParallax;
Float_t fStereoEyeOffsetFac;
Float_t fStereoFrustumAsymFac;
TGLLightSet *fLightSet;
TGLClipSet *fClipSet;
Bool_t fClipAutoUpdate;
TGLSelectRecord fCurrentSelRec;
TGLSelectRecord fSelRec;
TGLSelectRecord fSecSelRec;
TGLManipSet *fSelectedPShapeRef;
TGLOverlayElement *fCurrentOvlElm;
TGLOvlSelectRecord fOvlSelRec;
TGEventHandler *fEventHandler;
TGedEditor *fGedEditor;
TGLPShapeObj *fPShapeWrap;
public:
enum EPushAction { kPushStd,
kPushCamCenter, kPushAnnotate };
enum EDragAction { kDragNone,
kDragCameraRotate, kDragCameraTruck, kDragCameraDolly,
kDragOverlay };
protected:
EPushAction fPushAction;
EDragAction fDragAction;
TGLRedrawTimer *fRedrawTimer;
Float_t fMaxSceneDrawTimeHQ;
Float_t fMaxSceneDrawTimeLQ;
TGLRect fViewport;
TGLColorSet fDarkColorSet;
TGLColorSet fLightColorSet;
Float_t fPointScale;
Float_t fLineScale;
Bool_t fSmoothPoints;
Bool_t fSmoothLines;
Int_t fAxesType;
Bool_t fAxesDepthTest;
Bool_t fReferenceOn;
TGLVertex3 fReferencePos;
Bool_t fDrawCameraCenter;
TGLCameraOverlay *fCameraOverlay;
Bool_t fInitGL;
Bool_t fSmartRefresh;
Bool_t fDebugMode;
Bool_t fIsPrinting;
TString fPictureFileName;
Float_t fFader;
static TGLColorSet fgDefaultColorSet;
static Bool_t fgUseDefaultColorSetForNewViewers;
void InitGL();
void PreDraw();
void PostDraw();
void FadeView(Float_t alpha);
void MakeCurrent() const;
void SwapBuffers() const;
void SetViewport(Int_t x, Int_t y, Int_t width, Int_t height);
void SetViewport(const TGLRect& vp);
void SetupCameras(Bool_t reset);
protected:
TGLWidget *fGLWidget;
Int_t fGLDevice;
TGLContextIdentity *fGLCtxId;
Bool_t fIgnoreSizesOnUpdate;
Bool_t fResetCamerasOnUpdate;
Bool_t fResetCamerasOnNextUpdate;
public:
TGLViewer(TVirtualPad* pad, Int_t x, Int_t y, Int_t width, Int_t height);
TGLViewer(TVirtualPad* pad);
virtual ~TGLViewer();
void ResetInitGL();
virtual Bool_t CanLoopOnPrimitives() const { return kTRUE; }
virtual void PadPaint(TVirtualPad* pad);
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py);
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
virtual Bool_t PreferLocalFrame() const { return kTRUE; }
virtual void BeginScene() {}
virtual Bool_t BuildingScene() const { return kFALSE; }
virtual void EndScene() {}
virtual Int_t AddObject(const TBuffer3D&, Bool_t* = 0) { return TBuffer3D::kNone; }
virtual Int_t AddObject(UInt_t, const TBuffer3D&, Bool_t* = 0) { return TBuffer3D::kNone; }
virtual Bool_t OpenComposite(const TBuffer3D&, Bool_t* = 0) { return kFALSE; }
virtual void CloseComposite() {}
virtual void AddCompositeOp(UInt_t) {}
virtual void PrintObjects();
virtual void ResetCameras() { SetupCameras(kTRUE); }
virtual void ResetCamerasAfterNextUpdate() { fResetCamerasOnNextUpdate = kTRUE; }
TGLWidget* GetGLWidget() { return fGLWidget; }
virtual void CreateGLWidget() {}
virtual void DestroyGLWidget() {}
Int_t GetDev() const { return fGLDevice; }
Bool_t GetSmartRefresh() const { return fSmartRefresh; }
void SetSmartRefresh(Bool_t smart_ref) { fSmartRefresh = smart_ref; }
TGLColorSet& RefDarkColorSet() { return fDarkColorSet; }
TGLColorSet& RefLightColorSet() { return fLightColorSet; }
TGLColorSet& ColorSet() { return * fRnrCtx->GetBaseColorSet(); }
void UseDarkColorSet();
void UseLightColorSet();
void SwitchColorSet();
void UseDefaultColorSet(Bool_t x);
Bool_t IsUsingDefaultColorSet() const;
Bool_t IsColorSetDark() const;
void SetClearColor(Color_t col);
static TGLColorSet& GetDefaultColorSet();
static void UseDefaultColorSetForNewViewers(Bool_t x);
static Bool_t IsUsingDefaultColorSetForNewViewers();
Float_t GetPointScale() const { return fPointScale; }
Float_t GetLineScale() const { return fLineScale; }
void SetPointScale(Float_t s) { fPointScale = s; }
void SetLineScale (Float_t s) { fLineScale = s; }
Bool_t GetSmoothPoints() const { return fSmoothPoints; }
Bool_t GetSmoothLines() const { return fSmoothLines; }
void SetSmoothPoints(Bool_t s){ fSmoothPoints = s; }
void SetSmoothLines(Bool_t s) { fSmoothLines = s; }
TGLLightSet* GetLightSet() const { return fLightSet; }
TGLClipSet * GetClipSet() const { return fClipSet; }
Bool_t GetClipAutoUpdate() const { return fClipAutoUpdate; }
void SetClipAutoUpdate(Bool_t x) { fClipAutoUpdate = x; }
TGLCamera & CurrentCamera() const { return *fCurrentCamera; }
TGLCamera & RefCamera(ECameraType camera);
void SetCurrentCamera(ECameraType camera);
void SetOrthoCamera(ECameraType camera, Double_t zoom, Double_t dolly,
Double_t center[3], Double_t hRotate, Double_t vRotate);
void SetPerspectiveCamera(ECameraType camera, Double_t fov, Double_t dolly,
Double_t center[3], Double_t hRotate, Double_t vRotate);
void GetGuideState(Int_t & axesType, Bool_t & axesDepthTest, Bool_t & referenceOn, Double_t* referencePos) const;
void SetGuideState(Int_t axesType, Bool_t axesDepthTest, Bool_t referenceOn, const Double_t* referencePos);
void SetDrawCameraCenter(Bool_t x);
Bool_t GetDrawCameraCenter() { return fDrawCameraCenter; }
void PickCameraCenter() { fPushAction = kPushCamCenter; RefreshPadEditor(this); }
void PickAnnotate() { fPushAction = kPushAnnotate; RefreshPadEditor(this); }
TGLCameraOverlay* GetCameraOverlay() const { return fCameraOverlay; }
void SetCameraOverlay(TGLCameraOverlay* m) { fCameraOverlay = m; }
Bool_t GetStereo() const { return fStereo; }
Float_t GetStereoZeroParallax() const { return fStereoZeroParallax; }
Float_t GetStereoEyeOffsetFac() const { return fStereoEyeOffsetFac; }
Float_t GetStereoFrustumAsymFac() const { return fStereoFrustumAsymFac; }
void SetStereo(Bool_t s) { fStereo = s; }
void SetStereoZeroParallax(Float_t f) { fStereoZeroParallax = f; }
void SetStereoEyeOffsetFac(Float_t f) { fStereoEyeOffsetFac = f; }
void SetStereoFrustumAsymFac(Float_t f) { fStereoFrustumAsymFac = f; }
EPushAction GetPushAction() const { return fPushAction; }
EDragAction GetDragAction() const { return fDragAction; }
const TGLPhysicalShape * GetSelected() const;
Float_t GetMaxSceneDrawTimeHQ() const { return fMaxSceneDrawTimeHQ; }
Float_t GetMaxSceneDrawTimeLQ() const { return fMaxSceneDrawTimeLQ; }
void SetMaxSceneDrawTimeHQ(Float_t t) { fMaxSceneDrawTimeHQ = t; }
void SetMaxSceneDrawTimeLQ(Float_t t) { fMaxSceneDrawTimeLQ = t; }
void RequestDraw(Short_t LOD = TGLRnrCtx::kLODMed);
virtual void PreRender();
virtual void PostRender();
void DoDraw();
void DoDrawMono();
void DoDrawStereo();
void DrawGuides();
void DrawDebugInfo();
Bool_t RequestSelect(Int_t x, Int_t y);
Bool_t DoSelect(Int_t x, Int_t y);
Bool_t RequestSecondarySelect(Int_t x, Int_t y);
Bool_t DoSecondarySelect(Int_t x, Int_t y);
void ApplySelection();
Bool_t RequestOverlaySelect(Int_t x, Int_t y);
Bool_t DoOverlaySelect(Int_t x, Int_t y);
Bool_t SavePicture();
Bool_t SavePicture(const TString &fileName);
Bool_t SavePictureUsingBB (const TString &fileName);
Bool_t SavePictureUsingFBO(const TString &fileName, Int_t w, Int_t h, Float_t pixel_object_scale=0);
Bool_t SavePictureWidth (const TString &fileName, Int_t width, Bool_t pixel_object_scale=kTRUE);
Bool_t SavePictureHeight(const TString &fileName, Int_t height, Bool_t pixel_object_scale=kTRUE);
Bool_t SavePictureScale (const TString &fileName, Float_t scale, Bool_t pixel_object_scale=kTRUE);
const char* GetPictureFileName() const { return fPictureFileName.Data(); }
void SetPictureFileName(const TString& f) { fPictureFileName = f; }
Float_t GetFader() const { return fFader; }
void SetFader(Float_t x) { fFader = x; }
void AutoFade(Float_t fade, Float_t time=1, Int_t steps=10);
void UpdateScene();
Bool_t GetIgnoreSizesOnUpdate() const { return fIgnoreSizesOnUpdate; }
void SetIgnoreSizesOnUpdate(Bool_t v) { fIgnoreSizesOnUpdate = v; }
void ResetCurrentCamera();
Bool_t GetResetCamerasOnUpdate() const { return fResetCamerasOnUpdate; }
void SetResetCamerasOnUpdate(Bool_t v) { fResetCamerasOnUpdate = v; }
virtual void PostSceneBuildSetup(Bool_t resetCameras);
virtual void MouseIdle(TGLPhysicalShape*,UInt_t,UInt_t);
virtual void MouseOver(TGLPhysicalShape*);
virtual void MouseOver(TGLPhysicalShape*, UInt_t state);
virtual void Activated() { Emit("Activated()"); }
virtual void Clicked(TObject *obj);
virtual void Clicked(TObject *obj, UInt_t button, UInt_t state);
virtual void ReClicked(TObject *obj, UInt_t button, UInt_t state);
virtual void UnClicked(TObject *obj, UInt_t button, UInt_t state);
virtual void DoubleClicked() { Emit("DoubleClicked()"); }
TGEventHandler *GetEventHandler() const { return fEventHandler; }
virtual void SetEventHandler(TGEventHandler *handler);
TGedEditor* GetGedEditor() const { return fGedEditor; }
virtual void SetGedEditor(TGedEditor* ed) { fGedEditor = ed; }
virtual void SelectionChanged();
virtual void OverlayDragFinished();
virtual void RefreshPadEditor(TObject* obj=0);
virtual void RemoveOverlayElement(TGLOverlayElement* el);
TGLSelectRecord& GetSelRec() { return fSelRec; }
TGLOvlSelectRecord& GetOvlSelRec() { return fOvlSelRec; }
TGLOverlayElement* GetCurrentOvlElm() const { return fCurrentOvlElm; }
void ClearCurrentOvlElm();
ClassDef(TGLViewer,0)
};
class TGLRedrawTimer : public TTimer
{
private:
TGLViewer & fViewer;
Short_t fRedrawLOD;
Bool_t fPending;
public:
TGLRedrawTimer(TGLViewer & viewer) :
fViewer(viewer), fRedrawLOD(TGLRnrCtx::kLODHigh), fPending(kFALSE) {}
~TGLRedrawTimer() {}
void RequestDraw(Int_t milliSec, Short_t redrawLOD)
{
if (fPending) TurnOff(); else fPending = kTRUE;
if (redrawLOD < fRedrawLOD) fRedrawLOD = redrawLOD;
TTimer::Start(milliSec, kTRUE);
}
Bool_t IsPending() const { return fPending; }
virtual void Stop()
{
if (fPending) { TurnOff(); fPending = kFALSE; }
}
Bool_t Notify()
{
TurnOff();
fPending = kFALSE;
fViewer.RequestDraw(fRedrawLOD);
fRedrawLOD = TGLRnrCtx::kLODHigh;
return kTRUE;
}
};
class TGLFaderHelper {
private:
TGLFaderHelper(const TGLFaderHelper&);
TGLFaderHelper& operator=(const TGLFaderHelper&);
public:
TGLViewer *fViewer;
Float_t fFadeTarget;
Float_t fTime;
Int_t fNSteps;
TGLFaderHelper() :
fViewer(0), fFadeTarget(0), fTime(0), fNSteps(0) {}
TGLFaderHelper(TGLViewer* v, Float_t fade, Float_t time, Int_t steps) :
fViewer(v),fFadeTarget(fade), fTime(time), fNSteps(steps) {}
virtual ~TGLFaderHelper() {}
void MakeFadeStep();
ClassDef(TGLFaderHelper, 0);
};
#endif // ROOT_TGLViewer