Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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
36
37////////////////////////////////////////////////////////////////////////////////
38/// Constructor.
39
50
51////////////////////////////////////////////////////////////////////////////////
52/// Virtual from TGLEventHandler.
53/// Free the camera when home is pressed.
54
56{
57 if (event->fCode == kKey_Home)
58 fMode = kFree;
59
60 return TGLEventHandler::HandleKey(event);
61}
62
63////////////////////////////////////////////////////////////////////////////////
64/// Method to handle action TGLViewer::kDragCameraRotate. It switches from standard perspective
65/// view to bird-view bellow angle fTransTheta and restores view when accumulated theta is larger
66/// than transition angle.
67
69{
70 if ( !fLego ) return TGLEventHandler::Rotate(xDelta, yDelta, mod1, mod2);
71
72 TGLCamera &cam = fGLViewer->GetRnrCtx()->RefCamera();
73 Double_t hRotate = cam.AdjustDelta(-yDelta, TMath::Pi()/cam.RefViewport().Height(), mod1, mod2);
74
75 // get lego bounding box
76 Float_t *bb = fLego->AssertBBox();
78 box.SetAligned(TGLVertex3(bb[0], bb[2], bb[4]), TGLVertex3(bb[1], bb[3], bb[5]));
79 box.Transform(fLego->RefMainTrans().Array());
80
81 Bool_t camChanged = kFALSE;
82
83 if (cam.IsOrthographic())
84 {
85 fTheta += hRotate;
86 if (fTheta < 0) fTheta = 0;
87 if (fTheta > fTransTheta)
88 {
89 TGLCamera* ortho = &cam;
94
95 fGLViewer->SetCurrentCamera(TGLViewer::kCameraPerspXOY);
96 TGLPerspectiveCamera* persp = dynamic_cast<TGLPerspectiveCamera*>(&fGLViewer->GetRnrCtx()->RefCamera());
97 persp->Setup(box, kTRUE);
98
99 TGLVector3 extents = box.Extents();
100 Int_t sortInd[3];
101 TMath::Sort(3, extents.CArr(), sortInd);
102 Double_t size = TMath::Hypot(extents[sortInd[0]], extents[sortInd[1]]);
103 Double_t dolly = size / (2.0*TMath::Tan(30*TMath::Pi()/360));
104 Double_t fov = TMath::ATan(TMath::Hypot(t-b, r-l)/(2*dolly));
105
106 persp->SetCenterVecWarp(0.5*(l+r), 0.5*(t+b), 0);
107
108 Double_t vR = -0.5 * TMath::Pi(); // switch XY
109 Double_t hR = -0.5 * TMath::Pi() + fTransTheta; // fix top view angle
110 persp->Configure(fov*TMath::RadToDeg(), 0, nullptr, hR, vR);
111
112 fMode = kFree;
113 camChanged = kTRUE;
114 }
115 }
116 else
117 {
118 Double_t theta = cam.GetTheta();
119 Double_t thetaN = theta + hRotate;
120 if (thetaN > TMath::Pi() - cam.GetVAxisMinAngle()) thetaN = TMath::Pi() - cam.GetVAxisMinAngle();
121 else if (thetaN < cam.GetVAxisMinAngle()) thetaN = cam.GetVAxisMinAngle();
122
123 fTheta = thetaN;
124
125 if (thetaN < fTransTheta)
126 {
128 fGLViewer->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
129 TGLOrthoCamera* ortho = dynamic_cast<TGLOrthoCamera*>(& fGLViewer->GetRnrCtx()->RefCamera());
130 ortho->Setup(box, kTRUE);
131
132 // translation to the plane intersect
133 const TGLMatrix& mx = cam.GetCamBase() * cam.GetCamTrans();
135 TGLVertex3 p = d + mx.GetBaseVec(1);
136 TGLLine3 line(d, p);
137 const TGLPlane rp = TGLPlane(cam.GetCamBase().GetBaseVec(3), TGLVertex3());
138 std::pair<Bool_t, TGLVertex3> intersection;
139 intersection = Intersection(rp, line, kTRUE);
140 TGLVertex3 v = intersection.second;
141 ortho->Truck( v.X() - box.Center().X(), v.Y() - box.Center().Y());
142
143 // zoom
146 Double_t zoom = box.Extents().Y()/(t-b);
147 ortho->Configure(zoom, 0, nullptr, 0, 0);
148
149 fMode = kLocked;
150 camChanged = kTRUE;
151 }
152 else
153 {
154 camChanged = fGLViewer->CurrentCamera().Rotate(xDelta, -yDelta, mod1, mod2);
155 }
156 }
157 return camChanged;
158}
@ 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
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
std::pair< Bool_t, TGLLine3 > Intersection(const TGLPlane &p1, const TGLPlane &p2)
Find 3D line interestion of this plane with 'other'.
Definition TGLUtil.cxx:511
Visualization of calorimeter data as eta/phi histogram.
Definition TEveCalo.h:251
TEveLegoEventHandler(const TEveLegoEventHandler &)
Bool_t HandleKey(Event_t *event) override
Virtual from TGLEventHandler.
Bool_t Rotate(Int_t xDelta, Int_t yDelta, Bool_t mod1, Bool_t mod2) override
Method to handle action TGLViewer::kDragCameraRotate.
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:44
const TGLMatrix & GetCamBase() const
Definition TGLCamera.h:166
Float_t GetVAxisMinAngle()
Definition TGLCamera.h:203
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.
const TGLMatrix & GetCamTrans() const
Definition TGLCamera.h:167
Double_t GetTheta() const
Get angle between camera up axis.
virtual Bool_t IsOrthographic() const
Definition TGLCamera.h:118
const TGLPlane & FrustumPlane(EFrustumPlane plane) const
Definition TGLCamera.h:219
TGLRect & RefViewport()
Definition TGLCamera.h:128
Double_t AdjustDelta(Double_t screenShift, Double_t deltaFactor, Bool_t mod1, Bool_t mod2) const
Adjust a passed screen value and apply modifiers.
TGLEventHandler(TGWindow *w, TObject *obj)
Constructor.
TGLViewer * fGLViewer
virtual Bool_t Rotate(Int_t xDelta, Int_t yDelta, Bool_t mod1, Bool_t mod2)
Method to handle action TGLViewer::kDragCameraRotate.
Bool_t HandleKey(Event_t *event) override
Handle keyboard 'event'.
3D space, fixed length, line class, with direction / length 'vector', passing through point 'vertex'.
Definition TGLUtil.h:387
16 component (4x4) transform matrix - column MAJOR as per GL.
Definition TGLUtil.h:598
TGLVector3 GetBaseVec(Int_t b) const
Definition TGLUtil.h:754
TGLVector3 GetTranslation() const
Return the translation component of matrix.
Definition TGLUtil.cxx:788
Orthographic projection camera.
Bool_t Truck(Int_t xDelta, Int_t yDelta, Bool_t mod1, Bool_t mod2) override
Truck the camera - 'move camera parallel to film plane'.
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.
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.
3D plane class - of format Ax + By + Cz + D = 0
Definition TGLUtil.h:525
Double_t D() const
Definition TGLUtil.h:556
Int_t Height() const
Definition TGLUtil.h:452
3 component (x/y/z) vector class.
Definition TGLUtil.h:248
3 component (x/y/z) vertex class.
Definition TGLUtil.h:84
const Double_t * CArr() const
Definition TGLUtil.h:126
@ kCameraPerspXOY
Definition TGLViewer.h:61
@ kCameraOrthoXOY
Definition TGLViewer.h:62
ROOT GUI Window base class.
Definition TGWindow.h:23
Mother of all ROOT objects.
Definition TObject.h:42
TLine * line
void lego()
Definition lego.C:31
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)
Returns the principal value of the arc tangent of x, expressed in radians.
Definition TMath.h:651
Double_t Hypot(Double_t x, Double_t y)
Returns sqrt(x*x + y*y).
Definition TMath.cxx:59
constexpr Double_t Pi()
Definition TMath.h:40
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
Sort the n elements of the array a of generic templated type Element.
Definition TMathBase.h:413
Double_t Tan(Double_t)
Returns the tangent of an angle of x radians.
Definition TMath.h:611
constexpr Double_t RadToDeg()
Conversion from radian to degree: .
Definition TMath.h:75
Event structure.
Definition GuiTypes.h:175
UInt_t fCode
key or button code
Definition GuiTypes.h:181
TLine l
Definition textangle.C:4