Logo ROOT  
Reference Guide
TEveLegoEventHandler.cxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
3 * All rights reserved. *
4 * *
5 * For the licensing terms see $ROOTSYS/LICENSE. *
6 * For the list of contributors see $ROOTSYS/README/CREDITS. *
7 *************************************************************************/
8
9
11#include "TEveCaloLegoGL.h"
12
13#include "TGLViewer.h"
14#include "TGLWidget.h"
15#include "TGLOverlay.h"
16#include "TGLLogicalShape.h"
17#include "TGLPhysicalShape.h"
18#include "TGLCamera.h"
20#include "TGLOrthoCamera.h"
21#include "KeySymbols.h"
22
23#include "TMath.h"
24#include "TGLUtil.h"
25#include "TEveTrans.h"
26
27#include "TEveCalo.h"
28
29/** \class TEveLegoEventHandler
30\ingroup TEve
31A base class of TGLEventHandler. Switches current camera from perspective
32to orthographic bird-view, if camera theta is less than given threshold. It sets back
33perspective camera when accumulated angle is more than transition theta.
34*/
35
37
38////////////////////////////////////////////////////////////////////////////////
39/// Constructor.
40
42 TGLEventHandler(w, obj),
43
44 fMode(kFree),
45 fTransTheta(0.5f),
46 fTheta(0.f),
47
48 fLego(lego)
49{
50}
51
52////////////////////////////////////////////////////////////////////////////////
53/// Virtual from TGLEventHandler.
54/// Free the camera when home is pressed.
55
57{
58 if (event->fCode == kKey_Home)
59 fMode = kFree;
60
61 return TGLEventHandler::HandleKey(event);
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// Method to handle action TGLViewer::kDragCameraRotate. It switches from standard perspective
66/// view to bird-view bellow angle fTransTheta and restores view when accumulated theta is larger
67/// than transition angle.
68
70{
71 if ( !fLego ) return TGLEventHandler::Rotate(xDelta, yDelta, mod1, mod2);
72
74 Double_t hRotate = cam.AdjustDelta(-yDelta, TMath::Pi()/cam.RefViewport().Height(), mod1, mod2);
75
76 // get lego bounding box
77 Float_t *bb = fLego->AssertBBox();
79 box.SetAligned(TGLVertex3(bb[0], bb[2], bb[4]), TGLVertex3(bb[1], bb[3], bb[5]));
80 box.Transform(fLego->RefMainTrans().Array());
81
82 Bool_t camChanged = kFALSE;
83
84 if (cam.IsOrthographic())
85 {
86 fTheta += hRotate;
87 if (fTheta < 0) fTheta = 0;
88 if (fTheta > fTransTheta)
89 {
90 TGLCamera* ortho = &cam;
95
98 persp->Setup(box, kTRUE);
99
100 TGLVector3 extents = box.Extents();
101 Int_t sortInd[3];
102 TMath::Sort(3, extents.CArr(), sortInd);
103 Double_t size = TMath::Hypot(extents[sortInd[0]], extents[sortInd[1]]);
104 Double_t dolly = size / (2.0*TMath::Tan(30*TMath::Pi()/360));
105 Double_t fov = TMath::ATan(TMath::Hypot(t-b, r-l)/(2*dolly));
106
107 persp->SetCenterVecWarp(0.5*(l+r), 0.5*(t+b), 0);
108
109 Double_t vR = -0.5 * TMath::Pi(); // switch XY
110 Double_t hR = -0.5 * TMath::Pi() + fTransTheta; // fix top view angle
111 persp->Configure(fov*TMath::RadToDeg(), 0, 0, hR, vR);
112
113 fMode = kFree;
114 camChanged = kTRUE;
115 }
116 }
117 else
118 {
119 Double_t theta = cam.GetTheta();
120 Double_t thetaN = theta + hRotate;
121 if (thetaN > TMath::Pi() - cam.GetVAxisMinAngle()) thetaN = TMath::Pi() - cam.GetVAxisMinAngle();
122 else if (thetaN < cam.GetVAxisMinAngle()) thetaN = cam.GetVAxisMinAngle();
123
124 fTheta = thetaN;
125
126 if (thetaN < fTransTheta)
127 {
130 TGLOrthoCamera* ortho = dynamic_cast<TGLOrthoCamera*>(& fGLViewer->GetRnrCtx()->RefCamera());
131 ortho->Setup(box, kTRUE);
132
133 // translation to the plane intersect
134 const TGLMatrix& mx = cam.GetCamBase() * cam.GetCamTrans();
136 TGLVertex3 p = d + mx.GetBaseVec(1);
137 TGLLine3 line(d, p);
138 const TGLPlane rp = TGLPlane(cam.GetCamBase().GetBaseVec(3), TGLVertex3());
139 std::pair<Bool_t, TGLVertex3> intersection;
140 intersection = Intersection(rp, line, kTRUE);
141 TGLVertex3 v = intersection.second;
142 ortho->Truck( v.X() - box.Center().X(), v.Y() - box.Center().Y());
143
144 // zoom
147 Double_t zoom = box.Extents().Y()/(t-b);
148 ortho->Configure(zoom, 0, 0, 0, 0);
149
150 fMode = kLocked;
151 camChanged = kTRUE;
152 }
153 else
154 {
155 camChanged = fGLViewer->CurrentCamera().Rotate(xDelta, -yDelta, mod1, mod2);
156 }
157 }
158 return camChanged;
159}
@ kKey_Home
Definition: KeySymbols.h:38
ROOT::R::TRInterface & r
Definition: Object.C:4
#define d(i)
Definition: RSha256.hxx:102
#define b(i)
Definition: RSha256.hxx:100
const Bool_t kFALSE
Definition: RtypesCore.h:90
double Double_t
Definition: RtypesCore.h:57
float Float_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:89
#define ClassImp(name)
Definition: Rtypes.h:361
std::pair< Bool_t, TGLLine3 > Intersection(const TGLPlane &p1, const TGLPlane &p2)
Find 3D line interestion of this plane with 'other'.
Definition: TGLUtil.cxx:517
Float_t * AssertBBox()
Definition: TAttBBox.h:45
Visualization of calorimeter data as eta/phi histogram.
Definition: TEveCalo.h:250
virtual TEveTrans & RefMainTrans()
Return reference to main transformation.
A base class of TGLEventHandler.
virtual Bool_t Rotate(Int_t xDelta, Int_t yDelta, Bool_t mod1, Bool_t mod2)
Method to handle action TGLViewer::kDragCameraRotate.
TEveLegoEventHandler(const TEveLegoEventHandler &)
virtual Bool_t HandleKey(Event_t *event)
Virtual from TGLEventHandler.
Double_t * Array()
Definition: TEveTrans.h:94
Concrete class describing an orientated (free) or axis aligned box of 8 vertices.
Abstract base camera class - concrete classes for orthographic and perspective cameras derive from it...
Definition: TGLCamera.h:43
const TGLMatrix & GetCamBase() const
Definition: TGLCamera.h:165
Float_t GetVAxisMinAngle()
Definition: TGLCamera.h:202
virtual Bool_t Rotate(Int_t xDelta, Int_t yDelta, Bool_t mod1, Bool_t mod2)
Rotate the camera round view volume center established in Setup().
Definition: TGLCamera.cxx:916
void SetCenterVecWarp(Double_t x, Double_t y, Double_t z)
Set camera center vector and do not keep the same combined camera transformation matrix.
Definition: TGLCamera.cxx:867
const TGLMatrix & GetCamTrans() const
Definition: TGLCamera.h:166
Double_t GetTheta() const
Get angle between camera up axis.
Definition: TGLCamera.cxx:882
virtual Bool_t IsOrthographic() const
Definition: TGLCamera.h:117
const TGLPlane & FrustumPlane(EFrustumPlane plane) const
Definition: TGLCamera.h:218
TGLRect & RefViewport()
Definition: TGLCamera.h:127
Double_t AdjustDelta(Double_t screenShift, Double_t deltaFactor, Bool_t mod1, Bool_t mod2) const
Adjust a passed screen value and apply modifiers.
Definition: TGLCamera.cxx:762
Base-class and default implementation of event-handler for TGLViewer.
TGLViewer * fGLViewer
virtual Bool_t Rotate(Int_t xDelta, Int_t yDelta, Bool_t mod1, Bool_t mod2)
Method to handle action TGLViewer::kDragCameraRotate.
virtual Bool_t HandleKey(Event_t *event)
Handle keyboard 'event'.
3D space, fixed length, line class, with direction / length 'vector', passing through point 'vertex'.
Definition: TGLUtil.h:386
16 component (4x4) transform matrix - column MAJOR as per GL.
Definition: TGLUtil.h:597
TGLVector3 GetBaseVec(Int_t b) const
Definition: TGLUtil.h:753
TGLVector3 GetTranslation() const
Return the translation component of matrix.
Definition: TGLUtil.cxx:795
Orthographic projection camera.
virtual Bool_t Truck(Int_t xDelta, Int_t yDelta, Bool_t mod1, Bool_t mod2)
Truck the camera - 'move camera parallel to film plane'.
virtual void Setup(const TGLBoundingBox &box, Bool_t reset=kTRUE)
Setup camera limits suitable to view the world volume defined by 'box' and call Reset() to initialise...
virtual void Configure(Double_t zoom, Double_t dolly, Double_t center[3], Double_t hRotate, Double_t vRotate)
Configure the camera state.
Perspective projection camera - with characteristic foreshortening.
virtual void Configure(Double_t fov, Double_t dolly, Double_t center[3], Double_t hRotate, Double_t vRotate)
Configure the camera state.
virtual void Setup(const TGLBoundingBox &box, Bool_t reset=kTRUE)
Setup camera limits suitable to view the world volume defined by 'box' and call Reset() to initialise...
3D plane class - of format Ax + By + Cz + D = 0
Definition: TGLUtil.h:524
Double_t D() const
Definition: TGLUtil.h:555
Int_t Height() const
Definition: TGLUtil.h:451
TGLCamera & RefCamera()
Definition: TGLRnrCtx.h:157
3 component (x/y/z) vector class.
Definition: TGLUtil.h:247
3 component (x/y/z) vertex class.
Definition: TGLUtil.h:83
const Double_t * CArr() const
Definition: TGLUtil.h:125
TGLRnrCtx * GetRnrCtx() const
TGLCamera & CurrentCamera() const
Definition: TGLViewer.h:269
void SetCurrentCamera(ECameraType camera)
Set current active camera - 'cameraType' one of: kCameraPerspX, kCameraPerspY, kCameraPerspZ,...
Definition: TGLViewer.cxx:1792
@ kCameraPerspXOY
Definition: TGLViewer.h:63
@ kCameraOrthoXOY
Definition: TGLViewer.h:64
Mother of all ROOT objects.
Definition: TObject.h:37
TLine * line
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
Double_t ATan(Double_t)
Definition: TMath.h:665
Double_t Hypot(Double_t x, Double_t y)
Definition: TMath.cxx:57
constexpr Double_t Pi()
Definition: TMath.h:38
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
Definition: TMathBase.h:362
Double_t Tan(Double_t)
Definition: TMath.h:635
constexpr Double_t RadToDeg()
Conversion from radian to degree:
Definition: TMath.h:74
UInt_t fCode
Definition: GuiTypes.h:179
auto * l
Definition: textangle.C:4