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
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
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
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
const Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
float Float_t
Definition RtypesCore.h:57
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:364
std::pair< Bool_t, TGLLine3 > Intersection(const TGLPlane &p1, const TGLPlane &p2)
Find 3D line interestion of this plane with 'other'.
Definition TGLUtil.cxx:516
Float_t * AssertBBox()
Definition TAttBBox.h:45
Visualization of calorimeter data as eta/phi histogram.
Definition TEveCalo.h:251
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.
void SetAligned(const TGLVertex3 &lowVertex, const TGLVertex3 &highVertex)
Set ALIGNED box from two low/high 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
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().
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.
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: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:794
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:525
Double_t D() const
Definition TGLUtil.h:556
Int_t Height() const
Definition TGLUtil.h:452
TGLCamera & RefCamera()
Definition TGLRnrCtx.h:157
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
TGLRnrCtx * GetRnrCtx() const
TGLCamera & CurrentCamera() const
Definition TGLViewer.h:267
void SetCurrentCamera(ECameraType camera)
Set current active camera - 'cameraType' one of: kCameraPerspX, kCameraPerspY, kCameraPerspZ,...
@ 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:41
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)
Definition TMath.h:625
Double_t Hypot(Double_t x, Double_t y)
Definition TMath.cxx:57
constexpr Double_t Pi()
Definition TMath.h:37
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
Definition TMathBase.h:358
Double_t Tan(Double_t)
Definition TMath.h:597
constexpr Double_t RadToDeg()
Conversion from radian to degree:
Definition TMath.h:73
Event structure.
Definition GuiTypes.h:174
auto * l
Definition textangle.C:4