Logo ROOT  
Reference Guide
TTUBS.cxx
Go to the documentation of this file.
1 // @(#)root/g3d:$Id$
2 // Author: Nenad Buncic 18/09/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 "TTUBS.h"
13 #include "TNode.h"
14 #include "TBuffer3D.h"
15 #include "TBuffer3DTypes.h"
16 #include "TGeometry.h"
17 #include "TMath.h"
18 
20 
21 /** \class TTUBS
22 \ingroup g3d
23 A segment of a tube.
24 
25 \image html g3d_tubs.png
26 
27 It has 8 parameters:
28 
29  - name: name of the shape
30  - title: shape's title
31  - material: (see TMaterial)
32  - rmin: inside radius
33  - rmax: outside radius
34  - dz: half length in z
35  - phi1: starting angle of the segment
36  - phi2: ending angle of the segment
37 
38 
39 NOTE: phi1 should be smaller than phi2. If this is not the case,
40 the system adds 360 degrees to phi2.
41 */
42 
43 ////////////////////////////////////////////////////////////////////////////////
44 /// TUBS shape default constructor
45 
47 {
48  fPhi1 = 0.;
49  fPhi2 = 0.;
50 }
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// TUBS shape normal constructor
54 
55 TTUBS::TTUBS(const char *name, const char *title, const char *material, Float_t rmin,
56  Float_t rmax, Float_t dz, Float_t phi1, Float_t phi2)
57  : TTUBE(name,title,material,rmin,rmax,dz)
58 {
59  fPhi1 = phi1;
60  fPhi2 = phi2;
62 }
63 
64 ////////////////////////////////////////////////////////////////////////////////
65 /// TUBS shape "simplified" constructor
66 
67 TTUBS::TTUBS(const char *name, const char *title, const char *material, Float_t rmax, Float_t dz,
68  Float_t phi1, Float_t phi2)
69  : TTUBE(name,title,material,rmax,dz)
70 {
71  fPhi1 = phi1;
72  fPhi2 = phi2;
74 }
75 
76 ////////////////////////////////////////////////////////////////////////////////
77 /// Make table of sine and cosine.
78 
80 {
81  const Double_t pi = TMath::ATan(1) * 4.0;
82  const Double_t ragrad = pi/180.0;
83 
84  Int_t j;
85  Int_t n = GetNumberOfDivisions () + 1;
86 
87  if (fCoTab) delete [] fCoTab; // Delete the old tab if any
88  fCoTab = new Double_t [n];
89  if (!fCoTab ) return;
90 
91  if (fSiTab) delete [] fSiTab; // Delete the old tab if any
92  fSiTab = new Double_t [n];
93  if (!fSiTab ) return;
94 
95  Double_t phi1 = Double_t(fPhi1 * ragrad);
96  Double_t phi2 = Double_t(fPhi2 * ragrad);
97 
98  if (phi1 > phi2 ) phi2 += 2*pi;
99 
100  Double_t range = phi2- phi1;
101 
102  Double_t angstep = range/(n-1);
103 
104  Double_t ph = phi1;
105  for (j = 0; j < n; j++) {
106  ph = phi1 + j*angstep;
107  fCoTab[j] = TMath::Cos(ph);
108  fSiTab[j] = TMath::Sin(ph);
109  }
110 }
111 
112 ////////////////////////////////////////////////////////////////////////////////
113 /// TUBS shape default destructor
114 
116 {
117 }
118 
119 ////////////////////////////////////////////////////////////////////////////////
120 /// Compute distance from point px,py to a TUBE
121 ///
122 /// Compute the closest distance of approach from point px,py to each
123 /// computed outline point of the TUBE.
124 
126 {
128  Int_t numPoints = n*4;
129  return ShapeDistancetoPrimitive(numPoints,px,py);
130 }
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// Create TUBS points
134 
136 {
137  Int_t j, n;
138  Int_t indx = 0;
139  Float_t dz = TTUBE::fDz;
140 
141  n = GetNumberOfDivisions()+1;
142 
143  if (points) {
144  if (!fCoTab) MakeTableOfCoSin();
145  for (j = 0; j < n; j++) {
146  points[indx+6*n] = points[indx] = fRmin * fCoTab[j];
147  indx++;
148  points[indx+6*n] = points[indx] = fAspectRatio*fRmin * fSiTab[j];
149  indx++;
150  points[indx+6*n] = dz;
151  points[indx] =-dz;
152  indx++;
153  }
154  for (j = 0; j < n; j++) {
155  points[indx+6*n] = points[indx] = fRmax * fCoTab[j];
156  indx++;
157  points[indx+6*n] = points[indx] = fAspectRatio*fRmax * fSiTab[j];
158  indx++;
159  points[indx+6*n]= dz;
160  points[indx] =-dz;
161  indx++;
162  }
163  }
164 }
165 
166 ////////////////////////////////////////////////////////////////////////////////
167 /// Return total X3D needed by TNode::ls (when called with option "x")
168 
169 void TTUBS::Sizeof3D() const
170 {
172 
173  gSize3D.numPoints += n*4;
174  gSize3D.numSegs += n*8;
175  gSize3D.numPolys += n*4-2;
176 }
177 
178 ////////////////////////////////////////////////////////////////////////////////
179 /// Get buffer 3d.
180 
181 const TBuffer3D & TTUBS::GetBuffer3D(Int_t reqSections) const
182 {
183  static TBuffer3D buffer(TBuffer3DTypes::kGeneric);
184 
185  TShape::FillBuffer3D(buffer, reqSections);
186 
187  // TODO: Although we now have a TBuffer3DTubeSeg class for
188  // tube segment shapes, we do not use it for old geometry shapes, as
189  // OGL viewer needs various rotation matrix info we can't easily
190  // pass yet. To be revisited.
191 
192  // We also don't provide a bounding box - as fiddly to calculate
193  // leave to viewer to work it out from points
194 
195  if (reqSections & TBuffer3D::kRawSizes) {
196  const Int_t n = GetNumberOfDivisions()+1;
197  Int_t nbPnts = 4*n;
198  Int_t nbSegs = 2*nbPnts;
199  Int_t nbPols = nbPnts-2;
200 
201  if (buffer.SetRawSizes(nbPnts, 3*nbPnts, nbSegs, 3*nbSegs, nbPols, 6*nbPols)) {
203  }
204  }
205  if (reqSections & TBuffer3D::kRaw) {
206  // Points
207  SetPoints(buffer.fPnts);
208  if (!buffer.fLocalFrame) {
209  TransformPoints(buffer.fPnts, buffer.NbPnts());
210  }
211 
212  const Int_t n = GetNumberOfDivisions()+1;
213  Int_t i,j;
214  Int_t c = GetBasicColor();
215 
216  // Segments
217  memset(buffer.fSegs, 0, buffer.NbSegs()*3*sizeof(Int_t));
218  for (i = 0; i < 4; i++) {
219  for (j = 1; j < n; j++) {
220  buffer.fSegs[(i*n+j-1)*3 ] = c;
221  buffer.fSegs[(i*n+j-1)*3+1] = i*n+j-1;
222  buffer.fSegs[(i*n+j-1)*3+2] = i*n+j;
223  }
224  }
225  for (i = 4; i < 6; i++) {
226  for (j = 0; j < n; j++) {
227  buffer.fSegs[(i*n+j)*3 ] = c+1;
228  buffer.fSegs[(i*n+j)*3+1] = (i-4)*n+j;
229  buffer.fSegs[(i*n+j)*3+2] = (i-2)*n+j;
230  }
231  }
232  for (i = 6; i < 8; i++) {
233  for (j = 0; j < n; j++) {
234  buffer.fSegs[(i*n+j)*3 ] = c;
235  buffer.fSegs[(i*n+j)*3+1] = 2*(i-6)*n+j;
236  buffer.fSegs[(i*n+j)*3+2] = (2*(i-6)+1)*n+j;
237  }
238  }
239 
240  // Polygons
241  Int_t indx = 0;
242  memset(buffer.fPols, 0, buffer.NbPols()*6*sizeof(Int_t));
243  i = 0;
244  for (j = 0; j < n-1; j++) {
245  buffer.fPols[indx++] = c;
246  buffer.fPols[indx++] = 4;
247  buffer.fPols[indx++] = (4+i)*n+j+1;
248  buffer.fPols[indx++] = (2+i)*n+j;
249  buffer.fPols[indx++] = (4+i)*n+j;
250  buffer.fPols[indx++] = i*n+j;
251  }
252  i = 1;
253  for (j = 0; j < n-1; j++) {
254  buffer.fPols[indx++] = c;
255  buffer.fPols[indx++] = 4;
256  buffer.fPols[indx++] = i*n+j;
257  buffer.fPols[indx++] = (4+i)*n+j;
258  buffer.fPols[indx++] = (2+i)*n+j;
259  buffer.fPols[indx++] = (4+i)*n+j+1;
260  }
261  i = 2;
262  for (j = 0; j < n-1; j++) {
263  buffer.fPols[indx++] = c+i;
264  buffer.fPols[indx++] = 4;
265  buffer.fPols[indx++] = (i-2)*2*n+j;
266  buffer.fPols[indx++] = (4+i)*n+j;
267  buffer.fPols[indx++] = ((i-2)*2+1)*n+j;
268  buffer.fPols[indx++] = (4+i)*n+j+1;
269  }
270  i = 3;
271  for (j = 0; j < n-1; j++) {
272  buffer.fPols[indx++] = c+i;
273  buffer.fPols[indx++] = 4;
274  buffer.fPols[indx++] = (4+i)*n+j+1;
275  buffer.fPols[indx++] = ((i-2)*2+1)*n+j;
276  buffer.fPols[indx++] = (4+i)*n+j;
277  buffer.fPols[indx++] = (i-2)*2*n+j;
278  }
279  buffer.fPols[indx++] = c+2;
280  buffer.fPols[indx++] = 4;
281  buffer.fPols[indx++] = 6*n;
282  buffer.fPols[indx++] = 4*n;
283  buffer.fPols[indx++] = 7*n;
284  buffer.fPols[indx++] = 5*n;
285  buffer.fPols[indx++] = c+2;
286  buffer.fPols[indx++] = 4;
287  buffer.fPols[indx++] = 6*n-1;
288  buffer.fPols[indx++] = 8*n-1;
289  buffer.fPols[indx++] = 5*n-1;
290  buffer.fPols[indx++] = 7*n-1;
291 
293  }
294  return buffer;
295 }
c
#define c(i)
Definition: RSha256.hxx:101
n
const Int_t n
Definition: legend1.C:16
TBuffer3D::SetSectionsValid
void SetSectionsValid(UInt_t mask)
Definition: TBuffer3D.h:65
TTUBE::fDz
Float_t fDz
Definition: TTUBE.h:38
TTUBE::fCoTab
Double_t * fCoTab
Table of sin(fPhi1) .... sin(fPhil+fDphi1)
Definition: TTUBE.h:45
TMath::Cos
Double_t Cos(Double_t)
Definition: TMath.h:643
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TNode.h
TTUBE
A tube.
Definition: TTUBE.h:32
Float_t
float Float_t
Definition: RtypesCore.h:57
TTUBS::GetBuffer3D
virtual const TBuffer3D & GetBuffer3D(Int_t reqSections) const
Get buffer 3d.
Definition: TTUBS.cxx:181
TTUBE::GetNumberOfDivisions
virtual Int_t GetNumberOfDivisions() const
Definition: TTUBE.h:67
TBuffer3D::NbPnts
UInt_t NbPnts() const
Definition: TBuffer3D.h:80
TShape::ShapeDistancetoPrimitive
Int_t ShapeDistancetoPrimitive(Int_t numPoints, Int_t px, Int_t py)
Distance to primitive.
Definition: TShape.cxx:117
TBuffer3D::SetRawSizes
Bool_t SetRawSizes(UInt_t reqPnts, UInt_t reqPntsCapacity, UInt_t reqSegs, UInt_t reqSegsCapacity, UInt_t reqPols, UInt_t reqPolsCapacity)
Set kRaw tessellation section of buffer with supplied sizes.
Definition: TBuffer3D.cxx:359
TTUBS
A segment of a tube.
Definition: TTUBS.h:29
TBuffer3D::fSegs
Int_t * fSegs
Definition: TBuffer3D.h:113
TShape::GetBasicColor
Int_t GetBasicColor() const
Get basic color.
Definition: TShape.cxx:241
TGeometry.h
TTUBS::~TTUBS
virtual ~TTUBS()
TUBS shape default destructor.
Definition: TTUBS.cxx:115
TTUBE::fRmax
Float_t fRmax
Definition: TTUBE.h:36
TTUBS::fPhi2
Float_t fPhi2
Definition: TTUBS.h:32
TBuffer3D
Generic 3D primitive description class.
Definition: TBuffer3D.h:18
TBuffer3DTypes::kGeneric
@ kGeneric
Definition: TBuffer3DTypes.h:24
TShape::TransformPoints
void TransformPoints(Double_t *points, UInt_t NbPnts) const
Transform points (LocalToMaster)
Definition: TShape.cxx:190
TBuffer3D.h
gSize3D
#define gSize3D
Definition: X3DBuffer.h:40
TBuffer3DTypes.h
TMath::Sin
Double_t Sin(Double_t)
Definition: TMath.h:639
TBuffer3D::kRaw
@ kRaw
Definition: TBuffer3D.h:54
TTUBE::fAspectRatio
Float_t fAspectRatio
Definition: TTUBE.h:41
TTUBS::TTUBS
TTUBS()
TUBS shape default constructor.
Definition: TTUBS.cxx:46
TTUBS::fPhi1
Float_t fPhi1
Definition: TTUBS.h:31
TBuffer3D::NbPols
UInt_t NbPols() const
Definition: TBuffer3D.h:82
TTUBE::fRmin
Float_t fRmin
Definition: TTUBE.h:35
TMath::ATan
Double_t ATan(Double_t)
Definition: TMath.h:675
Double_t
double Double_t
Definition: RtypesCore.h:59
TBuffer3D::fLocalFrame
Bool_t fLocalFrame
Definition: TBuffer3D.h:90
TBuffer3D::NbSegs
UInt_t NbSegs() const
Definition: TBuffer3D.h:81
TGeant4Unit::pi
static constexpr double pi
Definition: TGeant4SystemOfUnits.h:67
points
point * points
Definition: X3DBuffer.c:22
TTUBS.h
TTUBE::fSiTab
Double_t * fSiTab
Definition: TTUBE.h:44
TBuffer3D::kRawSizes
@ kRawSizes
Definition: TBuffer3D.h:53
name
char name[80]
Definition: TGX11.cxx:110
TTUBS::Sizeof3D
virtual void Sizeof3D() const
Return total X3D needed by TNode::ls (when called with option "x")
Definition: TTUBS.cxx:169
TBuffer3D::fPnts
Double_t * fPnts
Definition: TBuffer3D.h:112
TShape::FillBuffer3D
virtual void FillBuffer3D(TBuffer3D &buffer, Int_t reqSections) const
We have to set kRawSize (unless already done) to allocate buffer space before kRaw can be filled.
Definition: TShape.cxx:211
TTUBS::DistancetoPrimitive
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to a TUBE.
Definition: TTUBS.cxx:125
TTUBS::MakeTableOfCoSin
virtual void MakeTableOfCoSin() const
Make table of sine and cosine.
Definition: TTUBS.cxx:79
TBuffer3D::fPols
Int_t * fPols
Definition: TBuffer3D.h:114
TTUBS::SetPoints
virtual void SetPoints(Double_t *points) const
Create TUBS points.
Definition: TTUBS.cxx:135
TMath.h
int