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