Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPCON.cxx
Go to the documentation of this file.
1// @(#)root/g3d:$Id$
2// Author: Nenad Buncic 29/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 "TPCON.h"
13#include "TNode.h"
14#include "TMath.h"
15#include "TBuffer.h"
16#include "TBuffer3D.h"
17#include "TBuffer3DTypes.h"
18#include "TGeometry.h"
19
20
21/** \class TPCON
22\ingroup g3d
23A polycone
24
25\image html g3d_pcon.png
26It has the following parameters:
27
28 - name: name of the shape
29 - title: shape's title
30 - material: (see TMaterial)
31 - phi1: the azimuthal angle phi at which the volume begins (angles
32 are counted counterclockwise)
33 - dphi: opening angle of the volume, which extends from
34 phi1 to phi1+dphi
35 - nz: number of planes perpendicular to the z axis where
36 the dimension of the section is given -- this number
37 should be at least 2
38 - rmin: array of dimension nz with minimum radius at a given plane
39 - rmax: array of dimension nz with maximum radius at a given plane
40 - z: array of dimension nz with z position of given plane
41*/
42
43////////////////////////////////////////////////////////////////////////////////
44/// PCON shape default constructor
45
47{
48 fRmin = nullptr;
49 fRmax = nullptr;
50 fDz = nullptr;
51 fCoTab = nullptr;
52 fSiTab = nullptr;
53 fPhi1 = 0.;
54 fDphi1 = 0.;
55 fNz = 0;
56 fNdiv = 0;
57}
58
59////////////////////////////////////////////////////////////////////////////////
60/// PCON shape normal constructor
61///
62/// Parameters of the nz positions must be entered via TPCON::DefineSection.
63
64TPCON::TPCON(const char *name, const char *title, const char *material, Float_t phi1, Float_t dphi1, Int_t nz)
65 : TShape(name, title,material)
66{
67 if (nz < 2 ) {
68 Error(name, "number of z planes for %s must be at least two !", name);
69 return;
70 }
71 fPhi1 = phi1;
72 fDphi1 = dphi1;
73 fNz = nz;
74 fNdiv = 0;
75 fRmin = new Float_t [nz+1];
76 fRmax = new Float_t [nz+1];
77 fDz = new Float_t [nz+1];
78
79 fCoTab = nullptr;
80 fSiTab = nullptr;
81
82 while (fDphi1 > 360) fDphi1 -= 360;
83
85}
86
87////////////////////////////////////////////////////////////////////////////////
88/// copy constructor
89
90TPCON::TPCON(const TPCON& pc) :
91 TShape(pc),
92 fSiTab(pc.fSiTab),
93 fCoTab(pc.fCoTab),
94 fPhi1(pc.fPhi1),
95 fDphi1(pc.fDphi1),
96 fNdiv(pc.fNdiv),
97 fNz(pc.fNz),
98 fRmin(pc.fRmin),
99 fRmax(pc.fRmax),
100 fDz(pc.fDz)
101{
102}
103
104////////////////////////////////////////////////////////////////////////////////
105/// assignment operator
106
108{
109 if(this!=&pc) {
111 fSiTab=pc.fSiTab;
112 fCoTab=pc.fCoTab;
113 fPhi1=pc.fPhi1;
114 fDphi1=pc.fDphi1;
115 fNdiv=pc.fNdiv;
116 fNz=pc.fNz;
117 fRmin=pc.fRmin;
118 fRmax=pc.fRmax;
119 fDz=pc.fDz;
120 }
121 return *this;
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// Make table of cosine and sine
126
128{
129 const Double_t pi = TMath::ATan(1) * 4.0;
130 const Double_t ragrad = pi/180.0;
131
133 if (fCoTab) delete [] fCoTab; // Delete the old tab if any
134 fCoTab = new Double_t [n];
135 if (!fCoTab ) return;
136
137 if (fSiTab) delete [] fSiTab; // Delete the old tab if any
138 fSiTab = new Double_t [n];
139 if (!fSiTab ) return;
140
143 Double_t angstep = range/(n-1);
144
146}
147
148////////////////////////////////////////////////////////////////////////////////
149/// PCON shape default destructor
150
152{
153 if (fRmin) delete [] fRmin;
154 if (fRmax) delete [] fRmax;
155 if (fDz) delete [] fDz;
156 if (fSiTab) delete [] fSiTab;
157 if (fCoTab) delete [] fCoTab;
158
159 fRmin = nullptr;
160 fRmax = nullptr;
161 fDz = nullptr;
162 fCoTab = nullptr;
163 fSiTab = nullptr;
164}
165
166////////////////////////////////////////////////////////////////////////////////
167/// Defines section secNum of the polycone
168///
169/// - rmin radius of the inner circle in the cross-section
170/// - rmax radius of the outer circle in the cross-section
171/// - z z coordinate of the section
172
174{
175 if ((secNum < 0) || (secNum >= fNz)) return;
176
177 fRmin[secNum] = rmin;
178 fRmax[secNum] = rmax;
179 fDz[secNum] = z;
180}
181
182////////////////////////////////////////////////////////////////////////////////
183/// Compute distance from point px,py to a PCON
184///
185/// Compute the closest distance of approach from point px,py to each
186/// computed outline point of the PCON.
187
189{
191 Int_t numPoints = fNz*2*n;
192 return ShapeDistancetoPrimitive(numPoints,px,py);
193}
194
195////////////////////////////////////////////////////////////////////////////////
196/// Fill the table of cos and sin to prepare drawing
197
199{
200 Double_t ph = phi-angstep;
201 for (Int_t j = 0; j < n; j++) {
202 ph += angstep;
203 fCoTab[j] = TMath::Cos(ph);
204 fSiTab[j] = TMath::Sin(ph);
205 }
206}
207
208////////////////////////////////////////////////////////////////////////////////
209/// Set number of divisions.
210
212{
213 if (GetNumberOfDivisions () == p) return;
214 fNdiv=p;
216}
217
218////////////////////////////////////////////////////////////////////////////////
219/// Create PCON points
220
222{
223 Int_t i, j;
224 Int_t indx = 0;
225
227
228 if (points) {
229 if (!fCoTab) MakeTableOfCoSin();
230 for (i = 0; i < fNz; i++) {
231 for (j = 0; j < n; j++) {
232 points[indx++] = fRmin[i] * fCoTab[j];
233 points[indx++] = fRmin[i] * fSiTab[j];
234 points[indx++] = fDz[i];
235 }
236 for (j = 0; j < n; j++) {
237 points[indx++] = fRmax[i] * fCoTab[j];
238 points[indx++] = fRmax[i] * fSiTab[j];
239 points[indx++] = fDz[i];
240 }
241 }
242 }
243}
244
245////////////////////////////////////////////////////////////////////////////////
246/// Return total X3D needed by TNode::ls (when called with option "x")
247
248void TPCON::Sizeof3D() const
249{
250 Int_t n;
251
253
254 gSize3D.numPoints += fNz*2*n;
255 gSize3D.numSegs += 4*(fNz*n-1+(fDphi1 == 360));
256 gSize3D.numPolys += 2*(fNz*n-1+(fDphi1 == 360));
257}
258
259////////////////////////////////////////////////////////////////////////////////
260/// Stream a class object
261
263{
264 if (b.IsReading()) {
266 Version_t R__v = b.ReadVersion(&R__s, &R__c);
267 if (R__v > 1) {
268 b.ReadClassBuffer(TPCON::Class(), this, R__v, R__s, R__c);
269 return;
270 }
271 //====process old versions before automatic schema evolution
273 b >> fPhi1;
274 b >> fDphi1;
275 b >> fNz;
276 fRmin = new Float_t [fNz];
277 fRmax = new Float_t [fNz];
278 fDz = new Float_t [fNz];
279 b.ReadArray(fRmin);
280 b.ReadArray(fRmax);
281 b.ReadArray(fDz);
282 b >> fNdiv;
283 b.CheckByteCount(R__s, R__c, TPCON::IsA());
284 //====end of old versions
285
286 } else {
287 b.WriteClassBuffer(TPCON::Class(),this);
288 }
289}
290
291////////////////////////////////////////////////////////////////////////////////
292/// Get buffer 3d.
293
295{
296 static TBuffer3D buffer(TBuffer3DTypes::kGeneric);
297
299
300 // No kShapeSpecific or kBoundingBox
301
303 {
304 const Int_t n = GetNumberOfDivisions()+1;
305 Int_t nbPnts = fNz*2*n;
306 Bool_t specialCase = (fDphi1 == 360);
307 Int_t nbSegs = 4*(fNz*n-1+(specialCase == kTRUE));
308 Int_t nbPols = 2*(fNz*n-1+(specialCase == kTRUE));
309
310 if (buffer.SetRawSizes(nbPnts, 3*nbPnts, nbSegs, 3*nbSegs, nbPols, 6*nbPols)) {
312 }
313 }
315 {
316 // Points
317 SetPoints(buffer.fPnts);
318 if (!buffer.fLocalFrame) {
319 TransformPoints(buffer.fPnts, buffer.NbPnts());
320 }
321
322 // Segments and Polygons
323 if (SetSegsAndPols(buffer))
324 {
326 }
327 }
328 return buffer;
329}
330
331////////////////////////////////////////////////////////////////////////////////
332/// Set segments and polygons.
333
335{
336 if (fNz < 2) return kFALSE;
337 const Int_t n = GetNumberOfDivisions()+1;
338 Bool_t specialCase = (fDphi1 == 360);
339
341
342 Int_t i, j, k;
343 Int_t indx = 0;
344 Int_t indx2 = 0;
345
346 //inside & outside circles, number of segments: 2*fNz*(n-1)
347 // special case number of segments: 2*fNz*n
348 for (i = 0; i < fNz*2; i++) {
349 indx2 = i*n;
350 for (j = 1; j < n; j++) {
351 buffer.fSegs[indx++] = c;
352 buffer.fSegs[indx++] = indx2+j-1;
353 buffer.fSegs[indx++] = indx2+j;
354 }
355 if (specialCase) {
356 buffer.fSegs[indx++] = c;
357 buffer.fSegs[indx++] = indx2+j-1;
358 buffer.fSegs[indx++] = indx2;
359 }
360 }
361
362 //bottom & top lines, number of segments: 2*n
363 for (i = 0; i < 2; i++) {
364 indx2 = i*(fNz-1)*2*n;
365 for (j = 0; j < n; j++) {
366 buffer.fSegs[indx++] = c;
367 buffer.fSegs[indx++] = indx2+j;
368 buffer.fSegs[indx++] = indx2+n+j;
369 }
370 }
371
372 //inside & outside cilindres, number of segments: 2*(fNz-1)*n
373 for (i = 0; i < (fNz-1); i++) {
374
375 //inside cilinder
376 indx2 = i*n*2;
377 for (j = 0; j < n; j++) {
378 buffer.fSegs[indx++] = c+2;
379 buffer.fSegs[indx++] = indx2+j;
380 buffer.fSegs[indx++] = indx2+n*2+j;
381 }
382 //outside cilinder
383 indx2 = i*n*2+n;
384 for (j = 0; j < n; j++) {
385 buffer.fSegs[indx++] = c+3;
386 buffer.fSegs[indx++] = indx2+j;
387 buffer.fSegs[indx++] = indx2+n*2+j;
388 }
389 }
390
391 //left & right sections, number of segments: 2*(fNz-2)
392 // special case number of segments: 0
393 if (!specialCase) {
394 for (i = 1; i < (fNz-1); i++) {
395 for (j = 0; j < 2; j++) {
396 buffer.fSegs[indx++] = c;
397 buffer.fSegs[indx++] = 2*i * n + j*(n-1);
398 buffer.fSegs[indx++] = (2*i+1) * n + j*(n-1);
399 }
400 }
401 }
402
403 Int_t m = n - 1 + (specialCase == kTRUE);
404 indx = 0;
405
406 //bottom & top, number of polygons: 2*(n-1)
407 // special case number of polygons: 2*n
408 for (j = 0; j < n-1; j++) {
409 buffer.fPols[indx++] = c+3;
410 buffer.fPols[indx++] = 4;
411 buffer.fPols[indx++] = 2*fNz*m+j;
412 buffer.fPols[indx++] = m+j;
413 buffer.fPols[indx++] = 2*fNz*m+j+1;
414 buffer.fPols[indx++] = j;
415 }
416 for (j = 0; j < n-1; j++) {
417 buffer.fPols[indx++] = c+3;
418 buffer.fPols[indx++] = 4;
419 buffer.fPols[indx++] = 2*fNz*m+n+j;
420 buffer.fPols[indx++] = (fNz*2-2)*m+j;
421 buffer.fPols[indx++] = 2*fNz*m+n+j+1;
422 buffer.fPols[indx++] = (fNz*2-2)*m+m+j;
423 }
424 if (specialCase) {
425 buffer.fPols[indx++] = c+3;
426 buffer.fPols[indx++] = 4;
427 buffer.fPols[indx++] = 2*fNz*m+j;
428 buffer.fPols[indx++] = m+j;
429 buffer.fPols[indx++] = 2*fNz*m;
430 buffer.fPols[indx++] = j;
431
432 buffer.fPols[indx++] = c+3;
433 buffer.fPols[indx++] = 4;
434 buffer.fPols[indx++] = 2*fNz*m+n+j;
435 buffer.fPols[indx++] = (fNz*2-2)*m+j;
436 buffer.fPols[indx++] = 2*fNz*m+n;
437 buffer.fPols[indx++] = (fNz*2-2)*m+m+j;
438 }
439 for (k = 0; k < (fNz-1); k++) {
440 for (j = 0; j < n-1; j++) {
441 buffer.fPols[indx++] = c;
442 buffer.fPols[indx++] = 4;
443 buffer.fPols[indx++] = 2*k*m+j;
444 buffer.fPols[indx++] = fNz*2*m+(2*k+2)*n+j+1;
445 buffer.fPols[indx++] = (2*k+2)*m+j;
446 buffer.fPols[indx++] = fNz*2*m+(2*k+2)*n+j;
447 }
448 for (j = 0; j < n-1; j++) {
449 buffer.fPols[indx++] = c+1;
450 buffer.fPols[indx++] = 4;
451 buffer.fPols[indx++] = (2*k+1)*m+j;
452 buffer.fPols[indx++] = fNz*2*m+(2*k+3)*n+j;
453 buffer.fPols[indx++] = (2*k+3)*m+j;
454 buffer.fPols[indx++] = fNz*2*m+(2*k+3)*n+j+1;
455 }
456
457 if (specialCase) {
458 buffer.fPols[indx++] = c;
459 buffer.fPols[indx++] = 4;
460 buffer.fPols[indx++] = 2*k*m+j;
461 buffer.fPols[indx++] = fNz*2*m+(2*k+2)*n;
462 buffer.fPols[indx++] = (2*k+2)*m+j;
463 buffer.fPols[indx++] = fNz*2*m+(2*k+2)*n+j;
464
465 buffer.fPols[indx++] = c+1;
466 buffer.fPols[indx++] = 4;
467 buffer.fPols[indx++] = (2*k+1)*m+j;
468 buffer.fPols[indx++] = fNz*2*m+(2*k+3)*n+j;
469 buffer.fPols[indx++] = (2*k+3)*m+j;
470 buffer.fPols[indx++] = fNz*2*m+(2*k+3)*n;
471 }
472 }
473
474 if (!specialCase) {
475 indx2 = fNz*2*(n-1);
476 for (k = 0; k < (fNz-1); k++) {
477 buffer.fPols[indx++] = c+2;
478 buffer.fPols[indx++] = 4;
479 buffer.fPols[indx++] = k==0 ? indx2 : indx2+2*fNz*n+2*(k-1);
480 buffer.fPols[indx++] = indx2+2*(k+1)*n;
481 buffer.fPols[indx++] = indx2+2*fNz*n+2*k;
482 buffer.fPols[indx++] = indx2+(2*k+3)*n;
483
484 buffer.fPols[indx++] = c+2;
485 buffer.fPols[indx++] = 4;
486 buffer.fPols[indx++] = k==0 ? indx2+n-1 : indx2+2*fNz*n+2*(k-1)+1;
487 buffer.fPols[indx++] = indx2+(2*k+3)*n+n-1;
488 buffer.fPols[indx++] = indx2+2*fNz*n+2*k+1;
489 buffer.fPols[indx++] = indx2+2*(k+1)*n+n-1;
490 }
491 buffer.fPols[indx-8] = indx2+n;
492 buffer.fPols[indx-2] = indx2+2*n-1;
493 }
494
495 return kTRUE;
496}
#define b(i)
Definition RSha256.hxx:100
#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
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
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
A polycone.
Definition TPCON.h:33
virtual void SetNumberOfDivisions(Int_t p)
Set number of divisions.
Definition TPCON.cxx:211
const TBuffer3D & GetBuffer3D(Int_t reqSections) const override
Get buffer 3d.
Definition TPCON.cxx:294
Double_t * fCoTab
Table of sin(fPhi1) .... sin(fPhil+fDphi1)
Definition TPCON.h:37
void Sizeof3D() const override
Return total X3D needed by TNode::ls (when called with option "x")
Definition TPCON.cxx:248
void Streamer(TBuffer &) override
Stream a class object.
Definition TPCON.cxx:262
Float_t fPhi1
Table of cos(fPhi1) .... cos(fPhil+fDphi1)
Definition TPCON.h:39
Float_t * fRmax
Definition TPCON.h:44
static TClass * Class()
virtual Int_t GetNumberOfDivisions() const
Definition TPCON.h:63
Int_t fNdiv
Definition TPCON.h:41
Int_t fNz
Definition TPCON.h:42
Float_t * fDz
Definition TPCON.h:45
TPCON & operator=(const TPCON &)
assignment operator
Definition TPCON.cxx:107
TPCON()
PCON shape default constructor.
Definition TPCON.cxx:46
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a PCON.
Definition TPCON.cxx:188
virtual Bool_t SetSegsAndPols(TBuffer3D &buffer) const
Set segments and polygons.
Definition TPCON.cxx:334
Float_t fDphi1
Definition TPCON.h:40
~TPCON() override
PCON shape default destructor.
Definition TPCON.cxx:151
Double_t * fSiTab
Definition TPCON.h:36
Float_t * fRmin
Definition TPCON.h:43
TClass * IsA() const override
Definition TPCON.h:74
virtual void FillTableOfCoSin(Double_t phi, Double_t angstep, Int_t n) const
Fill the table of cos and sin to prepare drawing.
Definition TPCON.cxx:198
virtual void DefineSection(Int_t secNum, Float_t z, Float_t rmin, Float_t rmax)
Defines section secNum of the polycone.
Definition TPCON.cxx:173
void SetPoints(Double_t *points) const override
Create PCON points.
Definition TPCON.cxx:221
virtual void MakeTableOfCoSin() const
Make table of cosine and sine.
Definition TPCON.cxx:127
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
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
TMarker m
Definition textangle.C:8