Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TEveTrans.h
Go to the documentation of this file.
1 // @(#)root/eve:$Id$
2 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TEveTrans
13 #define ROOT_TEveTrans
14 
15 #include "TEveVector.h"
16 #include "TVector3.h"
17 
18 class TGeoMatrix;
19 class TGeoHMatrix;
20 class TBuffer3D;
21 
22 /******************************************************************************/
23 // TEveTrans -- 3D transformation in generalised coordinates
24 /******************************************************************************/
25 
26 class TEveTrans : public TObject
27 {
28  friend class TEveTransSubEditor;
29  friend class TEveTransEditor;
30 
31 protected:
32  Double32_t fM[16];
33 
34  mutable Float_t fA1; //!
35  mutable Float_t fA2; //!
36  mutable Float_t fA3; //!
37  mutable Bool_t fAsOK; //!
38 
39  // TEveUtil
40  Bool_t fUseTrans; // use transformation matrix
41  Bool_t fEditTrans; // edit transformation in TGedFrame
42  Bool_t fEditRotation; // edit rotation
43  Bool_t fEditScale; // edit scale
44 
45  Double_t Norm3Column(Int_t col);
46  Double_t Orto3Column(Int_t col, Int_t ref);
47 
48 public:
49  TEveTrans();
50  TEveTrans(const TEveTrans& t);
51  TEveTrans(const Double_t arr[16]);
52  TEveTrans(const Float_t arr[16]);
53  virtual ~TEveTrans() {}
54 
55  // General operations
56 
57  void UnitTrans();
58  void ZeroTrans(Double_t w=1.0);
59  void UnitRot();
60  void SetTrans(const TEveTrans& t, Bool_t copyAngles=kTRUE);
61  void SetFromArray(const Double_t arr[16]);
62  void SetFromArray(const Float_t arr[16]);
63  TEveTrans& operator=(const TEveTrans& t) { SetTrans(t); return *this; }
64  void SetupRotation(Int_t i, Int_t j, Double_t f);
65  void SetupFromToVec(const TEveVector& from, const TEveVector& to);
66 
67  void OrtoNorm3();
68  Double_t Invert();
69 
70  void MultLeft(const TEveTrans& t);
71  void MultRight(const TEveTrans& t);
72  void operator*=(const TEveTrans& t) { MultRight(t); }
73 
74  void TransposeRotationPart();
75 
76  TEveTrans operator*(const TEveTrans& t);
77 
78  // Move & Rotate
79 
80  void MoveLF(Int_t ai, Double_t amount);
81  void Move3LF(Double_t x, Double_t y, Double_t z);
82  void RotateLF(Int_t i1, Int_t i2, Double_t amount);
83 
84  void MovePF(Int_t ai, Double_t amount);
85  void Move3PF(Double_t x, Double_t y, Double_t z);
86  void RotatePF(Int_t i1, Int_t i2, Double_t amount);
87 
88  void Move(const TEveTrans& a, Int_t ai, Double_t amount);
89  void Move3(const TEveTrans& a, Double_t x, Double_t y, Double_t z);
90  void Rotate(const TEveTrans& a, Int_t i1, Int_t i2, Double_t amount);
91 
92  // Element access
93 
94  Double_t* Array() { return fM; } const Double_t* Array() const { return fM; }
95  Double_t* ArrX() { return fM; } const Double_t* ArrX() const { return fM; }
96  Double_t* ArrY() { return fM + 4; } const Double_t* ArrY() const { return fM + 4; }
97  Double_t* ArrZ() { return fM + 8; } const Double_t* ArrZ() const { return fM + 8; }
98  Double_t* ArrT() { return fM + 12; } const Double_t* ArrT() const { return fM + 12; }
99 
100  Double_t operator[](Int_t i) const { return fM[i]; }
101  Double_t& operator[](Int_t i) { return fM[i]; }
102 
103  Double_t CM(Int_t i, Int_t j) const { return fM[4*j + i]; }
104  Double_t& CM(Int_t i, Int_t j) { return fM[4*j + i]; }
105 
106  Double_t operator()(Int_t i, Int_t j) const { return fM[4*j + i - 5]; }
107  Double_t& operator()(Int_t i, Int_t j) { return fM[4*j + i - 5]; }
108 
109  // Base-vector interface
110 
111  void SetBaseVec(Int_t b, Double_t x, Double_t y, Double_t z);
112  void SetBaseVec(Int_t b, const TVector3& v);
113 
114  TVector3 GetBaseVec(Int_t b) const;
115  void GetBaseVec(Int_t b, TVector3& v) const;
116 
117  // Position interface
118 
119  void SetPos(Double_t x, Double_t y, Double_t z);
120  void SetPos(Double_t* x);
121  void SetPos(Float_t * x);
122  void SetPos(const TEveTrans& t);
123 
124  void GetPos(Double_t& x, Double_t& y, Double_t& z) const;
125  void GetPos(Double_t* x) const;
126  void GetPos(Float_t * x) const;
127  void GetPos(TVector3& v) const;
128  TVector3 GetPos() const;
129 
130  // Cardan angle interface
131 
132  void SetRotByAngles(Float_t a1, Float_t a2, Float_t a3);
133  void SetRotByAnyAngles(Float_t a1, Float_t a2, Float_t a3, const char* pat);
134  void GetRotAngles(Float_t* x) const;
135 
136  // Scaling
137 
138  void Scale(Double_t sx, Double_t sy, Double_t sz);
139  Double_t Unscale();
140  void Unscale(Double_t& sx, Double_t& sy, Double_t& sz);
141  void GetScale(Double_t& sx, Double_t& sy, Double_t& sz) const;
142  void SetScale(Double_t sx, Double_t sy, Double_t sz);
143  void SetScaleX(Double_t sx);
144  void SetScaleY(Double_t sy);
145  void SetScaleZ(Double_t sz);
146 
147  // Operations on vectors
148 
149  void MultiplyIP(TVector3& v, Double_t w=1) const;
150  void MultiplyIP(Double_t* v, Double_t w=1) const;
151  void MultiplyIP(Float_t* v, Double_t w=1) const;
152  TVector3 Multiply(const TVector3& v, Double_t w=1) const;
153  void Multiply(const Double_t *vin, Double_t* vout, Double_t w=1) const;
154  void RotateIP(TVector3& v) const;
155  void RotateIP(Double_t* v) const;
156  void RotateIP(Float_t* v) const;
157  TVector3 Rotate(const TVector3& v) const;
158 
159  virtual void Print(Option_t* option = "") const;
160 
161  // TEveUtil stuff
162 
163  void SetFrom(Double_t* carr);
164  void SetFrom(const TGeoMatrix& mat);
165  void SetGeoHMatrix(TGeoHMatrix& mat);
166  void SetBuffer3D(TBuffer3D& buff);
167 
168  Bool_t GetUseTrans() const { return fUseTrans; }
169  void SetUseTrans(Bool_t v) { fUseTrans = v; }
170 
171  void SetEditRotation(Bool_t x){ fEditRotation = x; }
172  void SetEditScale(Bool_t x) { fEditScale = x; }
173  Bool_t GetEditRotation() { return fEditRotation; }
174  Bool_t GetEditScale() { return fEditScale; }
175 
176  Bool_t GetEditTrans() const { return fEditTrans; }
177  void SetEditTrans(Bool_t v) { fEditTrans = v; }
178 
179  Bool_t IsScale(Double_t low=0.9, Double_t high=1.1) const;
180 
181  ClassDef(TEveTrans, 1); // Column-major 4x4 transforamtion matrix for homogeneous coordinates.
182 };
183 
184 std::ostream& operator<<(std::ostream& s, const TEveTrans& t);
185 
186 #endif