00001
00002
00003
00004
00005
00006
00007
00008
00009
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
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 TTUBS::TTUBS()
00043 {
00044
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
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
00070
00071 fPhi1 = phi1;
00072 fPhi2 = phi2;
00073 MakeTableOfCoSin();
00074 }
00075
00076
00077
00078 void TTUBS::MakeTableOfCoSin() const
00079 {
00080
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;
00090 fCoTab = new Double_t [n];
00091 if (!fCoTab ) return;
00092
00093 if (fSiTab)
00094 delete [] fSiTab;
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
00120 }
00121
00122
00123
00124 Int_t TTUBS::DistancetoPrimitive(Int_t px, Int_t py)
00125 {
00126
00127
00128
00129
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
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
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
00189
00190 static TBuffer3D buffer(TBuffer3DTypes::kGeneric);
00191
00192 TShape::FillBuffer3D(buffer, reqSections);
00193
00194
00195
00196
00197
00198
00199
00200
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
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
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
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 }