Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TSPHE.cxx
Go to the documentation of this file.
1// @(#)root/g3d:$Id$
2// Author: Rene Brun 13/06/97
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 "TSPHE.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 TSPHE
22\ingroup g3d
23A Sphere.
24
25It has 9 parameters:
26
27 - name: name of the shape
28 - title: shape's title
29 - material: (see TMaterial)
30 - rmin: minimum radius
31 - rmax: maximum radius
32 - themin: theta min
33 - themax: theta max
34 - phimin: phi min
35 - phimax: phi max
36
37ROOT color indx = max(i-i0,j-j0);
38*/
39
40////////////////////////////////////////////////////////////////////////////////
41/// SPHE shape default constructor
42
44{
45 fRmin = 0;
46 fRmax = 0;
47 fThemin = 0;
48 fThemax = 0;
49 fPhimin = 0;
50 fPhimax = 0;
51 fSiTab = nullptr;
52 fCoTab = nullptr;
53 fCoThetaTab = nullptr;
54 fNdiv = 0;
55 fAspectRatio=1.0;
56 faX = faY = faZ = 1.0; // Coeff along Ox
57 fNz = 0;
58}
59
60////////////////////////////////////////////////////////////////////////////////
61/// SPHE shape normal constructor
62
63TSPHE::TSPHE(const char *name, const char *title, const char *material, Float_t rmin, Float_t rmax, Float_t themin,
65 : TShape(name, title,material)
66{
67 fRmin = rmin;
68 fRmax = rmax;
73
74 fSiTab = nullptr;
75 fCoTab = nullptr;
76 fCoThetaTab = nullptr;
77 fNdiv = 0;
78
79 fAspectRatio=1.0;
80 faX = faY = faZ = 1.0; // Coeff along Ox
81
83}
84
85////////////////////////////////////////////////////////////////////////////////
86/// SPHE shape "simplified" constructor
87
88TSPHE::TSPHE(const char *name, const char *title, const char *material, Float_t rmax)
89 : TShape(name, title,material)
90{
91 fRmin = 0;
92 fRmax = rmax;
93 fThemin = 0;
94 fThemax = 180;
95 fPhimin = 0;
96 fPhimax = 360;
97
98 fSiTab = nullptr;
99 fCoTab = nullptr;
100 fCoThetaTab = nullptr;
101 fNdiv = 0;
102
103 fAspectRatio=1.0;
104 faX = faY = faZ = 1.0; // Coeff along Ox
105
107}
108
109////////////////////////////////////////////////////////////////////////////////
110/// SPHE shape default destructor
111
113{
114 if (fCoThetaTab) delete [] fCoThetaTab;
115 if (fSiTab) delete [] fSiTab;
116 if (fCoTab) delete [] fCoTab;
117
118 fCoTab = nullptr;
119 fSiTab = nullptr;
120 fCoThetaTab=nullptr;
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Compute distance from point px,py to a PSPHE
125///
126/// Compute the closest distance of approach from point px,py to each
127/// computed outline point of the PSPHE (stolen from PCON).
128
130{
132 Int_t numPoints = 2*n*(fNz+1);
133 return ShapeDistancetoPrimitive(numPoints,px,py);
134}
135
136////////////////////////////////////////////////////////////////////////////////
137/// Set ellipse.
138
139void TSPHE::SetEllipse(const Float_t *factors)
140{
141 if (factors[0] > 0) faX = factors[0];
142 if (factors[1] > 0) faY = factors[1];
143 if (factors[2] > 0) faZ = factors[2];
144}
145
146////////////////////////////////////////////////////////////////////////////////
147/// Set number of divisions.
148
150{
151 if (GetNumberOfDivisions () == p) return;
152 fNdiv=p;
155}
156
157////////////////////////////////////////////////////////////////////////////////
158/// Create SPHE points
159
161{
162 Int_t i, j, n;
163 Int_t indx = 0;
164
166
167 if (points) {
168 if (!fCoTab) MakeTableOfCoSin();
169 Float_t z;
170 for (i = 0; i < fNz+1; i++) {
171 z = fRmin * fCoThetaTab[i]; // fSinPhiTab[i];
174 for (j = 0; j < n; j++) {
175 points[indx++] = faX*zi * fCoTab[j];
176 points[indx++] = faY*zi * fSiTab[j];
177 points[indx++] = faZ*z;
178 }
179 z = fRmax * fCoThetaTab[i];
180 zi = fRmax*sithet;
181 for (j = 0; j < n; j++) {
182 points[indx++] = faX*zi * fCoTab[j];
183 points[indx++] = faY*zi * fSiTab[j];
184 points[indx++] = faZ*z;
185 }
186 }
187 }
188}
189
190////////////////////////////////////////////////////////////////////////////////
191/// Return total X3D needed by TNode::ls (when called with option "x")
192
193void TSPHE::Sizeof3D() const
194{
195 Int_t n;
196
198 Int_t nz = fNz+1;
200
201 if (TMath::Abs(TMath::Sin(2*(fPhimax - fPhimin))) <= 0.01) //mark this as a very special case, when
202 specialCase = kTRUE; //we have to draw this PCON like a TUBE
203
204 gSize3D.numPoints += 2*n*nz;
205 gSize3D.numSegs += 4*(nz*n-1+(specialCase == kTRUE));
206 gSize3D.numPolys += 2*(nz*n-1+(specialCase == kTRUE));
207}
208
209////////////////////////////////////////////////////////////////////////////////
210/// Make table of sine and cosine.
211
213{
214 const Double_t pi = TMath::ATan(1) * 4.0;
215 const Double_t ragrad = pi/180.0;
216
218 while (dphi > 360) dphi -= 360;
219
221 while (dtet > 180) dtet -= 180;
222
223 Int_t j;
225 if (fCoTab)
226 delete [] fCoTab; // Delete the old tab if any
227 fCoTab = new Double_t [n];
228 if (!fCoTab ) return;
229
230 if (fSiTab)
231 delete [] fSiTab; // Delete the old tab if any
232 fSiTab = new Double_t [n];
233 if (!fSiTab ) return;
234
237 Double_t angstep = range/(n-1);
238
239 Double_t ph = phi1;
240 for (j = 0; j < n; j++)
241 {
242 ph = phi1 + j*angstep;
243 fCoTab[j] = TMath::Cos(ph);
244 fSiTab[j] = TMath::Sin(ph);
245 }
246
247 n = fNz + 1;
248
249 if (fCoThetaTab)
250 delete [] fCoThetaTab; // Delete the old tab if any
251 fCoThetaTab = new Double_t [n];
252 if (!fCoThetaTab ) return;
253
256 angstep = range/(n-1);
257
258 ph = phi1;
259 for (j = 0; j < n; j++)
260 {
262 ph += angstep;
263 }
264
265}
266
267////////////////////////////////////////////////////////////////////////////////
268/// Stream a class object
269
271{
272 if (b.IsReading()) {
274 Version_t R__v = b.ReadVersion(&R__s, &R__c);
275 if (R__v > 2) {
276 b.ReadClassBuffer(TSPHE::Class(), this, R__v, R__s, R__c);
277 Int_t ndiv = fNdiv;
278 fNdiv = 0;
280 return;
281 }
282 //====process old versions before automatic schema evolution
284 b >> fRmin; // minimum radius
285 b >> fRmax; // maximum radius
286 b >> fThemin; // minimum theta
287 b >> fThemax; // maximum theta
288 b >> fPhimin; // minimum phi
289 b >> fPhimax; // maximum phi
290 Int_t tNdiv; // XXX added by RvdE XXX (fNdiv is set by SetNumberOfDivisions)
291 b >> tNdiv;
292 if (R__v > 1) {
293 b >> faX;
294 b >> faY;
295 b >> faZ;
296 }
297 SetNumberOfDivisions (tNdiv); // XXX added by RvdE
298 b.CheckByteCount(R__s, R__c, TSPHE::IsA());
299 //====end of old versions
300
301 } else {
302 b.WriteClassBuffer(TSPHE::Class(),this);
303 }
304}
305
306////////////////////////////////////////////////////////////////////////////////
307/// Get buffer 3d.
308
310{
311 static TBuffer3D buffer(TBuffer3DTypes::kGeneric);
312
314
315 // Needed by kRawSizes / kRaw
316 const Int_t n = GetNumberOfDivisions()+1;
317 const Int_t nz = fNz+1;
319
321 Int_t nbPnts = 2*n*nz;
322 Int_t nbSegs = 4*(nz*n-1+(specialCase == kTRUE));
323 Int_t nbPols = 2*(nz*n-1+(specialCase == kTRUE));
324 if (buffer.SetRawSizes(nbPnts, 3*nbPnts, nbSegs, 3*nbSegs, nbPols, 6*nbPols)) {
326 }
327 }
329 // Points
330 SetPoints(buffer.fPnts);
331 if (!buffer.fLocalFrame) {
332 TransformPoints(buffer.fPnts, buffer.NbPnts());
333 }
334
336
337 // Segments
338 Int_t indx = 0;
339 Int_t indx2 = 0;
340 Int_t i, j, k;
341 //inside & outside spheres, number of segments: 2*nz*(n-1)
342 // special case number of segments: 2*nz*n
343 for (i = 0; i < nz*2; i++) {
344 indx2 = i*n;
345 for (j = 1; j < n; j++) {
346 buffer.fSegs[indx++] = c;
347 buffer.fSegs[indx++] = indx2+j-1;
348 buffer.fSegs[indx++] = indx2+j;
349 }
350 if (specialCase) {
351 buffer.fSegs[indx++] = c;
352 buffer.fSegs[indx++] = indx2+j-1;
353 buffer.fSegs[indx++] = indx2;
354 }
355 }
356
357 //bottom & top lines, number of segments: 2*n
358 for (i = 0; i < 2; i++) {
359 indx2 = i*(nz-1)*2*n;
360 for (j = 0; j < n; j++) {
361 buffer.fSegs[indx++] = c;
362 buffer.fSegs[indx++] = indx2+j;
363 buffer.fSegs[indx++] = indx2+n+j;
364 }
365 }
366
367 //inside & outside spheres, number of segments: 2*(nz-1)*n
368 for (i = 0; i < (nz-1); i++) {
369
370 //inside sphere
371 indx2 = i*n*2;
372 for (j = 0; j < n; j++) {
373 buffer.fSegs[indx++] = c+2;
374 buffer.fSegs[indx++] = indx2+j;
375 buffer.fSegs[indx++] = indx2+n*2+j;
376 }
377 //outside sphere
378 indx2 = i*n*2+n;
379 for (j = 0; j < n; j++) {
380 buffer.fSegs[indx++] = c+3;
381 buffer.fSegs[indx++] = indx2+j;
382 buffer.fSegs[indx++] = indx2+n*2+j;
383 }
384 }
385
386 //left & right sections, number of segments: 2*(nz-2)
387 // special case number of segments: 0
388 if (!specialCase) {
389 for (i = 1; i < (nz-1); i++) {
390 for (j = 0; j < 2; j++) {
391 buffer.fSegs[indx++] = c;
392 buffer.fSegs[indx++] = 2*i * n + j*(n-1);
393 buffer.fSegs[indx++] = (2*i+1) * n + j*(n-1);
394 }
395 }
396 }
397
398 // Polygons
399 Int_t m = n - 1 + (specialCase == kTRUE);
400 indx = 0;
401
402 //bottom & top, number of polygons: 2*(n-1)
403 // special case number of polygons: 2*n
404 for (j = 0; j < n-1; j++) {
405 buffer.fPols[indx++] = c+3;
406 buffer.fPols[indx++] = 4;
407 buffer.fPols[indx++] = 2*nz*m+j;
408 buffer.fPols[indx++] = m+j;
409 buffer.fPols[indx++] = 2*nz*m+j+1;
410 buffer.fPols[indx++] = j;
411 }
412 for (j = 0; j < n-1; j++) {
413 buffer.fPols[indx++] = c+3;
414 buffer.fPols[indx++] = 4;
415 buffer.fPols[indx++] = 2*nz*m+n+j;
416 buffer.fPols[indx++] = (nz*2-2)*m+j;
417 buffer.fPols[indx++] = 2*nz*m+n+j+1;
418 buffer.fPols[indx++] = (nz*2-2)*m+m+j;
419 }
420 if (specialCase) {
421 buffer.fPols[indx++] = c+3;
422 buffer.fPols[indx++] = 4;
423 buffer.fPols[indx++] = 2*nz*m+j;
424 buffer.fPols[indx++] = m+j;
425 buffer.fPols[indx++] = 2*nz*m;
426 buffer.fPols[indx++] = j;
427
428 buffer.fPols[indx++] = c+3;
429 buffer.fPols[indx++] = 4;
430 buffer.fPols[indx++] = 2*nz*m+n+j;
431 buffer.fPols[indx++] = (nz*2-2)*m+j;
432 buffer.fPols[indx++] = 2*nz*m+n;
433 buffer.fPols[indx++] = (nz*2-2)*m+m+j;
434 }
435
436 //inside & outside, number of polygons: (nz-1)*2*(n-1)
437 for (k = 0; k < (nz-1); k++) {
438 for (j = 0; j < n-1; j++) {
439 buffer.fPols[indx++] = c;
440 buffer.fPols[indx++] = 4;
441 buffer.fPols[indx++] = 2*k*m+j;
442 buffer.fPols[indx++] = nz*2*m+(2*k+2)*n+j+1;
443 buffer.fPols[indx++] = (2*k+2)*m+j;
444 buffer.fPols[indx++] = nz*2*m+(2*k+2)*n+j;
445 }
446 for (j = 0; j < n-1; j++) {
447 buffer.fPols[indx++] = c+1;
448 buffer.fPols[indx++] = 4;
449 buffer.fPols[indx++] = (2*k+1)*m+j;
450 buffer.fPols[indx++] = nz*2*m+(2*k + 3)*n+j;
451 buffer.fPols[indx++] = (2*k+ 3)*m+j;
452 buffer.fPols[indx++] = nz*2*m+(2*k+3)*n+j+1;
453 }
454
455 if (specialCase) {
456 buffer.fPols[indx++] = c;
457 buffer.fPols[indx++] = 4;
458 buffer.fPols[indx++] = 2*k*m+j;
459 buffer.fPols[indx++] = nz*2*m+(2*k+2)*n+j;
460 buffer.fPols[indx++] = (2*k+2)*m+j;
461 buffer.fPols[indx++] = nz*2*m+(2*k+2)*n;
462
463 buffer.fPols[indx++] = c+1;
464 buffer.fPols[indx++] = 4;
465 buffer.fPols[indx++] = (2*k+1)*m+j;
466 buffer.fPols[indx++] = nz*2*m+(2*k+3)*n+j;
467 buffer.fPols[indx++] = (2*k+3)*m+j;
468 buffer.fPols[indx++] = nz*2*m+(2*k+3)*n;
469 }
470 }
471
472 //left & right sections, number of polygons: 2*(nz-1)
473 // special case number of polygons: 0
474 if (!specialCase) {
475 indx2 = nz*2*(n-1);
476 for (k = 0; k < (nz-1); k++) {
477 buffer.fPols[indx++] = c+2;
478 buffer.fPols[indx++] = 4;
479 buffer.fPols[indx++] = k==0 ? indx2 : indx2+2*nz*n+2*(k-1);
480 buffer.fPols[indx++] = indx2+2*(k+1)*n;
481 buffer.fPols[indx++] = indx2+2*nz*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*nz*n+2*(k-1)+1;
487 buffer.fPols[indx++] = indx2+(2*k+3)*n+n-1;
488 buffer.fPols[indx++] = indx2+2*nz*n+2*k+1;
489 buffer.fPols[indx++] = indx2+2*(k+1)*n+n-1;
490 }
491
492 buffer.fPols[indx-8] = indx2+n;
493 buffer.fPols[indx-2] = indx2+2*n-1;
494 }
495
497 }
498
499 return buffer;
500}
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
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
Float_t faY
Definition TSPHE.h:46
virtual void SetNumberOfDivisions(Int_t p)
Set number of divisions.
Definition TSPHE.cxx:149
Float_t fPhimax
Definition TSPHE.h:44
~TSPHE() override
SPHE shape default destructor.
Definition TSPHE.cxx:112
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a PSPHE.
Definition TSPHE.cxx:129
Float_t fThemax
Definition TSPHE.h:42
virtual Int_t GetNumberOfDivisions() const
Definition TSPHE.h:67
virtual void MakeTableOfCoSin() const
Make table of sine and cosine.
Definition TSPHE.cxx:212
TSPHE()
SPHE shape default constructor.
Definition TSPHE.cxx:43
TClass * IsA() const override
Definition TSPHE.h:73
Float_t fRmax
Definition TSPHE.h:40
void Streamer(TBuffer &) override
Stream a class object.
Definition TSPHE.cxx:270
void SetPoints(Double_t *points) const override
Create SPHE points.
Definition TSPHE.cxx:160
const TBuffer3D & GetBuffer3D(Int_t reqSections) const override
Get buffer 3d.
Definition TSPHE.cxx:309
Float_t faX
Definition TSPHE.h:45
Int_t fNz
Definition TSPHE.h:35
Float_t fRmin
Definition TSPHE.h:39
Float_t fPhimin
Definition TSPHE.h:43
Float_t faZ
Definition TSPHE.h:47
static TClass * Class()
Double_t * fCoThetaTab
Table of cos(fPhimin) .... cos(Phi)
Definition TSPHE.h:33
Float_t fThemin
Definition TSPHE.h:41
Double_t * fCoTab
Table of sin(fPhimin) .... sin(Phi)
Definition TSPHE.h:32
virtual void SetEllipse(const Float_t *factors)
Set ellipse.
Definition TSPHE.cxx:139
Float_t fAspectRatio
number of sections
Definition TSPHE.h:36
Double_t * fSiTab
Definition TSPHE.h:31
void Sizeof3D() const override
Return total X3D needed by TNode::ls (when called with option "x")
Definition TSPHE.cxx:193
Int_t fNdiv
Table of sin(gThemin) .... cos(Theta)
Definition TSPHE.h:34
This is the base class for all geometry shapes.
Definition TShape.h:35
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 Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:673
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
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:124
TMarker m
Definition textangle.C:8