BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
BesTView.cxx
Go to the documentation of this file.
1// @(#)root/base:$Name: BesVisLib-00-05-04 $:$Id: BesTView.cxx,v 1.7 2018/11/06 00:35:15 longpx Exp $
2// Author: Rene Brun, Nenad Buncic, Evgueni Tcherniaev, Olivier Couet 18/08/95
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, 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//#include "TVirtualUtil3D.h"
13#include "TVirtualPad.h"
14#include "BesVisLib/BesTView.h"
15#include "TAxis3D.h"
16#include "TPolyLine3D.h"
17#include "TVirtualX.h"
18#include "TROOT.h"
19#include "TClass.h"
20#include "TList.h"
21//#include "TFile.h"
22#include "TPluginManager.h"
23#include "TMath.h"
24
25// Remove when TViewer3DPad fix in ExecuteRotateView() is removed
26#include "TVirtualViewer3D.h"
27
29
30//const Int_t kPerspective = BIT(14);
31
32const Int_t kCARTESIAN = 1;
33const Int_t kPOLAR = 2;
34const Double_t kRad = 3.14159265358979323846/180.0;
35
36
37
38//____________________________________________________________________________
40{
41 // Default constructor
42
43 fSystem = 1;
44 fOutline = 0;
45 fDefaultOutline = kFALSE;
46 fAutoRange = kFALSE;
47 fChanged = kFALSE;
48 SetBit(kMustCleanup);
49 for (Int_t i=0;i<3;i++) {
50 fX1[i] = fX2[i] = fY1[i] = fY2[i] = fZ1[i] = fZ2[i] = 0;
51 }
52}
53
54//____________________________________________________________________________
56 :TView(tv),
57 fLatitude(tv.fLatitude),
58 fLongitude(tv.fLongitude),
59 fPsi(tv.fPsi),
60 fDview(tv.fDview),
61 fDproj(tv.fDproj),
62 fUpix(tv.fUpix),
63 fVpix(tv.fVpix),
64 fSystem(tv.fSystem),
65 fOutline(tv.fOutline),
66 fDefaultOutline(tv.fDefaultOutline),
67 fAutoRange(tv.fAutoRange),
68 fChanged(tv.fChanged)
69{
70 // Copy constructor.
71
72 for (Int_t i=0; i<16; i++) {
73 fTN[i]=tv.fTN[i];
74 fTB[i]=tv.fTB[i];
75 fTnorm[i]=tv.fTnorm[i];
76 fTback[i]=tv.fTback[i];
77 }
78 for(Int_t i=0; i<3; i++) {
79 fRmax[i]=tv.fRmax[i];
80 fRmin[i]=tv.fRmin[i];
81 fX1[i]=tv.fX1[i];
82 fX2[i]=tv.fX2[i];
83 fY1[i]=tv.fY1[i];
84 fY2[i]=tv.fY2[i];
85 fZ1[i]=tv.fZ1[i];
86 fZ2[i]=tv.fZ2[i];
87 }
88 for(Int_t i=0; i<4; i++)
89 fUVcoord[i]=tv.fUVcoord[i];
90}
91
92//____________________________________________________________________________
94{
95 // Assignment operator.
96
97 if (this!=&tv) {
98 TView::operator=(tv);
101 fPsi=tv.fPsi;
102 fDview=tv.fDview;
103 fDproj=tv.fDproj;
104 fUpix=tv.fUpix;
105 fVpix=tv.fVpix;
106 fSystem=tv.fSystem;
111 for(Int_t i=0; i<16; i++) {
112 fTN[i]=tv.fTN[i];
113 fTB[i]=tv.fTB[i];
114 fTnorm[i]=tv.fTnorm[i];
115 fTback[i]=tv.fTback[i];
116 }
117 for(Int_t i=0; i<3; i++) {
118 fRmax[i]=tv.fRmax[i];
119 fRmin[i]=tv.fRmin[i];
120 fX1[i]=tv.fX1[i];
121 fX2[i]=tv.fX2[i];
122 fY1[i]=tv.fY1[i];
123 fY2[i]=tv.fY2[i];
124 fZ1[i]=tv.fZ1[i];
125 fZ2[i]=tv.fZ2[i];
126 }
127 for(Int_t i=0; i<4; i++)
128 fUVcoord[i]=tv.fUVcoord[i];
129 }
130 return *this;
131}
132
133//____________________________________________________________________________
135{
136//*-*-*-*-*-*-*-*-*-*-*-*-*-*View default destructor*-*-*-*-*-*-*-*-*-*-*-*-*
137//*-* =======================
138
139 if (fOutline) fOutline->Delete();
140 delete fOutline;
141 fOutline = 0;
142}
143
144//____________________________________________________________________________
146{
147//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*View constructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
148//*-* ================
149//*-* Creates a 3-D view in the current pad
150//*-* By default pad range in 3-D view is (-1,-1,1,1), so ...
151//*-*
152//*-* Before drawing a 3-D object in a pad, a 3-D view must be created.
153//*-* Note that a view is automatically created when drawing legos or surfaces.
154//*-*
155//*-* The coordinate system is selected via system:
156//*-* system = 1 Cartesian
157//*-* system = 2 Polar
158//*-* system = 3 Cylindrical
159//*-* system = 4 Spherical
160//*-* system = 5 PseudoRapidity/Phi
161//*-* system = 11 Perspective view
162//*-*
163//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
164 Int_t irep;
165
166 //create the 3d utility manager (a plugin)
167 if (!gROOT->GetListOfSpecials()->FindObject("R__TVirtualUtil3D")) {
168 TPluginHandler *h;
169 if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualUtil3D"))) {
170 if (h->LoadPlugin() == -1)
171 return;
172 h->ExecPlugin(0);
173 }
174 }
175
176 SetBit(kMustCleanup);
177
178 fSystem = system;
179 fOutline = 0;
180 fDefaultOutline = kFALSE;
181 fAutoRange = kFALSE;
182 fChanged = kFALSE;
183
184 if (system == kCARTESIAN || system == kPOLAR || system == 11) fPsi = 0;
185 else fPsi = 90;
186
187 //By default pad range in 3-D view is (-1,-1,1,1), so ...
188 if (gPad) {
189 gPad->Range(-1, -1, 1, 1);
190
191 Int_t i;
192 for (i = 0; i < 3; fRmin[i] = 0, fRmax[i] = 1, i++);
193 for (i=0;i<3;i++) {
194 fX1[i] = fX2[i] = fY1[i] = fY2[i] = fZ1[i] = fZ2[i] = 0;
195 }
196
197 fLongitude = -90 - gPad->GetPhi();
198 fLatitude = 90 - gPad->GetTheta();
200
201 gPad->SetView(this);
202 }
203 if (system == 11) SetPerspective();
204}
205
206
207//____________________________________________________________________________
208BesTView::BesTView(const Float_t *rmin, const Float_t *rmax, Int_t system)
209{
210//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*View constructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
211//*-* ================
212//*-* Creates a 3-D view in the current pad
213//*-* rmin[3], rmax[3] are the limits of the object depending on
214//*-* the selected coordinate system
215//*-*
216//*-* Before drawing a 3-D object in a pad, a 3-D view must be created.
217//*-* Note that a view is automatically created when drawing legos or surfaces.
218//*-*
219//*-* The coordinate system is selected via system:
220//*-* system = 1 Cartesian
221//*-* system = 2 Polar
222//*-* system = 3 Cylindrical
223//*-* system = 4 Spherical
224//*-* system = 5 PseudoRapidity/Phi
225//*-*
226//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
227
228 Int_t irep;
229
230 //create the 3d utility manager (a plugin)
231 if (!gROOT->GetListOfSpecials()->FindObject("R__TVirtualUtil3D")) {
232 TPluginHandler *h;
233 if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualUtil3D"))) {
234 if (h->LoadPlugin() == -1)
235 return;
236 h->ExecPlugin(0);
237 }
238 }
239
240 SetBit(kMustCleanup);
241
242 fSystem = system;
243 fOutline = 0;
244 fDefaultOutline = kFALSE;
245 fChanged = kFALSE;
246
247 if (system == kCARTESIAN || system == kPOLAR || system == 11) fPsi = 0;
248 else fPsi = 90;
249
250 //By default pad range in 3-D view is (-1,-1,1,1), so ...
251 gPad->Range(-1, -1, 1, 1);
252 fAutoRange = kFALSE;
253
254 Int_t i;
255 for (i = 0; i < 3; fRmin[i] = rmin[i], fRmax[i] = rmax[i], i++);
256 for (i=0;i<3;i++) {
257 fX1[i] = fX2[i] = fY1[i] = fY2[i] = fZ1[i] = fZ2[i] = 0;
258 }
259
260 fLongitude = -90 - gPad->GetPhi();
261 fLatitude = 90 - gPad->GetTheta();
263
264 if (gPad) gPad->SetView(this);
265 if (system == 11) SetPerspective();
266}
267
268
269//____________________________________________________________________________
270BesTView::BesTView(const Double_t *rmin, const Double_t *rmax, Int_t system)
271{
272//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*View constructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
273//*-* ================
274//*-* Creates a 3-D view in the current pad
275//*-* rmin[3], rmax[3] are the limits of the object depending on
276//*-* the selected coordinate system
277//*-*
278//*-* Before drawing a 3-D object in a pad, a 3-D view must be created.
279//*-* Note that a view is automatically created when drawing legos or surfaces.
280//*-*
281//*-* The coordinate system is selected via system:
282//*-* system = 1 Cartesian
283//*-* system = 2 Polar
284//*-* system = 3 Cylindrical
285//*-* system = 4 Spherical
286//*-* system = 5 PseudoRapidity/Phi
287//*-*
288//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
289
290 Int_t irep;
291
292 //create the 3d utility manager (a plugin)
293 if (!gROOT->GetListOfSpecials()->FindObject("R__TVirtualUtil3D")) {
294 TPluginHandler *h;
295 if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualUtil3D"))) {
296 if (h->LoadPlugin() == -1)
297 return;
298 h->ExecPlugin(0);
299 }
300 }
301
302 SetBit(kMustCleanup);
303
304 fSystem = system;
305 fOutline = 0;
306 fDefaultOutline = kFALSE;
307 fChanged = kFALSE;
308
309 if (system == kCARTESIAN || system == kPOLAR || system == 11) fPsi = 0;
310 else fPsi = 90;
311
312 //By default pad range in 3-D view is (-1,-1,1,1), so ...
313 gPad->Range(-1, -1, 1, 1);
314 fAutoRange = kFALSE;
315
316 Int_t i;
317 for (i = 0; i < 3; fRmin[i] = rmin[i], fRmax[i] = rmax[i], i++);
318 for (i=0;i<3;i++) {
319 fX1[i] = fX2[i] = fY1[i] = fY2[i] = fZ1[i] = fZ2[i] = 0;
320 }
321
322 fLongitude = -90 - gPad->GetPhi();
323 fLatitude = 90 - gPad->GetTheta();
325
326 if (gPad) gPad->SetView(this);
327 if (system == 11) SetPerspective();
328}
329
330
331//______________________________________________________________________________
332void BesTView::AxisVertex(Double_t ang, Double_t *av, Int_t &ix1, Int_t &ix2, Int_t &iy1, Int_t &iy2, Int_t &iz1, Int_t &iz2)
333{
334//*-*-*-*-*-*-*-*-*-*-*-*-*Define axis vertices*-*-*-*-*-*-*-*-*-*-*-*-*-*
335//*-* ===================== *
336//*-* *
337//*-* Input ANG - angle between X and Y axis *
338//*-* *
339//*-* Output: AV(3,8) - axis vertixes *
340//*-* IX1 - 1st point of X-axis *
341//*-* IX2 - 2nd point of X-axis *
342//*-* IY1 - 1st point of Y-axis *
343//*-* IY2 - 2nd point of Y-axis *
344//*-* IZ1 - 1st point of Z-axis *
345//*-* IZ2 - 2nd point of Z-axis *
346//*-* *
347//*-* 8 6 *
348//*-* / \ /|\ *
349//*-* 5 / \ 7 5 / | \ 7 *
350//*-* |\ /| | | | *
351//*-* THETA < 90 | \6/ | THETA > 90 | /2\ | *
352//*-* (Top view) | | | (Bottom view) |/ \| *
353//*-* 1 \ | /3 1 \ /3 *
354//*-* \|/ \ / *
355//*-* 2 4 *
356//*-* *
357//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
358 /* Local variables */
359 Double_t cosa, sina;
360 Int_t i, k;
361 Double_t p[8] /* was [2][4] */;
362 Int_t i1, i2, i3, i4, ix, iy;
363 ix = 0;
364
365 /* Parameter adjustments */
366 av -= 4;
367
368 sina = TMath::Sin(ang*kRad);
369 cosa = TMath::Cos(ang*kRad);
370 p[0] = fRmin[0];
371 p[1] = fRmin[1];
372 p[2] = fRmax[0];
373 p[3] = fRmin[1];
374 p[4] = fRmax[0];
375 p[5] = fRmax[1];
376 p[6] = fRmin[0];
377 p[7] = fRmax[1];
378//*-*- F I N D T H E M O S T L E F T P O I N T */
379 i1 = 1;
380 if (fTN[0] < 0) i1 = 2;
381 if (fTN[0]*cosa + fTN[1]*sina < 0) i1 = 5 - i1;
382
383//*-*- S E T O T H E R P O I N T S */
384 i2 = i1 % 4 + 1;
385 i3 = i2 % 4 + 1;
386 i4 = i3 % 4 + 1;
387
388//*-*- S E T A X I S V E R T I X E S */
389
390 av[4] = p[(i1 << 1) - 2];
391 av[5] = p[(i1 << 1) - 1];
392 av[7] = p[(i2 << 1) - 2];
393 av[8] = p[(i2 << 1) - 1];
394 av[10] = p[(i3 << 1) - 2];
395 av[11] = p[(i3 << 1) - 1];
396 av[13] = p[(i4 << 1) - 2];
397 av[14] = p[(i4 << 1) - 1];
398 for (i = 1; i <= 4; ++i) {
399 av[i*3 + 3] = fRmin[2];
400 av[i*3 + 13] = av[i*3 + 1];
401 av[i*3 + 14] = av[i*3 + 2];
402 av[i*3 + 15] = fRmax[2];
403 }
404
405//*-*- S E T A X I S
406
407 if (av[4] == av[7]) ix = 2;
408 if (av[5] == av[8]) ix = 1;
409 iy = 3 - ix;
410//*-*- X - A X I S
411 ix1 = ix;
412 if (av[ix*3 + 1] > av[(ix + 1)*3 + 1]) ix1 = ix + 1;
413 ix2 = (ix << 1) - ix1 + 1;
414//*-*- Y - A X I S
415 iy1 = iy;
416 if (av[iy*3 + 2] > av[(iy + 1)*3 + 2]) iy1 = iy + 1;
417 iy2 = (iy << 1) - iy1 + 1;
418//*-*- Z - A X I S
419 iz1 = 1;
420 iz2 = 5;
421
422 if (fTN[10] >= 0) return;
423 k = (ix1 - 1)*3 + ix2;
424 if (k%2) return;
425 if (k == 2) {
426 ix1 = 4;
427 ix2 = 3;
428 }
429 if (k == 4) {
430 ix1 = 3;
431 ix2 = 4;
432 }
433 if (k == 6) {
434 ix1 = 1;
435 ix2 = 4;
436 }
437 if (k == 8) {
438 ix1 = 4;
439 ix2 = 1;
440 }
441
442 k = (iy1 - 1)*3 + iy2;
443 if (k%2) return;
444 if (k == 2) {
445 iy1 = 4;
446 iy2 = 3;
447 return;
448 }
449 if (k == 4) {
450 iy1 = 3;
451 iy2 = 4;
452 return;
453 }
454 if (k == 6) {
455 iy1 = 1;
456 iy2 = 4;
457 return;
458 }
459 if (k == 8) {
460 iy1 = 4;
461 iy2 = 1;
462 }
463}
464
465//______________________________________________________________________________
467{
468//*-*-*-*-*-*-*-*-*-*-*-*-*-*Define perspective view *-*-*-*-*-*-*-*-*-*-*
469//*-* ================================================ *
470//*-* *
471//*-* Compute transformation matrix from world coordinates *
472//*-* to normalised coordinates (-1 to +1) *
473// Input :
474// theta, phi - spherical angles giving the direction of projection
475// psi - screen rotation angle
476// cov[3] - center of view
477// dview - distance from COV to COP (center of projection)
478// umin, umax, vmin, vmax - view window in projection plane
479// dproj - distance from COP to projection plane
480// bcut, fcut - backward/forward range w.r.t projection plane (fcut<=0)
481// Output :
482// nper[16] - normalizing transformation
483// compute tr+rot to get COV in origin, view vector parallel to -Z axis, up vector
484// parallel to Y.
485// ^Yv UP ^ proj. plane
486// | | /|
487// | | / |
488// | dproj / x--- center of window (COW)
489// COV |----------|--x--|------------> Zv
490// / | VRP'z
491// / ---> | /
492// / VPN |/
493// Xv
494//
495// 1 - translate COP to origin of MARS : Tper = T(-copx, -copy, -copz)
496// 2 - rotate VPN : R = Rz(-psi)*Rx(-theta)*Rz(-phi) (inverse Euler)
497// 3 - left-handed screen reference to right-handed one of MARS : Trl
498//
499// T12 = Tper*R*Trl
500//
501 Double_t t12[16];
502 Double_t cov[3];
503 Int_t i;
504 for (i=0; i<3; i++) cov[i] = 0.5*(fRmax[i]+fRmin[i]);
505
506 Double_t c1 = TMath::Cos(fPsi*kRad);
507 Double_t s1 = TMath::Sin(fPsi*kRad);
508 Double_t c2 = TMath::Cos(fLatitude*kRad);
509 Double_t s2 = TMath::Sin(fLatitude*kRad);
510 Double_t s3 = TMath::Cos(fLongitude*kRad);
511 Double_t c3 = -TMath::Sin(fLongitude*kRad);
512
513 t12[0] = c1*c3 - s1*c2*s3;
514 t12[4] = c1*s3 + s1*c2*c3;
515 t12[8] = s1*s2;
516 t12[3] = 0;
517
518 t12[1] = -s1*c3 - c1*c2*s3;
519 t12[5] = -s1*s3 + c1*c2*c3;
520 t12[9] = c1*s2;
521 t12[7] = 0;
522
523 t12[2] = s2*s3;
524 t12[6] = -s2*c3;
525 t12[10] = c2; // contains Trl
526 t12[11] = 0;
527
528 // translate with -COP (before rotation):
529 t12[12] = -(cov[0]*t12[0]+cov[1]*t12[4]+cov[2]*t12[8]);
530 t12[13] = -(cov[0]*t12[1]+cov[1]*t12[5]+cov[2]*t12[9]);
531 t12[14] = -(cov[0]*t12[2]+cov[1]*t12[6]+cov[2]*t12[10]);
532 t12[15] = 1;
533
534 // translate with (0, 0, -dview) after rotation
535
536 t12[14] -= fDview;
537
538 // reflection on Z :
539 t12[2] *= -1;
540 t12[6] *= -1;
541 t12[10] *= -1;
542 t12[14] *= -1;
543
544 // Now we shear the center of window from (0.5*(umin+umax), 0.5*(vmin+vmax), dproj)
545 // to (0, 0, dproj)
546
547 Double_t a2 = -fUVcoord[0]/fDproj; // shear coef. on x
548 Double_t b2 = -fUVcoord[1]/fDproj; // shear coef. on y
549
550 // | 1 0 0 0 |
551 // SHz(a2,b2) = | 0 1 0 0 |
552 // | a2 b2 1 0 |
553 // | 0 0 0 1 |
554
555 fTnorm[0] = t12[0] + a2*t12[2];
556 fTnorm[1] = t12[1] + b2*t12[2];
557 fTnorm[2] = t12[2];
558 fTnorm[3] = 0;
559
560 fTnorm[4] = t12[4] + a2*t12[6];
561 fTnorm[5] = t12[5] + b2*t12[6];
562 fTnorm[6] = t12[6];
563 fTnorm[7] = 0;
564
565 fTnorm[8] = t12[8] + a2*t12[10];
566 fTnorm[9] = t12[9] + b2*t12[10];
567 fTnorm[10] = t12[10];
568 fTnorm[11] = 0;
569
570 fTnorm[12] = t12[12] + a2*t12[14];
571 fTnorm[13] = t12[13] + b2*t12[14];
572 fTnorm[14] = t12[14];
573 fTnorm[15] = 1;
574
575 // Scale so that the view volume becomes the canonical one
576 //
577 // Sper = (2/(umax-umin), 2/(vmax-vmin), 1/dproj
578 //
579 Double_t sz = 1./fDproj;
580 Double_t sx = 1./fUVcoord[2];
581 Double_t sy = 1./fUVcoord[3];
582
583 fTnorm[0] *= sx;
584 fTnorm[4] *= sx;
585 fTnorm[8] *= sx;
586 fTnorm[1] *= sy;
587 fTnorm[5] *= sy;
588 fTnorm[9] *= sy;
589 fTnorm[2] *= sz;
590 fTnorm[6] *= sz;
591 fTnorm[10] *= sz;
592 fTnorm[12] *= sx;
593 fTnorm[13] *= sy;
594 fTnorm[14] *= sz;
595}
596
597
598
599//______________________________________________________________________________
600void BesTView::DefineViewDirection(const Double_t *s, const Double_t *c,
601 Double_t cosphi, Double_t sinphi,
602 Double_t costhe, Double_t sinthe,
603 Double_t cospsi, Double_t sinpsi,
604 Double_t *tnorm, Double_t *tback)
605{
606//*-*-*-*-*-*-*-*-*Define view direction (in spherical coordinates)-*-*-*-*
607//*-* ================================================ *
608//*-* *
609//*-* Compute transformation matrix from world coordinates *
610//*-* to normalised coordinates (-1 to +1) *
611//*-* *
612//*-* Input: S(3) - scale factors *
613//*-* C(3) - centre of scope *
614//*-* COSPHI - longitude COS *
615//*-* SINPHI - longitude SIN *
616//*-* COSTHE - latitude COS (angle between +Z and view direc.) *
617//*-* SINTHE - latitude SIN *
618//*-* COSPSI - screen plane rotation angle COS *
619//*-* SINPSI - screen plane rotation angle SIN *
620//*-* *
621//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
622
623 if (IsPerspective()) {
625 return;
626 }
627 Int_t i, k;
628 Double_t tran[16] /* was [4][4] */, rota[16] /* was [4][4] */;
629 Double_t c1, c2, c3, s1, s2, s3, scalex, scaley, scalez;
630
631 /* Parameter adjustments */
632 tback -= 5;
633 tnorm -= 5;
634
635 scalex = s[0];
636 scaley = s[1];
637 scalez = s[2];
638
639//*-*- S E T T R A N S L A T I O N M A T R I X
640
641 tran[0] = 1 / scalex;
642 tran[1] = 0;
643 tran[2] = 0;
644 tran[3] = -c[0] / scalex;
645
646 tran[4] = 0;
647 tran[5] = 1 / scaley;
648 tran[6] = 0;
649 tran[7] = -c[1] / scaley;
650
651 tran[8] = 0;
652 tran[9] = 0;
653 tran[10] = 1 / scalez;
654 tran[11] = -c[2] / scalez;
655
656 tran[12] = 0;
657 tran[13] = 0;
658 tran[14] = 0;
659 tran[15] = 1;
660
661//*-*- S E T R O T A T I O N M A T R I X
662
663// ( C(PSI) S(PSI) 0) (1 0 0 ) ( C(90+PHI) S(90+PHI) 0)
664// (-S(PSI) C(PSI) 0) * (0 C(THETA) S(THETA)) * (-S(90+PHI) C(90+PHI) 0)
665// ( 0 0 1) (0 -S(THETA) C(THETA)) ( 0 0 1)
666
667 c1 = cospsi;
668 s1 = sinpsi;
669 c2 = costhe;
670 s2 = sinthe;
671 c3 = -sinphi;
672 s3 = cosphi;
673
674 rota[0] = c1*c3 - s1*c2*s3;
675 rota[1] = c1*s3 + s1*c2*c3;
676 rota[2] = s1*s2;
677 rota[3] = 0;
678
679 rota[4] = -s1*c3 - c1* c2*s3;
680 rota[5] = -s1*s3 + c1* c2*c3;
681 rota[6] = c1*s2;
682 rota[7] = 0;
683
684 rota[8] = s2*s3;
685 rota[9] = -s2*c3;
686 rota[10] = c2;
687 rota[11] = 0;
688
689 rota[12] = 0;
690 rota[13] = 0;
691 rota[14] = 0;
692 rota[15] = 1;
693
694//*-*- F I N D T R A N S F O R M A T I O N M A T R I X
695
696 for (i = 1; i <= 3; ++i) {
697 for (k = 1; k <= 4; ++k) {
698 tnorm[k + (i << 2)] = rota[(i << 2) - 4]*tran[k - 1] + rota[(i
699 << 2) - 3]*tran[k + 3] + rota[(i << 2) - 2]*tran[k +7]
700 + rota[(i << 2) - 1]*tran[k + 11];
701 }
702 }
703
704//*-*- S E T B A C K T R A N S L A T I O N M A T R I X
705
706 tran[0] = scalex;
707 tran[3] = c[0];
708
709 tran[5] = scaley;
710 tran[7] = c[1];
711
712 tran[10] = scalez;
713 tran[11] = c[2];
714
715//*-*- F I N D B A C K T R A N S F O R M A T I O N
716
717 for (i = 1; i <= 3; ++i) {
718 for (k = 1; k <= 4; ++k) {
719 tback[k + (i << 2)] = tran[(i << 2) - 4]*rota[(k << 2) - 4] +
720 tran[(i << 2) - 3]*rota[(k << 2) - 3] + tran[(i << 2) -2]
721 *rota[(k << 2) - 2] + tran[(i << 2) - 1]*rota[(k <<2) - 1];
722 }
723 }
724}
725
726
727//______________________________________________________________________________
728void BesTView::DrawOutlineCube(TList *outline, Double_t *rmin, Double_t *rmax)
729{
730 // Draw the outline of a cube while rotaing a 3-d object in the pad.
731
732 TPolyLine3D::DrawOutlineCube(outline,rmin,rmax);
733}
734
735
736//______________________________________________________________________________
737void BesTView::ExecuteEvent(Int_t event, Int_t px, Int_t py)
738{
739//*-*-*-*-*-*-*-*-*Execute action corresponding to one event*-*-*-*-*-*-*-*-*
740
741 ExecuteRotateView(event,px,py);
742}
743
744//______________________________________________________________________________
745void BesTView::ExecuteRotateView(Int_t event, Int_t px, Int_t py)
746{
747//*-*-*-*-*-*-*-*-*Execute action corresponding to one event*-*-*-*-*-*-*-*-*-*
748//*-* ========================================= *
749//*-* This member function is called when a object is clicked with the locator *
750//*-* *
751//*-* If Left button clicked in the object area, while the button is kept down *
752//*-* the cube representing the surrounding frame for the corresponding *
753//*-* new latitude and longitude position is drawn. *
754//*-* *
755//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
756 static Int_t system, framewasdrawn;
757 static Double_t xrange, yrange, xmin, ymin, longitude1, latitude1, longitude2, latitude2;
758 static Double_t newlatitude, newlongitude, oldlatitude, oldlongitude;
759 Double_t dlatitude, dlongitude, x, y;
760 Int_t irep = 0;
761 Double_t psideg;
762
763 // all coordinate transformation are from absolute to relative
764
765 if (!gPad->IsEditable()) return;
766 gPad->AbsCoordinates(kTRUE);
767
768 switch (event) {
769
770 case kKeyPress :
771 //Long Peixun's update: KeyPress has been responsed by BesClient
772 //fChanged = kTRUE;
773 //MoveViewCommand(Char_t(px), py);
774 break;
775
776 case kMouseMotion:
777 gPad->SetCursor(kRotate);
778 break;
779
780 case kButton1Down:
781
782 // remember position of the cube
783 xmin = gPad->GetX1();
784 ymin = gPad->GetY1();
785 xrange = gPad->GetX2() - xmin;
786 yrange = gPad->GetY2() - ymin;
787 x = gPad->PixeltoX(px);
788 y = gPad->PixeltoY(py);
789 system = GetSystem();
790 framewasdrawn = 0;
791 if (system == kCARTESIAN || system == kPOLAR || IsPerspective()) {
792 longitude1 = 180*(x-xmin)/xrange;
793 latitude1 = 90*(y-ymin)/yrange;
794 } else {
795 latitude1 = 90*(x-xmin)/xrange;
796 longitude1 = 180*(y-ymin)/yrange;
797 }
798 newlongitude = oldlongitude = -90 - gPad->GetPhi();
799 newlatitude = oldlatitude = 90 - gPad->GetTheta();
800 psideg = GetPsi();
801
802 // if outline isn't set, make it look like a cube
803 if(!fOutline)
805 break;
806
807 case kButton1Motion:
808 {
809 // draw the surrounding frame for the current mouse position
810 // first: Erase old frame
811 fChanged = kTRUE;
812 if (framewasdrawn) fOutline->Paint();
813 framewasdrawn = 1;
814 x = gPad->PixeltoX(px);
815 y = gPad->PixeltoY(py);
816 if (system == kCARTESIAN || system == kPOLAR || IsPerspective()) {
817 longitude2 = 180*(x-xmin)/xrange;
818 latitude2 = 90*(y-ymin)/yrange;
819 } else {
820 latitude2 = 90*(x-xmin)/xrange;
821 longitude2 = 180*(y-ymin)/yrange;
822 }
823 dlongitude = longitude2 - longitude1;
824 dlatitude = latitude2 - latitude1;
825 newlatitude = oldlatitude + dlatitude;
826 newlongitude = oldlongitude - dlongitude;
827 psideg = GetPsi();
828 ResetView(newlongitude, newlatitude, psideg, irep);
829 fOutline->Paint();
830
831 break;
832 }
833 case kButton1Up:
834 if (gROOT->IsEscaped()) {
835 gROOT->SetEscape(kFALSE);
836 break;
837 }
838
839 // Temporary fix for 2D drawing problems on pad. fOutline contains
840 // a TPolyLine3D object for the rotation box. This will be painted
841 // through a newly created TViewer3DPad instance, which is left
842 // behind on pad. This remaining creates 2D drawing problems.
843 //
844 // This is a TEMPORARY fix - will be removed when proper multiple viewers
845 // on pad problems are resolved.
846 if (gPad) {
847 TVirtualViewer3D *viewer = gPad->GetViewer3D();
848 if (viewer && !strcmp(viewer->IsA()->GetName(),"TView3Der3DPad")) {
849 gPad->ReleaseViewer3D();
850 delete viewer;
851 }
852 }
853 // End fix
854
855 // Recompute new view matrix and redraw
856 psideg = GetPsi();
857 SetView(newlongitude, newlatitude, psideg, irep);
858 gPad->SetPhi(-90-newlongitude);
859 gPad->SetTheta(90-newlatitude);
860 gPad->Modified(kTRUE);
861
862 // Set line color, style and width
863 gVirtualX->SetLineColor(-1);
864 gVirtualX->SetLineStyle(-1);
865 gVirtualX->SetLineWidth(-1);
866 break;
867 }
868
869 // set back to default transformation mode
870 gPad->AbsCoordinates(kFALSE);
871}
872
873
874//______________________________________________________________________________
875void BesTView::FindNormal(Double_t x, Double_t y, Double_t z, Double_t &zn)
876{
877//*-*-*-*-*-*-*Find Z component of NORMAL in normalized coordinates-*-*-*-*
878//*-* ==================================================== *
879//*-* *
880//*-* Input: X - X-component of NORMAL *
881//*-* Y - Y-component of NORMAL *
882//*-* Z - Z-component of NORMAL *
883//*-* *
884//*-* Output: ZN - Z-component of NORMAL in normalized coordinates *
885//*-* *
886//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
887
888 zn = x*(fTN[1] * fTN[6] - fTN[2] * fTN[5]) + y*(fTN[2] * fTN[4] -
889 fTN[0] * fTN[6]) + z*(fTN[0] * fTN[5] - fTN[1] * fTN[4]);
890}
891
892//______________________________________________________________________________
893void BesTView::FindPhiSectors(Int_t iopt, Int_t &kphi, Double_t *aphi, Int_t &iphi1, Int_t &iphi2)
894{
895//*-*-*-*-*-*-*-*-*-*-*-*-*Find critical PHI sectors*-*-*-*-*-*-*-*-*-*-*-*
896//*-* ========================= *
897//*-* *
898//*-* Input: IOPT - options: 1 - from BACK to FRONT 'BF' *
899//*-* 2 - from FRONT to BACK 'FB' *
900//*-* KPHI - number of phi sectors *
901//*-* APHI(*) - PHI separators (modified internally) *
902//*-* *
903//*-* Output: IPHI1 - initial sector *
904//*-* IPHI2 - final sector *
905//*-* *
906//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
907
908 Int_t iphi[2], i, k;
909 Double_t dphi;
910 Double_t x1, x2, z1, z2, phi1, phi2;
911
912 /* Parameter adjustments */
913 --aphi;
914
915 if (aphi[kphi + 1] == aphi[1]) aphi[kphi + 1] += 360;
916 dphi = TMath::Abs(aphi[kphi + 1] - aphi[1]);
917 if (dphi != 360) {
918 aphi[kphi + 2] = (aphi[1] + aphi[kphi + 1]) / (float)2. + 180;
919 aphi[kphi + 3] = aphi[1] + 360;
920 kphi += 2;
921 }
922
923 //*-*- F I N D C R I T I C A L S E C T O R S
924
925 k = 0;
926 for (i = 1; i <= kphi; ++i) {
927 phi1 = kRad*aphi[i];
928 phi2 = kRad*aphi[i + 1];
929 x1 = fTN[0]*TMath::Cos(phi1) + fTN[1]*TMath::Sin(phi1);
930 x2 = fTN[0]*TMath::Cos(phi2) + fTN[1]*TMath::Sin(phi2);
931 if (x1 >= 0 && x2 > 0) continue;
932 if (x1 <= 0 && x2 < 0) continue;
933 ++k;
934 if (k == 3) break;
935 iphi[k - 1] = i;
936 }
937 if (k != 2) {
938 Error("FindPhiSectors", "something strange: num. of critical sector not equal 2");
939 iphi1 = 1;
940 iphi2 = 2;
941 return;
942 }
943
944 //*-*- F I N D O R D E R O F C R I T I C A L S E C T O R S
945
946 phi1 = kRad*(aphi[iphi[0]] + aphi[iphi[0] + 1]) / (float)2.;
947 phi2 = kRad*(aphi[iphi[1]] + aphi[iphi[1] + 1]) / (float)2.;
948 z1 = fTN[8]*TMath::Cos(phi1) + fTN[9]*TMath::Sin(phi1);
949 z2 = fTN[8]*TMath::Cos(phi2) + fTN[9]*TMath::Sin(phi2);
950 if ((z1 <= z2 && iopt == 1) || (z1 > z2 && iopt == 2)) {
951 iphi1 = iphi[0];
952 iphi2 = iphi[1];
953 } else {
954 iphi1 = iphi[1];
955 iphi2 = iphi[0];
956 }
957}
958
959//______________________________________________________________________________
960void BesTView::FindThetaSectors(Int_t iopt, Double_t phi, Int_t &kth, Double_t *ath, Int_t &ith1, Int_t &ith2)
961{
962//*-*-*-*-*-*-*-Find critical THETA sectors for given PHI sector*-*-*-*-*-*
963//*-* ================================================ *
964//*-* *
965//*-* Input: IOPT - options: 1 - from BACK to FRONT 'BF' *
966//*-* 2 - from FRONT to BACK 'FB' *
967//*-* PHI - PHI sector *
968//*-* KTH - number of THETA sectors *
969//*-* ATH(*) - THETA separators (modified internally) *
970//*-* *
971//*-* Output: ITH1 - initial sector *
972//*-* ITH2 - final sector *
973//*-* *
974//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
975
976 Int_t i, k, ith[2];
977 Double_t z1, z2, cosphi, sinphi, tncons, th1, th2, dth;
978
979 /* Parameter adjustments */
980 --ath;
981
982 /* Function Body */
983 dth = TMath::Abs(ath[kth + 1] - ath[1]);
984 if (dth != 360) {
985 ath[kth + 2] = 0.5*(ath[1] + ath[kth + 1]) + 180;
986 ath[kth + 3] = ath[1] + 360;
987 kth += 2;
988 }
989
990 //*-*- F I N D C R I T I C A L S E C T O R S
991
992 cosphi = TMath::Cos(phi*kRad);
993 sinphi = TMath::Sin(phi*kRad);
994 k = 0;
995 for (i = 1; i <= kth; ++i) {
996 th1 = kRad*ath[i];
997 th2 = kRad*ath[i + 1];
998 FindNormal(TMath::Cos(th1)*cosphi, TMath::Cos(th1)*sinphi, -TMath::Sin(th1), z1);
999 FindNormal(TMath::Cos(th2)*cosphi, TMath::Cos(th2)*sinphi, -TMath::Sin(th2), z2);
1000 if (z1 >= 0 && z2 > 0) continue;
1001 if (z1 <= 0 && z2 < 0) continue;
1002 ++k;
1003 if (k == 3) break;
1004 ith[k - 1] = i;
1005 }
1006 if (k != 2) {
1007 Error("FindThetaSectors", "Something strange: num. of critical sectors not equal 2");
1008 ith1 = 1;
1009 ith2 = 2;
1010 return;
1011 }
1012
1013 //*-*- F I N D O R D E R O F C R I T I C A L S E C T O R S
1014
1015 tncons = fTN[8]*TMath::Cos(phi*kRad) + fTN[9]*TMath::Sin(phi*kRad);
1016 th1 = kRad*(ath[ith[0]] + ath[ith[0] + 1]) / (float)2.;
1017 th2 = kRad*(ath[ith[1]] + ath[ith[1] + 1]) / (float)2.;
1018 z1 = tncons*TMath::Sin(th1) + fTN[10]*TMath::Cos(th1);
1019 z2 = tncons*TMath::Sin(th2) + fTN[10]*TMath::Cos(th2);
1020 if ((z1 <= z2 && iopt == 1) || (z1 > z2 && iopt == 2)) {
1021 ith1 = ith[0];
1022 ith2 = ith[1];
1023 } else {
1024 ith1 = ith[1];
1025 ith2 = ith[0];
1026 }
1027}
1028
1029
1030//______________________________________________________________________________
1031void BesTView::FindScope(Double_t *scale, Double_t *center, Int_t &irep)
1032{
1033//*-*-*-*-*-*-*-*Find centre of a MIN-MAX scope and scale factors-*-*-*-*-*
1034//*-* ================================================ *
1035//*-* *
1036//*-* Output: SCALE(3) - scale factors *
1037//*-* CENTER(3) - centre *
1038//*-* IREP - reply (-1 if error in min-max) *
1039//*-* *
1040//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1041
1042 irep = 0;
1043 Double_t sqrt3 = 0.5*TMath::Sqrt(3.0);
1044
1045 for (Int_t i = 0; i < 3; i++) {
1046 if (fRmin[i] >= fRmax[i]) { irep = -1; return;}
1047 scale[i] = sqrt3*(fRmax[i] - fRmin[i]);
1048 center[i] = 0.5*(fRmax[i] + fRmin[i]);
1049 }
1050}
1051
1052//______________________________________________________________________________
1053Int_t BesTView::GetDistancetoAxis(Int_t axis, Int_t px, Int_t py, Double_t &ratio)
1054{
1055//*-*-*-*-*-*-*-*-*-*-*-*-*Return distance to axis from point px,py*-*-*-*
1056//*-* ========================================
1057//*-*
1058//*-*
1059//*-* Algorithm:
1060//*-*
1061//*-* A(x1,y1) P B(x2,y2)
1062//*-* ------------------------------------------------
1063//*-* I
1064//*-* I
1065//*-* I
1066//*-* I
1067//*-* M(x,y)
1068//*-*
1069//*-* Let us call a = distance AM A=a**2
1070//*-* b = distance BM B=b**2
1071//*-* c = distance AB C=c**2
1072//*-* d = distance PM D=d**2
1073//*-* u = distance AP U=u**2
1074//*-* v = distance BP V=v**2 c = u + v
1075//*-*
1076//*-* D = A - U
1077//*-* D = B - V = B -(c-u)**2
1078//*-* ==> u = (A -B +C)/2c
1079//*-*
1080//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1081
1082 Double_t x1,y1,x2,y2;
1083 Double_t x = px;
1084 Double_t y = py;
1085 ratio = 0;
1086
1087 if (fSystem != 1) return 9998; // only implemented for Cartesian coordinates
1088 if (axis == 1) {
1089 x1 = gPad->XtoAbsPixel(fX1[0]);
1090 y1 = gPad->YtoAbsPixel(fX1[1]);
1091 x2 = gPad->XtoAbsPixel(fX2[0]);
1092 y2 = gPad->YtoAbsPixel(fX2[1]);
1093 } else if (axis == 2) {
1094 x1 = gPad->XtoAbsPixel(fY1[0]);
1095 y1 = gPad->YtoAbsPixel(fY1[1]);
1096 x2 = gPad->XtoAbsPixel(fY2[0]);
1097 y2 = gPad->YtoAbsPixel(fY2[1]);
1098 } else {
1099 x1 = gPad->XtoAbsPixel(fZ1[0]);
1100 y1 = gPad->YtoAbsPixel(fZ1[1]);
1101 x2 = gPad->XtoAbsPixel(fZ2[0]);
1102 y2 = gPad->YtoAbsPixel(fZ2[1]);
1103 }
1104 Double_t xx1 = x - x1;
1105 Double_t xx2 = x - x2;
1106 Double_t x1x2 = x1 - x2;
1107 Double_t yy1 = y - y1;
1108 Double_t yy2 = y - y2;
1109 Double_t y1y2 = y1 - y2;
1110 Double_t a = xx1*xx1 + yy1*yy1;
1111 Double_t b = xx2*xx2 + yy2*yy2;
1112 Double_t c = x1x2*x1x2 + y1y2*y1y2;
1113 if (c <= 0) return 9999;
1114 Double_t v = TMath::Sqrt(c);
1115 Double_t u = (a - b + c)/(2*v);
1116 Double_t d = TMath::Abs(a - u*u);
1117
1118 Int_t dist = Int_t(TMath::Sqrt(d) - 0.5);
1119 ratio = u/v;
1120 return dist;
1121}
1122
1123//______________________________________________________________________________
1124Double_t BesTView::GetExtent() const
1125{
1126//*-*-*-*-*-*-*-*-*-*-*-*-*-*Get maximum view extent-*-*-*-*-*-*-*-*-*-*-*-*-*
1127//*-* =======================
1128//*-*
1129 Double_t dx = 0.5*(fRmax[0]-fRmin[0]);
1130 Double_t dy = 0.5*(fRmax[1]-fRmin[1]);
1131 Double_t dz = 0.5*(fRmax[2]-fRmin[2]);
1132 Double_t extent = TMath::Sqrt(dx*dx+dy*dy+dz*dz);
1133 return extent;
1134}
1135
1136
1137//______________________________________________________________________________
1138void BesTView::GetRange(Float_t *min, Float_t *max)
1139{
1140//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*Get Range function-*-*-*-*-*-*-*-*-*-*-*-*-*
1141//*-* ==================
1142//*-*
1143 for (Int_t i = 0; i < 3; max[i] = fRmax[i], min[i] = fRmin[i], i++);
1144}
1145
1146
1147//______________________________________________________________________________
1148void BesTView::GetRange(Double_t *min, Double_t *max)
1149{
1150 // Get Range function.
1151
1152 for (Int_t i = 0; i < 3; max[i] = fRmax[i], min[i] = fRmin[i], i++) { }
1153}
1154
1155//______________________________________________________________________________
1156void BesTView::GetWindow(Double_t &u0, Double_t &v0, Double_t &du, Double_t &dv) const
1157{
1158// Get current window extent.
1159 u0 = fUVcoord[0];
1160 v0 = fUVcoord[1];
1161 du = fUVcoord[2];
1162 dv = fUVcoord[3];
1163}
1164
1165//______________________________________________________________________________
1166Bool_t BesTView::IsClippedNDC(Double_t *p) const
1167{
1168 //*-*-*-*-*-*-*Check if point is clipped in perspective view-*-*-*-*-*-*-*-*
1169 //*-* =============================================
1170 //*-*
1171 if (TMath::Abs(p[0])>p[2]) return kTRUE;
1172 if (TMath::Abs(p[1])>p[2]) return kTRUE;
1173 return kFALSE;
1174}
1175
1176//______________________________________________________________________________
1177void BesTView::NDCtoWC(const Float_t* pn, Float_t* pw)
1178{
1179 //*-*-*-*-*-*-*Transfer point from normalized to world coordinates*-*-*-*-*
1180 //*-* =================================================== *
1181 //*-* *
1182 //*-* Input: PN(3) - point in world coordinate system *
1183 //*-* PW(3) - point in normalized coordinate system *
1184 //*-* *
1185 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1186
1187 pw[0] = fTback[0]*pn[0] + fTback[1]*pn[1] + fTback[2]*pn[2] + fTback[3];
1188 pw[1] = fTback[4]*pn[0] + fTback[5]*pn[1] + fTback[6]*pn[2] + fTback[7];
1189 pw[2] = fTback[8]*pn[0] + fTback[9]*pn[1] + fTback[10]*pn[2] + fTback[11];
1190}
1191
1192//______________________________________________________________________________
1193void BesTView::NDCtoWC(const Double_t* pn, Double_t* pw)
1194{
1195 //*-*-*-*-*-*-*Transfer point from normalized to world coordinates*-*-*-*-*
1196 //*-* =================================================== *
1197 //*-* *
1198 //*-* Input: PN(3) - point in world coordinate system *
1199 //*-* PW(3) - point in normalized coordinate system *
1200 //*-* *
1201 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1202
1203 pw[0] = fTback[0]*pn[0] + fTback[1]*pn[1] + fTback[2]*pn[2] + fTback[3];
1204 pw[1] = fTback[4]*pn[0] + fTback[5]*pn[1] + fTback[6]*pn[2] + fTback[7];
1205 pw[2] = fTback[8]*pn[0] + fTback[9]*pn[1] + fTback[10]*pn[2] + fTback[11];
1206}
1207
1208//______________________________________________________________________________
1209void BesTView::NormalWCtoNDC(const Float_t *pw, Float_t *pn)
1210{
1211 //*-*-*Transfer vector of NORMAL from word to normalized coodinates-*-*-*-*
1212 //*-* ============================================================
1213 //*-*
1214 //*-* Input: PW(3) - vector of NORMAL in word coordinate system
1215 //*-* PN(3) - vector of NORMAL in normalized coordinate system
1216 //*-*
1217 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1218
1219 Double_t x, y, z, a1, a2, a3, b1, b2, b3, c1, c2, c3;
1220
1221 x = pw[0];
1222 y = pw[1];
1223 z = pw[2];
1224 a1 = fTnorm[0];
1225 a2 = fTnorm[1];
1226 a3 = fTnorm[2];
1227 b1 = fTnorm[4];
1228 b2 = fTnorm[5];
1229 b3 = fTnorm[6];
1230 c1 = fTnorm[8];
1231 c2 = fTnorm[9];
1232 c3 = fTnorm[10];
1233 pn[0] = x*(b2*c3 - b3*c2) + y*(b3*c1 - b1*c3) + z*(b1*c2 - b2*c1);
1234 pn[1] = x*(c2*a3 - c3*a2) + y*(c3*a1 - c1*a3) + z*(c1*a2 - c2*a1);
1235 pn[2] = x*(a2*b3 - a3*b2) + y*(a3*b1 - a1*b3) + z*(a1*b2 - a2*b1);
1236}
1237
1238//______________________________________________________________________________
1239void BesTView::NormalWCtoNDC(const Double_t *pw, Double_t *pn)
1240{
1241 //*-*-*Transfer vector of NORMAL from word to normalized coodinates-*-*-*-*
1242 //*-* ============================================================
1243 //*-*
1244 //*-* Input: PW(3) - vector of NORMAL in word coordinate system
1245 //*-* PN(3) - vector of NORMAL in normalized coordinate system
1246 //*-*
1247 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1248
1249 Double_t x, y, z, a1, a2, a3, b1, b2, b3, c1, c2, c3;
1250
1251 x = pw[0];
1252 y = pw[1];
1253 z = pw[2];
1254 a1 = fTnorm[0];
1255 a2 = fTnorm[1];
1256 a3 = fTnorm[2];
1257 b1 = fTnorm[4];
1258 b2 = fTnorm[5];
1259 b3 = fTnorm[6];
1260 c1 = fTnorm[8];
1261 c2 = fTnorm[9];
1262 c3 = fTnorm[10];
1263 pn[0] = x*(b2*c3 - b3*c2) + y*(b3*c1 - b1*c3) + z*(b1*c2 - b2*c1);
1264 pn[1] = x*(c2*a3 - c3*a2) + y*(c3*a1 - c1*a3) + z*(c1*a2 - c2*a1);
1265 pn[2] = x*(a2*b3 - a3*b2) + y*(a3*b1 - a1*b3) + z*(a1*b2 - a2*b1);
1266}
1267
1268//______________________________________________________________________________
1269void BesTView::PadRange(Int_t rback)
1270{
1271 //*-*-*-*-*Set the correct window size for lego and surface plots*-*-*-*-*
1272 //*-* ======================================================
1273 //*-*
1274 //*-* Set the correct window size for lego and surface plots.
1275 //*-* And draw the background if necessary.
1276 //*-*
1277 //*-* Input parameters:
1278 //*-*
1279 //*-* RBACK : Background colour
1280 //*-*
1281 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1282
1283 Int_t i, k;
1284 Double_t x, y, z, r1, r2, r3, xx, yy, smax[2];
1285 Double_t xgraf[6], ygraf[6];
1286
1287 for (i = 1; i <= 2; ++i) {
1288 smax[i - 1] = fTnorm[(i << 2) - 1];
1289 for (k = 1; k <= 3; ++k) {
1290 if (fTnorm[k + (i << 2) - 5] < 0) {
1291 smax[i - 1] += fTnorm[k + (i << 2) - 5]*fRmin[k-1];
1292 } else {
1293 smax[i - 1] += fTnorm[k + (i << 2) - 5]*fRmax[k-1];
1294 }
1295 }
1296 }
1297
1298 //*-*- Compute x,y range
1299 Double_t xmin = -smax[0];
1300 Double_t xmax = smax[0];
1301 Double_t ymin = -smax[1];
1302 Double_t ymax = smax[1];
1303 Double_t dx = xmax-xmin;
1304 Double_t dy = ymax-ymin;
1305 Double_t dxr = dx/(1 - gPad->GetLeftMargin() - gPad->GetRightMargin());
1306 Double_t dyr = dy/(1 - gPad->GetBottomMargin() - gPad->GetTopMargin());
1307
1308 // Range() could change the size of the pad pixmap and therefore should
1309 // be called before the other paint routines
1310 gPad->Range(xmin - dxr*gPad->GetLeftMargin(),
1311 ymin - dyr*gPad->GetBottomMargin(),
1312 xmax + dxr*gPad->GetRightMargin(),
1313 ymax + dyr*gPad->GetTopMargin());
1314 gPad->RangeAxis(xmin, ymin, xmax, ymax);
1315
1316 //*-*- Draw the background if necessary
1317
1318 if (rback > 0) {
1319 r1 = -1;
1320 r2 = -1;
1321 r3 = -1;
1322 xgraf[0] = -smax[0];
1323 xgraf[1] = -smax[0];
1324 xgraf[2] = -smax[0];
1325 xgraf[3] = -smax[0];
1326 xgraf[4] = smax[0];
1327 xgraf[5] = smax[0];
1328 ygraf[0] = -smax[1];
1329 ygraf[1] = smax[1];
1330 ygraf[2] = -smax[1];
1331 ygraf[3] = smax[1];
1332 ygraf[5] = smax[1];
1333 ygraf[4] = -smax[1];
1334 for (i = 1; i <= 8; ++i) {
1335 x = 0.5*((1 - r1)*fRmin[0] + (r1 + 1)*fRmax[0]);
1336 y = 0.5*((1 - r2)*fRmin[1] + (r2 + 1)*fRmax[1]);
1337 z = 0.5*((1 - r3)*fRmin[2] + (r3 + 1)*fRmax[2]);
1338 xx = fTnorm[0]*x + fTnorm[1]*y + fTnorm[2]*z + fTnorm[3];
1339 yy = fTnorm[4]*x + fTnorm[5]*y + fTnorm[6]*z + fTnorm[7];
1340 if (TMath::Abs(xx - xgraf[1]) <= 1e-4) {
1341 if (ygraf[1] >= yy) ygraf[1] = yy;
1342 if (ygraf[2] <= yy) ygraf[2] = yy;
1343 }
1344 if (TMath::Abs(xx - xgraf[5]) <= 1e-4) {
1345 if (ygraf[5] >= yy) ygraf[5] = yy;
1346 if (ygraf[4] <= yy) ygraf[4] = yy;
1347 }
1348 if (TMath::Abs(yy - ygraf[0]) <= 1e-4) xgraf[0] = xx;
1349 if (TMath::Abs(yy - ygraf[3]) <= 1e-4) xgraf[3] = xx;
1350 r1 = -r1;
1351 if (i % 2 == 0) r2 = -r2;
1352 if (i >= 4) r3 = 1;
1353 }
1354 gPad->PaintFillArea(6, xgraf, ygraf);
1355 }
1356}
1357
1358//______________________________________________________________________________
1359void BesTView::SetAxisNDC(const Double_t *x1, const Double_t *x2, const Double_t *y1, const Double_t *y2, const Double_t *z1, const Double_t *z2)
1360{
1361 //*-*-*-*-*-*-*-*-*-*-*-*-*Store axis coordinates in the NDC system*-*-*-*
1362 //*-* ========================================
1363 //*-*
1364
1365 for (Int_t i=0;i<3;i++) {
1366 fX1[i] = x1[i];
1367 fX2[i] = x2[i];
1368 fY1[i] = y1[i];
1369 fY2[i] = y2[i];
1370 fZ1[i] = z1[i];
1371 fZ2[i] = z2[i];
1372 }
1373}
1374
1375//______________________________________________________________________________
1377{
1378 // Set default viewing window
1379 if (!gPad) return;
1380 Double_t screen_factor = 1.;
1381 Double_t du, dv;
1382 Double_t extent = GetExtent();
1383 fDview = 3*extent;
1384 fDproj = 0.5*extent;
1385
1386 // widh in pixels
1387 fUpix = gPad->GetWw()*gPad->GetAbsWNDC();
1388
1389 // height in pixels
1390 fVpix = gPad->GetWh()*gPad->GetAbsHNDC();
1391 du = 0.5*screen_factor*fDproj;
1392 dv = du*fVpix/fUpix; // keep aspect ratio
1393 SetWindow(0, 0, du, dv);
1394}
1395
1396//______________________________________________________________________________
1398{
1399 //*-*-*-*-*-*-*This is a function which creates default outline*-*-*-*-*-*
1400 //*-* ================================================ *
1401 //*-* *
1402 //*-* x = fRmin[0] X = fRmax[0] *
1403 //*-* y = fRmin[1] Y = fRmax[1] *
1404 //*-* z = fRmin[2] Z = fRmax[2] *
1405 //*-* *
1406 //*-* *
1407 //*-* (x,Y,Z) +---------+ (X,Y,Z) *
1408 //*-* / /| *
1409 //*-* / / | *
1410 //*-* / / | *
1411 //*-* (x,y,Z) +---------+ | *
1412 //*-* | | + (X,Y,z) *
1413 //*-* | | / *
1414 //*-* | | / *
1415 //*-* | |/ *
1416 //*-* +---------+ *
1417 //*-* (x,y,z) (X,y,z) *
1418 //*-* *
1419 //*-* *
1420 //*-* *
1421 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**
1422
1423 if (!fOutline) {
1424 fDefaultOutline = kTRUE;
1425 fOutline = new TList();
1426 }
1428 //TVirtualUtil3D *util = (TVirtualUtil3D*)gROOT->GetListOfSpecials()->FindObject("R__TVirtualUtil3D");
1429 //if (util) util->DrawOutlineCube((TList*)fOutline,fRmin,fRmax);
1430}
1431
1432//______________________________________________________________________________
1434{
1435 //set the parallel option (default)
1436 if (!IsPerspective()) return;
1437 SetBit(kPerspective, kFALSE);
1438 Int_t irep;
1440}
1441
1442//______________________________________________________________________________
1444{
1445 //set perspective option
1446 if (IsPerspective()) return;
1447 SetBit(kPerspective, kTRUE);
1448 Int_t irep;
1451}
1452
1453//______________________________________________________________________________
1454void BesTView::SetRange(const Double_t *min, const Double_t *max)
1455{
1456 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*Set Range function-*-*-*-*-*-*-*-*-*-*-*-*-*
1457 //*-* ==================
1458 //*-*
1459 Int_t irep;
1460 for (Int_t i = 0; i < 3; fRmax[i] = max[i], fRmin[i] = min[i], i++) { }
1463 if(irep < 0)
1464 Error("SetRange", "problem setting view");
1466}
1467
1468
1469//______________________________________________________________________________
1470void BesTView::SetRange(Double_t x0, Double_t y0, Double_t z0, Double_t x1, Double_t y1, Double_t z1, Int_t flag)
1471{
1472 //*-*-*-*-*-*-*-*-*-*-*-*Set 3-D View range*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1473 //*-* ==================
1474 //*-*
1475 //*-* Input: x0, y0, z0 are minimum coordinates
1476 //*-* x1, y1, z1 are maximum coordinates
1477 //*-*
1478 //*-* flag values are: 0 (set always) <- default
1479 //*-* 1 (shrink view)
1480 //*-* 2 (expand view)
1481 //*-*
1482
1483
1484 Double_t rmax[3], rmin[3];
1485
1486 switch (flag) {
1487 case 2: // expand view
1488 GetRange(rmin, rmax);
1489 rmin[0] = x0 < rmin[0] ? x0 : rmin[0];
1490 rmin[1] = y0 < rmin[1] ? y0 : rmin[1];
1491 rmin[2] = z0 < rmin[2] ? z0 : rmin[2];
1492 rmax[0] = x1 > rmax[0] ? x1 : rmax[0];
1493 rmax[1] = y1 > rmax[1] ? y1 : rmax[1];
1494 rmax[2] = z1 > rmax[2] ? z1 : rmax[2];
1495 break;
1496
1497 case 1: // shrink view
1498 GetRange(rmin, rmax);
1499 rmin[0] = x0 > rmin[0] ? x0 : rmin[0];
1500 rmin[1] = y0 > rmin[1] ? y0 : rmin[1];
1501 rmin[2] = z0 > rmin[2] ? z0 : rmin[2];
1502 rmax[0] = x1 < rmax[0] ? x1 : rmax[0];
1503 rmax[1] = y1 < rmax[1] ? y1 : rmax[1];
1504 rmax[2] = z1 < rmax[2] ? z1 : rmax[2];
1505 break;
1506
1507 default:
1508 rmin[0] = x0; rmax[0] = x1;
1509 rmin[1] = y0; rmax[1] = y1;
1510 rmin[2] = z0; rmax[2] = z1;
1511 }
1512 SetRange(rmin, rmax);
1513}
1514
1515//______________________________________________________________________________
1516void BesTView::SetWindow(Double_t u0, Double_t v0, Double_t du, Double_t dv)
1517{
1518 // Set viewing window.
1519 fUVcoord[0] = u0;
1520 fUVcoord[1] = v0;
1521 fUVcoord[2] = du;
1522 fUVcoord[3] = dv;
1523}
1524
1525//______________________________________________________________________________
1526void BesTView::SetView(Double_t longitude, Double_t latitude, Double_t psi, Int_t &irep)
1527{
1528 //set view parameters
1529
1530 ResetView(longitude, latitude, psi, irep);
1531}
1532
1533//______________________________________________________________________________
1535{
1536 // Recompute window for perspective view
1537
1538 if (!IsPerspective()) return;
1539 Double_t upix = fUpix;
1540 Double_t vpix = fVpix;
1541 // widh in pixels
1542 fUpix = gPad->GetWw()*gPad->GetAbsWNDC();
1543 // height in pixels
1544 fVpix = gPad->GetWh()*gPad->GetAbsHNDC();
1545 Double_t u0 = fUVcoord[0]*fUpix/upix;
1546 Double_t v0 = fUVcoord[1]*fVpix/vpix;
1547 Double_t du = fUVcoord[2]*fUpix/upix;
1548 Double_t dv = fUVcoord[3]*fVpix/vpix;
1549 SetWindow(u0, v0, du, dv);
1551}
1552
1553//______________________________________________________________________________
1554void BesTView::ResetView(Double_t longitude, Double_t latitude, Double_t psi, Int_t &irep)
1555{
1556 //*-*-*-*-*-*-*-*-*Set view direction (in spherical coordinates)*-*-*-*-*-*
1557 //*-* ============================================= *
1558 //*-* *
1559 //*-* Input PHI - longitude *
1560 //*-* THETA - latitude (angle between +Z and view direction) *
1561 //*-* PSI - rotation in screen plane *
1562 //*-* *
1563 //*-* Output: IREP - reply (-1 if error in min-max) *
1564 //*-* *
1565 //*-* Errors: error in min-max scope *
1566 //*-* *
1567 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1568
1569 Double_t scale[3], centre[3];
1570 Double_t c1, c2, c3, s1, s2, s3;
1571
1572 //*-*- F I N D C E N T E R O F S C O P E A N D
1573 //*-*- S C A L E F A C T O R S
1574
1575 FindScope(scale, centre, irep);
1576 if (irep < 0) {
1577 Error("ResetView", "Error in min-max scope");
1578 return;
1579 }
1580
1581 //*-*- S E T T R A N S F O R M A T I O N M A T R I C E S
1582
1583
1584 fLongitude = longitude;
1585 fPsi = psi;
1586 fLatitude = latitude;
1587
1588 if (IsPerspective()) {
1590 return;
1591 }
1592
1593 c1 = TMath::Cos(longitude*kRad);
1594 s1 = TMath::Sin(longitude*kRad);
1595 c2 = TMath::Cos(latitude*kRad);
1596 s2 = TMath::Sin(latitude*kRad);
1597 c3 = TMath::Cos(psi*kRad);
1598 s3 = TMath::Sin(psi*kRad);
1599 DefineViewDirection(scale, centre, c1, s1, c2, s2, c3, s3, fTnorm, fTback);
1600 c3 = 1;
1601 s3 = 0;
1602 DefineViewDirection(scale, centre, c1, s1, c2, s2, c3, s3, fTN, fTB);
1603}
1604
1605
1606//______________________________________________________________________________
1607void BesTView::WCtoNDC(const Float_t *pw, Float_t *pn)
1608{
1609 //*-*-*-*-*-*-*Transfer point from world to normalized coordinates*-*-*-*-*
1610 //*-* =================================================== *
1611 //*-* *
1612 //*-* Input: PW(3) - point in world coordinate system *
1613 //*-* PN(3) - point in normalized coordinate system *
1614 //*-* *
1615 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1616
1617 // perspective view
1618 if (IsPerspective()) {
1619 for (Int_t i=0; i<3; i++)
1620 pn[i] = pw[0]*fTnorm[i]+pw[1]*fTnorm[i+4]+pw[2]*fTnorm[i+8]+fTnorm[i+12];
1621 if (pn[2]>0) {
1622 pn[0] /= pn[2];
1623 pn[1] /= pn[2];
1624 } else {
1625 pn[0] *= 1000.;
1626 pn[1] *= 1000.;
1627 }
1628 return;
1629 }
1630 // parallel view
1631 pn[0] = fTnorm[0]*pw[0] + fTnorm[1]*pw[1] + fTnorm[2]*pw[2] + fTnorm[3];
1632 pn[1] = fTnorm[4]*pw[0] + fTnorm[5]*pw[1] + fTnorm[6]*pw[2] + fTnorm[7];
1633 pn[2] = fTnorm[8]*pw[0] + fTnorm[9]*pw[1] + fTnorm[10]*pw[2] + fTnorm[11];
1634}
1635
1636
1637//______________________________________________________________________________
1638void BesTView::WCtoNDC(const Double_t *pw, Double_t *pn)
1639{
1640 //*-*-*-*-*-*-*Transfer point from world to normalized coordinates*-*-*-*-*
1641 //*-* =================================================== *
1642 //*-* *
1643 //*-* Input: PW(3) - point in world coordinate system *
1644 //*-* PN(3) - point in normalized coordinate system *
1645 //*-* *
1646 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1647
1648 // perspective view
1649 if (IsPerspective()) {
1650 for (Int_t i=0; i<3; i++)
1651 pn[i] = pw[0]*fTnorm[i]+pw[1]*fTnorm[i+4]+pw[2]*fTnorm[i+8]+fTnorm[i+12];
1652 if (pn[2]>0) {
1653 pn[0] /= pn[2];
1654 pn[1] /= pn[2];
1655 } else {
1656 pn[0] *= 1000.;
1657 pn[1] *= 1000.;
1658 }
1659 return;
1660 }
1661 // parallel view
1662 pn[0] = fTnorm[0]*pw[0] + fTnorm[1]*pw[1] + fTnorm[2]*pw[2] + fTnorm[3];
1663 pn[1] = fTnorm[4]*pw[0] + fTnorm[5]*pw[1] + fTnorm[6]*pw[2] + fTnorm[7];
1664 pn[2] = fTnorm[8]*pw[0] + fTnorm[9]*pw[1] + fTnorm[10]*pw[2] + fTnorm[11];
1665}
1666
1667//_______________________________________________________________________________________
1668void BesTView::AdjustPad(TVirtualPad *pad)
1669{
1670 // Force the current pad to be updated
1671 TVirtualPad *thisPad = pad;
1672 if (!thisPad) thisPad = gPad;
1673 if (thisPad) {
1674 thisPad->Modified();
1675 thisPad->Update();
1676 }
1677}
1678//_______________________________________________________________________________________
1679void BesTView::RotateView(Double_t phi, Double_t theta, TVirtualPad *pad)
1680{
1681 // API to rotate view and adjust the pad provided it the current one.
1682
1683 Int_t iret;
1684 Double_t p = phi;
1685 Double_t t = theta;
1686 SetView(p, t, 0, iret);
1687
1688 // Adjust current pad too
1689 TVirtualPad *thisPad = pad;
1690 if (!thisPad) thisPad = gPad;
1691 if (thisPad) {
1692 thisPad->SetPhi(-90-p);
1693 thisPad->SetTheta(90-t);
1694 thisPad->Modified();
1695 thisPad->Update();
1696 }
1697}
1698
1699//_______________________________________________________________________________________
1700void BesTView::SideView(TVirtualPad *pad)
1701{
1702 // Set to side view.
1703 RotateView(0,90.0,pad);
1704}
1705//_______________________________________________________________________________________
1706void BesTView::FrontView(TVirtualPad *pad)
1707{
1708 // Set to front view.
1709 RotateView(270.0,90.0,pad);
1710}
1711//_______________________________________________________________________________________
1712void BesTView::TopView(TVirtualPad *pad)
1713{
1714 // Set to top view.
1715 RotateView(270.0,0.0,pad);
1716}
1717//_______________________________________________________________________________________
1718void BesTView::ToggleRulers(TVirtualPad *pad)
1719{
1720 // Turn on /off 3D axis
1721 //TVirtualUtil3D *util = (TVirtualUtil3D*)gROOT->GetListOfSpecials()->FindObject("R__TVirtualUtil3D");
1722 //if (util) util->ToggleRulers(pad);
1723 TAxis3D::ToggleRulers(pad);
1724}
1725
1726//_______________________________________________________________________________________
1727void BesTView::ToggleZoom(TVirtualPad *pad)
1728{
1729 // Turn on /off the interactive option to
1730 // Zoom / Move / Change attributes of 3D axis correspond this view
1731 //TVirtualUtil3D *util = (TVirtualUtil3D*)gROOT->GetListOfSpecials()->FindObject("R__TVirtualUtil3D");
1732 //if (util) util->ToggleZoom(pad);
1733 TAxis3D::ToggleZoom(pad);
1734}
1735
1736//_______________________________________________________________________________________
1737void BesTView::AdjustScales(TVirtualPad *pad)
1738{
1739 // Adjust all sides of view in respect of the biggest one
1740 Double_t min[3],max[3];
1741 GetRange(min,max);
1742 int i;
1743 Double_t maxSide = 0;
1744 // Find the largest side
1745 for (i=0;i<3; i++) maxSide = TMath::Max(maxSide,max[i]-min[i]);
1746 //Adjust scales:
1747 for (i=0;i<3; i++) max[i] += maxSide - (max[i]-min[i]);
1748 SetRange(min,max);
1749
1750 AdjustPad(pad);
1751}
1752
1753//_______________________________________________________________________________________
1754void BesTView::Centered3DImages(TVirtualPad *pad)
1755{
1756 // Move view into the center of the scene
1757
1758 Double_t min[3],max[3];
1759 GetRange(min,max);
1760 int i;
1761 for (i=0;i<3; i++) {
1762 if (max[i] > 0) min[i] = -max[i];
1763 else max[i] = -min[i];
1764 }
1765 SetRange(min,max);
1766 AdjustPad(pad);
1767}
1768
1769//_______________________________________________________________________________________
1770void BesTView::UnzoomView(TVirtualPad *pad,Double_t unZoomFactor )
1771{
1772 // unZOOM this view
1773 if (TMath::Abs(unZoomFactor) < 0.001) return;
1774 ZoomView(pad,1./unZoomFactor);
1775}
1776
1777//_______________________________________________________________________________________
1778void BesTView::ZoomView(TVirtualPad *pad,Double_t zoomFactor)
1779{
1780 // ZOOM this view
1781
1782 if (TMath::Abs(zoomFactor) < 0.001) return;
1783 Double_t min[3],max[3];
1784 GetRange(min,max);
1785 int i;
1786 for (i=0;i<3; i++) {
1787 // Find center
1788 Double_t c = (max[i]+min[i])/2;
1789 // Find a new size
1790 Double_t s = (max[i]-min[i])/(2*zoomFactor);
1791 // Set a new size
1792 max[i] = c + s;
1793 min[i] = c - s;
1794 }
1795 SetRange(min,max);
1796 //Long Peixun's update: don't adjust pad immediately
1797 //AdjustPad(pad);
1798}
1799//___________
1800void BesTView::MoveFocus(Double_t *cov, Double_t dx, Double_t dy, Double_t dz, Int_t nsteps,
1801 Double_t dlong, Double_t dlat, Double_t dpsi)
1802{
1803 // Move focus to a different box position and extent in nsteps. Perform rotation
1804// with dlat,dlong,dpsi at each step.
1805 if (!IsPerspective()) return;
1806 if (nsteps<1) return;
1807 Double_t fc = 1./Double_t(nsteps);
1808 Double_t oc[3], od[3], dir[3];
1809 dir[0] = 0;
1810 dir[1] = 0;
1811 dir[2] = 1.;
1812 Int_t i, j;
1813 for (i=0; i<3; i++) {
1814 oc[i] = 0.5*(fRmin[i]+fRmax[i]);
1815 od[i] = 0.5*(fRmax[i]-fRmin[i]);
1816 }
1817 Double_t dox = cov[0]-oc[0];
1818 Double_t doy = cov[1]-oc[1];
1819 Double_t doz = cov[2]-oc[2];
1820
1821 Double_t dd = TMath::Sqrt(dox*dox+doy*doy+doz*doz);
1822 if (dd!=0) {
1823 dir[0] = dox/dd;
1824 dir[1] = doy/dd;
1825 dir[2] = doz/dd;
1826 }
1827 dd *= fc;
1828 dox = fc*(dx-od[0]);
1829 doy = fc*(dy-od[1]);
1830 doz = fc*(dz-od[2]);
1831 for (i=0; i<nsteps; i++) {
1832 oc[0] += dd*dir[0];
1833 oc[1] += dd*dir[1];
1834 oc[2] += dd*dir[2];
1835 od[0] += dox;
1836 od[1] += doy;
1837 od[2] += doz;
1838 for (j=0; j<3; j++) {
1839 fRmin[j] = oc[j]-od[j];
1840 fRmax[j] = oc[j]+od[j];
1841 }
1843 fLatitude += dlat;
1844 fLongitude += dlong;
1845 fPsi += dpsi;
1847 if (gPad) {
1848 gPad->Modified();
1849 gPad->Update();
1850 }
1851 }
1852}
1853
1854//_______________________________________________________________________________________
1855void BesTView::MoveViewCommand(Char_t option, Int_t count)
1856{
1857 //
1858 //*-* 'a' //*-* increase scale factor (clip cube borders)
1859 //*-* 's' //*-* decrease scale factor (clip cube borders)
1860 //
1861 if (count <= 0) count = 1;
1862 switch (option) {
1863 case '+':
1864 ZoomView();
1865 break;
1866 case '-':
1867 UnzoomView();
1868 break;
1869 case 's':
1870 case 'S':
1871 UnzoomView();
1872 break;
1873 case 'a':
1874 case 'A':
1875 ZoomView();
1876 break;
1877 case 'l':
1878 case 'L':
1879 case 'h':
1880 case 'H':
1881 case 'u':
1882 case 'U':
1883 case 'i':
1884 case 'I':
1885 MoveWindow(option);
1886 break;
1887 case 'j':
1888 case 'J':
1889 ZoomIn();
1890 break;
1891 case 'k':
1892 case 'K':
1893 ZoomOut();
1894 break;
1895 default:
1896 break;
1897 }
1898}
1899
1900//_______________________________________________________________________________________
1901void BesTView::MoveWindow(Char_t option)
1902{
1903 // Move view window :
1904 // l,L - left
1905 // h,H - right
1906 // u,U - down
1907 // i,I - up
1908 if (!IsPerspective()) return;
1909 Double_t shiftu = 0.1*fUVcoord[2];
1910 Double_t shiftv = 0.1*fUVcoord[3];
1911 switch (option) {
1912 case 'l':
1913 case 'L':
1914 fUVcoord[0] += shiftu;
1915 break;
1916 case 'h':
1917 case 'H':
1918 fUVcoord[0] -= shiftu;
1919 break;
1920 case 'u':
1921 case 'U':
1922 fUVcoord[1] += shiftv;
1923 break;
1924 case 'i':
1925 case 'I':
1926 fUVcoord[1] -= shiftv;
1927 break;
1928 default:
1929 return;
1930 }
1932 if (gPad) {
1933 gPad->Modified();
1934 gPad->Update();
1935 }
1936}
1937
1938//_______________________________________________________________________________________
1940{
1941 // Zoom in.
1942 if (!IsPerspective()) return;
1943 Double_t extent = GetExtent();
1944 Double_t fc = 0.1;
1945 if (fDview<extent) {
1946 fDview -= fc*extent;
1947 } else {
1948 fDview /= 1.25;
1949 }
1951 if (gPad) {
1952 gPad->Modified();
1953 gPad->Update();
1954 }
1955}
1956
1957//_______________________________________________________________________________________
1959{
1960 // Zoom out.
1961 if (!IsPerspective()) return;
1962 Double_t extent = GetExtent();
1963 Double_t fc = 0.1;
1964 if (fDview<extent) {
1965 fDview += fc*extent;
1966 } else {
1967 fDview *= 1.25;
1968 }
1970 if (gPad) {
1971 gPad->Modified();
1972 gPad->Update();
1973 }
1974}
1975
1976//______________________________________________________________________________
1977void BesTView::Streamer(TBuffer &R__b)
1978{
1979 // Stream an object of class BesTView.
1980
1981 if (R__b.IsReading()) {
1982 UInt_t R__s, R__c;
1983 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
1984 if (R__v > 1) {
1985 //BesTView::Class()->ReadBuffer(R__b, this, R__v, R__s, R__c);
1986 R__b.ReadClassBuffer(TView::Class(), this, R__v, R__s, R__c);
1987 return;
1988 }
1989 //====process old versions before automatic schema evolution
1990 //unfortunately we forgot to increment the BesTView version number
1991 //when the class was upgraded to double precision in version 2.25.
1992 //we are forced to use the file version number to recognize old files.
1993 if (R__b.GetParent() && R__b.GetVersionOwner() < 22500) { //old version in single precision
1994 //TFile *file = (TFile*)R__b.GetParent();
1995 //if (file && file->GetVersion() < 22500) { //old version in single precision
1996 TObject::Streamer(R__b);
1997 TAttLine::Streamer(R__b);
1998 Float_t single, sa[12];
1999 Int_t i;
2000 R__b >> fSystem;
2001 R__b >> single; fLatitude = single;
2002 R__b >> single; fLongitude = single;
2003 R__b >> single; fPsi = single;
2004 R__b.ReadStaticArray(sa); for (i=0;i<12;i++) fTN[i] = sa[i];
2005 R__b.ReadStaticArray(sa); for (i=0;i<12;i++) fTB[i] = sa[i];
2006 R__b.ReadStaticArray(sa); for (i=0;i<3;i++) fRmax[i] = sa[i];
2007 R__b.ReadStaticArray(sa); for (i=0;i<3;i++) fRmin[i] = sa[i];
2008 R__b.ReadStaticArray(sa); for (i=0;i<12;i++) fTnorm[i] = sa[i];
2009 R__b.ReadStaticArray(sa); for (i=0;i<12;i++) fTback[i] = sa[i];
2010 R__b.ReadStaticArray(sa); for (i=0;i<3;i++) fX1[i] = sa[i];
2011 R__b.ReadStaticArray(sa); for (i=0;i<3;i++) fX2[i] = sa[i];
2012 R__b.ReadStaticArray(sa); for (i=0;i<3;i++) fY1[i] = sa[i];
2013 R__b.ReadStaticArray(sa); for (i=0;i<3;i++) fY2[i] = sa[i];
2014 R__b.ReadStaticArray(sa); for (i=0;i<3;i++) fZ1[i] = sa[i];
2015 R__b.ReadStaticArray(sa); for (i=0;i<3;i++) fZ2[i] = sa[i];
2016 R__b >> fOutline;
2017 R__b >> fDefaultOutline;
2018 R__b >> fAutoRange;
2019 } else {
2020 TObject::Streamer(R__b);
2021 TAttLine::Streamer(R__b);
2022 R__b >> fLatitude;
2023 R__b >> fLongitude;
2024 R__b >> fPsi;
2025 R__b.ReadStaticArray(fTN);
2026 R__b.ReadStaticArray(fTB);
2027 R__b.ReadStaticArray(fRmax);
2028 R__b.ReadStaticArray(fRmin);
2029 R__b.ReadStaticArray(fTnorm);
2030 R__b.ReadStaticArray(fTback);
2031 R__b.ReadStaticArray(fX1);
2032 R__b.ReadStaticArray(fX2);
2033 R__b.ReadStaticArray(fY1);
2034 R__b.ReadStaticArray(fY2);
2035 R__b.ReadStaticArray(fZ1);
2036 R__b.ReadStaticArray(fZ2);
2037 R__b >> fSystem;
2038 R__b >> fOutline;
2039 R__b >> fDefaultOutline;
2040 R__b >> fAutoRange;
2041 }
2042 //====end of old versions
2043
2044 } else {
2045 R__b.WriteClassBuffer(TView::Class(),this);
2046 //BesTView::Class()->WriteBuffer(R__b,this);
2047 }
2048}
ClassImp(BesTView) const Int_t kCARTESIAN
const Double_t kRad
Definition: BesTView.cxx:34
const Int_t kPOLAR
Definition: BesTView.cxx:33
Double_t phi2
Double_t x[10]
Double_t phi1
XmlRpcServer s
Definition: HelloServer.cpp:11
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
Definition: KarLud.h:35
TTree * t
Definition: binning.cxx:23
Double_t fZ2[3]
Definition: BesTView.h:53
Int_t GetSystem()
Definition: BesTView.h:105
virtual void FrontView(TVirtualPad *pad=0)
Definition: BesTView.cxx:1706
virtual Int_t GetDistancetoAxis(Int_t axis, Int_t px, Int_t py, Double_t &ratio)
Definition: BesTView.cxx:1053
Double_t fRmin[3]
Definition: BesTView.h:44
Double_t fVpix
Definition: BesTView.h:40
virtual void TopView(TVirtualPad *pad=0)
Definition: BesTView.cxx:1712
Double_t fUpix
Definition: BesTView.h:39
virtual void SetOutlineToCube()
Definition: BesTView.cxx:1397
virtual void WCtoNDC(const Float_t *pw, Float_t *pn)
Definition: BesTView.cxx:1607
virtual void UnzoomView(TVirtualPad *pad=0, Double_t unZoomFactor=1.25)
Definition: BesTView.cxx:1770
virtual void SetAxisNDC(const Double_t *x1, const Double_t *x2, const Double_t *y1, const Double_t *y2, const Double_t *z1, const Double_t *z2)
Definition: BesTView.cxx:1359
@ kPerspective
Definition: BesTView.h:69
Double_t fRmax[3]
Definition: BesTView.h:43
Int_t fSystem
Definition: BesTView.h:54
Bool_t IsClippedNDC(Double_t *p) const
Definition: BesTView.cxx:1166
virtual void FindNormal(Double_t x, Double_t y, Double_t z, Double_t &zn)
Definition: BesTView.cxx:875
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Definition: BesTView.cxx:737
virtual void AdjustScales(TVirtualPad *pad=0)
Definition: BesTView.cxx:1737
virtual void FindPhiSectors(Int_t iopt, Int_t &kphi, Double_t *aphi, Int_t &iphi1, Int_t &iphi2)
Definition: BesTView.cxx:893
void SetWindow(Double_t u0, Double_t v0, Double_t du, Double_t dv)
Definition: BesTView.cxx:1516
Bool_t fChanged
Definition: BesTView.h:58
Double_t GetExtent() const
Definition: BesTView.cxx:1124
virtual void ToggleRulers(TVirtualPad *pad=0)
Definition: BesTView.cxx:1718
Double_t fY2[3]
Definition: BesTView.h:51
virtual void DefinePerspectiveView()
Definition: BesTView.cxx:466
virtual void ToggleZoom(TVirtualPad *pad=0)
Definition: BesTView.cxx:1727
Double_t fPsi
Definition: BesTView.h:36
virtual void Centered3DImages(TVirtualPad *pad=0)
Definition: BesTView.cxx:1754
virtual void NDCtoWC(const Float_t *pn, Float_t *pw)
Definition: BesTView.cxx:1177
TSeqCollection * fOutline
Definition: BesTView.h:55
void ResizePad()
Definition: BesTView.cxx:1534
virtual void AxisVertex(Double_t ang, Double_t *av, Int_t &ix1, Int_t &ix2, Int_t &iy1, Int_t &iy2, Int_t &iz1, Int_t &iz2)
Definition: BesTView.cxx:332
Double_t fLatitude
Definition: BesTView.h:34
Double_t fDproj
Definition: BesTView.h:38
virtual void ZoomView(TVirtualPad *pad=0, Double_t zoomFactor=1.25)
Definition: BesTView.cxx:1778
virtual void SetRange(const Double_t *min, const Double_t *max)
Definition: BesTView.cxx:1454
virtual void RotateView(Double_t phi, Double_t theta, TVirtualPad *pad=0)
Definition: BesTView.cxx:1679
virtual void NormalWCtoNDC(const Float_t *pw, Float_t *pn)
Definition: BesTView.cxx:1209
Double_t fDview
Definition: BesTView.h:37
Bool_t IsPerspective() const
Definition: BesTView.h:113
Double_t fTB[16]
Definition: BesTView.h:42
static void AdjustPad(TVirtualPad *pad=0)
Definition: BesTView.cxx:1668
virtual void ZoomOut()
Definition: BesTView.cxx:1958
void MoveFocus(Double_t *center, Double_t dx, Double_t dy, Double_t dz, Int_t nsteps=10, Double_t dlong=0, Double_t dlat=0, Double_t dpsi=0)
Definition: BesTView.cxx:1800
Double_t fX1[3]
Definition: BesTView.h:48
Bool_t fDefaultOutline
Definition: BesTView.h:56
Double_t GetPsi()
Definition: BesTView.h:96
Double_t fTN[16]
Definition: BesTView.h:41
Bool_t fAutoRange
Definition: BesTView.h:57
Double_t fTback[16]
Definition: BesTView.h:47
virtual void PadRange(Int_t rback)
Definition: BesTView.cxx:1269
BesTView()
Definition: BesTView.cxx:39
Double_t fX2[3]
Definition: BesTView.h:49
virtual void SetParallel()
Definition: BesTView.cxx:1433
void SetDefaultWindow()
Definition: BesTView.cxx:1376
virtual void GetRange(Float_t *min, Float_t *max)
Definition: BesTView.cxx:1138
Double_t fZ1[3]
Definition: BesTView.h:52
void ResetView(Double_t longitude, Double_t latitude, Double_t psi, Int_t &irep)
Definition: BesTView.cxx:1554
virtual void SideView(TVirtualPad *pad=0)
Definition: BesTView.cxx:1700
virtual void DefineViewDirection(const Double_t *s, const Double_t *c, Double_t cosphi, Double_t sinphi, Double_t costhe, Double_t sinthe, Double_t cospsi, Double_t sinpsi, Double_t *tnorm, Double_t *tback)
Definition: BesTView.cxx:600
virtual void SetView(Double_t longitude, Double_t latitude, Double_t psi, Int_t &irep)
Definition: BesTView.cxx:1526
Double_t fUVcoord[4]
Definition: BesTView.h:45
virtual void ExecuteRotateView(Int_t event, Int_t px, Int_t py)
Definition: BesTView.cxx:745
Double_t fTnorm[16]
Definition: BesTView.h:46
virtual void SetPerspective()
Definition: BesTView.cxx:1443
virtual void MoveViewCommand(Char_t chCode, Int_t count=1)
Definition: BesTView.cxx:1855
void MoveWindow(Char_t option)
Definition: BesTView.cxx:1901
virtual void ZoomIn()
Definition: BesTView.cxx:1939
virtual void DrawOutlineCube(TList *outline, Double_t *rmin, Double_t *rmax)
Definition: BesTView.cxx:728
Double_t fLongitude
Definition: BesTView.h:35
virtual void FindThetaSectors(Int_t iopt, Double_t phi, Int_t &kth, Double_t *ath, Int_t &ith1, Int_t &ith2)
Definition: BesTView.cxx:960
void GetWindow(Double_t &u0, Double_t &v0, Double_t &du, Double_t &dv) const
Definition: BesTView.cxx:1156
virtual void FindScope(Double_t *scale, Double_t *center, Int_t &irep)
Definition: BesTView.cxx:1031
Double_t fY1[3]
Definition: BesTView.h:50
virtual ~BesTView()
Definition: BesTView.cxx:134
BesTView & operator=(const BesTView &)
Definition: BesTView.cxx:93
double y[1000]
const double b
Definition: slope.cxx:9