12 #ifndef ROOT_TGLViewer
13 #define ROOT_TGLViewer
38 class TGLViewerEditor;
43 class TGLCameraOverlay;
44 class TGLContextIdentity;
53 class TGLViewer :
public TVirtualViewer3D,
58 friend class TGLOutput;
59 friend class TGLEventHandler;
60 friend class TGLAutoRotator;
63 enum ECameraType { kCameraPerspXOZ, kCameraPerspYOZ, kCameraPerspXOY,
64 kCameraOrthoXOY, kCameraOrthoXOZ, kCameraOrthoZOY, kCameraOrthoZOX,
65 kCameraOrthoXnOY, kCameraOrthoXnOZ, kCameraOrthoZnOY, kCameraOrthoZnOX };
73 TGLViewer(
const TGLViewer &);
74 TGLViewer & operator=(
const TGLViewer &);
76 void InitSecondaryObjects();
83 TContextMenu *fContextMenu;
87 TGLPerspectiveCamera fPerspectiveCameraXOZ;
88 TGLPerspectiveCamera fPerspectiveCameraYOZ;
89 TGLPerspectiveCamera fPerspectiveCameraXOY;
90 TGLOrthoCamera fOrthoXOYCamera;
91 TGLOrthoCamera fOrthoXOZCamera;
92 TGLOrthoCamera fOrthoZOYCamera;
93 TGLOrthoCamera fOrthoZOXCamera;
94 TGLOrthoCamera fOrthoXnOYCamera;
95 TGLOrthoCamera fOrthoXnOZCamera;
96 TGLOrthoCamera fOrthoZnOYCamera;
97 TGLOrthoCamera fOrthoZnOXCamera;
98 TGLCamera *fCurrentCamera;
99 TGLAutoRotator *fAutoRotator;
103 Bool_t fStereoQuadBuf;
104 Float_t fStereoZeroParallax;
105 Float_t fStereoEyeOffsetFac;
106 Float_t fStereoFrustumAsymFac;
109 TGLLightSet *fLightSet;
111 TGLClipSet *fClipSet;
113 TGLSelectRecord fCurrentSelRec;
114 TGLSelectRecord fSelRec;
115 TGLSelectRecord fSecSelRec;
116 TGLManipSet *fSelectedPShapeRef;
118 TGLOverlayElement *fCurrentOvlElm;
119 TGLOvlSelectRecord fOvlSelRec;
121 TGEventHandler *fEventHandler;
122 TGedEditor *fGedEditor;
123 TGLPShapeObj *fPShapeWrap;
127 enum EPushAction { kPushStd,
128 kPushCamCenter, kPushAnnotate };
129 enum EDragAction { kDragNone,
130 kDragCameraRotate, kDragCameraTruck, kDragCameraDolly,
133 EPushAction fPushAction;
134 EDragAction fDragAction;
137 TGLRedrawTimer *fRedrawTimer;
138 Float_t fMaxSceneDrawTimeHQ;
139 Float_t fMaxSceneDrawTimeLQ;
142 TGLColorSet fDarkColorSet;
143 TGLColorSet fLightColorSet;
146 Bool_t fSmoothPoints;
149 Bool_t fAxesDepthTest;
151 TGLVertex3 fReferencePos;
152 Bool_t fDrawCameraCenter;
153 TGLCameraOverlay *fCameraOverlay;
155 Bool_t fSmartRefresh;
160 TString fPictureFileName;
163 static TGLColorSet fgDefaultColorSet;
164 static Bool_t fgUseDefaultColorSetForNewViewers;
171 virtual void SetupClipObject();
177 void FadeView(Float_t alpha);
178 void MakeCurrent()
const;
179 void SwapBuffers()
const;
182 void SetViewport(Int_t x, Int_t y, Int_t width, Int_t height);
183 void SetViewport(
const TGLRect& vp);
184 void SetupCameras(Bool_t reset);
187 TGLWidget *fGLWidget;
189 TGLContextIdentity *fGLCtxId;
192 Bool_t fIgnoreSizesOnUpdate;
193 Bool_t fResetCamerasOnUpdate;
194 Bool_t fResetCamerasOnNextUpdate;
197 TGLViewer(TVirtualPad* pad, Int_t x, Int_t y, Int_t width, Int_t height);
198 TGLViewer(TVirtualPad* pad);
199 virtual ~TGLViewer();
204 virtual Bool_t CanLoopOnPrimitives()
const {
return kTRUE; }
205 virtual void PadPaint(TVirtualPad* pad);
207 virtual Int_t DistancetoPrimitive(Int_t px, Int_t py);
208 virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
211 virtual Bool_t PreferLocalFrame()
const {
return kTRUE; }
212 virtual void BeginScene() {}
213 virtual Bool_t BuildingScene()
const {
return kFALSE; }
214 virtual void EndScene() {}
215 virtual Int_t AddObject(
const TBuffer3D&, Bool_t* = 0) {
return TBuffer3D::kNone; }
216 virtual Int_t AddObject(UInt_t,
const TBuffer3D&, Bool_t* = 0) {
return TBuffer3D::kNone; }
217 virtual Bool_t OpenComposite(
const TBuffer3D&, Bool_t* = 0) {
return kFALSE; }
218 virtual void CloseComposite() {}
219 virtual void AddCompositeOp(UInt_t) {}
221 virtual void PrintObjects();
222 virtual void ResetCameras() { SetupCameras(kTRUE); }
223 virtual void ResetCamerasAfterNextUpdate() { fResetCamerasOnNextUpdate = kTRUE; }
225 TGLWidget* GetGLWidget() {
return fGLWidget; }
227 virtual void CreateGLWidget() {}
228 virtual void DestroyGLWidget() {}
230 Int_t GetDev()
const {
return fGLDevice; }
231 Bool_t GetSmartRefresh()
const {
return fSmartRefresh; }
232 void SetSmartRefresh(Bool_t smart_ref) { fSmartRefresh = smart_ref; }
234 TGLColorSet& RefDarkColorSet() {
return fDarkColorSet; }
235 TGLColorSet& RefLightColorSet() {
return fLightColorSet; }
236 TGLColorSet& ColorSet() {
return * fRnrCtx->GetBaseColorSet(); }
237 void UseDarkColorSet();
238 void UseLightColorSet();
239 void SwitchColorSet();
241 void UseDefaultColorSet(Bool_t x);
242 Bool_t IsUsingDefaultColorSet()
const;
243 Bool_t IsColorSetDark()
const;
245 void SetClearColor(Color_t col);
247 static TGLColorSet& GetDefaultColorSet();
248 static void UseDefaultColorSetForNewViewers(Bool_t x);
249 static Bool_t IsUsingDefaultColorSetForNewViewers();
251 const TGLRect& RefViewport()
const {
return fViewport; }
252 Int_t ViewportDiagonal()
const {
return fViewport.Diagonal(); }
254 Float_t GetPointScale()
const {
return fPointScale; }
255 Float_t GetLineScale()
const {
return fLineScale; }
256 void SetPointScale(Float_t s) { fPointScale = s; }
257 void SetLineScale (Float_t s) { fLineScale = s; }
258 Bool_t GetSmoothPoints()
const {
return fSmoothPoints; }
259 Bool_t GetSmoothLines()
const {
return fSmoothLines; }
260 void SetSmoothPoints(Bool_t s){ fSmoothPoints = s; }
261 void SetSmoothLines(Bool_t s) { fSmoothLines = s; }
263 TGLLightSet* GetLightSet()
const {
return fLightSet; }
264 TGLClipSet * GetClipSet()
const {
return fClipSet; }
265 Bool_t GetClipAutoUpdate()
const {
return fClipSet->GetAutoUpdate(); }
266 void SetClipAutoUpdate(Bool_t x) { fClipSet->SetAutoUpdate(x); }
269 TGLCamera & CurrentCamera()
const {
return *fCurrentCamera; }
270 TGLCamera & RefCamera(ECameraType camera);
271 void SetCurrentCamera(ECameraType camera);
272 void SetOrthoCamera(ECameraType camera, Double_t zoom, Double_t dolly,
273 Double_t center[3], Double_t hRotate, Double_t vRotate);
274 void SetPerspectiveCamera(ECameraType camera, Double_t fov, Double_t dolly,
275 Double_t center[3], Double_t hRotate, Double_t vRotate);
276 void ReinitializeCurrentCamera(
const TGLVector3& hAxis,
const TGLVector3& vAxis, Bool_t redraw=kTRUE);
277 void GetGuideState(Int_t & axesType, Bool_t & axesDepthTest, Bool_t & referenceOn, Double_t* referencePos)
const;
278 void SetGuideState(Int_t axesType, Bool_t axesDepthTest, Bool_t referenceOn,
const Double_t* referencePos);
279 void SetDrawCameraCenter(Bool_t x);
280 Bool_t GetDrawCameraCenter() {
return fDrawCameraCenter; }
281 void PickCameraCenter() { fPushAction = kPushCamCenter; RefreshPadEditor(
this); }
282 void PickAnnotate() { fPushAction = kPushAnnotate; RefreshPadEditor(
this); }
283 TGLCameraOverlay* GetCameraOverlay()
const {
return fCameraOverlay; }
284 void SetCameraOverlay(TGLCameraOverlay* m) { fCameraOverlay = m; }
285 TGLAutoRotator* GetAutoRotator();
286 void SetAutoRotator(TGLAutoRotator* ar);
289 Bool_t GetStereo()
const {
return fStereo; }
290 Float_t GetStereoZeroParallax()
const {
return fStereoZeroParallax; }
291 Float_t GetStereoEyeOffsetFac()
const {
return fStereoEyeOffsetFac; }
292 Float_t GetStereoFrustumAsymFac()
const {
return fStereoFrustumAsymFac; }
294 void SetStereo(Bool_t stereo, Bool_t quad_buf=kTRUE);
295 void SetStereoZeroParallax(Float_t f) { fStereoZeroParallax = f; }
296 void SetStereoEyeOffsetFac(Float_t f) { fStereoEyeOffsetFac = f; }
297 void SetStereoFrustumAsymFac(Float_t f) { fStereoFrustumAsymFac = f; }
300 EPushAction GetPushAction()
const {
return fPushAction; }
301 EDragAction GetDragAction()
const {
return fDragAction; }
303 const TGLPhysicalShape * GetSelected()
const;
309 Float_t GetMaxSceneDrawTimeHQ()
const {
return fMaxSceneDrawTimeHQ; }
310 Float_t GetMaxSceneDrawTimeLQ()
const {
return fMaxSceneDrawTimeLQ; }
311 void SetMaxSceneDrawTimeHQ(Float_t t) { fMaxSceneDrawTimeHQ = t; }
312 void SetMaxSceneDrawTimeLQ(Float_t t) { fMaxSceneDrawTimeLQ = t; }
315 void RequestDraw(Short_t LOD = TGLRnrCtx::kLODMed);
316 virtual void PreRender();
317 virtual void Render();
318 virtual void PostRender();
319 void DoDraw(Bool_t swap_buffers=kTRUE);
320 void DoDrawMono(Bool_t swap_buffers);
321 void DoDrawStereo(Bool_t swap_buffers);
324 void DrawDebugInfo();
326 Bool_t RequestSelect(Int_t x, Int_t y);
327 Bool_t DoSelect(Int_t x, Int_t y);
328 Bool_t RequestSecondarySelect(Int_t x, Int_t y);
329 Bool_t DoSecondarySelect(Int_t x, Int_t y);
330 void ApplySelection();
332 Bool_t RequestOverlaySelect(Int_t x, Int_t y);
333 Bool_t DoOverlaySelect(Int_t x, Int_t y);
336 Bool_t SavePicture();
337 Bool_t SavePicture(
const TString &fileName);
338 Bool_t SavePictureUsingBB (
const TString &fileName);
339 Bool_t SavePictureUsingFBO(
const TString &fileName, Int_t w, Int_t h, Float_t pixel_object_scale=0);
340 Bool_t SavePictureWidth (
const TString &fileName, Int_t width, Bool_t pixel_object_scale=kTRUE);
341 Bool_t SavePictureHeight(
const TString &fileName, Int_t height, Bool_t pixel_object_scale=kTRUE);
342 Bool_t SavePictureScale (
const TString &fileName, Float_t scale, Bool_t pixel_object_scale=kTRUE);
345 TImage* GetPictureUsingBB();
346 TImage* GetPictureUsingFBO(Int_t w, Int_t h,Float_t pixel_object_scale=0);
348 const char* GetPictureFileName()
const {
return fPictureFileName.Data(); }
349 void SetPictureFileName(
const TString& f) { fPictureFileName = f; }
350 Float_t GetFader()
const {
return fFader; }
351 void SetFader(Float_t x) { fFader = x; }
352 void AutoFade(Float_t fade, Float_t time=1, Int_t steps=10);
355 void UpdateScene(Bool_t redraw=kTRUE);
356 Bool_t GetIgnoreSizesOnUpdate()
const {
return fIgnoreSizesOnUpdate; }
357 void SetIgnoreSizesOnUpdate(Bool_t v) { fIgnoreSizesOnUpdate = v; }
358 void ResetCurrentCamera();
359 Bool_t GetResetCamerasOnUpdate()
const {
return fResetCamerasOnUpdate; }
360 void SetResetCamerasOnUpdate(Bool_t v) { fResetCamerasOnUpdate = v; }
362 virtual void PostSceneBuildSetup(Bool_t resetCameras);
364 virtual void Activated() { Emit(
"Activated()"); }
366 virtual void MouseIdle(TGLPhysicalShape*,UInt_t,UInt_t);
367 virtual void MouseOver(TGLPhysicalShape*);
368 virtual void MouseOver(TGLPhysicalShape*, UInt_t state);
369 virtual void MouseOver(TObject *obj, UInt_t state);
370 virtual void ReMouseOver(TObject *obj, UInt_t state);
371 virtual void UnMouseOver(TObject *obj, UInt_t state);
373 virtual void Clicked(TObject *obj);
374 virtual void Clicked(TObject *obj, UInt_t button, UInt_t state);
375 virtual void ReClicked(TObject *obj, UInt_t button, UInt_t state);
376 virtual void UnClicked(TObject *obj, UInt_t button, UInt_t state);
377 virtual void DoubleClicked() { Emit(
"DoubleClicked()"); }
379 TGEventHandler *GetEventHandler()
const {
return fEventHandler; }
380 virtual void SetEventHandler(TGEventHandler *handler);
382 TGedEditor* GetGedEditor()
const {
return fGedEditor; }
383 virtual void SetGedEditor(TGedEditor* ed) { fGedEditor = ed; }
385 virtual void SelectionChanged();
386 virtual void OverlayDragFinished();
387 virtual void RefreshPadEditor(TObject* obj=0);
389 virtual void RemoveOverlayElement(TGLOverlayElement* el);
391 TGLSelectRecord& GetSelRec() {
return fSelRec; }
392 TGLOvlSelectRecord& GetOvlSelRec() {
return fOvlSelRec; }
393 TGLOverlayElement* GetCurrentOvlElm()
const {
return fCurrentOvlElm; }
394 void ClearCurrentOvlElm();
396 ClassDef(TGLViewer,0)
402 class TGLRedrawTimer :
public TTimer
409 TGLRedrawTimer(TGLViewer & viewer) :
410 fViewer(viewer), fRedrawLOD(TGLRnrCtx::kLODHigh), fPending(kFALSE) {}
412 void RequestDraw(Int_t milliSec, Short_t redrawLOD)
414 if (fPending) TurnOff();
else fPending = kTRUE;
415 if (redrawLOD < fRedrawLOD) fRedrawLOD = redrawLOD;
416 TTimer::Start(milliSec, kTRUE);
418 Bool_t IsPending()
const {
return fPending; }
421 if (fPending) { TurnOff(); fPending = kFALSE; }
427 fViewer.RequestDraw(fRedrawLOD);
428 fRedrawLOD = TGLRnrCtx::kLODHigh;
433 class TGLFaderHelper {
435 TGLFaderHelper(
const TGLFaderHelper&);
436 TGLFaderHelper& operator=(
const TGLFaderHelper&);
445 fViewer(0), fFadeTarget(0), fTime(0), fNSteps(0) {}
446 TGLFaderHelper(TGLViewer* v, Float_t fade, Float_t time, Int_t steps) :
447 fViewer(v),fFadeTarget(fade), fTime(time), fNSteps(steps) {}
448 virtual ~TGLFaderHelper() {}
452 ClassDef(TGLFaderHelper, 0);
455 #endif // ROOT_TGLViewer