TAxis3D.cxx

Go to the documentation of this file.
00001 // @(#)root/g3d:$Id: TAxis3D.cxx 36245 2010-10-10 10:07:28Z brun $
00002 // Author: Valery Fine(fine@mail.cern.ch)   07/01/2000
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include <ctype.h>
00013 #include <assert.h>
00014 
00015 #include "Riostream.h"
00016 #include "TMath.h"
00017 #include "TList.h"
00018 #include "TClass.h"
00019 #include "TAxis3D.h"
00020 #include "TCanvas.h"
00021 #include "TPad.h"
00022 #include "TGaxis.h"
00023 #include "TView.h"
00024 #include "TVirtualPad.h"
00025 #include "TVirtualX.h"
00026 #include "TBrowser.h"
00027 #include "TStyle.h"
00028 
00029 //______________________________________________________________________________
00030 //   The 3D axis painter class
00031 //   ==========================
00032 //
00033 //  This class provide up to 3 axice to any 3D ROOT plot and
00034 //  "ZOOM" service.
00035 //  ExecuteEvent() method does provide zooming and moving a projection
00036 //  3D object within TPad client area. With Zoom mode on the user can access
00037 //  TAxis3D context menu and set /change the attributes of axice all together
00038 //  or separately.
00039 //
00040 //  To add the 3D rulers to any 3D view one has to create
00041 //  an instance of this class and Draw it.
00042 //
00043 //   TAxis3D rulers;
00044 //   rulers.Draw();
00045 //
00046 //  One can use a static method to create ruler and attach it to the current gPad
00047 //
00048 //   TAxis3D::ToggleRulers(); // Brings the 3D axice up
00049 //   TAxis3D::ToggleRulers(); // next calls remove the rulers from the TPad etc
00050 //
00051 //   To activate Zoomer one may call
00052 //
00053 //   TAxis3D::ToggleZoom();
00054 //
00055 //  each time one needs move or zoom the image. Then the user can:
00056 //    -  move:
00057 // Begin_Html <P ALIGN=CENTER> <IMG SRC="gif/MovePicture.gif"> </P> End_Html
00058 //    -  zoom:
00059 // Begin_Html <P ALIGN=CENTER> <IMG SRC="gif/ZoomPicture.gif"> </P> End_Html
00060 //  its 3D view with <left-mouse button> press / move.
00061 //  The "Zoom" deactivates itself just the user release the <left-mouse button>
00062 //
00063 //  To change attributes of the rulers attached to the current Pad, one may
00064 //  query its pointer first:
00065 //
00066 //  TAxis3D *axis = TAxis3D::GetPadAxis(); // Ask axis pointer
00067 //  if (axis) {
00068 //    TAxis3D::ToggleRulers()     // To pop axice down
00069 //    axis->SetLabelColor(kBlue); // Paint the axice labels with blue color
00070 //    axis->SetAxisColor(kRed);   // Paint the axice itself with blue color
00071 //    TAxis3D::ToggleRulers()     // To pop axice up
00072 //  }
00073 //
00074 // The attributes of the created axice are affected by the current style
00075 // (see TStyle class ) and Set... methods of this class
00076 //
00077 //  For example:
00078 //
00079 //   gStyle->SetAxisColor(kYellow,"X");
00080 //   gStyle->SetAxisColor(kYellow,"Y");
00081 //   gStyle->SetAxisColor(kYellow,"Z");
00082 //
00083 //   gStyle->SetLabelColor(kYellow,"X");
00084 //   gStyle->SetLabelColor(kYellow,"Y");
00085 //   gStyle->SetLabelColor(kYellow,"Z");
00086 //
00087 //   TAxis3D::ToggleRulers();
00088 //   TAxis3D::ToggleRulers();
00089 //
00090 //  will draw all axice and labels with yellow color.
00091 //
00092 
00093 const Char_t *TAxis3D::fgRulerName = "axis3druler";
00094 ClassImp(TAxis3D)
00095 
00096 
00097 //______________________________________________________________________________
00098 TAxis3D::TAxis3D() : TNamed(TAxis3D::fgRulerName,"ruler")
00099 {
00100    // Normal constructor.
00101 
00102    fSelected = 0;
00103    fZoomMode = kFALSE;
00104    fStickyZoom = kFALSE;
00105    InitSet();
00106 }
00107 
00108 
00109 //______________________________________________________________________________
00110 TAxis3D::TAxis3D(Option_t *) : TNamed(TAxis3D::fgRulerName,"ruler")
00111 {
00112    // Normal constructor.
00113 
00114    fSelected = 0;
00115    InitSet();
00116    fZoomMode = kFALSE;
00117    fStickyZoom = kFALSE;
00118 }
00119 
00120 
00121 //______________________________________________________________________________
00122 TAxis3D::TAxis3D(const TAxis3D &axis) : TNamed(axis)
00123 {
00124    // Copy  constructor.
00125 
00126    ((TAxis3D&)axis).Copy(*this);
00127 }
00128 
00129 
00130 //______________________________________________________________________________
00131 void TAxis3D::Copy(TObject &obj) const
00132 {
00133    // Copy axis3d
00134 
00135    TNamed::Copy(obj);
00136    for (Int_t i=0;i<2;i++) fAxis[i].Copy(((TAxis3D&)obj).fAxis[i]);
00137 }
00138 
00139 
00140 //______________________________________________________________________________
00141 void TAxis3D::InitSet()
00142 {
00143    // Initialization.
00144 
00145    fAxis[0].SetName("xaxis");
00146    fAxis[1].SetName("yaxis");
00147    fAxis[2].SetName("zaxis");
00148 
00149    fAxis[0].Set(1,0.,1.);
00150    fAxis[1].Set(1,0.,1.);
00151    fAxis[2].Set(1,0.,1.);
00152    UseCurrentStyle();
00153 }
00154 
00155 
00156 //______________________________________________________________________________
00157 void TAxis3D::Browse(TBrowser *b)
00158 {
00159    // Add all 3 axes to the TBrowser
00160 
00161    for (Int_t i=0;i<3;i++) b->Add(&fAxis[i],fAxis[i].GetTitle());
00162 }
00163 
00164 
00165 //______________________________________________________________________________
00166 Int_t TAxis3D::DistancetoPrimitive(Int_t px, Int_t py)
00167 {
00168    // Compute distance from point px,py to a line.
00169 
00170    Int_t dist = 9;
00171    for (int i=0;i<3;i++) {
00172       Int_t axDist = fAxis[i].DistancetoPrimitive(px,py);
00173       if (dist > axDist) { dist = axDist; fSelected = &fAxis[i]; }
00174    }
00175    if (fZoomMode)
00176       return 0;
00177    else
00178       return dist;
00179 }
00180 
00181 
00182 //______________________________________________________________________________
00183 void TAxis3D::ExecuteEvent(Int_t event, Int_t px, Int_t py)
00184 {
00185    // Execute action corresponding to one event.
00186    //
00187    // This member function is called when an axis is clicked with the locator
00188 
00189    if (fSelected) fSelected->ExecuteEvent(event,px,py);
00190 
00191    // Execute action corresponding to the mouse event
00192 
00193    static Double_t x0, y0, x1, y1;
00194 
00195    static Int_t pxold, pyold;
00196    static Int_t px0, py0;
00197    static Int_t linedrawn;
00198 
00199    if (!fZoomMode) return;
00200 
00201    // something to zoom ?
00202 
00203    gPad->SetCursor(kCross);
00204 
00205    switch (event) {
00206 
00207    case kButton1Down:
00208       gVirtualX->SetLineColor(-1);
00209       gPad->TAttLine::Modify();  //Change line attributes only if necessary
00210       ((TPad *)gPad)->AbsPixeltoXY(px,py,x0,y0);
00211       px0   = px; py0   = py;
00212       pxold = px; pyold = py;
00213       linedrawn = 0;
00214       break;
00215 
00216    case kButton1Motion:
00217       if (linedrawn) gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
00218       pxold = px;
00219       pyold = py;
00220       linedrawn = 1;
00221       gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
00222       break;
00223 
00224    case kButton1Up: {
00225       Int_t i;
00226       gPad->SetDoubleBuffer(1);
00227       gVirtualX->SetDrawMode(TVirtualX::kCopy); // set drawing mode back to normal (copy) mode
00228       TView *view = gPad->GetView();
00229       if (!view) break;                       // no 3D view yet
00230 
00231       Double_t min[3],max[3],viewCenter[3],viewCenterNDC[3];
00232 
00233       view->GetRange(min,max);
00234       for (i =0; i<3;i++) viewCenter[i] = (max[i]+min[i])/2;
00235       view->WCtoNDC(viewCenter,viewCenterNDC);
00236       // Define the center
00237       Double_t center[3],pointNDC[3],size[3],oldSize[3];
00238       ((TPad *)gPad)->AbsPixeltoXY(px,py,x1,y1);
00239       pointNDC[0] = (x0+x1)/2; pointNDC[1] = (y0+y1)/2;
00240       pointNDC[2] = viewCenterNDC[2];
00241       view->NDCtoWC(pointNDC, center);
00242 
00243       for (i =0; i<3;i++) oldSize[i] = size[i]= (max[i]-min[i])/2;
00244 
00245       // If there was a small motion, move the center only, do not change a scale
00246       if (TMath::Abs(px-px0)+TMath::Abs(py - py0) > 4 ) {
00247          Double_t newEdge[3];
00248          for (i =0; i<3;i++) size[i] = -1;
00249 
00250          pointNDC[0] = x0; pointNDC[1] = y0;
00251 
00252          view->NDCtoWC(pointNDC, newEdge);
00253          for (i =0; i<3;i++) {
00254             Double_t newSize = TMath::Abs(newEdge[i]-center[i]);
00255             if ( newSize/oldSize[i] > 0.002)
00256                size[i] = TMath::Max(size[i], newSize);
00257             else
00258                size[i] = oldSize[i];
00259          }
00260 
00261          pointNDC[0] = x1; pointNDC[1] = y1;
00262 
00263          view->NDCtoWC(pointNDC, newEdge);
00264          for (i =0; i<3;i++) {
00265             Double_t newSize = TMath::Abs(newEdge[i]-center[i]);
00266             if ( newSize/oldSize[i] > 0.002)
00267                size[i] = TMath::Max(size[i], newSize);
00268             else
00269                size[i] = oldSize[i];
00270          }
00271 #if 0
00272          if (fZooms == kMAXZOOMS) fZoom = 0;
00273          fZooms++;
00274          memcpy(fZoomMin[fZooms],min,3*sizeof(Float_t));
00275          memcpy(fZoomMax[fZooms],max,3*sizeof(Float_t));
00276 #endif
00277       }
00278       for (i =0; i<3;i++) {
00279          max[i] = center[i] + size[i];
00280          min[i] = center[i] - size[i];
00281       }
00282       view->SetRange(min,max);
00283 
00284       if(!fStickyZoom)SwitchZoom();
00285          gPad->Modified(kTRUE);
00286          gPad->Update();
00287          break;
00288       }
00289       default: break;
00290    }
00291 }
00292 
00293 
00294 //______________________________________________________________________________
00295 char *TAxis3D::GetObjectInfo(Int_t , Int_t ) const
00296 {
00297    //  Dummy method
00298    //  returns the const char * to "axis3d"
00299 
00300    return (char*)"axis3d";
00301 }
00302 
00303 
00304 //______________________________________________________________________________
00305 void TAxis3D::Paint(Option_t *)
00306 {
00307    // Paint axis over 3D view on the TPad
00308 
00309    TGaxis axis;
00310    PaintAxis(&axis, 90);
00311 }
00312 
00313 
00314 //______________________________________________________________________________
00315 void TAxis3D::PaintAxis(TGaxis *axis, Float_t ang)
00316 {
00317    // Draw the axis for TView object.
00318    //
00319    // The original idea belongs:
00320    //
00321    // void THistPainter::PaintLegoAxis(TGaxis *axis, Double_t ang)
00322 
00323    static Double_t epsil = 0.001;
00324 
00325    Double_t cosa, sina;
00326    Double_t bmin, bmax;
00327    Double_t r[24]       /* was [3][8] */;
00328    Int_t ndiv, i;
00329    Double_t x1[3], x2[3], y1[3], y2[3], z1[3], z2[3], av[24]  /*  was [3][8] */;
00330    char chopax[10];
00331    Int_t ix1, ix2, iy1, iy2, iz1, iz2;
00332    Double_t rad;
00333 
00334    TView *view = gPad->GetView();
00335    if (!view) {
00336       Error("PaintAxis", "no TView in current pad");
00337       return;
00338    }
00339 
00340    rad  = TMath::ATan(1.) * 4. / 180.;
00341    cosa = TMath::Cos(ang*rad);
00342    sina = TMath::Sin(ang*rad);
00343 
00344    view->AxisVertex(ang, av, ix1, ix2, iy1, iy2, iz1, iz2);
00345    for (i = 1; i <= 8; ++i) {
00346       r[i*3 - 3] = av[i*3 - 3] + av[i*3 - 2]*cosa;
00347       r[i*3 - 2] = av[i*3 - 2]*sina;
00348       r[i*3 - 1] = av[i*3 - 1];
00349    }
00350 
00351    view->WCtoNDC(&r[ix1*3 - 3], x1);
00352    view->WCtoNDC(&r[ix2*3 - 3], x2);
00353    view->WCtoNDC(&r[iy1*3 - 3], y1);
00354    view->WCtoNDC(&r[iy2*3 - 3], y2);
00355    view->WCtoNDC(&r[iz1*3 - 3], z1);
00356    view->WCtoNDC(&r[iz2*3 - 3], z2);
00357 
00358    view->SetAxisNDC(x1, x2, y1, y2, z1, z2);
00359 
00360    Double_t *rmin = view->GetRmin();
00361    Double_t *rmax = view->GetRmax();
00362 
00363    axis->SetLineWidth(1);
00364 
00365    for (i=0;i<3;i++) {
00366 
00367       // X axis drawing
00368       Double_t ax[2], ay[2];
00369       Bool_t logAx = kFALSE;
00370       memset(chopax,0,sizeof(chopax));
00371       switch (i) {
00372          case 0 :
00373             ax[0] = x1[0]; ax[1] = x2[0];
00374             ay[0] = x1[1]; ay[1] = x2[1];
00375             logAx = gPad->GetLogx();
00376             break;
00377          case 1 :
00378             if (TMath::Abs(y1[0] - y2[0]) < epsil)  y2[0] = y1[0];
00379             ax[0] = y1[0]; ax[1] = y2[0];
00380             ay[0] = y1[1]; ay[1] = y2[1];
00381             logAx = gPad->GetLogy();
00382             break;
00383          case 2 :
00384             ax[0] = z1[0]; ax[1] = z2[0];
00385             ay[0] = z1[1]; ay[1] = z2[1];
00386             strlcpy(chopax, "SDH+=",10);
00387             logAx = gPad->GetLogz();
00388             break;
00389          default:
00390             assert(0);
00391             continue;
00392       };
00393 
00394       // If the axis is too short - skip it
00395       if ( ( TMath::Abs(ax[0] - ax[1]) + TMath::Abs(ay[0] - ay[1]))  < epsil  ) continue;
00396 
00397       if (i != 2 ) {
00398          if (ax[0] > ax[1]) strlcpy(chopax, "SDHV=+",10);
00399          else               strlcpy(chopax, "SDHV=-",10);
00400       }
00401 
00402       if (i==1 && (TMath::Abs(z1[0] - z2[0]) + TMath::Abs(z1[1] - z2[1])) < epsil)
00403          strlcpy(chopax, "SDH+=",10);
00404 
00405       // Initialize the axis options
00406       if (logAx) {
00407          strlcat(chopax,"G",10);
00408          bmin = TMath::Power(10, rmin[i]);
00409          bmax = TMath::Power(10, rmax[i]);
00410       } else {
00411          bmin = rmin[i];
00412          bmax = rmax[i];
00413       }
00414 
00415       axis->SetLineColor(  fAxis[i].GetAxisColor());
00416       axis->SetTextFont(   fAxis[i].GetTitleFont());
00417       axis->SetTextColor(  fAxis[i].GetTitleColor());
00418       axis->SetTickSize(   fAxis[i].GetTickLength());
00419       axis->SetLabelColor( fAxis[i].GetLabelColor());
00420       axis->SetLabelFont(  fAxis[i].GetLabelFont());
00421       axis->SetLabelOffset(fAxis[i].GetLabelOffset()+fAxis[i].GetTickLength());
00422       axis->SetLabelSize(  fAxis[i].GetLabelSize());
00423       axis->SetTitle(      fAxis[i].GetTitle());
00424       axis->SetTitleOffset(fAxis[i].GetTitleOffset());
00425       axis->SetTitleSize(  fAxis[i].GetTitleSize());
00426       enum { kCenterTitle = BIT(12) }; // to be removed with the last version of ROOT
00427       axis->SetBit(kCenterTitle, fAxis[i].TestBit(kCenterTitle));
00428 
00429       //*-*-    Initialize the number of divisions. If the
00430       //*-*-    number of divisions is negative, option 'N' is required.
00431       ndiv = fAxis[i].GetNdivisions();
00432       if (ndiv < 0) {
00433          ndiv = -ndiv;
00434          chopax[6] = 'N';
00435       }
00436 
00437       // Option time display is required ?
00438       if (fAxis[i].GetTimeDisplay()) {
00439          strlcat(chopax,"t",10);
00440          if (strlen(fAxis[i].GetTimeFormatOnly()) == 0) {
00441             axis->SetTimeFormat(fAxis[i].ChooseTimeFormat(bmax-bmin));
00442          } else {
00443             axis->SetTimeFormat(fAxis[i].GetTimeFormat());
00444          }
00445       }
00446       axis->SetOption(chopax);
00447       axis->PaintAxis(ax[0], ay[0], ax[1], ay[1], bmin, bmax, ndiv, chopax);
00448    }
00449 }
00450 
00451 
00452 //______________________________________________________________________________
00453 Double_t *TAxis3D::PixeltoXYZ(Double_t px, Double_t py, Double_t *point3D, TView *view)
00454 {
00455    // Convert "screen pixel" coordinates to some center of 3D WC coordinate
00456    // if view and gPad present
00457 
00458    Double_t *thisPoint = 0;
00459    if (!view && gPad) view = gPad->GetView();
00460    if (view) {
00461       Double_t x[3] = {px,py,0.5}; // ((TPad *)thisPad)->AbsPixeltoXY(px,py,x[0],x[1]);
00462       Double_t min[3], max[3];
00463       view->GetRange(min,max);
00464       Int_t i;
00465       for (i =0; i<3;i++) min[i] = (max[i]+min[i])/2;
00466       view->WCtoNDC(min,max);
00467       min[0] = x[0]; min[1] = x[1];
00468       min[2] = max[2];
00469       view->NDCtoWC(min, x);
00470       for (i=0;i<3;i++) point3D[i] = x[i];
00471       thisPoint = point3D;
00472    }
00473    return thisPoint;
00474 }
00475 
00476 
00477 //______________________________________________________________________________
00478 void TAxis3D::SavePrimitive(ostream &out, Option_t * /*= ""*/)
00479 {
00480    // Save primitive as a C++ statement(s) on output stream out
00481 
00482    fAxis[0].SaveAttributes(out,GetName(),"->GetXaxis()");
00483    fAxis[1].SaveAttributes(out,GetName(),"->GetYaxis()");
00484    fAxis[2].SaveAttributes(out,GetName(),"->GetZaxis()");
00485 }
00486 
00487 
00488 //______________________________________________________________________________
00489 void TAxis3D::UseCurrentStyle()
00490 {
00491    // Replace current attributes by current style.
00492 
00493    if (gStyle->IsReading()) {
00494       fAxis[0].ResetAttAxis("X");
00495       fAxis[1].ResetAttAxis("Y");
00496       fAxis[2].ResetAttAxis("Z");
00497 
00498       fAxis[0].SetTitle("x");
00499       fAxis[0].SetLabelColor(kRed);   fAxis[0].SetAxisColor(kRed);
00500       fAxis[1].SetLabelColor(kGreen); fAxis[1].SetAxisColor(kGreen);
00501       fAxis[2].SetLabelColor(kBlue);  fAxis[2].SetAxisColor(kBlue);
00502    } else {
00503       gStyle->SetNdivisions (fAxis[0].GetNdivisions(), "x");
00504       gStyle->SetAxisColor  (fAxis[0].GetAxisColor(),  "x");
00505       gStyle->SetLabelColor (fAxis[0].GetLabelColor(), "x");
00506       gStyle->SetLabelFont  (fAxis[0].GetLabelFont(),  "x");
00507       gStyle->SetLabelOffset(fAxis[0].GetLabelOffset(),"x");
00508       gStyle->SetLabelSize  (fAxis[0].GetLabelSize(),  "x");
00509       gStyle->SetTickLength (fAxis[0].GetTickLength(), "x");
00510       gStyle->SetTitleOffset(fAxis[0].GetTitleOffset(),"x");
00511       gStyle->SetTitleSize  (fAxis[0].GetTitleSize(),  "x");
00512       gStyle->SetTitleColor (fAxis[0].GetTitleColor(), "x");
00513       gStyle->SetTitleFont  (fAxis[0].GetTitleFont(),  "x");
00514 
00515       gStyle->SetNdivisions (fAxis[1].GetNdivisions(), "y");
00516       gStyle->SetAxisColor  (fAxis[1].GetAxisColor(),  "y");
00517       gStyle->SetLabelColor (fAxis[1].GetLabelColor(), "y");
00518       gStyle->SetLabelFont  (fAxis[1].GetLabelFont(),  "y");
00519       gStyle->SetLabelOffset(fAxis[1].GetLabelOffset(),"y");
00520       gStyle->SetLabelSize  (fAxis[1].GetLabelSize(),  "y");
00521       gStyle->SetTickLength (fAxis[1].GetTickLength(), "y");
00522       gStyle->SetTitleOffset(fAxis[1].GetTitleOffset(),"y");
00523       gStyle->SetTitleSize  (fAxis[1].GetTitleSize(),  "y");
00524       gStyle->SetTitleColor (fAxis[1].GetTitleColor(), "y");
00525       gStyle->SetTitleFont  (fAxis[1].GetTitleFont(),  "y");
00526 
00527       gStyle->SetNdivisions (fAxis[2].GetNdivisions(), "z");
00528       gStyle->SetAxisColor  (fAxis[2].GetAxisColor(),  "z");
00529       gStyle->SetLabelColor (fAxis[2].GetLabelColor(), "z");
00530       gStyle->SetLabelFont  (fAxis[2].GetLabelFont(),  "z");
00531       gStyle->SetLabelOffset(fAxis[2].GetLabelOffset(),"z");
00532       gStyle->SetLabelSize  (fAxis[2].GetLabelSize(),  "z");
00533       gStyle->SetTickLength (fAxis[2].GetTickLength(), "z");
00534       gStyle->SetTitleOffset(fAxis[2].GetTitleOffset(),"z");
00535       gStyle->SetTitleSize  (fAxis[2].GetTitleSize(),  "z");
00536       gStyle->SetTitleColor (fAxis[2].GetTitleColor(), "z");
00537       gStyle->SetTitleFont  (fAxis[2].GetTitleFont(),  "z");
00538    }
00539 }
00540 
00541 
00542 //______________________________________________________________________________
00543 Int_t TAxis3D::AxisChoice( Option_t *axis) const
00544 {
00545    // Return the axis index by its name
00546 
00547    char achoice = toupper(axis[0]);
00548    if (achoice == 'X') return 0;
00549    if (achoice == 'Y') return 1;
00550    if (achoice == 'Z') return 2;
00551    return -1;
00552 }
00553 
00554 
00555 //______________________________________________________________________________
00556 Int_t TAxis3D::GetNdivisions( Option_t *axis) const
00557 {
00558    // Get number of divisions.
00559 
00560    Int_t ax = AxisChoice(axis);
00561    if (ax < 0) return 0;
00562    return fAxis[ax].GetNdivisions();
00563 }
00564 
00565 
00566 //______________________________________________________________________________
00567 Color_t TAxis3D::GetAxisColor( Option_t *axis) const
00568 {
00569    // Get axis color.
00570 
00571    Int_t ax = AxisChoice(axis);
00572    if (ax < 0) return 0;
00573    return fAxis[ax].GetAxisColor();
00574 }
00575 
00576 
00577 //______________________________________________________________________________
00578 Color_t TAxis3D::GetLabelColor( Option_t *axis) const
00579 {
00580    // Get label color.
00581 
00582    Int_t ax = AxisChoice(axis);
00583    if (ax < 0) return 0;
00584    return fAxis[ax].GetLabelColor();
00585 }
00586 
00587 
00588 //______________________________________________________________________________
00589 Style_t TAxis3D::GetLabelFont( Option_t *axis) const
00590 {
00591    // Get label font.
00592 
00593    Int_t ax = AxisChoice(axis);
00594    if (ax < 0) return 0;
00595    return fAxis[ax].GetLabelFont();
00596 }
00597 
00598 
00599 //______________________________________________________________________________
00600 Float_t TAxis3D::GetLabelOffset( Option_t *axis) const
00601 {
00602    // Get label offset.
00603 
00604    Int_t ax = AxisChoice(axis);
00605    if (ax < 0) return 0;
00606    return fAxis[ax].GetLabelOffset();
00607 }
00608 
00609 
00610 //______________________________________________________________________________
00611 Float_t TAxis3D::GetLabelSize( Option_t *axis) const
00612 {
00613    // Get label size.
00614 
00615    Int_t ax = AxisChoice(axis);
00616    if (ax < 0) return 0;
00617    return fAxis[ax].GetLabelSize();
00618 }
00619 
00620 
00621 //______________________________________________________________________________
00622 Float_t TAxis3D::GetTickLength( Option_t *axis) const
00623 {
00624    // Get tick mark length.
00625 
00626    Int_t ax = AxisChoice(axis);
00627    if (ax < 0) return 0;
00628    return fAxis[ax].GetTickLength();
00629 }
00630 
00631 
00632 //______________________________________________________________________________
00633 Float_t TAxis3D::GetTitleOffset( Option_t *axis) const
00634 {
00635    // Get title offset.
00636 
00637    Int_t ax = AxisChoice(axis);
00638    if (ax < 0) return 0;
00639    return fAxis[ax].GetTitleOffset();
00640 }
00641 
00642 
00643 //______________________________________________________________________________
00644 #define AXISCHOICE                \
00645    Int_t i = AxisChoice(axis);    \
00646    Int_t nax = 1;                 \
00647    if (i == -1) { i = 0; nax = 3;}\
00648    for (Int_t ax=i;ax<nax+i;ax++)
00649 
00650 
00651 //______________________________________________________________________________
00652 void TAxis3D::SetNdivisions(Int_t n, Option_t *axis)
00653 {
00654    // Set number of divisions.
00655 
00656    AXISCHOICE {fAxis[ax].SetNdivisions(n);}
00657 }
00658 
00659 
00660 //______________________________________________________________________________
00661 void TAxis3D::SetAxisColor(Color_t color, Option_t *axis)
00662 {
00663    // Set axis color.
00664 
00665    AXISCHOICE {fAxis[ax].SetAxisColor(color);}
00666 }
00667 
00668 
00669 //______________________________________________________________________________
00670 void TAxis3D::SetAxisRange(Double_t xmin, Double_t xmax, Option_t *axis)
00671 {
00672    // Set axis range.
00673 
00674    Int_t ax = AxisChoice(axis);
00675    if (ax < 0) return;
00676    TAxis *theAxis = &fAxis[ax];
00677    Int_t bin1 = theAxis->FindBin(xmin);
00678    Int_t bin2 = theAxis->FindBin(xmax);
00679    theAxis->SetRange(bin1, bin2);
00680 }
00681 
00682 
00683 //______________________________________________________________________________
00684 void TAxis3D::SetLabelColor(Color_t color, Option_t *axis)
00685 {
00686    // Set label color.
00687 
00688    AXISCHOICE { fAxis[ax].SetLabelColor(color); }
00689 }
00690 
00691 
00692 //______________________________________________________________________________
00693 void TAxis3D::SetLabelFont(Style_t font, Option_t *axis)
00694 {
00695    // Set label font.
00696 
00697    AXISCHOICE { fAxis[ax].SetLabelFont(font); }
00698 }
00699 
00700 
00701 //______________________________________________________________________________
00702 void TAxis3D::SetLabelOffset(Float_t offset, Option_t *axis)
00703 {
00704    // Set label offset.
00705 
00706    AXISCHOICE { fAxis[ax].SetLabelOffset(offset); }
00707 }
00708 
00709 
00710 //______________________________________________________________________________
00711 void TAxis3D::SetLabelSize(Float_t size, Option_t *axis)
00712 {
00713    // Set label size.
00714 
00715    AXISCHOICE { fAxis[ax].SetLabelSize(size); }
00716 }
00717 
00718 
00719 //______________________________________________________________________________
00720 void TAxis3D::SetTickLength(Float_t length, Option_t *axis)
00721 {
00722    // Set tick mark length.
00723 
00724    AXISCHOICE { fAxis[ax].SetTickLength(length); }
00725 }
00726 
00727 
00728 //______________________________________________________________________________
00729 void TAxis3D::SetTitleOffset(Float_t offset, Option_t *axis)
00730 {
00731    // Set title offset.
00732 
00733    AXISCHOICE { fAxis[ax].SetTitleOffset(offset); }
00734 }
00735 #undef AXISCHOICE
00736 
00737 
00738 //______________________________________________________________________________
00739 TAxis3D *TAxis3D::GetPadAxis(TVirtualPad *pad)
00740 {
00741    // Returns the "pad" Axis3D object pointer if any.
00742 
00743    TObject *obj = 0;
00744    TVirtualPad *thisPad=pad;
00745    if (!thisPad) thisPad = gPad;
00746    if (thisPad) {
00747       // Find axis in the current thisPad
00748       obj = thisPad->FindObject(TAxis3D::fgRulerName);
00749       if (!(obj && obj->InheritsFrom(Class()->GetName()))) obj = 0;
00750    }
00751    return (TAxis3D *)obj;
00752 }
00753 
00754 
00755 //______________________________________________________________________________
00756 TAxis3D *TAxis3D::ToggleRulers(TVirtualPad *pad)
00757 {
00758    // Turn ON / OFF the "Ruler", TAxis3D object attached
00759    // to the current pad
00760 
00761    TAxis3D *ax = 0;
00762    TVirtualPad *thisPad=pad;
00763    if (!thisPad) thisPad = gPad;
00764    if (thisPad && thisPad->GetView() ) {
00765       TAxis3D *a =  GetPadAxis(pad);
00766       if (a)  delete a;
00767       else {
00768          ax = new TAxis3D;
00769          ax->SetBit(kCanDelete);
00770          ax->Draw();
00771       }
00772       thisPad->Modified();
00773       thisPad->Update();
00774    }
00775    return ax;
00776 }
00777 
00778 
00779 //______________________________________________________________________________
00780 TAxis3D *TAxis3D::ToggleZoom(TVirtualPad *pad)
00781 {
00782    // Turn ON / OFF the "Ruler" and "zoom mode" of the TAxis3D object attached
00783    // to the current pad (if pad = 0; gPad is used "by default")
00784    //
00785    // User is given a chance to either:
00786    //  1.  move the center of the 3D scene at the cursor position
00787    //  2.  zoom view with mouse "drugging" the bounder rectangle with "left" mouse
00788    //  3.  Change the axuce attributes via TContextMenu with "righ mouse button click"
00789 
00790    TAxis3D *ax = 0;
00791    TVirtualPad *thisPad=pad;
00792    if (!thisPad) thisPad = gPad;
00793    if (thisPad && thisPad->GetView()) {
00794       // Find axis in the current thisPad
00795       TList *l = thisPad->GetListOfPrimitives();
00796       TObject *o = l->FindObject(TAxis3D::fgRulerName);
00797       if (o && o->InheritsFrom(Class()->GetName())) { // Find axis
00798          if (o != l->Last()) { // make sure the TAxis3D is the last object of the Pad.
00799             l->Remove(o);
00800             l->AddLast(o);
00801          }
00802          ax = (TAxis3D *)o;
00803       } else { // There is no
00804          ax = new TAxis3D;
00805          ax->SetBit(kCanDelete);
00806          ax->Draw();
00807       }
00808       ax->SwitchZoom();
00809    }
00810    return ax;
00811 }

Generated on Tue Jul 5 14:16:40 2011 for ROOT_528-00b_version by  doxygen 1.5.1