Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TTUBE.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 "TTUBE.h"
13#include "TNode.h"
14#include "TBuffer.h"
15#include "TBuffer3D.h"
16#include "TBuffer3DTypes.h"
17#include "TGeometry.h"
18#include "TMath.h"
19
20
21/** \class TTUBE
22\ingroup g3d
23A tube.
24
25\image html g3d_tube.png
26
27It has 6 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*/
36
37////////////////////////////////////////////////////////////////////////////////
38/// TUBE shape default constructor
39
41{
42 fCoTab = nullptr;
43 fSiTab = nullptr;
44 fAspectRatio = 1;
45 fDz = 0.;
46 fNdiv = 0;
47 fRmin = 0.;
48 fRmax = 0.;
49}
50
51////////////////////////////////////////////////////////////////////////////////
52/// TUBE shape normal constructor
53
54TTUBE::TTUBE(const char *name, const char *title, const char *material, Float_t rmin, Float_t rmax, Float_t dz,Float_t aspect)
55 : TShape(name, title,material)
56{
57 fRmin = rmin;
58 fRmax = rmax;
59
60 fDz = dz;
61 fNdiv = 0;
62
63 fCoTab = nullptr;
64 fSiTab = nullptr;
65
67
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// TUBE shape "simplified" constructor
73
74TTUBE::TTUBE(const char *name, const char *title, const char *material, Float_t rmax, Float_t dz)
75 : TShape(name, title,material)
76{
77 fRmin = 0;
78 fRmax = rmax;
79
80 fDz = dz;
81 fNdiv = 0;
82
83 fCoTab = nullptr;
84 fSiTab = nullptr;
85
86 fAspectRatio = 1;
87
89}
90
91////////////////////////////////////////////////////////////////////////////////
92///copy constructor
93
95 TShape(tu),
96 fRmin(tu.fRmin),
97 fRmax(tu.fRmax),
98 fDz(tu.fDz),
99 fNdiv(tu.fNdiv),
100 fAspectRatio(tu.fAspectRatio),
101 fSiTab(tu.fSiTab),
102 fCoTab(tu.fCoTab)
103{
104}
105
106////////////////////////////////////////////////////////////////////////////////
107/// assignment operator
108
110{
111 if(this!=&tu) {
113 fRmin=tu.fRmin;
114 fRmax=tu.fRmax;
115 fDz=tu.fDz;
116 fNdiv=tu.fNdiv;
117 fAspectRatio=tu.fAspectRatio;
118 fSiTab=tu.fSiTab;
119 fCoTab=tu.fCoTab;
120 }
121 return *this;
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// Make table of sine and cosine.
126
127void TTUBE::MakeTableOfCoSin() const // Internal cache - const so other const fn can use
128{
129 const Double_t pi = TMath::ATan(1) * 4.0;
130
131 Int_t j;
133 if (fCoTab) delete [] fCoTab; // Delete the old tab if any
134 fCoTab = new Double_t [n];
135 if (!fCoTab ) {
136 Error("MakeTableOfCoSin()","No cos table done");
137 return;
138 }
139
140 if (fSiTab) delete [] fSiTab; // Delete the old tab if any
141 fSiTab = new Double_t [n];
142 if (!fSiTab ) {
143 Error("MakeTableOfCoSin()","No sin table done");
144 return;
145 }
146
147 Double_t range = 2*pi;
148
150
151 Double_t ph = 0;
152 for (j = 0; j < n; j++) {
153 ph = j*angstep;
154 fCoTab[j] = TMath::Cos(ph);
155 fSiTab[j] = TMath::Sin(ph);
156 }
157}
158
159////////////////////////////////////////////////////////////////////////////////
160/// TUBE shape default destructor
161
163{
164 delete [] fCoTab;
165 delete [] fSiTab;
166}
167
168////////////////////////////////////////////////////////////////////////////////
169/// Compute distance from point px,py to a TUBE
170///
171/// Compute the closest distance of approach from point px,py to each
172/// computed outline point of the TUBE.
173
175{
177 Int_t numPoints = n*4;
178 return ShapeDistancetoPrimitive(numPoints,px,py);
179}
180
181////////////////////////////////////////////////////////////////////////////////
182/// Set number of divisions used to draw this tube
183
185{
186 fNdiv = ndiv;
188}
189
190////////////////////////////////////////////////////////////////////////////////
191/// Create TUBE points
192
194{
195 Int_t j, n;
196 Int_t indx = 0;
197
199
200 if (points) {
201 if (!fCoTab) MakeTableOfCoSin();
202 for (j = 0; j < n; j++) {
203 points[indx+6*n] = points[indx] = fRmin * fCoTab[j];
204 indx++;
206 indx++;
207 points[indx+6*n] = fDz;
208 points[indx] =-fDz;
209 indx++;
210 }
211 for (j = 0; j < n; j++) {
212 points[indx+6*n] = points[indx] = fRmax * fCoTab[j];
213 indx++;
215 indx++;
216 points[indx+6*n]= fDz;
217 points[indx] =-fDz;
218 indx++;
219 }
220 }
221}
222
223////////////////////////////////////////////////////////////////////////////////
224/// Set segments and polygons.
225
227{
228 Int_t i, j;
231
232 for (i = 0; i < 4; i++) {
233 for (j = 0; j < n; j++) {
234 buffer.fSegs[(i*n+j)*3 ] = c;
235 buffer.fSegs[(i*n+j)*3+1] = i*n+j;
236 buffer.fSegs[(i*n+j)*3+2] = i*n+j+1;
237 }
238 buffer.fSegs[(i*n+j-1)*3+2] = i*n;
239 }
240 for (i = 4; i < 6; i++) {
241 for (j = 0; j < n; j++) {
242 buffer.fSegs[(i*n+j)*3 ] = c+1;
243 buffer.fSegs[(i*n+j)*3+1] = (i-4)*n+j;
244 buffer.fSegs[(i*n+j)*3+2] = (i-2)*n+j;
245 }
246 }
247 for (i = 6; i < 8; i++) {
248 for (j = 0; j < n; j++) {
249 buffer.fSegs[(i*n+j)*3 ] = c;
250 buffer.fSegs[(i*n+j)*3+1] = 2*(i-6)*n+j;
251 buffer.fSegs[(i*n+j)*3+2] = (2*(i-6)+1)*n+j;
252 }
253 }
254
255 Int_t indx = 0;
256 i=0;
257 for (j = 0; j < n; j++) {
258 indx = 6*(i*n+j);
259 buffer.fPols[indx ] = c;
260 buffer.fPols[indx+1] = 4;
261 buffer.fPols[indx+5] = i*n+j;
262 buffer.fPols[indx+4] = (4+i)*n+j;
263 buffer.fPols[indx+3] = (2+i)*n+j;
264 buffer.fPols[indx+2] = (4+i)*n+j+1;
265 }
266 buffer.fPols[indx+2] = (4+i)*n;
267 i=1;
268 for (j = 0; j < n; j++) {
269 indx = 6*(i*n+j);
270 buffer.fPols[indx ] = c;
271 buffer.fPols[indx+1] = 4;
272 buffer.fPols[indx+2] = i*n+j;
273 buffer.fPols[indx+3] = (4+i)*n+j;
274 buffer.fPols[indx+4] = (2+i)*n+j;
275 buffer.fPols[indx+5] = (4+i)*n+j+1;
276 }
277 buffer.fPols[indx+5] = (4+i)*n;
278 i=2;
279 for (j = 0; j < n; j++) {
280 indx = 6*(i*n+j);
281 buffer.fPols[indx ] = c+i;
282 buffer.fPols[indx+1] = 4;
283 buffer.fPols[indx+2] = (i-2)*2*n+j;
284 buffer.fPols[indx+3] = (4+i)*n+j;
285 buffer.fPols[indx+4] = ((i-2)*2+1)*n+j;
286 buffer.fPols[indx+5] = (4+i)*n+j+1;
287 }
288 buffer.fPols[indx+5] = (4+i)*n;
289 i=3;
290 for (j = 0; j < n; j++) {
291 indx = 6*(i*n+j);
292 buffer.fPols[indx ] = c+i;
293 buffer.fPols[indx+1] = 4;
294 buffer.fPols[indx+5] = (i-2)*2*n+j;
295 buffer.fPols[indx+4] = (4+i)*n+j;
296 buffer.fPols[indx+3] = ((i-2)*2+1)*n+j;
297 buffer.fPols[indx+2] = (4+i)*n+j+1;
298 }
299 buffer.fPols[indx+2] = (4+i)*n;
300}
301
302////////////////////////////////////////////////////////////////////////////////
303/// Return total X3D needed by TNode::ls (when called with option "x")
304
305void TTUBE::Sizeof3D() const
306{
308
309 gSize3D.numPoints += n*4;
310 gSize3D.numSegs += n*8;
311 gSize3D.numPolys += n*4;
312}
313
314////////////////////////////////////////////////////////////////////////////////
315/// Stream an object of class TTUBE.
316
318{
319 if (R__b.IsReading()) {
321 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
322 if (R__v > 2) {
323 R__b.ReadClassBuffer(TTUBE::Class(), this, R__v, R__s, R__c);
324 return;
325 }
326 //====process old versions before automatic schema evolution
328 R__b >> fRmin;
329 R__b >> fRmax;
330 R__b >> fDz;
331 R__b >> fNdiv;
332 if (R__v > 1) R__b >> fAspectRatio;
333 R__b.CheckByteCount(R__s, R__c, TTUBE::IsA());
334 //====end of old versions
335 } else {
336 R__b.WriteClassBuffer(TTUBE::Class(),this);
337 }
338}
339
340////////////////////////////////////////////////////////////////////////////////
341/// Get buffer 3d.
342
344{
345 static TBuffer3D buffer(TBuffer3DTypes::kGeneric);
346
348
349 // TODO: Although we now have a TBuffer3DTube class for
350 // tube shapes, we do not use it for old geometry tube, as
351 // OGL viewer needs various rotation matrix info we can't easily
352 // pass yet. To be revisited.
353
354 // We also do not fill the bounding box as derived classes can adjust shape
355 // leave up to viewer to work out
358 Int_t nbPnts = 4*n;
359 Int_t nbSegs = 8*n;
360 Int_t nbPols = 4*n;
361 if (buffer.SetRawSizes(nbPnts, 3*nbPnts, nbSegs, 3*nbSegs, nbPols, 6*nbPols)) {
363 }
364 }
366 SetPoints(buffer.fPnts);
367 if (!buffer.fLocalFrame) {
368 TransformPoints(buffer.fPnts, buffer.NbPnts());
369 }
370 SetSegsAndPols(buffer);
372 }
373 return buffer;
374}
#define c(i)
Definition RSha256.hxx:101
short Version_t
Class version identifier (short)
Definition RtypesCore.h:79
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
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 NbPnts() const
Definition TBuffer3D.h:80
Bool_t SectionsValid(UInt_t mask) const
Definition TBuffer3D.h:67
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
Buffer base class used for serializing objects.
Definition TBuffer.h:43
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
This is the base class for all geometry shapes.
Definition TShape.h:35
TShape & operator=(const TShape &)
assignment operator
Definition TShape.cxx:91
void Streamer(TBuffer &) override
Stream an object of class TShape.
Definition TShape.cxx:161
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
virtual void MakeTableOfCoSin() const
Make table of sine and cosine.
Definition TTUBE.cxx:127
Float_t fAspectRatio
Definition TTUBE.h:41
static TClass * Class()
TTUBE & operator=(const TTUBE &)
assignment operator
Definition TTUBE.cxx:109
void Streamer(TBuffer &) override
Stream an object of class TTUBE.
Definition TTUBE.cxx:317
Float_t fRmin
Definition TTUBE.h:35
Int_t fNdiv
Definition TTUBE.h:39
virtual void SetNumberOfDivisions(Int_t ndiv)
Set number of divisions used to draw this tube.
Definition TTUBE.cxx:184
const TBuffer3D & GetBuffer3D(Int_t reqSections) const override
Get buffer 3d.
Definition TTUBE.cxx:343
void Sizeof3D() const override
Return total X3D needed by TNode::ls (when called with option "x")
Definition TTUBE.cxx:305
Float_t fDz
Definition TTUBE.h:38
TClass * IsA() const override
Definition TTUBE.h:72
~TTUBE() override
TUBE shape default destructor.
Definition TTUBE.cxx:162
virtual void SetSegsAndPols(TBuffer3D &buffer) const
Set segments and polygons.
Definition TTUBE.cxx:226
void SetPoints(Double_t *points) const override
Create TUBE points.
Definition TTUBE.cxx:193
TTUBE()
TUBE shape default constructor.
Definition TTUBE.cxx:40
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a TUBE.
Definition TTUBE.cxx:174
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