TTUBS.cxx

Go to the documentation of this file.
00001 // @(#)root/g3d:$Id: TTUBS.cxx 31624 2009-12-08 09:58:40Z couet $
00002 // Author: Nenad Buncic   18/09/95
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 "TTUBS.h"
00013 #include "TNode.h"
00014 #include "TVirtualPad.h"
00015 #include "TBuffer3D.h"
00016 #include "TBuffer3DTypes.h"
00017 #include "TGeometry.h"
00018 #include "TMath.h"
00019 
00020 ClassImp(TTUBS)
00021 
00022 
00023 //______________________________________________________________________________
00024 // Begin_Html <P ALIGN=CENTER> <IMG SRC="gif/tubs.gif"> </P> End_Html
00025 // TUBS is a segment of a tube. It has 8 parameters:
00026 //
00027 //     - name       name of the shape
00028 //     - title      shape's title
00029 //     - material  (see TMaterial)
00030 //     - rmin       inside radius
00031 //     - rmax       outside radius
00032 //     - dz         half length in z
00033 //     - phi1       starting angle of the segment
00034 //     - phi2       ending angle of the segment
00035 //
00036 //
00037 // NOTE: phi1 should be smaller than phi2. If this is not the case,
00038 //       the system adds 360 degrees to phi2.
00039 
00040 
00041 //______________________________________________________________________________
00042 TTUBS::TTUBS()
00043 {
00044    // TUBS shape default constructor
00045 
00046    fPhi1 = 0.;
00047    fPhi2 = 0.;
00048 }
00049 
00050 
00051 //______________________________________________________________________________
00052 TTUBS::TTUBS(const char *name, const char *title, const char *material, Float_t rmin,
00053              Float_t rmax, Float_t dz, Float_t phi1, Float_t phi2)
00054       : TTUBE(name,title,material,rmin,rmax,dz)
00055 {
00056    // TUBS shape normal constructor
00057 
00058    fPhi1 = phi1;
00059    fPhi2 = phi2;
00060    MakeTableOfCoSin();
00061 }
00062 
00063 
00064 //______________________________________________________________________________
00065 TTUBS::TTUBS(const char *name, const char *title, const char *material, Float_t rmax, Float_t dz,
00066                Float_t phi1, Float_t phi2)
00067       : TTUBE(name,title,material,rmax,dz)
00068 {
00069    // TUBS shape "simplified" constructor
00070 
00071    fPhi1 = phi1;
00072    fPhi2 = phi2;
00073    MakeTableOfCoSin();
00074 }
00075 
00076 
00077 //______________________________________________________________________________
00078 void TTUBS::MakeTableOfCoSin() const
00079 {
00080    // Make table of sine and cosine.
00081 
00082    const Double_t pi  = TMath::ATan(1) * 4.0;
00083    const Double_t ragrad  = pi/180.0;
00084 
00085    Int_t j;
00086    Int_t n = GetNumberOfDivisions () + 1;
00087 
00088    if (fCoTab)
00089       delete [] fCoTab; // Delete the old tab if any
00090       fCoTab = new Double_t [n];
00091    if (!fCoTab ) return;
00092 
00093    if (fSiTab)
00094       delete [] fSiTab; // Delete the old tab if any
00095    fSiTab = new Double_t [n];
00096    if (!fSiTab ) return;
00097 
00098    Double_t phi1    = Double_t(fPhi1  * ragrad);
00099    Double_t phi2    = Double_t(fPhi2  * ragrad);
00100 
00101    if (phi1 > phi2 ) phi2 += 2*pi;
00102 
00103    Double_t range = phi2- phi1;
00104 
00105    Double_t angstep = range/(n-1);
00106 
00107    Double_t ph = phi1;
00108    for (j = 0; j < n; j++) {
00109       ph = phi1 + j*angstep;
00110       fCoTab[j] = TMath::Cos(ph);
00111       fSiTab[j] = TMath::Sin(ph);
00112    }
00113 }
00114 
00115 
00116 //______________________________________________________________________________
00117 TTUBS::~TTUBS()
00118 {
00119    // TUBS shape default destructor
00120 }
00121 
00122 
00123 //______________________________________________________________________________
00124 Int_t TTUBS::DistancetoPrimitive(Int_t px, Int_t py)
00125 {
00126    // Compute distance from point px,py to a TUBE
00127    //
00128    // Compute the closest distance of approach from point px,py to each
00129    // computed outline point of the TUBE.
00130 
00131    Int_t n = GetNumberOfDivisions()+1;
00132    Int_t numPoints = n*4;
00133    return ShapeDistancetoPrimitive(numPoints,px,py);
00134 }
00135 
00136 
00137 //______________________________________________________________________________
00138 void TTUBS::SetPoints(Double_t *points) const
00139 {
00140    // Create TUBS points
00141 
00142    Int_t j, n;
00143    Int_t indx = 0;
00144    Float_t dz = TTUBE::fDz;
00145 
00146    n = GetNumberOfDivisions()+1;
00147 
00148    if (points) {
00149       if (!fCoTab)   MakeTableOfCoSin();
00150       for (j = 0; j < n; j++) {
00151          points[indx+6*n] = points[indx] = fRmin * fCoTab[j];
00152          indx++;
00153          points[indx+6*n] = points[indx] = fAspectRatio*fRmin * fSiTab[j];
00154          indx++;
00155          points[indx+6*n] = dz;
00156          points[indx]     =-dz;
00157          indx++;
00158       }
00159       for (j = 0; j < n; j++) {
00160          points[indx+6*n] = points[indx] = fRmax * fCoTab[j];
00161          indx++;
00162          points[indx+6*n] = points[indx] = fAspectRatio*fRmax * fSiTab[j];
00163          indx++;
00164          points[indx+6*n]= dz;
00165          points[indx]    =-dz;
00166          indx++;
00167       }
00168    }
00169 }
00170 
00171 
00172 //______________________________________________________________________________
00173 void TTUBS::Sizeof3D() const
00174 {
00175    // Return total X3D needed by TNode::ls (when called with option "x")
00176 
00177    Int_t n = GetNumberOfDivisions()+1;
00178 
00179    gSize3D.numPoints += n*4;
00180    gSize3D.numSegs   += n*8;
00181    gSize3D.numPolys  += n*4-2;  
00182 }
00183 
00184 
00185 //_______________________________________________________________________
00186 const TBuffer3D & TTUBS::GetBuffer3D(Int_t reqSections) const
00187 {
00188    // Get buffer 3d.
00189 
00190    static TBuffer3D buffer(TBuffer3DTypes::kGeneric);
00191 
00192    TShape::FillBuffer3D(buffer, reqSections);
00193 
00194    // TODO: Although we now have a TBuffer3DTubeSeg class for
00195    // tube segment shapes, we do not use it for old geometry shapes, as 
00196    // OGL viewer needs various rotation matrix info we can't easily
00197    // pass yet. To be revisited.
00198 
00199    // We also don't provide a bounding box - as fiddly to calculate
00200    // leave to viewer to work it out from points
00201 
00202    if (reqSections & TBuffer3D::kRawSizes) {
00203       const Int_t n = GetNumberOfDivisions()+1;
00204       Int_t nbPnts = 4*n;
00205       Int_t nbSegs = 2*nbPnts;
00206       Int_t nbPols = nbPnts-2;
00207 
00208       if (buffer.SetRawSizes(nbPnts, 3*nbPnts, nbSegs, 3*nbSegs, nbPols, 6*nbPols)) {
00209          buffer.SetSectionsValid(TBuffer3D::kRawSizes);
00210       }
00211    }
00212    if (reqSections & TBuffer3D::kRaw) {
00213       // Points
00214       SetPoints(buffer.fPnts);
00215       if (!buffer.fLocalFrame) {
00216          TransformPoints(buffer.fPnts, buffer.NbPnts());
00217       }
00218 
00219       const Int_t n = GetNumberOfDivisions()+1;
00220       Int_t i,j;
00221       Int_t c = GetBasicColor();
00222 
00223       // Segments
00224       memset(buffer.fSegs, 0, buffer.NbSegs()*3*sizeof(Int_t));
00225       for (i = 0; i < 4; i++) {
00226          for (j = 1; j < n; j++) {
00227             buffer.fSegs[(i*n+j-1)*3  ] = c;
00228             buffer.fSegs[(i*n+j-1)*3+1] = i*n+j-1;
00229             buffer.fSegs[(i*n+j-1)*3+2] = i*n+j;
00230          }
00231       }
00232       for (i = 4; i < 6; i++) {
00233          for (j = 0; j < n; j++) {
00234             buffer.fSegs[(i*n+j)*3  ] = c+1;
00235             buffer.fSegs[(i*n+j)*3+1] = (i-4)*n+j;
00236             buffer.fSegs[(i*n+j)*3+2] = (i-2)*n+j;
00237          }
00238       }
00239       for (i = 6; i < 8; i++) {
00240          for (j = 0; j < n; j++) {
00241             buffer.fSegs[(i*n+j)*3  ] = c;
00242             buffer.fSegs[(i*n+j)*3+1] = 2*(i-6)*n+j;
00243             buffer.fSegs[(i*n+j)*3+2] = (2*(i-6)+1)*n+j;
00244          }
00245       }
00246 
00247       // Polygons
00248       Int_t indx = 0;
00249       memset(buffer.fPols, 0, buffer.NbPols()*6*sizeof(Int_t));
00250       i = 0;
00251       for (j = 0; j < n-1; j++) {
00252          buffer.fPols[indx++] = c;
00253          buffer.fPols[indx++] = 4;
00254          buffer.fPols[indx++] = (4+i)*n+j+1;
00255          buffer.fPols[indx++] = (2+i)*n+j;
00256          buffer.fPols[indx++] = (4+i)*n+j;
00257          buffer.fPols[indx++] = i*n+j;
00258       }
00259       i = 1;
00260       for (j = 0; j < n-1; j++) {
00261          buffer.fPols[indx++] = c;
00262          buffer.fPols[indx++] = 4;
00263          buffer.fPols[indx++] = i*n+j;
00264          buffer.fPols[indx++] = (4+i)*n+j;
00265          buffer.fPols[indx++] = (2+i)*n+j;
00266          buffer.fPols[indx++] = (4+i)*n+j+1;
00267       }
00268       i = 2;
00269       for (j = 0; j < n-1; j++) {
00270          buffer.fPols[indx++] = c+i;
00271          buffer.fPols[indx++] = 4;
00272          buffer.fPols[indx++] = (i-2)*2*n+j;
00273          buffer.fPols[indx++] = (4+i)*n+j;
00274          buffer.fPols[indx++] = ((i-2)*2+1)*n+j;
00275          buffer.fPols[indx++] = (4+i)*n+j+1;
00276       }
00277       i = 3;
00278       for (j = 0; j < n-1; j++) {
00279          buffer.fPols[indx++] = c+i;
00280          buffer.fPols[indx++] = 4;
00281          buffer.fPols[indx++] = (4+i)*n+j+1;
00282          buffer.fPols[indx++] = ((i-2)*2+1)*n+j;
00283          buffer.fPols[indx++] = (4+i)*n+j;
00284          buffer.fPols[indx++] = (i-2)*2*n+j;
00285       }
00286       buffer.fPols[indx++] = c+2;
00287       buffer.fPols[indx++] = 4;
00288       buffer.fPols[indx++] = 6*n;
00289       buffer.fPols[indx++] = 4*n;
00290       buffer.fPols[indx++] = 7*n;
00291       buffer.fPols[indx++] = 5*n;
00292       buffer.fPols[indx++] = c+2;
00293       buffer.fPols[indx++] = 4;
00294       buffer.fPols[indx++] = 6*n-1;
00295       buffer.fPols[indx++] = 8*n-1;
00296       buffer.fPols[indx++] = 5*n-1;
00297       buffer.fPols[indx++] = 7*n-1;
00298 
00299       buffer.SetSectionsValid(TBuffer3D::kRaw);
00300    }
00301    return buffer;
00302 }

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