/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/EventDisplay/BesVisLib/BesVisLib-00-04-04/src/Bes2DView.cxx

Go to the documentation of this file.
00001 //
00002 // Bes2DView.cxx
00003 //
00004 // $Author: maqm $
00005 // $Date: 2011/03/09 07:22:53 $
00006 // $Revision: 1.7 $
00007 //
00008 
00009 #include "BesVisLib/Bes2DView.h"
00010 #include <iostream>
00011 
00012 #ifndef ROOT_TGeometry
00013 #include <TGeometry.h>
00014 #endif
00015 
00016 #ifndef ROOT_TPad
00017 #include <TPad.h>
00018 #endif
00019 
00020 // #ifndef ROOT_TVirtualPS
00021 // #include <TVirtualPS.h>
00022 // #endif
00023 
00024 #ifndef ROOT_TPaveLabel
00025 #include <TPaveLabel.h>
00026 #endif
00027 
00028 #ifndef ROOT_TROOT
00029 #include <TROOT.h>
00030 #endif
00031 
00032 #ifndef ROOT_TMath
00033 #include <TMath.h>
00034 #endif
00035 #include <TCanvas.h>
00036 
00037 using namespace std;
00038 
00039 #ifndef __CINT__
00040 ClassImp(Bes2DView)
00041 #endif
00042 
00043 //_____________________________________________________
00044 // Bes2DView
00045 // View class designed for the Bes event display
00046 //
00047 Bes2DView::Bes2DView() : BesTView(1) {
00048     //
00049     // Bes2DView normal constructor
00050     if ( gDebug ) cout << "Bes2DView normal ctor called" << endl;
00051 
00052     // init Label
00053     fLabel = new TPaveLabel(0.02,0.17,0.02,0.09,"3D View");
00054     fLabel->SetFillColor(42);
00055 
00056 
00057     // init status of 3D view
00058     fStatus3D = new BesStatus();
00059     fStatus3D->Default(k3DView);
00060 
00061     // init status of XY view
00062     fStatusXY = new BesStatus();
00063     fStatusXY->Default(kXYView);
00064 
00065     // init status of ZR view
00066     fStatusZR = new BesStatus();
00067     fStatusZR->Default(kZRView);
00068 
00069     // init status of current view
00070     fStatusCurrent = new BesStatus();
00071 
00072     // Init
00073     f2DViewType = 0;  // XY:0, ZR:1;
00074     fStatusCurrent->Transfer(fStatus3D,1);
00075     SetRange(-200,-200,-200,200,200,200);
00076     fZoomFactor = 1.5;
00077 
00078     fMarkerSize = 0.1;
00079 }
00080 
00081 //_____________________________________________________
00082 
00083 Bes2DView::~Bes2DView() {
00084     //
00085     // Bes2DView default destructor
00086     if ( gDebug ) cout << "Bes2DView default dtor called" << endl;
00087 
00088     delete fLabel;
00089 
00090     delete fStatus3D;
00091     delete fStatusXY;
00092     delete fStatusZR;
00093     delete fStatusCurrent;
00094 
00095 }
00096 
00097 //_____________________________________________________
00098 
00099 void Bes2DView::ClearPad() {
00100     //
00101     // Clear current without deleting this view
00102     //
00103     // Probably this doesn't work for the postscript output
00104     // Look at TPad::Clear() for more details
00105     if ( gDebug ) cout << "Bes2DView::ClearPad called" << endl;
00106     if ( gPad->GetListOfPrimitives() ) gPad->GetListOfPrimitives()->Clear();
00107 }
00108 
00109 //_____________________________________________________
00110 
00111 void Bes2DView::ExecuteEvent(Int_t event, Int_t px, Int_t py) {
00112     //
00113     // Execute mouse events
00114     if ( gDebug ) cout << "Bes2DView::ExecuteEvent called" << endl;
00115     //cout << "f2DViewType " << f2DViewType << "  k3DView " << k3DView << endl;
00116 
00117     /*
00118     if ( fViewType & k3DView ) {
00119       ExecuteRotateView(event, px, py);
00120     } else {
00121     */
00122 
00123     // Editor mode
00124     if (gROOT->GetEditorMode()) {
00125         cout << "ROOT" << endl;
00126         gPad->ExecuteEvent(event,px,py);
00127         return;
00128     }
00129 
00130     static Double_t xmin, ymin, xmax, ymax, x0, y0;
00131     Double_t dx, dy, x, y;
00132     switch (event) {
00133 
00134     case kButton1Down:
00135         gPad->SetCursor(kMove);
00136         // Remember position of pointer
00137         xmin = gPad->GetX1();
00138         ymin = gPad->GetY1();
00139         xmax = gPad->GetX2();
00140         ymax = gPad->GetY2();
00141         x0   = gPad->AbsPixeltoX(px);
00142         y0   = gPad->AbsPixeltoY(py);
00143         break;
00144 
00145     case kButton1Motion:
00146         gPad->SetCursor(kMove);
00147 
00148     case kButton1Up:
00149         // Set new pad range
00150         x  = gPad->AbsPixeltoX(px);
00151         y  = gPad->AbsPixeltoY(py);
00152         dx = -(x - x0);
00153         dy = -(y - y0);
00154         //((TPad*)gPad)->SetNoAspect(kTRUE);
00155         gPad->Range(xmin+dx, ymin+dy, xmax+dx, ymax+dy);
00156         //((TPad*)gPad)->SetNoAspect(kFALSE);
00157         gPad->Modified();
00158         break;
00159 
00160     default:
00161         gPad->SetCursor(kCross);
00162     }
00163 }
00164 
00165 //_____________________________________________________
00166 
00167 void Bes2DView::Move(Int_t px, Int_t py) {
00168     //
00169     // Move (px, py in pixel coordinates)
00170     Double_t x1, y1, x2, y2, dx, dy, x, y, x0, y0;
00171     x1 = gPad->GetX1();
00172     y1 = gPad->GetY1();
00173     x2 = gPad->GetX2();
00174     y2 = gPad->GetY2();
00175     x0 = gPad->PixeltoX(0);
00176     y0 = gPad->PixeltoY(0);
00177     x = gPad->PixeltoX(px);
00178     y = gPad->PixeltoY(py);
00179     dx = -(x - x0);
00180     dy = -(y - y0);
00181     //((TPad*)gPad)->SetNoAspect(kTRUE);
00182     gPad->Range(x1+dx, y1+dy, x2+dx, y2+dy);
00183     //((TPad*)gPad)->SetNoAspect(kFALSE);
00184     gPad->Modified();
00185 }
00186 
00187 //_____________________________________________________
00188 
00189 void Bes2DView::Center() {
00190     //
00191     // Center view
00192     /*
00193     if ( fViewType & k3DView ){
00194       this->Centered();
00195     } else {
00196     */
00197     Double_t xrange, yrange;
00198     xrange = gPad->GetX2() - gPad->GetX1();
00199     yrange = gPad->GetY2() - gPad->GetY1();
00200     gPad->Range(-xrange/2, -yrange/2, xrange/2, yrange/2);
00201     gPad->Modified();
00202 }
00203 
00204 //_____________________________________________________
00205 
00206 void Bes2DView::Zoom() {
00207     //
00208     // Magnify
00209     fMarkerSize = fMarkerSize * fZoomFactor;
00210     ZoomView(gPad, fZoomFactor);
00211 }
00212 
00213 //_____________________________________________________
00214 
00215 void Bes2DView::UnZoom() {
00216     //
00217     // Demagnify
00218     fMarkerSize = fMarkerSize / fZoomFactor;
00219     UnzoomView(gPad, fZoomFactor);
00220 }
00221 
00222 //_____________________________________________________
00223 
00224 Int_t Bes2DView::GetRSign(Float_t Phi) {
00225     //
00226     // Get sign of the R coordinate (ZR view)
00227     // for a given phi (in radians)
00228     Int_t Sign;
00229 
00230     // Convert to deg, because phi range is given in degrees
00231     Float_t Phi2 = (Phi - 2*TMath::Pi()*Int_t(Phi/(2*TMath::Pi())))
00232                    * 180./TMath::Pi();
00233     if ( Phi2 < 0 ) Phi2 += 360;
00234     if ( Phi2 >= fStatusCurrent->fPhiRangeMin && Phi2 < fStatusCurrent->fPhiRangeMax ) {
00235         Sign = 1;
00236     } else {
00237         Sign = -1;
00238     }
00239     return Sign;
00240 }
00241 
00242 
00243 //_____________________________________________________
00244 
00245 void Bes2DView::UpdateView(Bool_t resetview) {
00246     //
00247     // Update current view
00248     if ( !gGeometry ) return;
00249 
00250     // Redraw
00251     //SetViewType(fViewType,resetview);
00252 }
00253 
00254 
00255 
00256 
00257 void Bes2DView::DrawLabel() {
00258     //
00259     // Draw label for current view
00260 
00261     fLabel->SetX1NDC(0.05);
00262     fLabel->SetX2NDC(0.20);
00263     fLabel->SetY1NDC(0.05);
00264     fLabel->SetY2NDC(0.12);
00265 
00266     switch (f2DViewType) {
00267         //case k3DView:
00268         //fLabel->SetLabel("3D View");
00269         //break;
00270     case 0:
00271         fLabel->SetLabel("XY View");
00272         break;
00273     case 1:
00274         fLabel->SetLabel("ZR View");
00275         break;
00276     }
00277     fLabel->Draw("BR,NDC,SAME");
00278 }
00279 
00280 //_____________________________________________________
00281 
00282 void Bes2DView::WCtoNDC(const Float_t *pw, Float_t *pn) {
00283     //
00284     // Transform world coordinates to
00285     // normalised device coordinates.
00286     // This method was taken from BesTView
00287     // and extended by FishEye view
00288     BesTView::WCtoNDC(pw, pn);
00289     //cout << "fFishEye " << fFishEye << endl;
00290 
00291     if ( fStatusCurrent->fFishEye == kTRUE ) {
00292         Float_t r, s;
00293         if ( f2DViewType == 1) {
00294             Float_t pvWC[3], pvNDC[3];
00295             pvWC[0] = +4;
00296             pvWC[1] = 0;
00297             pvWC[2] = 0;
00298             BesTView::WCtoNDC(pvWC, pvNDC);
00299             pn[0] = TMath::Sign(Double_t(TMath::Sqrt(TMath::Abs(pn[0] - pvNDC[0]))),
00300                                 Double_t(pn[0] - pvNDC[0])) + pvNDC[0];
00301             pn[1] = TMath::Sign(Double_t(TMath::Sqrt(TMath::Abs(pn[1] - pvNDC[1]))),
00302                                 Double_t(pn[1] - pvNDC[1])) + pvNDC[1];
00303         } else {
00304             r = TMath::Sqrt(TMath::Power(pn[0],2)
00305                             +TMath::Power(pn[1],2));
00306             s = TMath::Sqrt(r)/r;
00307             pn[0] *= s;
00308             pn[1] *= s;
00309         }
00310     }
00311 }
00312 
00313 //_____________________________________________________
00314 
00315 void Bes2DView::WCtoNDC(const Double_t *pw, Double_t *pn) {
00316     //
00317     // Transform world coordinates to
00318     // normalised device coordinates.
00319     // This method was taken from BesTView
00320     // and extended by FishEye view
00321     BesTView::WCtoNDC(pw, pn);
00322 
00323     if ( fStatusCurrent->fFishEye == kTRUE ) {
00324         Double_t r, s;
00325         if ( f2DViewType == 1 ) {
00326             Double_t pvWC[3], pvNDC[3];
00327             pvWC[0] = +4;
00328             pvWC[1] = 0;
00329             pvWC[2] = 0;
00330             BesTView::WCtoNDC(pvWC, pvNDC);
00331             pn[0] = TMath::Sign(TMath::Sqrt(TMath::Abs(pn[0] - pvNDC[0])),
00332                                 pn[0] - pvNDC[0]) + pvNDC[0];
00333             pn[1] = TMath::Sign(TMath::Sqrt(TMath::Abs(pn[1] - pvNDC[1])),
00334                                 pn[1] - pvNDC[1]) + pvNDC[1];
00335         } else {
00336 
00337             r = TMath::Sqrt(TMath::Power(pn[0],2)
00338                             +TMath::Power(pn[1],2));
00339             s = TMath::Sqrt(r)/r;
00340             pn[0] *= s;
00341             pn[1] *= s;
00342         }
00343     }
00344 }
00345 
00346 //_____________________________________________________
00347 
00348 void Bes2DView::NDCtoWC(const Float_t* pn, Float_t* pw) {
00349     //
00350     // Transform back from NDCs
00351     Float_t p[3];
00352     if (f2DViewType == 0) { // XYView
00353         p[0] = pn[0];
00354         p[1] = pn[1];
00355         p[2] = pn[2];
00356     }
00357     else {                // ZRView
00358         p[0] = pn[2];
00359         p[1] = pn[1];
00360         p[2] = pn[0];
00361     }
00362 
00363     if ( fStatusCurrent->fFishEye == kTRUE ) {
00364         Float_t r;
00365         if ( f2DViewType == 1 ) {
00366             Float_t pvWC[3], pvNDC[3];
00367             pvWC[0] = +4;
00368             pvWC[1] = 0;
00369             pvWC[2] = 0;
00370             BesTView::WCtoNDC(pvWC, pvNDC);
00371             p[0] = TMath::Sign((pn[0] - pvNDC[0])*(pn[0] - pvNDC[0]),
00372                                pn[0] - pvNDC[0]) + pvNDC[0];
00373             p[1] = TMath::Sign((pn[1] - pvNDC[1])*(pn[1] - pvNDC[1]),
00374                                pn[1] - pvNDC[1]) + pvNDC[1];
00375         } else {
00376             r = TMath::Sqrt(TMath::Power(p[0],2)
00377                             +TMath::Power(p[1],2));
00378             p[0] *= r;
00379             p[1] *= r;
00380         }
00381     }
00382     BesTView::NDCtoWC(p, pw);
00383 }
00384 
00385 //_____________________________________________________
00386 
00387 void Bes2DView::NDCtoWC(const Double_t* pn, Double_t* pw) {
00388     //
00389     // Transform back from NDCs
00390     Double_t p[3];
00391     if (f2DViewType == 0) { // XYView
00392         p[0] = pn[0];
00393         p[1] = pn[1];
00394         p[2] = pn[2];
00395     }
00396     else {                // ZRView
00397         p[0] = pn[2];
00398         p[1] = pn[1];
00399         p[2] = pn[0];
00400     }
00401 
00402     if ( fStatusCurrent->fFishEye == kTRUE ) {
00403         Double_t r;
00404         if ( f2DViewType == 1 ) {
00405             Double_t pvWC[3], pvNDC[3];
00406             pvWC[0] = +4;
00407             pvWC[1] = 0;
00408             pvWC[2] = 0;
00409             BesTView::WCtoNDC(pvWC, pvNDC);
00410             p[0] = TMath::Sign((pn[0] - pvNDC[0])*(pn[0] - pvNDC[0]),
00411                                pn[0] - pvNDC[0]) + pvNDC[0];
00412             p[1] = TMath::Sign((pn[1] - pvNDC[1])*(pn[1] - pvNDC[1]),
00413                                pn[1] - pvNDC[1]) + pvNDC[1];
00414         } else {
00415             r = TMath::Sqrt(TMath::Power(p[0],2)
00416                             +TMath::Power(p[1],2));
00417             p[0] *= r;
00418             p[1] *= r;
00419         }
00420     }
00421     BesTView::NDCtoWC(p, pw);
00422 }
00423 
00424 //_____________________________________________________
00425 
00426 char *Bes2DView::GetObjectInfo(Int_t px, Int_t py) const {
00427     //
00428     // Returns string containing info about the object at position (px,py).
00429     Double_t pw[3];
00430     //((TPad*)gPad)->PixeltoWC(px, py, pw);
00431 
00432     static char info[64];
00433     if ( f2DViewType == 1 ) {
00434         sprintf(info, "z=%-.3fcm, r=%-.3fcm", pw[0], pw[1]);
00435         return info;
00436     } else {
00437         sprintf(info, "x=%-.3fcm, y=%-.3fcm", pw[0], pw[1]);
00438         return info;
00439     }
00440 }
00441 
00442 //_____________________________________________________
00443 
00444 void Bes2DView::Reset() {
00445     //
00446     // reset view to default values
00447 
00448     // reset status instances of views
00449     //fStatus3D->Default(k3DView);
00450     //fStatusXY->Default(kXYView);
00451     //fStatusZR->Default(kZRView);
00452     fZoomFactor = 1.5;
00453 
00454     // reset current status instance tp fViewType
00455     //fStatusCurrent->Default(fViewType);
00456 
00457     // center the view
00458     this->Center();
00459     this->SetRange(-2635,-2635,-2875,2635,2635,2875);
00460     //int iret;
00461     //this->SetView(0,0,270,iret);
00462     this->ZoomView(gPad, 1.5);
00463 
00464     // reset phirange
00465     //  this->SetPhiRange(0,180);
00466     //this->UpdateView();
00467     gPad->Update();
00468 }

Generated on Tue Nov 29 23:12:04 2016 for BOSS_7.0.2 by  doxygen 1.4.7