Logo ROOT   6.10/09
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 
10 #include "TEveLegoEventHandler.h"
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"
19 #include "TGLPerspectiveCamera.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
31 A base class of TGLEventHandler. Switches current camera from perspective
32 to orthographic bird-view, if camera theta is less than given threshold. It sets back
33 perspective 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]));
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;
93  Double_t t = ortho->FrustumPlane(TGLCamera::kTop).D();
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  {
128  TGLPerspectiveCamera* persp = (TGLPerspectiveCamera*)(&cam);
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();
135  TGLVertex3 d = mx.GetTranslation();
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
145  Double_t t = persp->FrustumPlane(TGLCamera::kTop).D();
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 }
void SetAligned(const TGLVertex3 &lowVertex, const TGLVertex3 &highVertex)
Set ALIGNED box from two low/high vertices.
TGLVertex3 Center() const
A base class of TGLEventHandler.
Abstract base camera class - concrete classes for orthographic and perspective cameras derive from it...
Definition: TGLCamera.h:43
TGLVector3 Extents() const
TLine * line
float Float_t
Definition: RtypesCore.h:53
16 component (4x4) transform matrix - column MAJOR as per GL.
Definition: TGLUtil.h:596
TGLCamera & RefCamera()
Definition: TGLRnrCtx.h:157
const TGLMatrix & GetCamTrans() const
Definition: TGLCamera.h:167
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TGLRect & RefViewport()
Definition: TGLCamera.h:128
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
Perspective projection camera - with characteristic foreshortening.
TEveLegoEventHandler(const TEveLegoEventHandler &)
TGLCamera & CurrentCamera() const
Definition: TGLViewer.h:267
Double_t D() const
Definition: TGLUtil.h:555
void Transform(const TGLMatrix &matrix)
Transform all vertices with matrix.
3 component (x/y/z) vertex class.
Definition: TGLUtil.h:82
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
Definition: TMath.h:1151
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
3 component (x/y/z) vector class.
Definition: TGLUtil.h:246
const TGLMatrix & GetCamBase() const
Definition: TGLCamera.h:166
constexpr Double_t Pi()
Definition: TMath.h:40
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
virtual Bool_t HandleKey(Event_t *event)
Virtual from TGLEventHandler.
virtual void Setup(const TGLBoundingBox &box, Bool_t reset=kTRUE)
Setup camera limits suitable to view the world volume defined by &#39;box&#39; and call Reset() to initialise...
TGLVector3 GetTranslation() const
Return the translation component of matrix.
Definition: TGLUtil.cxx:822
virtual void Setup(const TGLBoundingBox &box, Bool_t reset=kTRUE)
Setup camera limits suitable to view the world volume defined by &#39;box&#39; and call Reset() to initialise...
Double_t * Array()
Definition: TEveTrans.h:94
TGLRnrCtx * GetRnrCtx() const
TGLViewer * fGLViewer
TRandom2 r(17)
SVector< double, 2 > v
Definition: Dict.h:5
TLine * l
Definition: textangle.C:4
3D space, fixed length, line class, with direction / length &#39;vector&#39;, passing through point &#39;vertex&#39;...
Definition: TGLUtil.h:387
virtual Bool_t Truck(Int_t xDelta, Int_t yDelta, Bool_t mod1, Bool_t mod2)
Truck the camera - &#39;move camera parallel to film plane&#39;.
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
virtual Bool_t IsOrthographic() const
Definition: TGLCamera.h:118
const Bool_t kFALSE
Definition: RtypesCore.h:92
Visualization of calorimeter data as eta/phi histogram.
Definition: TEveCalo.h:249
Float_t GetVAxisMinAngle()
Definition: TGLCamera.h:203
virtual void Configure(Double_t fov, Double_t dolly, Double_t center[3], Double_t hRotate, Double_t vRotate)
Configure the camera state.
#define ClassImp(name)
Definition: Rtypes.h:336
double f(double x)
virtual Bool_t Rotate(Int_t xDelta, Int_t yDelta, Bool_t mod1, Bool_t mod2)
Method to handle action TGLViewer::kDragCameraRotate.
double Double_t
Definition: RtypesCore.h:55
UInt_t fCode
Definition: GuiTypes.h:179
Base-class and default implementation of event-handler for TGLViewer.
void SetCurrentCamera(ECameraType camera)
Set current active camera - &#39;cameraType&#39; one of: kCameraPerspX, kCameraPerspY, kCameraPerspZ, kCameraOrthoXOY, kCameraOrthoXOZ, kCameraOrthoZOY, kCameraOrthoXnOY, kCameraOrthoXnOZ, kCameraOrthoZnOY.
Definition: TGLViewer.cxx:1786
Double_t Hypot(Double_t x, Double_t y)
Definition: TMath.cxx:60
virtual void Configure(Double_t zoom, Double_t dolly, Double_t center[3], Double_t hRotate, Double_t vRotate)
Configure the camera state.
Orthographic projection camera.
Mother of all ROOT objects.
Definition: TObject.h:37
Concrete class describing an orientated (free) or axis aligned box of 8 vertices. ...
constexpr Double_t RadToDeg()
Definition: TMath.h:60
const Double_t * CArr() const
Definition: TGLUtil.h:125
Float_t * AssertBBox()
Definition: TAttBBox.h:45
const TGLPlane & FrustumPlane(EFrustumPlane plane) const
Definition: TGLCamera.h:219
virtual TEveTrans & RefMainTrans()
Return reference to main transformation.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
Double_t GetTheta() const
Get angle between camera up axis.
Definition: TGLCamera.cxx:882
virtual Bool_t Rotate(Int_t xDelta, Int_t yDelta, Bool_t mod1, Bool_t mod2)
Method to handle action TGLViewer::kDragCameraRotate.
Int_t Height() const
Definition: TGLUtil.h:453
Double_t Y() const
Definition: TGLUtil.h:120
const Bool_t kTRUE
Definition: RtypesCore.h:91
3D plane class - of format Ax + By + Cz + D = 0
Definition: TGLUtil.h:525
Double_t Tan(Double_t)
Definition: TMath.h:554
TGLVector3 GetBaseVec(Int_t b) const
Definition: TGLUtil.h:753
virtual Bool_t HandleKey(Event_t *event)
Handle keyboard &#39;event&#39;.
Double_t ATan(Double_t)
Definition: TMath.h:578
std::pair< Bool_t, TGLLine3 > Intersection(const TGLPlane &p1, const TGLPlane &p2)
Find 3D line interestion of this plane with &#39;other&#39;.
Definition: TGLUtil.cxx:544
Double_t X() const
Definition: TGLUtil.h:118