Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
23A segment of a tube.
24
25\image html g3d_tubs.png
26
27It 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
39NOTE: phi1 should be smaller than phi2. If this is not the case,
40the 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
55TTUBS::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
67TTUBS::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;
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
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
169void 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
181const 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;
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}
#define c(i)
Definition RSha256.hxx:101
float Float_t
Definition RtypesCore.h:57
double Double_t
Definition RtypesCore.h:59
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t points
char name[80]
Definition TGX11.cxx:110
#define gSize3D
Definition X3DBuffer.h:40
Generic 3D primitive description class.
Definition TBuffer3D.h:18
Int_t * fPols
Definition TBuffer3D.h:115
UInt_t NbPols() const
Definition TBuffer3D.h:82
UInt_t NbPnts() const
Definition TBuffer3D.h:80
UInt_t NbSegs() const
Definition TBuffer3D.h:81
void SetSectionsValid(UInt_t mask)
Definition TBuffer3D.h:65
Int_t * fSegs
Definition TBuffer3D.h:114
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.
Double_t * fPnts
Definition TBuffer3D.h:113
Int_t GetBasicColor() const
Get basic color.
Definition TShape.cxx:241
Int_t ShapeDistancetoPrimitive(Int_t numPoints, Int_t px, Int_t py)
Distance to primitive.
Definition TShape.cxx:117
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
void TransformPoints(Double_t *points, UInt_t NbPnts) const
Transform points (LocalToMaster)
Definition TShape.cxx:190
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
~TTUBS() override
TUBS shape default destructor.
Definition TTUBS.cxx:115
void SetPoints(Double_t *points) const override
Create TUBS points.
Definition TTUBS.cxx:135
void Sizeof3D() const override
Return total X3D needed by TNode::ls (when called with option "x")
Definition TTUBS.cxx:169
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a TUBE.
Definition TTUBS.cxx:125
Float_t fPhi1
Definition TTUBS.h:31
void MakeTableOfCoSin() const override
Make table of sine and cosine.
Definition TTUBS.cxx:79
const TBuffer3D & GetBuffer3D(Int_t reqSections) const override
Get buffer 3d.
Definition TTUBS.cxx:181
Float_t fPhi2
Definition TTUBS.h:32
TTUBS()
TUBS shape default constructor.
Definition TTUBS.cxx:46
const Int_t n
Definition legend1.C:16
Double_t ATan(Double_t)
Returns the principal value of the arc tangent of x, expressed in radians.
Definition TMath.h:640
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:594
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:588