ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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;
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
146  Double_t b = -persp->FrustumPlane(TGLCamera::kBottom).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.
ClassImp(TEveLegoEventHandler)
A base class of TGLEventHandler.
Abstract base camera class - concrete classes for orthographic and perspective cameras derive from it...
Definition: TGLCamera.h:43
TLine * line
float Float_t
Definition: RtypesCore.h:53
Double_t D() const
Definition: TGLUtil.h:559
Float_t theta
Definition: shapesAnim.C:5
TGLVector3 GetTranslation() const
Return the translation component of matrix.
Definition: TGLUtil.cxx:822
16 component (4x4) transform matrix - column MAJOR as per GL.
Definition: TGLUtil.h:600
const Double_t * CArr() const
Definition: TGLUtil.h:129
TGLCamera & RefCamera()
Definition: TGLRnrCtx.h:157
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
TGLRnrCtx * GetRnrCtx() const
Double_t GetTheta() const
Get angle between camera up axis.
Definition: TGLCamera.cxx:882
TGLVertex3 Center() const
Double_t RadToDeg()
Definition: TMath.h:49
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
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.
const TGLMatrix & GetCamBase() const
Definition: TGLCamera.h:166
TFile * f
TEveLegoEventHandler(const TEveLegoEventHandler &)
virtual Bool_t IsOrthographic() const
Definition: TGLCamera.h:118
void Transform(const TGLMatrix &matrix)
Transform all vertices with matrix.
3 component (x/y/z) vertex class.
Definition: TGLUtil.h:86
int d
Definition: tornado.py:11
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
Definition: TMath.h:1002
const TGLMatrix & GetCamTrans() const
Definition: TGLCamera.h:167
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:250
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
TGLVector3 Extents() const
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 'box' and call Reset() to initialise...
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...
TGLVector3 GetBaseVec(Int_t b) const
Definition: TGLUtil.h:757
TThread * t[5]
Definition: threadsh1.C:13
Double_t * Array()
Definition: TEveTrans.h:94
TGLViewer * fGLViewer
ROOT::R::TRInterface & r
Definition: Object.C:4
SVector< double, 2 > v
Definition: Dict.h:5
TGLCamera & CurrentCamera() const
Definition: TGLViewer.h:267
tuple w
Definition: qtexample.py:51
TLine * l
Definition: textangle.C:4
3D space, fixed length, line class, with direction / length 'vector', passing through point 'vertex'...
Definition: TGLUtil.h:391
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'.
Double_t Pi()
Definition: TMath.h:44
Visualization of calorimeter data as eta/phi histogram.
Definition: TEveCalo.h:249
Float_t GetVAxisMinAngle()
Definition: TGLCamera.h:203
void lego()
Definition: lego.C:4
virtual void Configure(Double_t fov, Double_t dolly, Double_t center[3], Double_t hRotate, Double_t vRotate)
Configure the camera state.
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:181
Base-class and default implementation of event-handler for TGLViewer.
void SetCurrentCamera(ECameraType camera)
Set current active camera - 'cameraType' one of: kCameraPerspX, kCameraPerspY, kCameraPerspZ, kCameraOrthoXOY, kCameraOrthoXOZ, kCameraOrthoZOY, kCameraOrthoXnOY, kCameraOrthoXnOZ, kCameraOrthoZnOY.
Definition: TGLViewer.cxx:1779
Double_t Hypot(Double_t x, Double_t y)
Definition: TMath.cxx:60
Double_t X() const
Definition: TGLUtil.h:122
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:58
Concrete class describing an orientated (free) or axis aligned box of 8 vertices. ...
Double_t Y() const
Definition: TGLUtil.h:124
Float_t * AssertBBox()
Definition: TAttBBox.h:47
virtual TEveTrans & RefMainTrans()
Return reference to main transformation.
Int_t Height() const
Definition: TGLUtil.h:457
virtual Bool_t Rotate(Int_t xDelta, Int_t yDelta, Bool_t mod1, Bool_t mod2)
Method to handle action TGLViewer::kDragCameraRotate.
const TGLPlane & FrustumPlane(EFrustumPlane plane) const
Definition: TGLCamera.h:219
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
3D plane class - of format Ax + By + Cz + D = 0
Definition: TGLUtil.h:529
Double_t Tan(Double_t)
Definition: TMath.h:427
virtual Bool_t HandleKey(Event_t *event)
Handle keyboard 'event'.
Double_t ATan(Double_t)
Definition: TMath.h:451
std::pair< Bool_t, TGLLine3 > Intersection(const TGLPlane &p1, const TGLPlane &p2)
Find 3D line interestion of this plane with 'other'.
Definition: TGLUtil.cxx:544