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