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