]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/Reve/ZTrans.cxx
Updated signature of AliMUONSegFactory
[u/mrichter/AliRoot.git] / EVE / Reve / ZTrans.cxx
CommitLineData
76082cd6 1// $Header$
2
3// Copyright (C) 1999-2005, Matevz Tadel. All rights reserved.
4// This file is part of GLED, released under GNU General Public License version 2.
5// For the licensing terms see $GLEDSYS/LICENSE or http://www.gnu.org/.
6
7//______________________________________________________________________
8// ZTrans
9//
10// ZTrans is a 4x4 transformation matrix for homogeneous coordinates
11// stored internaly in a column-major order to allow direct usage by
12// GL. The element type is Double32_t as statically the floats would
13// be precise enough but continuous operations on the matrix must
14// retain precision of column vectors.
15//
16// Cartan angles in mA[1-3] (+z, -y, +x) are stored for backward
17// compatibility and will probably be removed soon.
18//
19// Direct element access (first two should be used with care):
20// operator[i] direct access to elements, i:0->15
21// CM(i,j) element 4*j + i; i,j:0->3 { CM ~ c-matrix }
22// operator(i,j) element 4*(j-1) + i - 1 i,j:1->4
23//
24// Column-vector access:
25// USet Get/SetBaseVec(), Get/SetPos() and Arr[XYZT]() methods.
26//
27// For all methods taking the matrix indices:
28// 1->X, 2->Y, 3->Z; 4->Position (if applicable). 0 reserved for time.
29//
30// Shorthands in method-names:
31// LF ~ LocalFrame; PF ~ ParentFrame; IP ~ InPlace
32
33#include "ZTrans.h"
34#include "Reve.h"
35#include <TMath.h>
36
37#include <ctype.h>
38
39#define F00 0
40#define F01 4
41#define F02 8
42#define F03 12
43
44#define F10 1
45#define F11 5
46#define F12 9
47#define F13 13
48
49#define F20 2
50#define F21 6
51#define F22 10
52#define F23 14
53
54#define F30 3
55#define F31 7
56#define F32 11
57#define F33 15
58
59using namespace Reve;
60
61ClassImp(ZTrans)
62
63/**************************************************************************/
64
65ZTrans::ZTrans() { UnitTrans(); fUseTrans = kTRUE; fEditTrans = kFALSE; }
66
67ZTrans::ZTrans(const ZTrans& z) : TObject() { *this = z; }
68
69/**************************************************************************/
70
71void ZTrans::UnitTrans()
72{
73 // Reset matrix to unity.
74
75 memset(M, 0, 16*sizeof(Double_t));
76 M[F00] = M[F11] = M[F22] = M[F33] = 1;
77 mA1 = mA2 = mA3 = 0;
78 bAsOK = true;
79}
80
81void ZTrans::UnitRot()
82{
83 // Reset rotation part of the matrix to unity.
84
85 memset(M, 0, 12*sizeof(Double_t));
86 M[F00] = M[F11] = M[F22] = 1;
87 mA1 = mA2 = mA3 = 0;
88 bAsOK = true;
89}
90
91void ZTrans::SetTrans(const ZTrans& t)
92{
93 memcpy(M, t.M, sizeof(M));
94 bAsOK = false;
95}
96
97
98void ZTrans::SetupRotation(Int_t i, Int_t j, Double_t f)
99{
100 // Setup the matrix as an elementary rotation.
101 // Optimized versions of left/right multiplication with an elementary
102 // rotation matrix are implemented in RotatePF/RotateLF.
103 // Expects identity matrix.
104
105 if(i == j) return;
106 ZTrans& M = *this;
107 M(i,i) = M(j,j) = TMath::Cos(f);
108 Double_t s = TMath::Sin(f);
109 M(i,j) = -s; M(j,i) = s;
110 bAsOK = false;
111}
112
113/**************************************************************************/
114
115// OrtoNorm3 and Invert are near the bottom.
116
117/**************************************************************************/
118
119void ZTrans::MultLeft(const ZTrans& t)
120{
121 Double_t B[4];
122 Double_t* C = M;
123 for(int c=0; c<4; ++c, C+=4) {
124 const Double_t* T = t.M;
125 for(int r=0; r<4; ++r, ++T)
126 B[r] = T[0]*C[0] + T[4]*C[1] + T[8]*C[2] + T[12]*C[3];
127 C[0] = B[0]; C[1] = B[1]; C[2] = B[2]; C[3] = B[3];
128 }
129 bAsOK = false;
130}
131
132void ZTrans::MultRight(const ZTrans& t)
133{
134 Double_t B[4];
135 Double_t* C = M;
136 for(int r=0; r<4; ++r, ++C) {
137 const Double_t* T = t.M;
138 for(int c=0; c<4; ++c, T+=4)
139 B[c] = C[0]*T[0] + C[4]*T[1] + C[8]*T[2] + C[12]*T[3];
140 C[0] = B[0]; C[4] = B[1]; C[8] = B[2]; C[12] = B[3];
141 }
142 bAsOK = false;
143}
144
145ZTrans ZTrans::operator*(const ZTrans& t)
146{
147 ZTrans b(*this);
148 b.MultRight(t);
149 return b;
150}
151
152/**************************************************************************/
153// Move & Rotate
154/**************************************************************************/
155
156void ZTrans::MoveLF(Int_t ai, Double_t amount)
157{
158 const Double_t *C = M + 4*--ai;
159 M[F03] += amount*C[0]; M[F13] += amount*C[1]; M[F23] += amount*C[2];
160}
161
162void ZTrans::Move3LF(Double_t x, Double_t y, Double_t z)
163{
164 M[F03] += x*M[0] + y*M[4] + z*M[8];
165 M[F13] += x*M[1] + y*M[5] + z*M[9];
166 M[F23] += x*M[2] + y*M[6] + z*M[10];
167}
168
169void ZTrans::RotateLF(Int_t i1, Int_t i2, Double_t amount)
170{
171 // Rotate in local frame. Does optimised version of MultRight.
172
173 if(i1 == i2) return;
174 // Algorithm: ZTrans a; a.SetupRotation(i1, i2, amount); MultRight(a);
175 // Optimized version:
176 const Double_t cos = TMath::Cos(amount), sin = TMath::Sin(amount);
177 Double_t b1, b2;
178 Double_t* C = M;
179 --i1 <<= 2; --i2 <<= 2; // column major
180 for(int r=0; r<4; ++r, ++C) {
181 b1 = cos*C[i1] + sin*C[i2];
182 b2 = cos*C[i2] - sin*C[i1];
183 C[i1] = b1; C[i2] = b2;
184 }
185 bAsOK = false;
186}
187
188/**************************************************************************/
189
190void ZTrans::MovePF(Int_t ai, Double_t amount)
191{
192 M[F03 + --ai] += amount;
193}
194
195void ZTrans::Move3PF(Double_t x, Double_t y, Double_t z)
196{
197 M[F03] += x;
198 M[F13] += y;
199 M[F23] += z;
200}
201
202void ZTrans::RotatePF(Int_t i1, Int_t i2, Double_t amount)
203{
204 // Rotate in parent frame. Does optimised version of MultLeft.
205
206 if(i1 == i2) return;
207 // Algorithm: ZTrans a; a.SetupRotation(i1, i2, amount); MultLeft(a);
208
209 // Optimized version:
210 const Double_t cos = TMath::Cos(amount), sin = TMath::Sin(amount);
211 Double_t b1, b2;
212 Double_t* C = M;
213 --i1; --i2;
214 for(int c=0; c<4; ++c, C+=4) {
215 b1 = cos*C[i1] - sin*C[i2];
216 b2 = cos*C[i2] + sin*C[i1];
217 C[i1] = b1; C[i2] = b2;
218 }
219 bAsOK = false;
220}
221
222/**************************************************************************/
223
224void ZTrans::Move(const ZTrans& a, Int_t ai, Double_t amount)
225{
226 const Double_t* A = a.M + 4*--ai;
227 M[F03] += amount*A[0];
228 M[F13] += amount*A[1];
229 M[F23] += amount*A[2];
230}
231
232void ZTrans::Move3(const ZTrans& a, Double_t x, Double_t y, Double_t z)
233{
234 const Double_t* A = a.M;
235 M[F03] += x*A[F00] + y*A[F01] + z*A[F02];
236 M[F13] += x*A[F10] + y*A[F11] + z*A[F12];
237 M[F23] += x*A[F20] + y*A[F21] + z*A[F22];
238}
239
240void ZTrans::Rotate(const ZTrans& a, Int_t i1, Int_t i2, Double_t amount)
241{
242 if(i1 == i2) return;
243 ZTrans X(a);
244 X.Invert();
245 MultLeft(X);
246 RotatePF(i1, i2, amount);
247 MultLeft(a);
248 bAsOK = false;
249}
250
251/**************************************************************************/
252// Base-vector interface
253/**************************************************************************/
254
255void ZTrans::SetBaseVec(Int_t b, Double_t x, Double_t y, Double_t z)
256{
257 Double_t* C = M + 4*--b;
258 C[0] = x; C[1] = y; C[2] = z;
259 bAsOK = false;
260}
261
262void ZTrans::SetBaseVec(Int_t b, const TVector3& v)
263{
264 Double_t* C = M + 4*--b;
265 v.GetXYZ(C);
266 bAsOK = false;
267}
268
269TVector3 ZTrans::GetBaseVec(Int_t b) const
270{ return TVector3(&M[4*--b]); }
271
272void ZTrans::GetBaseVec(Int_t b, TVector3& v) const
273{
274 const Double_t* C = M + 4*--b;
275 v.SetXYZ(C[0], C[1], C[2]);
276}
277
278/**************************************************************************/
279// Position interface
280/**************************************************************************/
281
282void ZTrans::SetPos(Double_t x, Double_t y, Double_t z)
283{ M[F03] = x; M[F13] = y; M[F23] = z; }
284
285void ZTrans::SetPos(Double_t* x)
286{ M[F03] = x[0]; M[F13] = x[1]; M[F23] = x[2]; }
287
288void ZTrans::SetPos(const ZTrans& t)
289{
290 const Double_t* T = t.M;
291 M[F03] = T[F03]; M[F13] = T[F13]; M[F23] = T[F23];
292}
293
294void ZTrans::GetPos(Double_t& x, Double_t& y, Double_t& z) const
295{ x = M[F03]; y = M[F13]; z = M[F23]; }
296
297void ZTrans::GetPos(Double_t* x) const
298{ x[0] = M[F03]; x[1] = M[F13]; x[2] = M[F23]; }
299
300void ZTrans::GetPos(TVector3& v) const
301{ v.SetXYZ(M[F03], M[F13], M[F23]); }
302
303TVector3 ZTrans::GetPos() const
304{ return TVector3(M[F03], M[F13], M[F23]); }
305
306/**************************************************************************/
307// Cardan angle interface
308/**************************************************************************/
309
310namespace {
311 inline void clamp_angle(Float_t& a) {
312 while(a < -TMath::TwoPi()) a += TMath::TwoPi();
313 while(a > TMath::TwoPi()) a -= TMath::TwoPi();
314 }
315}
316
317void ZTrans::SetRotByAngles(Float_t a1, Float_t a2, Float_t a3)
318{
319 // Sets Rotation part as given by angles:
320 // a1 around z, -a2 around y, a3 around x
321 clamp_angle(a1); clamp_angle(a2); clamp_angle(a3);
322
323 Double_t A, B, C, D, E, F;
324 A = TMath::Cos(a3); B = TMath::Sin(a3);
325 C = TMath::Cos(a2); D = TMath::Sin(a2); // should be -sin(a2) for positive direction
326 E = TMath::Cos(a1); F = TMath::Sin(a1);
327 Double_t AD = A*D, BD = B*D;
328
329 M[F00] = C*E; M[F01] = -BD*E - A*F; M[F02] = -AD*E + B*F;
330 M[F10] = C*F; M[F11] = -BD*F + A*E; M[F12] = -AD*F - B*E;
331 M[F20] = D; M[F21] = B*C; M[F22] = A*C;
332
333 mA1 = a1; mA2 = a2; mA3 = a3;
334 bAsOK = true;
335}
336
337void ZTrans::SetRotByAnyAngles(Float_t a1, Float_t a2, Float_t a3,
338 const Text_t* pat)
339{
340 // Sets Rotation part as given by angles a1, a1, a3 and pattern pat.
341 // Pattern consists of "XxYyZz" characters.
342 // eg: x means rotate about x axis, X means rotate in negative direction
343 // xYz -> R_x(a3) * R_y(-a2) * R_z(a1); (standard Gled representation)
344 // Note that angles and pattern elements have inversed order!
345 //
346 // Implements Eulerian/Cardanian angles in a uniform way.
347
348 int n = strspn(pat, "XxYyZz"); if(n > 3) n = 3;
349 // Build Trans ... assign ...
350 Float_t a[] = { a3, a2, a1 };
351 UnitRot();
352 for(int i=0; i<n; i++) {
353 if(isupper(pat[i])) a[i] = -a[i];
354 switch(pat[i]) {
355 case 'x': case 'X': RotateLF(2, 3, a[i]); break;
356 case 'y': case 'Y': RotateLF(3, 1, a[i]); break;
357 case 'z': case 'Z': RotateLF(1, 2, a[i]); break;
358 }
359 }
360 bAsOK = false;
361}
362
363void ZTrans::GetRotAngles(Float_t* x) const
364{
365 // Get Cardan rotation angles (pattern xYz above).
366
367 if(!bAsOK) {
368 Double_t sx, sy, sz;
369 GetScale(sx, sy, sz);
370 Double_t d = M[F20]/sx;
371 if(d>1) d=1; else if(d<-1) d=-1; // Fix numerical errors
372 mA2 = TMath::ASin(d);
373 Double_t C = TMath::Cos(mA2);
374 if(TMath::Abs(C) > 8.7e-6) {
375 mA1 = TMath::ATan2(M[F10], M[F00]);
376 mA3 = TMath::ATan2(M[F21]/sy, M[F22]/sz);
377 } else {
378 mA1 = TMath::ATan2(M[F10]/sx, M[F11]/sy);
379 mA3 = 0;
380 }
381 bAsOK = true;
382 }
383 x[0] = mA1; x[1] = mA2; x[2] = mA3;
384}
385
386/**************************************************************************/
387// Scaling
388/**************************************************************************/
389
390void ZTrans::Scale(Double_t sx, Double_t sy, Double_t sz)
391{
392 M[F00] *= sx; M[F10] *= sx; M[F20] *= sx;
393 M[F01] *= sy; M[F11] *= sy; M[F21] *= sy;
394 M[F02] *= sz; M[F12] *= sz; M[F22] *= sz;
395}
396
397void ZTrans::GetScale(Double_t& sx, Double_t& sy, Double_t& sz) const
398{
399 sx = TMath::Sqrt( M[F00]*M[F00] + M[F10]*M[F10] + M[F20]*M[F20] );
400 sy = TMath::Sqrt( M[F01]*M[F01] + M[F11]*M[F11] + M[F21]*M[F21] );
401 sz = TMath::Sqrt( M[F02]*M[F02] + M[F12]*M[F12] + M[F22]*M[F22] );
402}
403
404void ZTrans::Unscale(Double_t& sx, Double_t& sy, Double_t& sz)
405{
406 GetScale(sx, sy, sz);
407 M[F00] /= sx; M[F10] /= sx; M[F20] /= sx;
408 M[F01] /= sy; M[F11] /= sy; M[F21] /= sy;
409 M[F02] /= sz; M[F12] /= sz; M[F22] /= sz;
410}
411
412Double_t ZTrans::Unscale()
413{
414 Double_t sx, sy, sz;
415 Unscale(sx, sy, sz);
416 return (sx + sy + sz)/3;
417}
418
419/**************************************************************************/
420// Operations on vectors
421/**************************************************************************/
422
423void ZTrans::MultiplyIP(TVector3& v, Double_t w) const
424{
425 v.SetXYZ(M[F00]*v.x() + M[F01]*v.y() + M[F02]*v.z() + M[F03]*w,
426 M[F10]*v.x() + M[F11]*v.y() + M[F12]*v.z() + M[F13]*w,
427 M[F20]*v.x() + M[F21]*v.y() + M[F22]*v.z() + M[F23]*w);
428}
429
430TVector3 ZTrans::Multiply(const TVector3& v, Double_t w) const
431{
432 return TVector3(M[F00]*v.x() + M[F01]*v.y() + M[F02]*v.z() + M[F03]*w,
433 M[F10]*v.x() + M[F11]*v.y() + M[F12]*v.z() + M[F13]*w,
434 M[F20]*v.x() + M[F21]*v.y() + M[F22]*v.z() + M[F23]*w);
435}
436
437void ZTrans::RotateIP(TVector3& v) const
438{
439 v.SetXYZ(M[F00]*v.x() + M[F01]*v.y() + M[F02]*v.z(),
440 M[F10]*v.x() + M[F11]*v.y() + M[F12]*v.z(),
441 M[F20]*v.x() + M[F21]*v.y() + M[F22]*v.z());
442}
443
444TVector3 ZTrans::Rotate(const TVector3& v) const
445{
446 return TVector3(M[F00]*v.x() + M[F01]*v.y() + M[F02]*v.z(),
447 M[F10]*v.x() + M[F11]*v.y() + M[F12]*v.z(),
448 M[F20]*v.x() + M[F21]*v.y() + M[F22]*v.z());
449}
450
451/**************************************************************************/
452// Normalization, ortogonalization
453/**************************************************************************/
454
455Double_t ZTrans::norm3_column(Int_t col)
456{
457 Double_t* C = M + 4*--col;
458 const Double_t l = TMath::Sqrt(C[0]*C[0] + C[1]*C[1] + C[2]*C[2]);
459 C[0] /= l; C[1] /= l; C[2] /= l;
460 return l;
461}
462
463Double_t ZTrans::orto3_column(Int_t col, Int_t ref)
464{
465 Double_t* C = M + 4*--col;
466 Double_t* R = M + 4*--ref;
467 const Double_t dp = C[0]*R[0] + C[1]*R[1] + C[2]*R[2];
468 C[0] -= R[0]*dp; C[1] -= R[1]*dp; C[2] -= R[2]*dp;
469 return dp;
470}
471
472void ZTrans::OrtoNorm3()
473{
474 norm3_column(1);
475 orto3_column(2,1); norm3_column(2);
476 M[F02] = M[F10]*M[F21] - M[F11]*M[F20];
477 M[F12] = M[F20]*M[F01] - M[F21]*M[F00];
478 M[F22] = M[F00]*M[F11] - M[F01]*M[F10];
479 // cross-product faster.
480 // orto3_column(3,1); orto3_column(3,2); norm3_column(3);
481}
482
483/**************************************************************************/
484// Inversion
485/**************************************************************************/
486
487Double_t ZTrans::Invert()
488{
489 // Copied from ROOT's TMatrixFCramerInv.
490
491 static const Exc_t _eh("ZTrans::Invert ");
492
493 // Find all NECESSARY 2x2 dets: (18 of them)
494 const Double_t det2_12_01 = M[F10]*M[F21] - M[F11]*M[F20];
495 const Double_t det2_12_02 = M[F10]*M[F22] - M[F12]*M[F20];
496 const Double_t det2_12_03 = M[F10]*M[F23] - M[F13]*M[F20];
497 const Double_t det2_12_13 = M[F11]*M[F23] - M[F13]*M[F21];
498 const Double_t det2_12_23 = M[F12]*M[F23] - M[F13]*M[F22];
499 const Double_t det2_12_12 = M[F11]*M[F22] - M[F12]*M[F21];
500 const Double_t det2_13_01 = M[F10]*M[F31] - M[F11]*M[F30];
501 const Double_t det2_13_02 = M[F10]*M[F32] - M[F12]*M[F30];
502 const Double_t det2_13_03 = M[F10]*M[F33] - M[F13]*M[F30];
503 const Double_t det2_13_12 = M[F11]*M[F32] - M[F12]*M[F31];
504 const Double_t det2_13_13 = M[F11]*M[F33] - M[F13]*M[F31];
505 const Double_t det2_13_23 = M[F12]*M[F33] - M[F13]*M[F32];
506 const Double_t det2_23_01 = M[F20]*M[F31] - M[F21]*M[F30];
507 const Double_t det2_23_02 = M[F20]*M[F32] - M[F22]*M[F30];
508 const Double_t det2_23_03 = M[F20]*M[F33] - M[F23]*M[F30];
509 const Double_t det2_23_12 = M[F21]*M[F32] - M[F22]*M[F31];
510 const Double_t det2_23_13 = M[F21]*M[F33] - M[F23]*M[F31];
511 const Double_t det2_23_23 = M[F22]*M[F33] - M[F23]*M[F32];
512
513 // Find all NECESSARY 3x3 dets: (16 of them)
514 const Double_t det3_012_012 = M[F00]*det2_12_12 - M[F01]*det2_12_02 + M[F02]*det2_12_01;
515 const Double_t det3_012_013 = M[F00]*det2_12_13 - M[F01]*det2_12_03 + M[F03]*det2_12_01;
516 const Double_t det3_012_023 = M[F00]*det2_12_23 - M[F02]*det2_12_03 + M[F03]*det2_12_02;
517 const Double_t det3_012_123 = M[F01]*det2_12_23 - M[F02]*det2_12_13 + M[F03]*det2_12_12;
518 const Double_t det3_013_012 = M[F00]*det2_13_12 - M[F01]*det2_13_02 + M[F02]*det2_13_01;
519 const Double_t det3_013_013 = M[F00]*det2_13_13 - M[F01]*det2_13_03 + M[F03]*det2_13_01;
520 const Double_t det3_013_023 = M[F00]*det2_13_23 - M[F02]*det2_13_03 + M[F03]*det2_13_02;
521 const Double_t det3_013_123 = M[F01]*det2_13_23 - M[F02]*det2_13_13 + M[F03]*det2_13_12;
522 const Double_t det3_023_012 = M[F00]*det2_23_12 - M[F01]*det2_23_02 + M[F02]*det2_23_01;
523 const Double_t det3_023_013 = M[F00]*det2_23_13 - M[F01]*det2_23_03 + M[F03]*det2_23_01;
524 const Double_t det3_023_023 = M[F00]*det2_23_23 - M[F02]*det2_23_03 + M[F03]*det2_23_02;
525 const Double_t det3_023_123 = M[F01]*det2_23_23 - M[F02]*det2_23_13 + M[F03]*det2_23_12;
526 const Double_t det3_123_012 = M[F10]*det2_23_12 - M[F11]*det2_23_02 + M[F12]*det2_23_01;
527 const Double_t det3_123_013 = M[F10]*det2_23_13 - M[F11]*det2_23_03 + M[F13]*det2_23_01;
528 const Double_t det3_123_023 = M[F10]*det2_23_23 - M[F12]*det2_23_03 + M[F13]*det2_23_02;
529 const Double_t det3_123_123 = M[F11]*det2_23_23 - M[F12]*det2_23_13 + M[F13]*det2_23_12;
530
531 // Find the 4x4 det:
532 const Double_t det = M[F00]*det3_123_123 - M[F01]*det3_123_023 +
533 M[F02]*det3_123_013 - M[F03]*det3_123_012;
534
535 if(det == 0) {
536 throw(_eh + "matrix is singular.");
537 }
538
539 const Double_t oneOverDet = 1.0/det;
540 const Double_t mn1OverDet = - oneOverDet;
541
542 M[F00] = det3_123_123 * oneOverDet;
543 M[F01] = det3_023_123 * mn1OverDet;
544 M[F02] = det3_013_123 * oneOverDet;
545 M[F03] = det3_012_123 * mn1OverDet;
546
547 M[F10] = det3_123_023 * mn1OverDet;
548 M[F11] = det3_023_023 * oneOverDet;
549 M[F12] = det3_013_023 * mn1OverDet;
550 M[F13] = det3_012_023 * oneOverDet;
551
552 M[F20] = det3_123_013 * oneOverDet;
553 M[F21] = det3_023_013 * mn1OverDet;
554 M[F22] = det3_013_013 * oneOverDet;
555 M[F23] = det3_012_013 * mn1OverDet;
556
557 M[F30] = det3_123_012 * mn1OverDet;
558 M[F31] = det3_023_012 * oneOverDet;
559 M[F32] = det3_013_012 * mn1OverDet;
560 M[F33] = det3_012_012 * oneOverDet;
561
562 bAsOK = false;
563 return det;
564}
565
566/**************************************************************************/
567
568void ZTrans::Streamer(TBuffer &R__b)
569{
570 // Stream an object of class ZTrans.
571
572 if (R__b.IsReading()) {
573 ZTrans::Class()->ReadBuffer(R__b, this);
574 bAsOK = false;
575 } else {
576 ZTrans::Class()->WriteBuffer(R__b, this);
577 }
578}
579
580/**************************************************************************/
581/**************************************************************************/
582
583void ZTrans::Print(Option_t* /*option*/) const
584{
585 const Double_t* C = M;
586 for(Int_t i=0; i<4; ++i, ++C)
587 printf("%8.3f %8.3f %8.3f | %8.3f\n", C[0], C[4], C[8], C[12]);
588}
589
590#include <iomanip>
591
592ostream& Reve::operator<<(ostream& s, const ZTrans& t) {
593 s.setf(std::ios::fixed, std::ios::floatfield);
594 s.precision(3);
595 for(Int_t i=1; i<=4; i++)
596 for(Int_t j=1; j<=4; j++)
597 s << t(i,j) << ((j==4) ? "\n" : "\t");
598 return s;
599}
600
601/**************************************************************************/
602// Reve stuff
603/**************************************************************************/
604
605#include <TGeoMatrix.h>
606#include <TBuffer3D.h>
607
608void ZTrans::SetFrom(Double_t* carr)
609{
610 fUseTrans = kTRUE;
611 memcpy(M, carr, 16*sizeof(Double_t));
612 bAsOK = false;
613}
614
615void ZTrans::SetFrom(const TGeoMatrix& mat)
616{
617 fUseTrans = kTRUE;
618 const Double_t *r = mat.GetRotationMatrix();
619 const Double_t *t = mat.GetTranslation();
620 const Double_t *s = mat.GetScale();
621 Double_t *m = M;
622 m[0] = r[0]*s[0]; m[1] = r[3]*s[0]; m[2] = r[6]*s[0]; m[3] = 0; m += 4;
623 m[0] = r[1]*s[1]; m[1] = r[4]*s[1]; m[2] = r[7]*s[1]; m[3] = 0; m += 4;
624 m[0] = r[2]*s[2]; m[1] = r[5]*s[2]; m[2] = r[8]*s[2]; m[3] = 0; m += 4;
625 m[0] = t[0]; m[1] = t[1]; m[2] = t[2]; m[3] = 1;
626 bAsOK = false;
627}
628
629void ZTrans::SetBuffer3D(TBuffer3D& buff)
630{
631 buff.fLocalFrame = fUseTrans;
632 if (fUseTrans)
633 memcpy(buff.fLocalMaster, M, 16*sizeof(Double_t));
634}
635
636Bool_t ZTrans::IsScale(Double_t low, Double_t high) const
637{
638 // Test if the transformation is a scale.
639 // To be used by ROOT TGLObject descendants that potentially need to
640 // use GL_NORMALIZE.
641 // The low/high limits are expected to be squares of acutal limits.
642 //
643 // Ideally this should be done by the TGLViewer [but is not].
644
645 if (!fUseTrans) return kFALSE;
646 Double_t s;
647 s = M[F00]*M[F00] + M[F10]*M[F10] + M[F20]*M[F20];
648 if (s < low || s > high) return kTRUE;
649 s = M[F01]*M[F01] + M[F11]*M[F11] + M[F21]*M[F21];
650 if (s < low || s > high) return kTRUE;
651 s = M[F02]*M[F02] + M[F12]*M[F12] + M[F22]*M[F22];
652 if (s < low || s > high) return kTRUE;
653 return kFALSE;
654}