Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGLViewer.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Richard Maunder 25/05/2005
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, 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#include "TGLViewer.h"
13#include "TGLIncludes.h"
14#include "TGLStopwatch.h"
15#include "TGLRnrCtx.h"
16#include "TGLSelectBuffer.h"
17#include "TGLLightSet.h"
18#include "TGLManipSet.h"
19#include "TGLCameraOverlay.h"
20#include "TGLAutoRotator.h"
21
22#include "TGLScenePad.h"
23#include "TGLLogicalShape.h"
24#include "TGLPhysicalShape.h"
25#include "TGLObject.h"
26#include "TBuffer3D.h"
27#include "TBuffer3DTypes.h"
28
29#include "TGLOutput.h"
30
31#include "TROOT.h"
32#include "TVirtualMutex.h"
33
34#include "TVirtualPad.h" // Remove when pad removed - use signal
35#include "TVirtualX.h"
36
37#include "TMath.h"
38#include "TColor.h"
39#include "TError.h"
40#include "TEnv.h"
41
42// For event type translation ExecuteEvent
43#include "Buttons.h"
44#include "GuiTypes.h"
45
46#include "TVirtualGL.h"
47
48#include "TGLWidget.h"
49#include "TGLFBO.h"
50#include "TGLViewerEditor.h"
51#include "TGedEditor.h"
52#include "TGLPShapeObj.h"
53
54#include "KeySymbols.h"
55#include "TContextMenu.h"
56#include "TImage.h"
57
58#include <stdexcept>
59
60#ifndef GL_BGRA
61#define GL_BGRA GL_BGRA_EXT
62#endif
63
64/** \class TGLViewer
65\ingroup opengl
66Base GL viewer object - used by both standalone and embedded (in pad)
67GL. Contains core viewer objects :
68
69GL scene - collection of main drawn objects - see TGLStdScene
70Cameras (fXyzzCamera) - ortho and perspective cameras - see TGLCamera
71Clipping (fClipXyzz) - collection of clip objects - see TGLClip
72Manipulators (fXyzzManip) - collection of manipulators - see TGLManip
73
74It maintains the current active draw styles, clipping object,
75manipulator, camera etc.
76
77TGLViewer is 'GUI free' in that it does not derive from any ROOT GUI
78TGFrame etc - see TGLSAViewer for this. However it contains GUI
79GUI style methods HandleButton() etc to which GUI events can be
80directed from standalone frame or embedding pad to perform
81interaction.
82
83Also, the TGLWidget needs to be created externally. It is not owned
84by the viewer.
85
86For embedded (pad) GL this viewer is created directly by plugin
87manager. For standalone the derived TGLSAViewer is.
88*/
89
90
94
95////////////////////////////////////////////////////////////////////////////////
96
99 fPad(pad),
100 fContextMenu(nullptr),
101 fPerspectiveCameraXOZ(TGLVector3(-1.0, 0.0, 0.0), TGLVector3(0.0, 1.0, 0.0)), // XOZ floor
102 fPerspectiveCameraYOZ(TGLVector3( 0.0,-1.0, 0.0), TGLVector3(1.0, 0.0, 0.0)), // YOZ floor
103 fPerspectiveCameraXOY(TGLVector3(-1.0, 0.0, 0.0), TGLVector3(0.0, 0.0, 1.0)), // XOY floor
104 fOrthoXOYCamera (TGLOrthoCamera::kXOY, TGLVector3( 0.0, 0.0, 1.0), TGLVector3(0.0, 1.0, 0.0)), // Looking down Z axis, X horz, Y vert
105 fOrthoXOZCamera (TGLOrthoCamera::kXOZ, TGLVector3( 0.0,-1.0, 0.0), TGLVector3(0.0, 0.0, 1.0)), // Looking along Y axis, X horz, Z vert
106 fOrthoZOYCamera (TGLOrthoCamera::kZOY, TGLVector3(-1.0, 0.0, 0.0), TGLVector3(0.0, 1.0, 0.0)), // Looking along X axis, Z horz, Y vert
107 fOrthoZOXCamera (TGLOrthoCamera::kZOX, TGLVector3( 0.0,-1.0, 0.0), TGLVector3(1.0, 0.0, 0.0)), // Looking along Y axis, Z horz, X vert
108 fOrthoXnOYCamera(TGLOrthoCamera::kXnOY, TGLVector3( 0.0, 0.0,-1.0), TGLVector3(0.0, 1.0, 0.0)), // Looking along Z axis, -X horz, Y vert
109 fOrthoXnOZCamera(TGLOrthoCamera::kXnOZ, TGLVector3( 0.0, 1.0, 0.0), TGLVector3(0.0, 0.0, 1.0)), // Looking down Y axis, -X horz, Z vert
110 fOrthoZnOYCamera(TGLOrthoCamera::kZnOY, TGLVector3( 1.0, 0.0, 0.0), TGLVector3(0.0, 1.0, 0.0)), // Looking down X axis, -Z horz, Y vert
111 fOrthoZnOXCamera(TGLOrthoCamera::kZnOX, TGLVector3( 0.0, 1.0, 0.0), TGLVector3(1.0, 0.0, 0.0)), // Looking down Y axis, -Z horz, X vert
112 fCurrentCamera(&fPerspectiveCameraXOZ),
113 fAutoRotator(nullptr),
114
115 fStereo (kFALSE),
116 fStereoQuadBuf (kFALSE),
117 fStereoZeroParallax (0.03f),
118 fStereoEyeOffsetFac (1.0f),
119 fStereoFrustumAsymFac (1.0f),
120
121 fLightSet (nullptr),
122 fClipSet (nullptr),
123 fSelectedPShapeRef (nullptr),
124 fCurrentOvlElm (nullptr),
125
126 fEventHandler(nullptr),
127 fGedEditor(nullptr),
128 fPShapeWrap(nullptr),
129 fPushAction(kPushStd), fDragAction(kDragNone),
130 fRedrawTimer(nullptr),
131 fMaxSceneDrawTimeHQ(5000),
132 fMaxSceneDrawTimeLQ(100),
133 fPointScale (1), fLineScale(1), fSmoothPoints(kFALSE), fSmoothLines(kFALSE),
134 fAxesType(TGLUtil::kAxesNone),
135 fAxesDepthTest(kTRUE),
136 fReferenceOn(kFALSE),
137 fReferencePos(0.0, 0.0, 0.0),
138 fDrawCameraCenter(kFALSE),
139 fCameraOverlay(nullptr),
140 fSmartRefresh(kFALSE),
141 fDebugMode(kFALSE),
142 fIsPrinting(kFALSE),
143 fPictureFileName("viewer.jpg"),
144 fFader(0),
145 fGLWidget(nullptr),
146 fGLDevice(-1),
147 fGLCtxId(nullptr),
148 fIgnoreSizesOnUpdate(kFALSE),
149 fResetCamerasOnUpdate(kTRUE),
150 fResetCamerasOnNextUpdate(kFALSE)
151{
152 // Construct the viewer object, with following arguments:
153 // 'pad' - external pad viewer is bound to
154 // 'x', 'y' - initial top left position
155 // 'width', 'height' - initial width/height
156
158
160}
161
162////////////////////////////////////////////////////////////////////////////////
163
165 fPad(pad),
166 fContextMenu(nullptr),
167 fPerspectiveCameraXOZ(TGLVector3(-1.0, 0.0, 0.0), TGLVector3(0.0, 1.0, 0.0)), // XOZ floor
168 fPerspectiveCameraYOZ(TGLVector3( 0.0,-1.0, 0.0), TGLVector3(1.0, 0.0, 0.0)), // YOZ floor
169 fPerspectiveCameraXOY(TGLVector3(-1.0, 0.0, 0.0), TGLVector3(0.0, 0.0, 1.0)), // XOY floor
170 fOrthoXOYCamera (TGLOrthoCamera::kXOY, TGLVector3( 0.0, 0.0, 1.0), TGLVector3(0.0, 1.0, 0.0)), // Looking down Z axis, X horz, Y vert
171 fOrthoXOZCamera (TGLOrthoCamera::kXOZ, TGLVector3( 0.0,-1.0, 0.0), TGLVector3(0.0, 0.0, 1.0)), // Looking along Y axis, X horz, Z vert
172 fOrthoZOYCamera (TGLOrthoCamera::kZOY, TGLVector3(-1.0, 0.0, 0.0), TGLVector3(0.0, 1.0, 0.0)), // Looking along X axis, Z horz, Y vert
173 fOrthoZOXCamera (TGLOrthoCamera::kZOX, TGLVector3( 0.0,-1.0, 0.0), TGLVector3(1.0, 0.0, 0.0)), // Looking along Y axis, Z horz, X vert
174 fOrthoXnOYCamera(TGLOrthoCamera::kXnOY, TGLVector3( 0.0, 0.0,-1.0), TGLVector3(0.0, 1.0, 0.0)), // Looking along Z axis, -X horz, Y vert
175 fOrthoXnOZCamera(TGLOrthoCamera::kXnOZ, TGLVector3( 0.0, 1.0, 0.0), TGLVector3(0.0, 0.0, 1.0)), // Looking down Y axis, -X horz, Z vert
176 fOrthoZnOYCamera(TGLOrthoCamera::kZnOY, TGLVector3( 1.0, 0.0, 0.0), TGLVector3(0.0, 1.0, 0.0)), // Looking down X axis, -Z horz, Y vert
177 fOrthoZnOXCamera(TGLOrthoCamera::kZnOX, TGLVector3( 0.0, 1.0, 0.0), TGLVector3(1.0, 0.0, 0.0)), // Looking down Y axis, -Z horz, X vert
178 fCurrentCamera(&fPerspectiveCameraXOZ),
179 fAutoRotator(nullptr),
180
181 fStereo (kFALSE),
182 fStereoQuadBuf (kFALSE),
183 fStereoZeroParallax (0.03f),
184 fStereoEyeOffsetFac (1.0f),
185 fStereoFrustumAsymFac (1.0f),
186
187 fLightSet (nullptr),
188 fClipSet (nullptr),
189 fSelectedPShapeRef (nullptr),
190 fCurrentOvlElm (nullptr),
191
192 fEventHandler(nullptr),
193 fGedEditor(nullptr),
194 fPShapeWrap(nullptr),
195 fPushAction(kPushStd), fDragAction(kDragNone),
196 fRedrawTimer(nullptr),
197 fMaxSceneDrawTimeHQ(5000),
198 fMaxSceneDrawTimeLQ(100),
199 fPointScale (1), fLineScale(1), fSmoothPoints(kFALSE), fSmoothLines(kFALSE),
200 fAxesType(TGLUtil::kAxesNone),
201 fAxesDepthTest(kTRUE),
202 fReferenceOn(kFALSE),
203 fReferencePos(0.0, 0.0, 0.0),
204 fDrawCameraCenter(kFALSE),
205 fCameraOverlay(nullptr),
206 fSmartRefresh(kFALSE),
207 fDebugMode(kFALSE),
208 fIsPrinting(kFALSE),
209 fPictureFileName("viewer.jpg"),
210 fFader(0),
211 fGLWidget(nullptr),
212 fGLDevice(fPad->GetGLDevice()),
213 fGLCtxId(nullptr),
214 fIgnoreSizesOnUpdate(kFALSE),
215 fResetCamerasOnUpdate(kTRUE),
216 fResetCamerasOnNextUpdate(kFALSE)
217{
218 //gl-embedded viewer's ctor
219 // Construct the viewer object, with following arguments:
220 // 'pad' - external pad viewer is bound to
221 // 'x', 'y' - initial top left position
222 // 'width', 'height' - initial width/height
223
225
226 if (fGLDevice != -1) {
227 // For the moment instantiate a fake context identity.
229 fGLCtxId->AddRef(nullptr);
230 Int_t viewport[4] = {0};
231 gGLManager->ExtractViewport(fGLDevice, viewport);
233 }
234}
235
236////////////////////////////////////////////////////////////////////////////////
237/// Common initialization.
238
269
270////////////////////////////////////////////////////////////////////////////////
271/// Destroy viewer object.
272
274{
275 delete fAutoRotator;
276
277 delete fLightSet;
278 // fClipSet, fSelectedPShapeRef and fCameraOverlay deleted via overlay.
279
280 delete fContextMenu;
281 delete fRedrawTimer;
282
283 if (fEventHandler) {
284 if (fGLWidget)
285 fGLWidget->SetEventHandler(nullptr);
286 delete fEventHandler;
287 }
288
289 if (fPad)
291 if (fGLDevice != -1)
292 fGLCtxId->Release(nullptr);
293}
294
295
296////////////////////////////////////////////////////////////////////////////////
297/// Entry point for updating viewer contents via VirtualViewer3D
298/// interface.
299/// We search and forward the request to appropriate TGLScenePad.
300/// If it is not found we create a new TGLScenePad so this can
301/// potentially also be used for registration of new pads.
302
304{
305 TGLScenePad* scenepad = nullptr;
306 for (SceneInfoList_i si = fScenes.begin(); si != fScenes.end(); ++si)
307 {
308 scenepad = dynamic_cast<TGLScenePad*>((*si)->GetScene());
309 if (scenepad && scenepad->GetPad() == pad)
310 break;
311 scenepad = nullptr;
312 }
313 if (scenepad == nullptr)
314 {
315 scenepad = new TGLScenePad(pad);
317 }
318
319 scenepad->PadPaintFromViewer(this);
320
323
324 RequestDraw();
325}
326
327
328/**************************************************************************/
329/**************************************************************************/
330
331////////////////////////////////////////////////////////////////////////////////
332/// Force update of pad-scenes. Eventually this could be generalized
333/// to all scene-types via a virtual function in TGLSceneBase.
334
336{
337 // Cancel any pending redraw timer.
339
340 for (SceneInfoList_i si = fScenes.begin(); si != fScenes.end(); ++si)
341 {
342 TGLScenePad* scenepad = dynamic_cast<TGLScenePad*>((*si)->GetScene());
343 if (scenepad)
344 scenepad->PadPaintFromViewer(this);
345 }
346
349
350 if (redraw)
351 RequestDraw();
352}
353
354////////////////////////////////////////////////////////////////////////////////
355/// Resets position/rotation of current camera to default values.
356
362
363////////////////////////////////////////////////////////////////////////////////
364/// Setup cameras for current bounding box.
365
367{
368 if (IsLocked()) {
369 Error("TGLViewer::SetupCameras", "expected kUnlocked, found %s", LockName(CurrentLock()));
370 return;
371 }
372
373 // Setup cameras if scene box is not empty
375 if (!box.IsEmpty()) {
379 fOrthoXOYCamera.Setup(box, reset);
380 fOrthoXOZCamera.Setup(box, reset);
381 fOrthoZOYCamera.Setup(box, reset);
382 fOrthoXnOYCamera.Setup(box, reset);
383 fOrthoXnOZCamera.Setup(box, reset);
384 fOrthoZnOYCamera.Setup(box, reset);
385 }
386}
387
388////////////////////////////////////////////////////////////////////////////////
389/// Perform post scene-build setup.
390
400
401
402/**************************************************************************/
403/**************************************************************************/
404
405////////////////////////////////////////////////////////////////////////////////
406/// Initialise GL state.
407
432
433////////////////////////////////////////////////////////////////////////////////
434/// Post request for redraw of viewer at level of detail 'LOD'
435/// Request is directed via cross thread gVirtualGL object.
436
438{
440 // Ignore request if GL window or context not yet available or shown.
441 if ((!fGLWidget && fGLDevice == -1) || (fGLWidget && !fGLWidget->IsMapped()))
442 {
443 return;
444 }
445
446 // Take scene draw lock - to be revisited
447 if ( ! TakeLock(kDrawLock)) {
448 // If taking drawlock fails the previous draw is still in progress
449 // set timer to do this one later
450 if (gDebug>3) {
451 Info("TGLViewer::RequestDraw", "viewer locked - requesting another draw.");
452 }
454 return;
455 }
456 fLOD = LODInput;
457
458 if (!gVirtualX->IsCmdThread())
459 gROOT->ProcessLineFast(Form("((TGLViewer *)0x%zx)->DoDraw()", (size_t)this));
460 else
461 DoDraw();
462}
463
464////////////////////////////////////////////////////////////////////////////////
465/// Setup clip-object. Protected virtual method.
466
478////////////////////////////////////////////////////////////////////////////////
479/// Initialize objects that influence rendering.
480/// Called before every render.
481
512
513////////////////////////////////////////////////////////////////////////////////
514/// Normal rendering, used by mono and stereo rendering.
515
531
532////////////////////////////////////////////////////////////////////////////////
533/// Restore state set in PreRender().
534/// Called after every render.
535
543
544////////////////////////////////////////////////////////////////////////////////
545/// Draw out the viewer.
546
548{
549 // Locking mainly for Win32 multi thread safety - but no harm in all using it
550 // During normal draws a draw lock is taken in other thread (Win32) in RequestDraw()
551 // to ensure thread safety. For PrintObjects repeated Draw() calls are made.
552 // If no draw lock taken get one now.
553
555
557
558 if (CurrentLock() != kDrawLock) {
559 if ( ! TakeLock(kDrawLock)) {
560 Error("TGLViewer::DoDraw", "viewer is %s", LockName(CurrentLock()));
561 return;
562 }
563 }
564
565 TUnlocker ulck(this);
566
567 if (fGLDevice == -1 && (fViewport.Width() <= 1 || fViewport.Height() <= 1)) {
568 if (gDebug > 2) {
569 Info("TGLViewer::DoDraw()", "zero surface area, draw skipped.");
570 }
571 return;
572 }
573
574 if (fGLDevice != -1) {
575 Int_t viewport[4] = {};
576 gGLManager->ExtractViewport(fGLDevice, viewport);
578 }
579
581 if (gDebug>2) {
582 timer.Start();
583 }
584
585 // Setup scene draw time
589
592 {
594 }
595 else
596 {
598 }
599
601
602 if (gDebug>2) {
603 Info("TGLViewer::DoDraw()", "Took %f msec", timer.End());
604 }
605
606 // Check if further redraws are needed and schedule them.
607
608 if (CurrentCamera().UpdateInterest(kFALSE)) {
609 // Reset major view-dependant cache.
612 }
613
614 if (fLOD != TGLRnrCtx::kLODHigh &&
616 {
617 // Request final draw pass.
619 }
620}
621
622////////////////////////////////////////////////////////////////////////////////
623/// Draw out in monoscopic mode.
624
626{
627 MakeCurrent();
628
629 if (!fIsPrinting) PreDraw();
630 PreRender();
631
633 if (fFader < 1)
634 {
635 Render();
636 }
638
639 PostRender();
640
641 if (fFader > 0)
642 {
644 }
645
646 PostDraw();
647
648 if (swap_buffers)
649 {
650 SwapBuffers();
651 }
652}
653
654////////////////////////////////////////////////////////////////////////////////
655/// Draw out in stereoscopic mode.
656
658{
660
666
667 MakeCurrent();
668
669 // Draw left
670 if (fStereoQuadBuf)
671 {
673 }
674 else
675 {
678 }
679 PreDraw();
680 PreRender();
681
682 gl_near = c.GetNearClip();
683 gl_far = c.GetFarClip();
685
686 h_half = TMath::Tan(0.5*TMath::DegToRad()*c.GetFOV()) * gl_near;
688
691
693
694 TGLMatrix abs_trans(c.RefCamBase());
695 abs_trans *= c.RefCamTrans();
696 TGLVector3 left_vec = abs_trans.GetBaseVec(2);
697
699
705
707 if (fFader < 1)
708 {
709 Render();
710 }
712
713 PostRender();
714
715 if (fFader > 0)
716 {
718 }
719 PostDraw();
720
721 // Draw right
722 if (fStereoQuadBuf)
723 {
725 }
726 else
727 {
729 }
730 PreDraw();
731 PreRender();
732 if ( ! fStereoQuadBuf)
733 {
735 }
736
738
744
746 if (fFader < 1)
747 {
748 Render();
749 }
751
752 PostRender();
753
754 if (fFader > 0)
755 {
757 }
758 PostDraw();
759
760 // End
761 if (swap_buffers)
762 {
763 SwapBuffers();
764 }
765
766 if (fStereoQuadBuf)
767 {
769 }
770 else
771 {
774 }
775}
776
777////////////////////////////////////////////////////////////////////////////////
778/// Save current image using the default file name which can be set
779/// via SetPictureFileName() and defaults to "viewer.jpg".
780/// Really useful for the files ending with 'gif+'.
781
786
787////////////////////////////////////////////////////////////////////////////////
788/// Save current image in various formats (gif, gif+, jpg, png, eps, pdf).
789/// 'gif+' will append image to an existing file (animated gif).
790/// 'eps' and 'pdf' do not fully support transparency and texturing.
791/// The viewer window most be fully contained within the desktop but
792/// can be covered by other windows.
793/// Returns false if something obvious goes wrong, true otherwise.
794///
795/// The mage is saved using a frame-buffer object if the GL implementation
796/// claims to support it -- this claim is not always true, especially when
797/// running over ssh with drastically different GL implementations on the
798/// client and server sides. Set this in .rootrc to enforce creation of
799/// pictures using the back-buffer:
800/// OpenGL.SavePicturesViaFBO: off
801
803{
804 if (fileName.EndsWith(".eps"))
805 {
806 return TGLOutput::Capture(*this, TGLOutput::kEPS_BSP, fileName.Data());
807 }
808 else if (fileName.EndsWith(".pdf"))
809 {
810 return TGLOutput::Capture(*this, TGLOutput::kPDF_BSP, fileName.Data());
811 }
812 else
813 {
814 if (GLEW_EXT_framebuffer_object && gEnv->GetValue("OpenGL.SavePicturesViaFBO", 1))
815 {
817 }
818 else
819 {
820 return SavePictureUsingBB(fileName);
821 }
822 }
823}
824
825////////////////////////////////////////////////////////////////////////////////
826/// Save current image in various formats (gif, gif+, jpg, png).
827/// 'gif+' will append image to an existing file (animated gif).
828/// Back-Buffer is used for capturing of the image.
829/// The viewer window most be fully contained within the desktop but
830/// can be covered by other windows.
831/// Returns false if something obvious goes wrong, true otherwise.
832
834{
835 static const TString eh("TGLViewer::SavePictureUsingBB");
836
837 if (! fileName.EndsWith(".gif") && ! fileName.Contains(".gif+") &&
838 ! fileName.EndsWith(".jpg") && ! fileName.EndsWith(".png"))
839 {
840 Warning(eh, "file %s cannot be saved with this extension.", fileName.Data());
841 return kFALSE;
842 }
843
844 if ( ! TakeLock(kDrawLock)) {
845 Error(eh, "viewer locked - try later.");
846 return kFALSE;
847 }
848
849 TUnlocker ulck(this);
850
853
854 if (!gVirtualX->IsCmdThread())
855 gROOT->ProcessLineFast(Form("((TGLViewer *)0x%zx)->DoDraw(kFALSE)", (size_t)this));
856 else
857 DoDraw(kFALSE);
858
860
862
863 UChar_t* xx = new UChar_t[4 * fViewport.Width() * fViewport.Height()];
867
868 std::unique_ptr<TImage> image(TImage::Create());
869 image->FromGLBuffer(xx, fViewport.Width(), fViewport.Height());
870 image->WriteImage(fileName);
871
872 delete [] xx;
873
874 return kTRUE;
875}
876
877////////////////////////////////////////////////////////////////////////////////
878/// Save current image in various formats (gif, gif+, jpg, png).
879/// 'gif+' will append image to an existing file (animated gif).
880/// Frame-Buffer-Object is used for capturing of the image - OpenGL
881/// 1.5 is required.
882/// The viewer window does not have to be visible at all.
883/// Returns false if something obvious goes wrong, true otherwise.
884///
885/// pixel_object_scale is used to scale (as much as possible) the
886/// objects whose representation size is pixel based (point-sizes,
887/// line-widths, bitmap/pixmap font-sizes).
888/// If set to 0 (default) no scaling is applied.
889
892{
893 static const TString eh("TGLViewer::SavePictureUsingFBO");
894
895 if (! fileName.EndsWith(".gif") && ! fileName.Contains(".gif+") &&
896 ! fileName.EndsWith(".jpg") && ! fileName.EndsWith(".png"))
897 {
898 Warning(eh, "file %s cannot be saved with this extension.", fileName.Data());
899 return kFALSE;
900 }
901
902 if ( ! TakeLock(kDrawLock)) {
903 Error(eh, "viewer locked - try later.");
904 return kFALSE;
905 }
906
907 TUnlocker ulck(this);
908
909 MakeCurrent();
910
911 TGLFBO *fbo = new TGLFBO();
912 try
913 {
914 fbo->Init(w, h, fGLWidget->GetPixelFormat()->GetSamples());
915 }
916 catch (std::runtime_error& exc)
917 {
918 Error(eh, "%s",exc.what());
919 if (gEnv->GetValue("OpenGL.SavePictureFallbackToBB", 1)) {
920 Info(eh, "Falling back to saving image via back-buffer. Window must be fully visible.");
921 if (w != fViewport.Width() || h != fViewport.Height())
922 Warning(eh, "Back-buffer does not support image scaling, window size will be used.");
923 return SavePictureUsingBB(fileName);
924 } else {
925 return kFALSE;
926 }
927 }
928
930 SetViewport(0, 0, w, h);
931
932 Float_t old_scale = 1;
933 if (pixel_object_scale != 0)
934 {
937 }
938
939 fbo->Bind();
940
943
944 if (!gVirtualX->IsCmdThread())
945 gROOT->ProcessLineFast(Form("((TGLViewer *)0x%zx)->DoDraw(kFALSE)", (size_t)this));
946 else
947 DoDraw(kFALSE);
948
950
951 fbo->Unbind();
952
953 fbo->SetAsReadBuffer();
954
955 UChar_t* xx = new UChar_t[4 * fViewport.Width() * fViewport.Height()];
959
960 std::unique_ptr<TImage> image(TImage::Create());
961 image->FromGLBuffer(xx, fViewport.Width(), fViewport.Height());
962 image->WriteImage(fileName);
963
964 delete [] xx;
965
966 delete fbo;
967
968 if (pixel_object_scale != 0)
969 {
971 }
972
974
975 return kTRUE;
976}
977
978////////////////////////////////////////////////////////////////////////////////
979/// Returns current image.
980/// Back-Buffer is used for capturing of the image.
981/// The viewer window most be fully contained within the desktop but
982/// can be covered by other windows.
983
985{
986 static const TString eh("TGLViewer::GetPictureUsingBB");
987
988 if ( ! TakeLock(kDrawLock)) {
989 Error(eh, "viewer locked - try later.");
990 return nullptr;
991 }
992
993 TUnlocker ulck(this);
994
997
998 if (!gVirtualX->IsCmdThread())
999 gROOT->ProcessLineFast(Form("((TGLViewer *)0x%zx)->DoDraw(kFALSE)", (size_t)this));
1000 else
1001 DoDraw(kFALSE);
1002
1004
1006
1007 UChar_t* xx = new UChar_t[4 * fViewport.Width() * fViewport.Height()];
1011
1013 image->FromGLBuffer(xx, fViewport.Width(), fViewport.Height());
1014
1015 delete [] xx;
1016
1017 return image;
1018}
1019
1020////////////////////////////////////////////////////////////////////////////////
1021/// Returns current image.
1022/// Frame-Buffer-Object is used for capturing of the image - OpenGL
1023/// 1.5 is required.
1024/// The viewer window does not have to be visible at all.
1025///
1026/// pixel_object_scale is used to scale (as much as possible) the
1027/// objects whose representation size is pixel based (point-sizes,
1028/// line-widths, bitmap/pixmap font-sizes).
1029/// If set to 0 (default) no scaling is applied.
1030
1032{
1033 static const TString eh("TGLViewer::GetPictureUsingFBO");
1034
1035 if ( ! TakeLock(kDrawLock)) {
1036 Error(eh, "viewer locked - try later.");
1037 return nullptr;
1038 }
1039
1040 TUnlocker ulck(this);
1041
1042 MakeCurrent();
1043
1044 TGLFBO *fbo = new TGLFBO();
1045 try
1046 {
1047 fbo->Init(w, h, fGLWidget->GetPixelFormat()->GetSamples());
1048 }
1049 catch (std::runtime_error& exc)
1050 {
1051 Error(eh, "%s",exc.what());
1052 if (gEnv->GetValue("OpenGL.GetPictureFallbackToBB", 1)) {
1053 Info(eh, "Falling back to saving image via back-buffer. Window must be fully visible.");
1054 if (w != fViewport.Width() || h != fViewport.Height())
1055 Warning(eh, "Back-buffer does not support image scaling, window size will be used.");
1056 return GetPictureUsingBB();
1057 } else {
1058 return nullptr;
1059 }
1060 }
1061
1063 SetViewport(0, 0, w, h);
1064
1065 Float_t old_scale = 1;
1066 if (pixel_object_scale != 0)
1067 {
1070 }
1071
1072 fbo->Bind();
1073
1076
1077 if (!gVirtualX->IsCmdThread())
1078 gROOT->ProcessLineFast(Form("((TGLViewer *)0x%zx)->DoDraw(kFALSE)", (size_t)this));
1079 else
1080 DoDraw(kFALSE);
1081
1083
1084 fbo->Unbind();
1085
1086 fbo->SetAsReadBuffer();
1087
1088 UChar_t* xx = new UChar_t[4 * fViewport.Width() * fViewport.Height()];
1092
1094 image->FromGLBuffer(xx, fViewport.Width(), fViewport.Height());
1095
1096 delete [] xx;
1097 delete fbo;
1098
1099 if (pixel_object_scale != 0)
1100 {
1102 }
1103
1105
1106 return image;
1107}
1108
1109
1110////////////////////////////////////////////////////////////////////////////////
1111/// Save picture with given width (height scaled proportionally).
1112/// If pixel_object_scale is true (default), the corresponding
1113/// scaling gets calculated from the current window size.
1114
1123
1124////////////////////////////////////////////////////////////////////////////////
1125/// Save picture with given height (width scaled proportionally).
1126/// If pixel_object_scale is true (default), the corresponding
1127/// scaling gets calculated from the current window size.
1128
1137
1138////////////////////////////////////////////////////////////////////////////////
1139/// Save picture with given scale to current window size.
1140/// If pixel_object_scale is true (default), the same scaling is
1141/// used.
1142
1151
1152////////////////////////////////////////////////////////////////////////////////
1153/// Draw reference marker and coordinate axes.
1154
1186
1187////////////////////////////////////////////////////////////////////////////////
1188/// If in debug mode draw camera aids and overall bounding box.
1189
1191{
1192 if (fDebugMode)
1193 {
1196
1197 // Green scene bounding box
1198 glColor3d(0.0, 1.0, 0.0);
1200
1201 // Scene bounding box center sphere (green) and
1205 const TGLVertex3 & center = fOverallBoundingBox.Center();
1208
1210 }
1211}
1212
1213////////////////////////////////////////////////////////////////////////////////
1214/// Perform GL work which must be done before each draw.
1215
1217{
1218 InitGL();
1219
1220 // For embedded gl clear color must be pad's background color.
1221 {
1222 Color_t ci = (fGLDevice != -1) ? gPad->GetFillColor() : fRnrCtx->ColorSet().Background().GetColorIndex();
1223 TColor *color = gROOT->GetColor(ci);
1224 Float_t rgb[3];
1225 if (color)
1226 color->GetRGB(rgb[0], rgb[1], rgb[2]);
1227 else
1228 rgb[0] = rgb[1] = rgb[2] = 0.0f;
1229
1230 glClearColor(rgb[0], rgb[1], rgb[2], 0.0f);
1231 }
1232
1234
1235 TGLUtil::CheckError("TGLViewer::PreDraw");
1236}
1237
1238////////////////////////////////////////////////////////////////////////////////
1239/// Perform GL work which must be done after each draw.
1240
1242{
1243 glFlush();
1244 TGLUtil::CheckError("TGLViewer::PostDraw");
1245}
1246
1247////////////////////////////////////////////////////////////////////////////////
1248/// Draw a rectangle (background color and given alpha) across the
1249/// whole viewport.
1250
1272
1273////////////////////////////////////////////////////////////////////////////////
1274/// Make GL context current
1275
1277{
1278 if (fGLDevice == -1)
1280 else
1281 gGLManager->MakeCurrent(fGLDevice);
1282}
1283
1284////////////////////////////////////////////////////////////////////////////////
1285/// Swap GL buffers
1286
1288{
1289 if ( ! IsDrawOrSelectLock()) {
1290 Error("TGLViewer::SwapBuffers", "viewer is %s", LockName(CurrentLock()));
1291 }
1292 if (fGLDevice == -1)
1294 else {
1295 gGLManager->ReadGLBuffer(fGLDevice);
1296 gGLManager->Flush(fGLDevice);
1297 gGLManager->MarkForDirectCopy(fGLDevice, kFALSE);
1298 }
1299}
1300
1301////////////////////////////////////////////////////////////////////////////////
1302/// Post request for selection render pass viewer, picking objects
1303/// around the window point (x,y).
1304
1306{
1307 // Take select lock on scene immediately we enter here - it is released
1308 // in the other (drawing) thread - see TGLViewer::DoSelect()
1309
1310 if ( ! TakeLock(kSelectLock)) {
1311 return kFALSE;
1312 }
1313
1314 if (!gVirtualX->IsCmdThread())
1315 return Bool_t(gROOT->ProcessLineFast(Form("((TGLViewer *)0x%zx)->DoSelect(%d, %d)", (size_t)this, x, y)));
1316 else
1317 return DoSelect(x, y);
1318}
1319
1320////////////////////////////////////////////////////////////////////////////////
1321/// Perform GL selection, picking objects overlapping WINDOW
1322/// area described by 'rect'. Return kTRUE if selection should be
1323/// changed, kFALSE otherwise.
1324/// Select lock should already been taken in other thread in
1325/// TGLViewer::ReqSelect().
1326
1328{
1330
1331 if (CurrentLock() != kSelectLock) {
1332 Error("TGLViewer::DoSelect", "expected kSelectLock, found %s", LockName(CurrentLock()));
1333 return kFALSE;
1334 }
1335
1337
1338 TUnlocker ulck(this);
1339
1340 MakeCurrent();
1341
1344
1345 PreRender();
1347 PostRender();
1348
1351
1352 // Process selection.
1353 if (gDebug > 0) Info("TGLViewer::DoSelect", "Primary select nHits=%d.", nHits);
1354
1355 if (nHits > 0)
1356 {
1357 Int_t idx = 0;
1358 if (FindClosestRecord(fSelRec, idx))
1359 {
1361 {
1363 if (FindClosestOpaqueRecord(opaque, ++idx))
1364 fSelRec = opaque;
1366 fSelRec.Reset();
1367 }
1368 if (gDebug > 1) fSelRec.Print();
1369 }
1370 } else {
1371 fSelRec.Reset();
1372 }
1373
1376}
1377
1378////////////////////////////////////////////////////////////////////////////////
1379/// Request secondary select.
1380
1382{
1383 if ( ! TakeLock(kSelectLock)) {
1384 return kFALSE;
1385 }
1386
1387 if (!gVirtualX->IsCmdThread())
1388 return Bool_t(gROOT->ProcessLineFast(Form("((TGLViewer *)0x%zx)->DoSecondarySelect(%d, %d)", (size_t)this, x, y)));
1389 else
1390 return DoSecondarySelect(x, y);
1391}
1392
1393////////////////////////////////////////////////////////////////////////////////
1394/// Secondary selection.
1395
1397{
1399
1400 if (CurrentLock() != kSelectLock) {
1401 Error("TGLViewer::DoSecondarySelect", "expected kSelectLock, found %s", LockName(CurrentLock()));
1402 return kFALSE;
1403 }
1404
1406
1407 TUnlocker ulck(this);
1408
1409 if (! fSelRec.GetSceneInfo() || ! fSelRec.GetPhysShape() ||
1411 {
1412 if (gDebug > 0)
1413 Info("TGLViewer::SecondarySelect", "Skipping secondary selection "
1414 "(sinfo=0x%zx, pshape=0x%zx).\n",
1415 (size_t)fSelRec.GetSceneInfo(), (size_t)fSelRec.GetPhysShape());
1416 fSecSelRec.Reset();
1417 return kFALSE;
1418 }
1419
1420 MakeCurrent();
1421
1423 TGLSceneBase* scene = sinfo->GetScene();
1425
1427 foo.push_back(sinfo);
1428 fScenes.swap(foo);
1432
1433 PreRender();
1435 scene->PreRender(*fRnrCtx);
1438 glPushName(pshp->ID());
1439 // !!! Hack: does not use clipping and proper draw-pass settings.
1440 pshp->Draw(*fRnrCtx);
1441 glPopName();
1442 scene->PostRender(*fRnrCtx);
1443 fRnrCtx->SetSceneInfo(nullptr);
1444 PostRender();
1445
1448 fScenes.swap(foo);
1449
1450 if (gDebug > 0) Info("TGLViewer::DoSelect", "Secondary select nSecHits=%d.", nSecHits);
1451
1453
1454 if (nSecHits > 0)
1455 {
1458 if (gDebug > 1) fSecSelRec.Print();
1459 return kTRUE;
1460 } else {
1461 fSecSelRec.Reset();
1462 return kFALSE;
1463 }
1464}
1465
1466////////////////////////////////////////////////////////////////////////////////
1467/// Process result from last selection (in fSelRec) and
1468/// extract a new current selection from it.
1469/// Here we only use physical shape.
1470
1472{
1474
1477
1478 // Inform external client selection has been modified.
1480
1482}
1483
1484////////////////////////////////////////////////////////////////////////////////
1485/// Post request for secondary selection rendering of selected object
1486/// around the window point (x,y).
1487
1489{
1490 // Take select lock on viewer immediately - it is released
1491 // in the other (drawing) thread - see TGLViewer::DoSecondarySelect().
1492
1493 if ( ! TakeLock(kSelectLock)) {
1494 return kFALSE;
1495 }
1496
1497 if (!gVirtualX->IsCmdThread())
1498 return Bool_t(gROOT->ProcessLineFast(Form("((TGLViewer *)0x%zx)->DoOverlaySelect(%d, %d)", (size_t)this, x, y)));
1499 else
1500 return DoOverlaySelect(x, y);
1501}
1502
1503////////////////////////////////////////////////////////////////////////////////
1504/// Perform GL selection, picking overlay objects only.
1505/// Return TRUE if the selected overlay-element has changed.
1506
1508{
1510
1511 if (CurrentLock() != kSelectLock) {
1512 Error("TGLViewer::DoOverlaySelect", "expected kSelectLock, found %s", LockName(CurrentLock()));
1513 return kFALSE;
1514 }
1515
1517
1518 TUnlocker ulck(this);
1519
1520 MakeCurrent();
1521
1524
1528
1531
1532 // Process overlay selection.
1533 TGLOverlayElement * selElm = nullptr;
1534 if (nHits > 0)
1535 {
1536 Int_t idx = 0;
1537 while (idx < nHits && FindClosestOverlayRecord(fOvlSelRec, idx))
1538 {
1540 if (el == fCurrentOvlElm)
1541 {
1542 if (el->MouseStillInside(fOvlSelRec))
1543 {
1544 selElm = el;
1545 break;
1546 }
1547 }
1548 else if (el->MouseEnter(fOvlSelRec))
1549 {
1550 selElm = el;
1551 break;
1552 }
1553 ++idx;
1554 }
1555 }
1556 else
1557 {
1558 fOvlSelRec.Reset();
1559 }
1560
1562
1563 if (fCurrentOvlElm != selElm)
1564 {
1567 return kTRUE;
1568 }
1569 else
1570 {
1571 return kFALSE;
1572 }
1573}
1574
1575////////////////////////////////////////////////////////////////////////////////
1576/// Make one fading step and request redraw.
1577
1579{
1581
1582 if (fade == fFadeTarget) {
1583 delete this; return;
1584 }
1585 if (TMath::Abs(fFadeTarget - fade) < 1e-3) {
1588 delete this;
1589 return;
1590 }
1591
1594 fViewer->SetFader(fade + df);
1596 fTime -= dt; --fNSteps;
1598 "TGLFaderHelper", this, "MakeFadeStep()");
1599}
1600
1601////////////////////////////////////////////////////////////////////////////////
1602/// Animate fading from current value to fade over given time (sec)
1603/// and number of steps.
1604
1606{
1607 TGLFaderHelper* fh = new TGLFaderHelper(this, fade, time, steps);
1608 fh->MakeFadeStep();
1609}
1610
1611////////////////////////////////////////////////////////////////////////////////
1612/// Use the dark color-set.
1613
1619
1620////////////////////////////////////////////////////////////////////////////////
1621/// Use the light color-set.
1622
1628
1629////////////////////////////////////////////////////////////////////////////////
1630/// Switch between dark and light colorsets.
1631
1633{
1635 {
1636 Info("SwitchColorSet()", "Global color-set is in use, switch not supported.");
1637 return;
1638 }
1639
1642 else
1644}
1645
1646////////////////////////////////////////////////////////////////////////////////
1647/// Set usage of the default color set.
1648
1657
1658////////////////////////////////////////////////////////////////////////////////
1659/// Check if the viewer is using the default color set.
1660/// If yes, some operations might be disabled.
1661
1666
1667////////////////////////////////////////////////////////////////////////////////
1668/// Set background method.
1669/// Deprecated method - set background color in the color-set.
1670
1675
1676////////////////////////////////////////////////////////////////////////////////
1677/// Returns reference to the default color-set.
1678/// Static function.
1679
1684
1685////////////////////////////////////////////////////////////////////////////////
1686/// Sets static flag that determines if new viewers should use the
1687/// default color-set.
1688/// This is false at startup.
1689
1694
1695////////////////////////////////////////////////////////////////////////////////
1696/// Returns the value of the static flag that determines if new
1697/// viewers should use the default color-set.
1698/// This is false at startup.
1699
1704
1705 ////////////////////////////////////////////////////////////////////////////////
1706/// Sets static scaling facor that allows simple guide axies to have label values
1707/// scaled relative to actual scene dimensions.
1708/// This is set to 1 in static initialization.
1709
1714
1715////////////////////////////////////////////////////////////////////////////////
1716/// Returns true if current color set is dark.
1717
1722
1723/**************************************************************************/
1724// Viewport
1725/**************************************************************************/
1726
1727////////////////////////////////////////////////////////////////////////////////
1728/// Set viewer viewport (window area) with bottom/left at (x,y), with
1729/// dimensions 'width'/'height'
1730
1732{
1733 if (fStereo && ! fStereoQuadBuf) width /= 2;
1734
1735 // Only process if changed
1736 if (fViewport.X() == x && fViewport.Y() == y &&
1737 fViewport.Width() == width && fViewport.Height() == height) {
1738 return;
1739 }
1740
1743
1744 if (gDebug > 2) {
1745 Info("TGLViewer::SetViewport", "updated - corner %d,%d dimensions %d,%d", x, y, width, height);
1746 }
1747}
1748
1750{
1751 // Set viewer viewport from TGLRect.
1752
1753 SetViewport(vp.X(), vp.Y(), vp.Width(), vp.Height());
1754}
1755
1756/**************************************************************************/
1757// Camera methods
1758/**************************************************************************/
1759
1760////////////////////////////////////////////////////////////////////////////////
1761/// Return camera reference by type.
1762
1764{
1765 // TODO: Move these into a vector!
1766 switch(cameraType) {
1767 case kCameraPerspXOZ:
1768 return fPerspectiveCameraXOZ;
1769 case kCameraPerspYOZ:
1770 return fPerspectiveCameraYOZ;
1771 case kCameraPerspXOY:
1772 return fPerspectiveCameraXOY;
1773 case kCameraOrthoXOY:
1774 return fOrthoXOYCamera;
1775 case kCameraOrthoXOZ:
1776 return fOrthoXOZCamera;
1777 case kCameraOrthoZOY:
1778 return fOrthoZOXCamera;
1779 case kCameraOrthoZOX:
1780 return fOrthoZOYCamera;
1781 case kCameraOrthoXnOY:
1782 return fOrthoXnOYCamera;
1783 case kCameraOrthoXnOZ:
1784 return fOrthoXnOZCamera;
1785 case kCameraOrthoZnOY:
1786 return fOrthoZnOYCamera;
1787 case kCameraOrthoZnOX:
1788 return fOrthoZnOXCamera;
1789 default:
1790 Error("TGLViewer::SetCurrentCamera", "invalid camera type");
1791 return *fCurrentCamera;
1792 }
1793}
1794
1795////////////////////////////////////////////////////////////////////////////////
1796/// Set current active camera - 'cameraType' one of:
1797/// kCameraPerspX, kCameraPerspY, kCameraPerspZ,
1798/// kCameraOrthoXOY, kCameraOrthoXOZ, kCameraOrthoZOY,
1799/// kCameraOrthoXnOY, kCameraOrthoXnOZ, kCameraOrthoZnOY
1800
1802{
1803 if (IsLocked()) {
1804 Error("TGLViewer::SetCurrentCamera", "expected kUnlocked, found %s", LockName(CurrentLock()));
1805 return;
1806 }
1807
1808 // TODO: Move these into a vector!
1809 TGLCamera *prev = fCurrentCamera;
1810 switch (cameraType)
1811 {
1812 case kCameraPerspXOZ: {
1814 break;
1815 }
1816 case kCameraPerspYOZ: {
1818 break;
1819 }
1820 case kCameraPerspXOY: {
1822 break;
1823 }
1824 case kCameraOrthoXOY: {
1826 break;
1827 }
1828 case kCameraOrthoXOZ: {
1830 break;
1831 }
1832 case kCameraOrthoZOY: {
1834 break;
1835 }
1836 case kCameraOrthoZOX: {
1838 break;
1839 }
1840 case kCameraOrthoXnOY: {
1842 break;
1843 }
1844 case kCameraOrthoXnOZ: {
1846 break;
1847 }
1848 case kCameraOrthoZnOY: {
1850 break;
1851 }
1852 case kCameraOrthoZnOX: {
1854 break;
1855 }
1856 default: {
1857 Error("TGLViewer::SetCurrentCamera", "invalid camera type");
1858 break;
1859 }
1860 }
1861
1862 if (fCurrentCamera != prev)
1863 {
1864 // Ensure any viewport has been propagated to the current camera
1866 RefreshPadEditor(this);
1867
1868 if (fAutoRotator)
1869 {
1870 if (fAutoRotator->IsRunning())
1871 {
1872 fAutoRotator->Stop();
1873 }
1874 else
1875 {
1877 {
1879 }
1880 }
1881 }
1882
1884 }
1885}
1886
1887////////////////////////////////////////////////////////////////////////////////
1888/// Set an orthographic camera to supplied configuration - note this
1889/// does not need to be the current camera - though you will not see
1890/// the effect if it is not.
1891///
1892/// 'camera' defines the ortho camera - one of kCameraOrthoXOY / XOZ / ZOY
1893/// 'left' / 'right' / 'top' / 'bottom' define the WORLD coordinates which
1894/// correspond with the left/right/top/bottom positions on the GL viewer viewport
1895/// E.g. for kCameraOrthoXOY camera left/right are X world coords,
1896/// top/bottom are Y world coords
1897/// As this is an orthographic camera the other axis (in eye direction) is
1898/// no relevant. The near/far clip planes are set automatically based in scene
1899/// contents
1900
1903 Double_t center[3],
1905{
1906 // TODO: Move these into a vector!
1907 switch(camera) {
1908 case kCameraOrthoXOY: {
1912 }
1913 break;
1914 }
1915 case kCameraOrthoXOZ: {
1919 }
1920 break;
1921 }
1922 case kCameraOrthoZOY: {
1926 }
1927 break;
1928 }
1929 case kCameraOrthoZOX: {
1933 }
1934 break;
1935 }
1936 default: {
1937 Error("TGLViewer::SetOrthoCamera", "invalid camera type");
1938 break;
1939 }
1940 }
1941}
1942
1943////////////////////////////////////////////////////////////////////////////////
1944/// Set a perspective camera to supplied configuration - note this
1945/// does not need to be the current camera - though you will not see
1946/// the effect if it is not.
1947///
1948/// - 'camera' defines the persp camera - one of kCameraPerspXOZ, kCameraPerspYOZ, kCameraPerspXOY
1949/// - 'fov' - field of view (lens angle) in degrees (clamped to 0.1 - 170.0)
1950/// - 'dolly' - distance from 'center'
1951/// - 'center' - world position from which dolly/hRotate/vRotate are measured
1952/// camera rotates round this, always facing in (in center of viewport)
1953/// - 'hRotate' - horizontal rotation from initial configuration in radians
1954/// - 'vRotate' - vertical rotation from initial configuration in radians
1955
1958 Double_t center[3],
1960{
1961 // TODO: Move these into a vector!
1962 switch(camera) {
1963 case kCameraPerspXOZ: {
1967 }
1968 break;
1969 }
1970 case kCameraPerspYOZ: {
1974 }
1975 break;
1976 }
1977 case kCameraPerspXOY: {
1981 }
1982 break;
1983 }
1984 default: {
1985 Error("TGLViewer::SetPerspectiveCamera", "invalid camera type");
1986 break;
1987 }
1988 }
1989}
1990
1991////////////////////////////////////////////////////////////////////////////////
1992/// Change base-vectors defining the camera-base transformation of current
1993/// camera. hAxis and vAxis are the default directions for forward
1994/// (inverted) and upwards.
1995
2004
2005////////////////////////////////////////////////////////////////////////////////
2006/// Get the auto-rotator for this viewer.
2007
2009{
2010 if (fAutoRotator == nullptr)
2011 fAutoRotator = new TGLAutoRotator(this);
2012 return fAutoRotator;
2013}
2014
2015////////////////////////////////////////////////////////////////////////////////
2016/// Set the auto-rotator for this viewer. The old rotator is deleted.
2017
2023
2024////////////////////////////////////////////////////////////////////////////////
2025/// Enable stereo rendering.
2026/// If quad_buf is true rendering is done into separate left and right GL
2027/// buffers. This requires hardware support. Otherwise left and right images
2028/// get rendered into left and right half of the window.
2029/// Note that mouse highlighting and selection will not work exactly right
2030/// as image for each eye gets slightly shifted and there are two different
2031/// directions through the mouse pointer, one for each eye.
2032
2046
2047/**************************************************************************/
2048// Guide methods
2049/**************************************************************************/
2050
2051////////////////////////////////////////////////////////////////////////////////
2052/// Fetch the state of guides (axes & reference markers) into arguments
2053
2064
2065////////////////////////////////////////////////////////////////////////////////
2066/// Set the state of guides (axes & reference markers) from arguments.
2067
2079
2080////////////////////////////////////////////////////////////////////////////////
2081/// Draw camera look at and rotation point.
2082
2088
2089// Selected physical
2090////////////////////////////////////////////////////////////////////////////////
2091/// Return selected physical shape.
2092
2094{
2095 return fSelectedPShapeRef->GetPShape();
2096}
2097
2098/**************************************************************************/
2099/**************************************************************************/
2100
2101////////////////////////////////////////////////////////////////////////////////
2102/// Emit MouseOver signal.
2103
2105{
2106 Emit("MouseOver(TGLPhysicalShape*)", (Longptr_t)shape);
2107}
2108
2109////////////////////////////////////////////////////////////////////////////////
2110/// Emit MouseOver signal.
2111
2113{
2114 Longptr_t args[2];
2115 args[0] = (Longptr_t)shape;
2116 args[1] = state;
2117 Emit("MouseOver(TGLPhysicalShape*,UInt_t)", args);
2118}
2119
2120////////////////////////////////////////////////////////////////////////////////
2121/// Emit MouseOver signal.
2122
2124{
2125 Longptr_t args[2];
2126 args[0] = (Longptr_t)obj;
2127 args[1] = state;
2128 Emit("MouseOver(TObject*,UInt_t)", args);
2129}
2130
2131////////////////////////////////////////////////////////////////////////////////
2132/// Emit MouseOver signal.
2133
2135{
2136 Longptr_t args[2];
2137 args[0] = (Longptr_t)obj;
2138 args[1] = state;
2139 Emit("ReMouseOver(TObject*,UInt_t)", args);
2140}
2141
2142
2143////////////////////////////////////////////////////////////////////////////////
2144/// Emit UnMouseOver signal.
2145
2147{
2148 Longptr_t args[2];
2149 args[0] = (Longptr_t)obj;
2150 args[1] = state;
2151 Emit("UnMouseOver(TObject*,UInt_t)", args);
2152}
2153
2154////////////////////////////////////////////////////////////////////////////////
2155/// Emit Clicked signal.
2156
2158{
2159 Emit("Clicked(TObject*)", (Longptr_t)obj);
2160}
2161
2162////////////////////////////////////////////////////////////////////////////////
2163/// Emit Clicked signal with button id and modifier state.
2164
2166{
2167 Longptr_t args[3];
2168 args[0] = (Longptr_t)obj;
2169 args[1] = button;
2170 args[2] = state;
2171 Emit("Clicked(TObject*,UInt_t,UInt_t)", args);
2172}
2173
2174
2175////////////////////////////////////////////////////////////////////////////////
2176/// Emit ReClicked signal with button id and modifier state.
2177
2179{
2180 Longptr_t args[3];
2181 args[0] = (Longptr_t)obj;
2182 args[1] = button;
2183 args[2] = state;
2184 Emit("ReClicked(TObject*,UInt_t,UInt_t)", args);
2185}
2186
2187////////////////////////////////////////////////////////////////////////////////
2188/// Emit UnClicked signal with button id and modifier state.
2189
2191{
2192 Longptr_t args[3];
2193 args[0] = (Longptr_t)obj;
2194 args[1] = button;
2195 args[2] = state;
2196 Emit("UnClicked(TObject*,UInt_t,UInt_t)", args);
2197}
2198
2199////////////////////////////////////////////////////////////////////////////////
2200/// Emit MouseIdle signal.
2201
2203{
2204 Longptr_t args[3];
2205 static UInt_t oldx = 0, oldy = 0;
2206
2207 if (oldx != posx || oldy != posy) {
2208 args[0] = (Longptr_t)shape;
2209 args[1] = posx;
2210 args[2] = posy;
2211 Emit("MouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)", args);
2212 oldx = posx;
2213 oldy = posy;
2214 }
2215}
2216
2217/**************************************************************************/
2218/**************************************************************************/
2219////////////////////////////////////////////////////////////////////////////////
2220/// Calculate and return pixel distance to nearest viewer object from
2221/// window location px, py
2222/// This is provided for use when embedding GL viewer into pad
2223
2225{
2226 // Can't track the indvidual objects in rollover. Just set the viewer as the
2227 // selected object, and return 0 (object identified) so we receive ExecuteEvent calls
2228 gPad->SetSelected(this);
2229 return 0;
2230}
2231
2232////////////////////////////////////////////////////////////////////////////////
2233/// Process event of type 'event' - one of EEventType types,
2234/// occurring at window location px, py
2235/// This is provided for use when embedding GL viewer into pad
2236
2238{
2239 if (fEventHandler)
2240 return fEventHandler->ExecuteEvent(event, px, py);
2241}
2242
2243////////////////////////////////////////////////////////////////////////////////
2244/// Pass viewer for print capture by TGLOutput.
2245
2247{
2248 TGLOutput::Capture(*this);
2249}
2250
2251////////////////////////////////////////////////////////////////////////////////
2252/// Update GUI components for embedded viewer selection change.
2253
2255{
2256 if (!fGedEditor)
2257 return;
2258
2259 TGLPhysicalShape *selected = const_cast<TGLPhysicalShape*>(GetSelected());
2260
2261 if (selected) {
2262 fPShapeWrap->fPShape = selected;
2264 } else {
2265 fPShapeWrap->fPShape = nullptr;
2267 }
2268}
2269
2270////////////////////////////////////////////////////////////////////////////////
2271/// An overlay operation can result in change to an object.
2272/// Refresh geditor.
2273
2281
2282////////////////////////////////////////////////////////////////////////////////
2283/// Update GED editor if it is set.
2284
2286{
2287 if (fGedEditor && (obj == nullptr || fGedEditor->GetModel() == obj))
2288 {
2290 }
2291}
2292
2293////////////////////////////////////////////////////////////////////////////////
2294/// Set the event-handler. The event-handler is owned by the viewer.
2295/// If GLWidget is set, the handler is propagated to it.
2296///
2297/// If called with handler=0, the current handler will be deleted
2298/// (also from TGLWidget).
2299
2301{
2302 if (fEventHandler)
2303 delete fEventHandler;
2304
2305 fEventHandler = handler;
2306 if (fGLWidget)
2308}
2309
2310////////////////////////////////////////////////////////////////////////////////
2311/// Remove overlay element.
2312
2321
2322////////////////////////////////////////////////////////////////////////////////
2323/// Reset current overlay-element to zero, eventually notifying the
2324/// old one that the mouse has left.
2325/// Usually called when mouse leaves the window.
2326
2328{
2329 if (fCurrentOvlElm)
2330 {
2332 fCurrentOvlElm = nullptr;
2333 RequestDraw();
2334 }
2335}
@ kButton1Down
Definition Buttons.h:17
#define c(i)
Definition RSha256.hxx:101
#define h(i)
Definition RSha256.hxx:106
#define e(i)
Definition RSha256.hxx:103
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
short Color_t
Color number (short)
Definition RtypesCore.h:99
long Longptr_t
Integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:89
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
short Short_t
Signed Short integer 2 bytes (short)
Definition RtypesCore.h:53
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
#define GL_BGRA
Definition TGLViewer.cxx:61
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t button
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:627
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:411
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2495
@ kDragNone
#define gGLManager
Definition TVirtualGL.h:159
#define R__LOCKGUARD(mutex)
#define gPad
#define gVirtualX
Definition TVirtualX.h:337
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:31
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:35
The color creation and management class.
Definition TColor.h:22
virtual void GetRGB(Float_t &r, Float_t &g, Float_t &b) const
Definition TColor.h:55
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
Definition TColor.cxx:1926
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:490
Automatically rotates GL camera.
void Start()
Start the auto-rotator.
Bool_t IsRunning() const
TGLCamera * GetCamera() const
void Stop()
Stop the auto-rotator.
Concrete class describing an orientated (free) or axis aligned box of 8 vertices.
TGLVector3 Extents() const
TGLVertex3 Center() const
void Draw(Bool_t solid=kFALSE) const
Draw the bounding box as either wireframe (default) of solid using current GL color.
A GL overlay element which displays camera furstum.
Abstract base camera class - concrete classes for orthographic and perspective cameras derive from it...
Definition TGLCamera.h:44
virtual Bool_t IsPerspective() const
Definition TGLCamera.h:119
TGLVector3 ViewportDeltaToWorld(const TGLVertex3 &worldRef, Double_t viewportXDelta, Double_t viewportYDelta, TGLMatrix *modviewMat=nullptr) const
Apply a 2D viewport delta (shift) to the projection of worldRef onto viewport, returning the resultan...
Double_t * GetCenterVec()
Definition TGLCamera.h:157
void DrawDebugAids() const
Draw out some debugging aids for the camera:
virtual void Setup(const TGLBoundingBox &box, Bool_t reset=kTRUE)=0
void SetViewport(const TGLRect &viewport)
Set viewport extents from passed 'viewport' rect.
Definition TGLCamera.cxx:98
TGLMatrix & RefCamBase()
Definition TGLCamera.h:169
A collection of concrete TGLClip objects to be selected from.
Definition TGLClip.h:140
TGLClip * GetCurrentClip() const
Definition TGLClip.h:170
void SetupCurrentClip(const TGLBoundingBox &sceneBBox)
Setup current clipping object for given scene bounding box.
Definition TGLClip.cxx:431
void SetupCurrentClipIfInvalid(const TGLBoundingBox &sceneBBox)
Setup current clipping object for given scene bounding box.
Definition TGLClip.cxx:441
Class encapsulating a set of colors used throughout standard rendering.
Definition TGLUtil.h:836
TGLColor & Foreground()
Definition TGLUtil.h:852
void StdLightBackground()
Set defaults for light (white) background.
Definition TGLUtil.cxx:1381
TGLColor & Background()
Definition TGLUtil.h:851
void SetColor(Int_t r, Int_t g, Int_t b, Int_t a=255)
Set color with Int_t values.
Definition TGLUtil.cxx:1228
Color_t GetColorIndex() const
Returns color-index representing the color.
Definition TGLUtil.cxx:1210
Identifier of a shared GL-context.
Definition TGLContext.h:81
void DeleteGLResources()
Delete GL resources registered for destruction.
void Release(TGLContext *ctx)
Remove context ctx from the list of references.
void AddRef(TGLContext *ctx)
Add context ctx to the list of references.
Frame-buffer object.
Definition TGLFBO.h:18
void MakeFadeStep()
Make one fading step and request redraw.
Float_t fFadeTarget
Definition TGLViewer.h:439
Float_t fTime
Definition TGLViewer.h:440
TGLViewer * fViewer
Definition TGLViewer.h:438
Encapsulates a set of lights for OpenGL.
Definition TGLLightSet.h:22
void StdSetupLights(const TGLBoundingBox &bbox, const TGLCamera &camera, Bool_t debug=kFALSE)
Setup lights for current given bounding box and camera.
Bool_t TakeLock(ELock lock) const
Lock the object in mode 'lock'.
ELock CurrentLock() const
Definition TGLLockable.h:61
Bool_t ReleaseLock(ELock lock) const
Release current lock, make sure it the same as the 'lock' argument.
static const char * LockName(ELock lock)
Return name-string for given lock-type.
Bool_t IsLocked() const
Definition TGLLockable.h:60
Bool_t IsDrawOrSelectLock() const
Definition TGLLockable.h:63
virtual Bool_t SupportsSecondarySelect() const
Combine all available manipulators in a collection.
Definition TGLManipSet.h:22
void SetDrawBBox(Bool_t bb)
Definition TGLManipSet.h:54
void SetPShape(TGLPhysicalShape *shape) override
Set phys-shape, override of virtual from TGLPShapeRef.
16 component (4x4) transform matrix - column MAJOR as per GL.
Definition TGLUtil.h:598
TGLVector3 GetTranslation() const
Return the translation component of matrix.
Definition TGLUtil.cxx:788
void Set(const TGLVertex3 &origin, const TGLVector3 &zAxis, const TGLVector3 &xAxis=nullptr)
Set matrix which when applied puts local origin at 'origin' and the local Z axis in direction 'z'.
Definition TGLUtil.cxx:730
Orthographic projection camera.
void Setup(const TGLBoundingBox &box, Bool_t reset=kTRUE) override
Setup camera limits suitable to view the world volume defined by 'box' and call Reset() to initialise...
void Configure(Double_t zoom, Double_t dolly, Double_t center[3], Double_t hRotate, Double_t vRotate) override
Configure the camera state.
static Bool_t Capture(TGLViewer &viewer, EFormat format, const char *filePath=nullptr)
Capture viewer to file.
Definition TGLOutput.cxx:42
An overlay element.
Definition TGLOverlay.h:23
virtual void MouseLeave()
Mouse has left the element.
void Reset() override
Reinitialise all data to null values.
TGLOverlayElement * GetOvlElement() const
Wrap TGLPysicalShape into TObject so that it can be edited using GED.
TGLPhysicalShape * fPShape
TGLPhysicalShape * GetPShape() const
Perspective projection camera - with characteristic foreshortening.
void Setup(const TGLBoundingBox &box, Bool_t reset=kTRUE) override
Setup camera limits suitable to view the world volume defined by 'box' and call Reset() to initialise...
void Configure(Double_t fov, Double_t dolly, Double_t center[3], Double_t hRotate, Double_t vRotate) override
Configure the camera state.
Concrete physical shape - a GL drawable.
Viewport (pixel base) 2D rectangle class.
Definition TGLUtil.h:422
Int_t Y() const
Definition TGLUtil.h:448
Int_t Height() const
Definition TGLUtil.h:452
Int_t Width() const
Definition TGLUtil.h:450
void Set(Int_t x, Int_t y, Int_t width, Int_t height)
Definition TGLUtil.h:471
Int_t X() const
Definition TGLUtil.h:446
Double_t Aspect() const
Definition TGLUtil.h:500
void Stop() override
Definition TGLViewer.h:418
void RequestDraw(Int_t milliSec, Short_t redrawLOD)
Definition TGLViewer.h:411
void SetRenderScale(Float_t s)
Definition TGLRnrCtx.h:245
void SetSceneInfo(TGLSceneInfo *si)
Definition TGLRnrCtx.h:168
TGLColorSet * ChangeBaseColorSet(TGLColorSet *set)
Change the default/bottom color-set.
void SetRenderTimeOut(Double_t tout)
Definition TGLRnrCtx.h:211
void SetShapeLOD(Short_t LOD)
Definition TGLRnrCtx.h:178
void BeginSelection(Int_t x, Int_t y, Int_t r=3)
Setup context for running selection.
Short_t SelectTransparents() const
Definition TGLRnrCtx.h:227
Float_t GetRenderScale() const
Definition TGLRnrCtx.h:244
void SetSecSelection(Bool_t secSel)
Definition TGLRnrCtx.h:225
TGLColorSet * GetBaseColorSet()
Returns the current base color-set.
TGLSelectBuffer * GetSelectBuffer() const
Definition TGLRnrCtx.h:231
void SetGLCtxIdentity(TGLContextIdentity *cid)
Definition TGLRnrCtx.h:255
void SetGrabImage(Bool_t gi)
Definition TGLRnrCtx.h:266
TGLColorSet & ColorSet()
Return reference to current color-set (top of the stack).
Bool_t GetGrabImage() const
Definition TGLRnrCtx.h:267
void StartStopwatch()
Start the stopwatch.
void StopStopwatch()
Stop the stopwatch.
void EndSelection(Int_t glResult)
End selection.
void SetDrawPass(Short_t dpass)
Definition TGLRnrCtx.h:205
Bool_t Selection() const
Definition TGLRnrCtx.h:222
Scene base-class – provides basic interface expected by the TGLViewer or its sub-classes:
Base class for extended scene context.
Implements VirtualViewer3D interface and fills the base-class visualization structures from pad conte...
Definition TGLScenePad.h:26
UInt_t * RawRecord(Int_t i)
void SetRawOnly(UInt_t *data)
Setup the record from raw buffer.
Standard selection record including information about containing scene and details ob out selected ob...
static Bool_t AreSameSelectionWise(const TGLSelectRecord &r1, const TGLSelectRecord &r2)
Check if the records imply the same selection result, that is, their secondary members are all equal.
void Reset() override
Reinitialise all data to null values.
Bool_t GetTransparent() const
TGLLogicalShape * GetLogShape() const
TGLPhysicalShape * GetPhysShape() const
void Print()
Print contents of the select record to stdout.
TGLSceneInfo * GetSceneInfo() const
Stopwatch object for timing GL work.
Wrapper class for various misc static functions - error checking, draw helpers etc.
Definition TGLUtil.h:879
static void DrawSphere(const TGLVertex3 &position, Double_t radius, const UChar_t rgba[4])
Draw sphere, centered on vertex 'position', with radius 'radius', color 'rgba'.
Definition TGLUtil.cxx:2348
static const UChar_t fgWhite[4]
Definition TGLUtil.h:1425
static void SetLineWidthScale(Float_t scale)
Set global line-width scale.
Definition TGLUtil.cxx:1898
static void DrawReferenceMarker(const TGLCamera &camera, const TGLVertex3 &pos, Float_t radius=3, const UChar_t *rgba=nullptr)
Draw a sphere- marker on world-coordinate 'pos' with pixel radius 'radius'.
Definition TGLUtil.cxx:2470
static Int_t CheckError(const char *loc)
Check current GL error state, outputting details via ROOT Error method if one.
Definition TGLUtil.cxx:1637
static void ColorAlpha(const TGLColor &color, UChar_t alpha)
Set color from TGLColor and alpha value.
Definition TGLUtil.cxx:1696
static Int_t GetPickingRadius()
Returns picking radius.
Definition TGLUtil.cxx:1862
static void SetPointSizeScale(Float_t scale)
Set global point-size scale.
Definition TGLUtil.cxx:1882
static const UChar_t fgGreen[4]
Definition TGLUtil.h:1422
static void DrawSimpleAxes(const TGLCamera &camera, const TGLBoundingBox &bbox, Int_t axesType, Float_t labelScale=1)
Draw simple xyz-axes for given bounding-box.
Definition TGLUtil.cxx:2485
static void PointToViewport(Int_t &x, Int_t &y)
Convert from point/screen coordinates to GL viewport coordinates.
Definition TGLUtil.cxx:1814
3 component (x/y/z) vector class.
Definition TGLUtil.h:248
Double_t Mag() const
Definition TGLUtil.h:298
3 component (x/y/z) vertex class.
Definition TGLUtil.h:84
Double_t X() const
Definition TGLUtil.h:119
Double_t Z() const
Definition TGLUtil.h:123
void Set(Double_t x, Double_t y, Double_t z)
Definition TGLUtil.h:210
Double_t Y() const
Definition TGLUtil.h:121
virtual void PreRenderOverlaySelection()
Perform minimal initialization for overlay selection.
SceneInfoList_t fScenes
TGLRnrCtx * fRnrCtx
TGLCamera * fCamera
Bool_t FindClosestOpaqueRecord(TGLSelectRecord &rec, Int_t &recIdx)
Find next select record that can be resolved and whose result is not transparent, starting from posit...
virtual void ResetSceneInfos()
Force rebuild of view-dependent scene-info structures.
TGLSceneInfo * AddScene(TGLSceneBase *scene)
Add new scene, appropriate scene-info is created.
virtual void RemoveOverlayElement(TGLOverlayElement *el)
Remove overlay element.
TGLClip * fClip
virtual void RenderOverlay(Int_t state, Bool_t selection)
Render overlay objects.
virtual void Render()
Render all scenes.
virtual void PostRenderOverlaySelection()
Perform cleanup after overlay selection.
virtual void PreRender()
Initialize render-context, setup camera, GL, render-area.
virtual void PostRender()
Function called after rendering is finished.
Bool_t FindClosestOverlayRecord(TGLOvlSelectRecord &rec, Int_t &recIdx)
Find next overlay-select record that can be resolved, starting from position 'recIdx'.
virtual void MergeSceneBBoxes(TGLBoundingBox &bbox)
Merge bounding-boxes of all active registered scenes.
TGLBoundingBox fOverallBoundingBox
std::list< TGLSceneInfo * > SceneInfoList_t
virtual void RenderSelectedForHighlight()
Render selected objects from all scenes for highlight.
SceneInfoList_t::iterator SceneInfoList_i
virtual void AddOverlayElement(TGLOverlayElement *el)
Add overlay element.
Bool_t FindClosestRecord(TGLSelectRecord &rec, Int_t &recIdx)
Find next select record that can be resolved, starting from position 'recIdx'.
TGLRedrawTimer * fRedrawTimer
Definition TGLViewer.h:135
virtual void MouseOver(TGLPhysicalShape *)
Emit MouseOver signal.
void SetDrawCameraCenter(Bool_t x)
Draw camera look at and rotation point.
TGLAutoRotator * fAutoRotator
Definition TGLViewer.h:97
Float_t fLineScale
size scale for points
Definition TGLViewer.h:143
void FadeView(Float_t alpha)
Draw a rectangle (background color and given alpha) across the whole viewport.
Bool_t SavePictureScale(const TString &fileName, Float_t scale, Bool_t pixel_object_scale=kTRUE)
Save picture with given scale to current window size.
TGLCamera * fCurrentCamera
Definition TGLViewer.h:96
TGLCameraOverlay * fCameraOverlay
reference marker on?
Definition TGLViewer.h:151
virtual void RefreshPadEditor(TObject *obj=nullptr)
Update GED editor if it is set.
Bool_t fAxesDepthTest
axes type
Definition TGLViewer.h:147
virtual void SetEventHandler(TGEventHandler *handler)
Set the event-handler.
TGLPerspectiveCamera fPerspectiveCameraYOZ
Definition TGLViewer.h:86
void PrintObjects() override
Pass viewer for print capture by TGLOutput.
TGLOrthoCamera fOrthoXOYCamera
Definition TGLViewer.h:88
TGLSelectRecord fSelRec
select record in use as selected
Definition TGLViewer.h:112
void SetFader(Float_t x)
Definition TGLViewer.h:350
virtual void ReMouseOver(TObject *obj, UInt_t state)
Emit MouseOver signal.
TImage * GetPictureUsingFBO(Int_t w, Int_t h, Float_t pixel_object_scale=0)
Returns current image.
TGLOrthoCamera fOrthoXnOZCamera
Definition TGLViewer.h:93
static TGLColorSet & GetDefaultColorSet()
Returns reference to the default color-set.
void InitGL()
Initialise GL state.
void SetAutoRotator(TGLAutoRotator *ar)
Set the auto-rotator for this viewer. The old rotator is deleted.
virtual void Clicked(TObject *obj)
Emit Clicked signal.
void MakeCurrent() const
Make GL context current.
Bool_t fIsPrinting
debug mode (forced rebuild + draw scene/frustum/interest boxes)
Definition TGLViewer.h:157
static TGLColorSet fgDefaultColorSet
fade the view (0 - no fade/default, 1 - full fade/no rendering done)
Definition TGLViewer.h:161
void SetupClipObject() override
allow simple guide axes labels to be scaled relative to scene units
TGEventHandler * fEventHandler
select record from last overlay select
Definition TGLViewer.h:119
TGLPerspectiveCamera fPerspectiveCameraXOY
Definition TGLViewer.h:87
TGLOrthoCamera fOrthoZnOYCamera
Definition TGLViewer.h:94
TGLRect fViewport
max time for scene rendering at high LOD (in ms)
Definition TGLViewer.h:139
virtual void SelectionChanged()
Update GUI components for embedded viewer selection change.
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Process event of type 'event' - one of EEventType types, occurring at window location px,...
virtual void UnClicked(TObject *obj, UInt_t button, UInt_t state)
Emit UnClicked signal with button id and modifier state.
void SetPerspectiveCamera(ECameraType camera, Double_t fov, Double_t dolly, Double_t center[3], Double_t hRotate, Double_t vRotate)
Set a perspective camera to supplied configuration - note this does not need to be the current camera...
TGLVertex3 fReferencePos
reference marker on?
Definition TGLViewer.h:149
void PreRender() override
Initialize objects that influence rendering.
Bool_t RequestOverlaySelect(Int_t x, Int_t y)
Post request for secondary selection rendering of selected object around the window point (x,...
static Bool_t IsUsingDefaultColorSetForNewViewers()
Returns the value of the static flag that determines if new viewers should use the default color-set.
virtual void MouseIdle(TGLPhysicalShape *, UInt_t, UInt_t)
Emit MouseIdle signal.
Bool_t SavePictureWidth(const TString &fileName, Int_t width, Bool_t pixel_object_scale=kTRUE)
Save picture with given width (height scaled proportionally).
void DoDrawStereo(Bool_t swap_buffers)
Draw out in stereoscopic mode.
void RequestDraw(Short_t LOD=TGLRnrCtx::kLODMed)
Post request for redraw of viewer at level of detail 'LOD' Request is directed via cross thread gVirt...
void SetGuideState(Int_t axesType, Bool_t axesDepthTest, Bool_t referenceOn, const Double_t *referencePos)
Set the state of guides (axes & reference markers) from arguments.
void DoDraw(Bool_t swap_buffers=kTRUE)
Draw out the viewer.
TGLOrthoCamera fOrthoZOYCamera
Definition TGLViewer.h:90
void SwitchColorSet()
Switch between dark and light colorsets.
TGLPShapeObj * fPShapeWrap
GED editor.
Definition TGLViewer.h:121
TGLSelectRecord fSecSelRec
select record from last select (should go to context)
Definition TGLViewer.h:113
~TGLViewer() override
Destroy viewer object.
TGLWidget * fGLWidget
Definition TGLViewer.h:185
void DrawDebugInfo()
If in debug mode draw camera aids and overall bounding box.
void AutoFade(Float_t fade, Float_t time=1, Int_t steps=10)
Animate fading from current value to fade over given time (sec) and number of steps.
Bool_t fReferenceOn
remove guides hidden-lines
Definition TGLViewer.h:148
TGLCamera & CurrentCamera() const
Definition TGLViewer.h:268
void SetCurrentCamera(ECameraType camera)
Set current active camera - 'cameraType' one of: kCameraPerspX, kCameraPerspY, kCameraPerspZ,...
void SetupCameras(Bool_t reset)
Setup cameras for current bounding box.
Bool_t fResetCamerasOnUpdate
Definition TGLViewer.h:191
Int_t fAxesType
smooth line edge rendering
Definition TGLViewer.h:146
void SetStereo(Bool_t stereo, Bool_t quad_buf=kTRUE)
Enable stereo rendering.
TImage * GetPictureUsingBB()
Returns current image.
TGLCamera & RefCamera(ECameraType camera)
Return camera reference by type.
TContextMenu * fContextMenu
external pad - remove replace with signal
Definition TGLViewer.h:81
void UseLightColorSet()
Use the light color-set.
Bool_t IsUsingDefaultColorSet() const
Check if the viewer is using the default color set.
Bool_t DoSelect(Int_t x, Int_t y)
Perform GL selection, picking objects overlapping WINDOW area described by 'rect'.
void PreDraw()
Perform GL work which must be done before each draw.
Float_t fStereoZeroParallax
draw quad buffer or left/right stereo in left/right half of window
Definition TGLViewer.h:102
virtual void PostSceneBuildSetup(Bool_t resetCameras)
Perform post scene-build setup.
Float_t fStereoEyeOffsetFac
position of zero-parallax plane: 0 - near clipping plane, 1 - far clipping plane
Definition TGLViewer.h:103
Bool_t SavePictureUsingBB(const TString &fileName)
Save current image in various formats (gif, gif+, jpg, png).
Bool_t SavePicture()
Save current image using the default file name which can be set via SetPictureFileName() and defaults...
Float_t fFader
default file-name for SavePicture()
Definition TGLViewer.h:159
@ kDragCameraDolly
Definition TGLViewer.h:128
void UpdateScene(Bool_t redraw=kTRUE)
Force update of pad-scenes.
TGLOrthoCamera fOrthoZOXCamera
Definition TGLViewer.h:91
Bool_t SavePictureUsingFBO(const TString &fileName, Int_t w, Int_t h, Float_t pixel_object_scale=0)
Save current image in various formats (gif, gif+, jpg, png).
friend class TGLAutoRotator
Definition TGLViewer.h:58
static void SetAxisLabelScale(Float_t als)
Sets static scaling facor that allows simple guide axies to have label values scaled relative to actu...
TGLOrthoCamera fOrthoXOZCamera
Definition TGLViewer.h:89
Bool_t GetClipAutoUpdate() const
Definition TGLViewer.h:264
virtual void OverlayDragFinished()
An overlay operation can result in change to an object.
Bool_t SavePictureHeight(const TString &fileName, Int_t height, Bool_t pixel_object_scale=kTRUE)
Save picture with given height (width scaled proportionally).
void SetOrthoCamera(ECameraType camera, Double_t zoom, Double_t dolly, Double_t center[3], Double_t hRotate, Double_t vRotate)
Set an orthographic camera to supplied configuration - note this does not need to be the current came...
void DrawGuides()
Draw reference marker and coordinate axes.
void UseDefaultColorSet(Bool_t x)
Set usage of the default color set.
Float_t fMaxSceneDrawTimeHQ
timer for triggering redraws
Definition TGLViewer.h:136
Bool_t RequestSecondarySelect(Int_t x, Int_t y)
Request secondary select.
TGedEditor * fGedEditor
event handler
Definition TGLViewer.h:120
void SetViewport(Int_t x, Int_t y, Int_t width, Int_t height)
Set viewer viewport (window area) with bottom/left at (x,y), with dimensions 'width'/'height'.
Float_t fPointScale
color-set with light background
Definition TGLViewer.h:142
TGLColorSet fLightColorSet
color-set with dark background
Definition TGLViewer.h:141
TGLClipSet * fClipSet
Definition TGLViewer.h:109
Bool_t fStereo
Definition TGLViewer.h:100
virtual void UnMouseOver(TObject *obj, UInt_t state)
Emit UnMouseOver signal.
void PadPaint(TVirtualPad *pad) override
Entry point for updating viewer contents via VirtualViewer3D interface.
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Calculate and return pixel distance to nearest viewer object from window location px,...
TVirtualPad * fPad
Definition TGLViewer.h:78
virtual void ReClicked(TObject *obj, UInt_t button, UInt_t state)
Emit ReClicked signal with button id and modifier state.
Bool_t fResetCamerasOnNextUpdate
Definition TGLViewer.h:192
Bool_t fSmoothPoints
width scale for lines
Definition TGLViewer.h:144
TGLOrthoCamera fOrthoZnOXCamera
Definition TGLViewer.h:95
Float_t fMaxSceneDrawTimeLQ
max time for scene rendering at high LOD (in ms)
Definition TGLViewer.h:137
Bool_t fSmoothLines
smooth point edge rendering
Definition TGLViewer.h:145
TGLManipSet * fSelectedPShapeRef
select record from last secondary select (should go to context)
Definition TGLViewer.h:114
TString fPictureFileName
Definition TGLViewer.h:158
void ClearCurrentOvlElm()
Reset current overlay-element to zero, eventually notifying the old one that the mouse has left.
void ApplySelection()
Process result from last selection (in fSelRec) and extract a new current selection from it.
TGLColorSet fDarkColorSet
viewport - drawn area
Definition TGLViewer.h:140
void InitSecondaryObjects()
Common initialization.
Bool_t DoSecondarySelect(Int_t x, Int_t y)
Secondary selection.
void UseDarkColorSet()
Use the dark color-set.
Float_t GetFader() const
Definition TGLViewer.h:349
TGLLightSet * fLightSet
Definition TGLViewer.h:107
Bool_t RequestSelect(Int_t x, Int_t y)
Post request for selection render pass viewer, picking objects around the window point (x,...
void SetClearColor(Color_t col)
Set background method.
static Float_t fgAxisLabelScale
name says it all
Definition TGLViewer.h:163
Bool_t DoOverlaySelect(Int_t x, Int_t y)
Perform GL selection, picking overlay objects only.
Bool_t fDrawCameraCenter
reference position
Definition TGLViewer.h:150
void ReinitializeCurrentCamera(const TGLVector3 &hAxis, const TGLVector3 &vAxis, Bool_t redraw=kTRUE)
Change base-vectors defining the camera-base transformation of current camera.
Bool_t IsColorSetDark() const
Returns true if current color set is dark.
void PostDraw()
Perform GL work which must be done after each draw.
TGLAutoRotator * GetAutoRotator()
Get the auto-rotator for this viewer.
TGLPerspectiveCamera fPerspectiveCameraXOZ
Definition TGLViewer.h:85
void Render() override
Normal rendering, used by mono and stereo rendering.
const TGLPhysicalShape * GetSelected() const
Return selected physical shape.
Float_t fStereoFrustumAsymFac
Definition TGLViewer.h:104
Bool_t fDebugMode
cache logicals during scene rebuilds
Definition TGLViewer.h:156
TGLOrthoCamera fOrthoXnOYCamera
Definition TGLViewer.h:92
static Bool_t fgUseDefaultColorSetForNewViewers
a shared, default color-set
Definition TGLViewer.h:162
void GetGuideState(Int_t &axesType, Bool_t &axesDepthTest, Bool_t &referenceOn, Double_t *referencePos) const
Fetch the state of guides (axes & reference markers) into arguments.
void RemoveOverlayElement(TGLOverlayElement *el) override
Remove overlay element.
TGLSelectRecord fCurrentSelRec
Definition TGLViewer.h:111
TGLViewer(const TGLViewer &)=delete
void DoDrawMono(Bool_t swap_buffers)
Draw out in monoscopic mode.
Bool_t fStereoQuadBuf
use stereo rendering
Definition TGLViewer.h:101
@ kCameraPerspXOY
Definition TGLViewer.h:61
@ kCameraPerspXOZ
Definition TGLViewer.h:61
@ kCameraOrthoXnOZ
Definition TGLViewer.h:63
@ kCameraPerspYOZ
Definition TGLViewer.h:61
@ kCameraOrthoZnOY
Definition TGLViewer.h:63
@ kCameraOrthoZOY
Definition TGLViewer.h:62
@ kCameraOrthoXOY
Definition TGLViewer.h:62
@ kCameraOrthoZOX
Definition TGLViewer.h:62
@ kCameraOrthoZnOX
Definition TGLViewer.h:63
@ kCameraOrthoXOZ
Definition TGLViewer.h:62
@ kCameraOrthoXnOY
Definition TGLViewer.h:63
TGLContextIdentity * fGLCtxId
for embedded gl viewer
Definition TGLViewer.h:187
Int_t fGLDevice
Definition TGLViewer.h:186
void PostRender() override
Restore state set in PreRender().
static void UseDefaultColorSetForNewViewers(Bool_t x)
Sets static flag that determines if new viewers should use the default color-set.
TGLOvlSelectRecord fOvlSelRec
current overlay element
Definition TGLViewer.h:117
TGLOverlayElement * fCurrentOvlElm
Definition TGLViewer.h:116
void SwapBuffers() const
Swap GL buffers.
void ResetCurrentCamera()
Resets position/rotation of current camera to default values.
Bool_t MakeCurrent() override
Make the gl-context current.
void SwapBuffers() override
Swap buffers.
void SetEventHandler(TGEventHandler *eh)
Set event-handler. All events are passed to this object.
const TGLFormat * GetPixelFormat() const override
Pixel format.
virtual Bool_t IsMapped()
Returns kTRUE if window is mapped on screen, kFALSE otherwise.
Definition TGWindow.cxx:293
virtual void SetModel(TVirtualPad *pad, TObject *obj, Int_t event, Bool_t force=kFALSE)
Activate object editors according to the selected object.
virtual TObject * GetModel() const
Definition TGedEditor.h:79
An abstract interface to image processing library.
Definition TImage.h:29
static TImage * Create()
Create an image.
Definition TImage.cxx:34
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1057
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to an event at (px,py).
Definition TObject.cxx:411
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1045
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition TQObject.h:164
Basic string class.
Definition TString.h:138
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2250
const char * Data() const
Definition TString.h:384
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:640
static void SingleShot(Int_t milliSec, const char *receiver_class, void *receiver, const char *method)
This static function calls a slot after a given time interval.
Definition TTimer.cxx:261
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
virtual void ReleaseViewer3D(Option_t *type="")=0
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition fillpatterns.C:1
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Int_t Nint(T x)
Round to nearest integer. Rounds half integers to the nearest even integer.
Definition TMath.h:704
constexpr Double_t DegToRad()
Conversion from degree to radian: .
Definition TMath.h:82
Int_t CeilNint(Double_t x)
Returns the nearest integer of TMath::Ceil(x).
Definition TMath.h:685
Double_t Tan(Double_t)
Returns the tangent of an angle of x radians.
Definition TMath.h:611
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:124