Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveTrans.hxx
Go to the documentation of this file.
1// @(#)root/eve7:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007, 2018
3
4/*************************************************************************
5 * Copyright (C) 1995-2019, 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 ROOT7_REveTrans
13#define ROOT7_REveTrans
14
15#include <ROOT/REveVector.hxx>
16#include "TVector3.h"
17
18#include <memory>
19
20class TGeoMatrix;
21class TGeoHMatrix;
22class TBuffer3D;
23
24namespace ROOT {
25namespace Experimental {
26
27////////////////////////////////////////////////////////////////////////////////
28/// How a transformation is changing: the state REveTrans::SetMotion() records.
29/// Held by pointer and allocated on demand, the way REveElement holds its
30/// REveTrans, because most transformations never move.
31
33 // clang-format off
34 REveVectorD fVel; ///< velocity, units/s
35 REveVectorD fAcc; ///< acceleration, units/s^2
36 REveVectorD fSpinAxis; ///< spin axis, unit length, local frame
37 Double_t fSpinRate{0.}; ///< rad/s about fSpinAxis
38 Double_t fMaxDt{0.}; ///< seconds the trajectory may be trusted
39 Double_t fMotionT0{0.}; ///< REveUtil::ServerTimeMs() when set
40 // clang-format on
41};
42
43/******************************************************************************/
44// REveTrans -- 3D transformation in generalised coordinates
45/******************************************************************************/
46
47class REveTrans : public TObject
48{
49protected:
51
52 mutable Float_t fA1; ///<!
53 mutable Float_t fA2; ///<!
54 mutable Float_t fA3; ///<!
55 mutable Bool_t fAsOK; ///<!
56
57 // REveUtil
58 Bool_t fUseTrans; // use transformation matrix
59 Bool_t fEditTrans; // edit transformation in TGedFrame
60 Bool_t fEditRotation; // edit rotation
61 Bool_t fEditScale; // edit scale
62
63 /// Streamed motion, null unless set. Transient: a velocity at an instant is
64 /// runtime state, not something a saved transformation should carry.
65 std::unique_ptr<REveDeltaTrans> fDeltaTrans; ///<!
66
69
70public:
71 REveTrans();
72 REveTrans(const REveTrans &t);
73 REveTrans(const Double_t arr[16]);
74 REveTrans(const Float_t arr[16]);
75 ~REveTrans() override {}
76
77 /// \name Streamed motion
78 /// How this transformation is changing, so the client can extrapolate between
79 /// updates. Spin is an axis and a rate in the local frame.
80 /// @{
81 void SetMotion(const REveVectorD &vel, const REveVectorD &acc, Double_t max_dt);
82 // clang-format off
83 void SetMotion(const REveVectorD &vel, const REveVectorD &acc,
84 const REveVectorD &spin_axis, Double_t spin_rate, Double_t max_dt);
85 // clang-format on
86 void ClearMotion();
87
88 Bool_t HasMotion() const { return fDeltaTrans != nullptr; }
89 const REveDeltaTrans *GetDeltaTrans() const { return fDeltaTrans.get(); }
90 /// @}
91
92 // General operations
93
94 void UnitTrans();
95 void ZeroTrans(Double_t w = 1.0);
96 void UnitRot();
97 void SetTrans(const REveTrans &t, Bool_t copyAngles = kTRUE);
98 void SetFromArray(const Double_t arr[16]);
99 void SetFromArray(const Float_t arr[16]);
100 /// The delta-trans is owned, so a copy gets its own. Assigning from a
101 /// transformation that is not moving clears the target's, rather than
102 /// leaving it to keep extrapolating a trajectory it no longer has.
104 {
105 if (this != &t) {
106 SetTrans(t);
107 fDeltaTrans = t.fDeltaTrans ? std::make_unique<REveDeltaTrans>(*t.fDeltaTrans) : nullptr;
108 }
109 return *this;
110 }
111 void SetupRotation(Int_t i, Int_t j, Double_t f);
112 void SetupFromToVec(const REveVector &from, const REveVector &to);
113
114 void OrtoNorm3();
116
117 void MultLeft(const REveTrans &t);
118 void MultRight(const REveTrans &t);
119 void operator*=(const REveTrans &t) { MultRight(t); }
120
122
123 REveTrans operator*(const REveTrans &t);
124
125 // Move & Rotate
126
127 void MoveLF(Int_t ai, Double_t amount);
129 void RotateLF(Int_t i1, Int_t i2, Double_t amount);
130
131 void MovePF(Int_t ai, Double_t amount);
133 void RotatePF(Int_t i1, Int_t i2, Double_t amount);
134
135 void Move(const REveTrans &a, Int_t ai, Double_t amount);
136 void Move3(const REveTrans &a, Double_t x, Double_t y, Double_t z);
137 void Rotate(const REveTrans &a, Int_t i1, Int_t i2, Double_t amount);
138
139 // Element access
140
141 Double_t *Array() { return fM; }
142 const Double_t *Array() const { return fM; }
143 Double_t *ArrX() { return fM; }
144 const Double_t *ArrX() const { return fM; }
145 Double_t *ArrY() { return fM + 4; }
146 const Double_t *ArrY() const { return fM + 4; }
147 Double_t *ArrZ() { return fM + 8; }
148 const Double_t *ArrZ() const { return fM + 8; }
149 Double_t *ArrT() { return fM + 12; }
150 const Double_t *ArrT() const { return fM + 12; }
151
152 Double_t operator[](Int_t i) const { return fM[i]; }
153 Double_t &operator[](Int_t i) { return fM[i]; }
154
155 Double_t CM(Int_t i, Int_t j) const { return fM[4 * j + i]; }
156 Double_t &CM(Int_t i, Int_t j) { return fM[4 * j + i]; }
157
158 Double_t operator()(Int_t i, Int_t j) const { return fM[4 * j + i - 5]; }
159 Double_t &operator()(Int_t i, Int_t j) { return fM[4 * j + i - 5]; }
160
161 // Base-vector interface
162
164 void SetBaseVec(Int_t b, const TVector3 &v);
165
166 TVector3 GetBaseVec(Int_t b) const;
167 void GetBaseVec(Int_t b, TVector3 &v) const;
168
169 // Position interface
170
172 void SetPos(Double_t *x);
173 void SetPos(Float_t *x);
174 void SetPos(const REveTrans &t);
175
176 void GetPos(Double_t &x, Double_t &y, Double_t &z) const;
177 void GetPos(Double_t *x) const;
178 void GetPos(Float_t *x) const;
179 void GetPos(TVector3 &v) const;
180 TVector3 GetPos() const;
181
182 // Cardan angle interface
183
184 void SetRotByAngles(Float_t a1, Float_t a2, Float_t a3);
185 void SetRotByAnyAngles(Float_t a1, Float_t a2, Float_t a3, const char *pat);
186 void GetRotAngles(Float_t *x) const;
187
188 // Scaling
189
190 void Scale(Double_t sx, Double_t sy, Double_t sz);
192 void Unscale(Double_t &sx, Double_t &sy, Double_t &sz);
193 void GetScale(Double_t &sx, Double_t &sy, Double_t &sz) const;
194 void SetScale(Double_t sx, Double_t sy, Double_t sz);
195 void SetScaleX(Double_t sx);
196 void SetScaleY(Double_t sy);
197 void SetScaleZ(Double_t sz);
198
199 // Operations on vectors
200
201 void MultiplyIP(TVector3 &v, Double_t w = 1) const;
202 void MultiplyIP(Double_t *v, Double_t w = 1) const;
203 void MultiplyIP(Float_t *v, Double_t w = 1) const;
204 TVector3 Multiply(const TVector3 &v, Double_t w = 1) const;
205 void Multiply(const Double_t *vin, Double_t *vout, Double_t w = 1) const;
206 void RotateIP(TVector3 &v) const;
207 void RotateIP(Double_t *v) const;
208 void RotateIP(Float_t *v) const;
209 TVector3 Rotate(const TVector3 &v) const;
210
211 void Print(Option_t *option = "") const override;
212
213 // REveUtil stuff
214
215 void SetFrom(Double_t *carr);
216 void SetFrom(const TGeoMatrix &mat);
217 void SetGeoHMatrix(TGeoHMatrix &mat);
218 void SetBuffer3D(TBuffer3D &buff);
219
220 Bool_t GetUseTrans() const { return fUseTrans; }
222
227
228 Bool_t GetEditTrans() const { return fEditTrans; }
230
231 Bool_t IsScale(Double_t low = 0.9, Double_t high = 1.1) const;
232
233 ClassDefOverride(REveTrans, 1); // Column-major 4x4 transforamtion matrix for homogeneous coordinates.
234};
235
236std::ostream &operator<<(std::ostream &s, const REveTrans &t);
237
238} // namespace Experimental
239} // namespace ROOT
240
241#endif
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define a(i)
Definition RSha256.hxx:99
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:78
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
Option_t Option_t option
REveTrans operator*(const REveTrans &t)
Copy, multiply from right and return product.
const Double_t * ArrT() const
void UnitRot()
Reset rotation part of the matrix to unity.
void SetBuffer3D(TBuffer3D &buff)
Fill transformation part TBuffer3D core section.
void SetupRotation(Int_t i, Int_t j, Double_t f)
Setup the matrix as an elementary rotation.
Double_t Norm3Column(Int_t col)
Norm 3-vector in column col.
void SetScaleY(Double_t sy)
Change y scaling.
void RotatePF(Int_t i1, Int_t i2, Double_t amount)
Rotate in parent frame. Does optimised version of MultLeft.
Double_t Invert()
Invert matrix.
void MultiplyIP(TVector3 &v, Double_t w=1) const
Multiply vector in-place.
void RotateLF(Int_t i1, Int_t i2, Double_t amount)
Rotate in local frame. Does optimised version of MultRight.
void operator*=(const REveTrans &t)
std::unique_ptr< REveDeltaTrans > fDeltaTrans
Streamed motion, null unless set.
Definition REveTrans.hxx:65
Double_t & CM(Int_t i, Int_t j)
const Double_t * ArrX() const
void SetMotion(const REveVectorD &vel, const REveVectorD &acc, Double_t max_dt)
Declare how this transformation is changing; position still comes from the matrix.
Definition REveTrans.cxx:49
void GetScale(Double_t &sx, Double_t &sy, Double_t &sz) const
Deduce scales from sizes of base vectors.
REveTrans()
Default constructor.
void TransposeRotationPart()
Transpose 3x3 rotation sub-matrix.
Double_t & operator[](Int_t i)
REveTrans & operator=(const REveTrans &t)
The delta-trans is owned, so a copy gets its own.
void ZeroTrans(Double_t w=1.0)
Reset matrix to zero, only the perspective scaling is set to w (1 by default).
void Move3PF(Double_t x, Double_t y, Double_t z)
General move in parent-frame.
void SetTrans(const REveTrans &t, Bool_t copyAngles=kTRUE)
Set matrix from another,.
void SetFromArray(const Double_t arr[16])
Set matrix from Double_t array.
void MovePF(Int_t ai, Double_t amount)
Move in parent-frame along axis index ai.
const REveDeltaTrans * GetDeltaTrans() const
Definition REveTrans.hxx:89
void SetBaseVec(Int_t b, Double_t x, Double_t y, Double_t z)
Set base-vector with index b.
void SetScaleX(Double_t sx)
Change x scaling.
void MoveLF(Int_t ai, Double_t amount)
Move in local-frame along axis with index ai.
Double_t Orto3Column(Int_t col, Int_t ref)
Orto-norm 3-vector in column col with respect to column ref.
Double_t operator()(Int_t i, Int_t j) const
void SetGeoHMatrix(TGeoHMatrix &mat)
Set TGeoHMatrix mat.
void SetScale(Double_t sx, Double_t sy, Double_t sz)
Set scaling.
void OrtoNorm3()
Orto-norm columns 1 to 3.
void Move(const REveTrans &a, Int_t ai, Double_t amount)
Move in a's coord-system along axis-index ai.
void SetFrom(Double_t *carr)
void Move3LF(Double_t x, Double_t y, Double_t z)
General move in local-frame.
void GetRotAngles(Float_t *x) const
Get Cardan rotation angles (pattern xYz above).
void SetupFromToVec(const REveVector &from, const REveVector &to)
A function for creating a rotation matrix that rotates a vector called "from" into another vector cal...
Double_t CM(Int_t i, Int_t j) const
void Print(Option_t *option="") const override
Print in reasonable format.
TVector3 Multiply(const TVector3 &v, Double_t w=1) const
Multiply vector and return it.
const Double_t * Array() const
const Double_t * ArrZ() const
void SetPos(Double_t x, Double_t y, Double_t z)
Set position (base-vec 4).
void Scale(Double_t sx, Double_t sy, Double_t sz)
Scale matrix. Translation part untouched.
const Double_t * ArrY() const
Double_t & operator()(Int_t i, Int_t j)
void UnitTrans()
Reset matrix to unity.
Bool_t IsScale(Double_t low=0.9, Double_t high=1.1) const
Test if the transformation is a scale.
void Move3(const REveTrans &a, Double_t x, Double_t y, Double_t z)
General move in a's coord-system.
void RotateIP(TVector3 &v) const
Rotate vector in-place. Translation is NOT applied.
void MultRight(const REveTrans &t)
Multiply from right: this = this * t.
void ClearMotion()
Stop extrapolating: the element holds wherever the matrix puts it.
Definition REveTrans.cxx:90
Double_t Unscale()
Remove scaling, make all base vectors of unit length.
void SetScaleZ(Double_t sz)
Change z scaling.
void SetRotByAnyAngles(Float_t a1, Float_t a2, Float_t a3, const char *pat)
Sets Rotation part as given by angles a1, a1, a3 and pattern pat.
void SetRotByAngles(Float_t a1, Float_t a2, Float_t a3)
void MultLeft(const REveTrans &t)
Multiply from left: this = t * this.
Double_t operator[](Int_t i) const
TVector3 GetBaseVec(Int_t b) const
Get base-vector with index b.
void Rotate(const REveTrans &a, Int_t i1, Int_t i2, Double_t amount)
Rotate in a's coord-system, rotating base vector with index i1 into i2.
Generic 3D primitive description class.
Definition TBuffer3D.h:18
Matrix class used for computing global transformations Should NOT be used for node definition.
Definition TGeoMatrix.h:459
Geometrical transformation package.
Definition TGeoMatrix.h:39
Mother of all ROOT objects.
Definition TObject.h:42
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
std::ostream & operator<<(std::ostream &s, const REveTrans &t)
How a transformation is changing: the state REveTrans::SetMotion() records.
Definition REveTrans.hxx:32
REveVectorD fSpinAxis
spin axis, unit length, local frame
Definition REveTrans.hxx:36
Double_t fSpinRate
rad/s about fSpinAxis
Definition REveTrans.hxx:37
REveVectorD fAcc
acceleration, units/s^2
Definition REveTrans.hxx:35
Double_t fMaxDt
seconds the trajectory may be trusted
Definition REveTrans.hxx:38
REveVectorD fVel
velocity, units/s
Definition REveTrans.hxx:34
Double_t fMotionT0
REveUtil::ServerTimeMs() when set.
Definition REveTrans.hxx:39