Logo ROOT   6.08/07
Reference Guide
TBRIK.cxx
Go to the documentation of this file.
1 // @(#)root/g3d:$Id$
2 // Author: Nenad Buncic 17/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 "TBRIK.h"
13 #include "TNode.h"
14 #include "TVirtualPad.h"
15 #include "TBuffer3D.h"
16 #include "TBuffer3DTypes.h"
17 #include "TGeometry.h"
18 
20 
21 /** \class TBRIK
22 \ingroup g3d
23 A box with faces perpendicular to the axes.
24 
25 \image html g3d_brik.png
26 It has 6 parameters:
27 
28  - name: name of the shape
29  - title: shape's title
30  - material: (see TMaterial)
31  - dx: half-length of the box along the x-axis
32  - dy: half-length of the box along the y-axis
33  - dz: half-length of the box along the z-axis
34 */
35 
36 ////////////////////////////////////////////////////////////////////////////////
37 /// BRIK shape default constructor
38 
40 {
41  fDx = 0.;
42  fDy = 0.;
43  fDz = 0.;
44 }
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// BRIK shape normal constructor
48 
49 TBRIK::TBRIK(const char *name, const char *title, const char *material, Float_t dx, Float_t dy, Float_t dz)
50  : TShape (name, title,material)
51 {
52  fDx = dx;
53  fDy = dy;
54  fDz = dz;
55 }
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// BRIK shape default destructor
59 
61 {
62 }
63 
64 ////////////////////////////////////////////////////////////////////////////////
65 /// Compute distance from point px,py to a BRIK
66 ///
67 /// Compute the closest distance of approach from point px,py to each corner
68 /// point of the BRIK.
69 
71 {
72  const Int_t numPoints = 8;
73  return ShapeDistancetoPrimitive(numPoints,px,py);
74 }
75 
76 ////////////////////////////////////////////////////////////////////////////////
77 /// Create BRIK points
78 
80 {
81  if (points) {
82  points[ 0] = -fDx ; points[ 1] = -fDy ; points[ 2] = -fDz;
83  points[ 3] = -fDx ; points[ 4] = fDy ; points[ 5] = -fDz;
84  points[ 6] = fDx ; points[ 7] = fDy ; points[ 8] = -fDz;
85  points[ 9] = fDx ; points[10] = -fDy ; points[11] = -fDz;
86  points[12] = -fDx ; points[13] = -fDy ; points[14] = fDz;
87  points[15] = -fDx ; points[16] = fDy ; points[17] = fDz;
88  points[18] = fDx ; points[19] = fDy ; points[20] = fDz;
89  points[21] = fDx ; points[22] = -fDy ; points[23] = fDz;
90  }
91 }
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 /// Return total X3D needed by TNode::ls (when called with option "x")
95 
96 void TBRIK::Sizeof3D() const
97 {
98  gSize3D.numPoints += 8;
99  gSize3D.numSegs += 12;
100  gSize3D.numPolys += 6;
101 }
102 
103 ////////////////////////////////////////////////////////////////////////////////
104 /// Get buffer 3D
105 
106 const TBuffer3D & TBRIK::GetBuffer3D(Int_t reqSections) const
107 {
108  static TBuffer3D buffer(TBuffer3DTypes::kGeneric);
109 
110  TShape::FillBuffer3D(buffer, reqSections);
111 
112  // No kShapeSpecific or kBoundingBox
113 
114  if (reqSections & TBuffer3D::kRawSizes) {
115  Int_t nbPnts = 8;
116  Int_t nbSegs = 12;
117  Int_t nbPols = 6;
118  if (buffer.SetRawSizes(nbPnts, nbPnts*3, nbSegs, nbSegs*3, nbPols, nbPols*6)) {
119  buffer.SetSectionsValid(TBuffer3D::kRawSizes);
120  }
121  }
122  if ((reqSections & TBuffer3D::kRaw) && buffer.SectionsValid(TBuffer3D::kRawSizes)) {
123  // Points
124  SetPoints(buffer.fPnts);
125  if (!buffer.fLocalFrame) {
126  TransformPoints(buffer.fPnts, buffer.NbPnts());
127  }
128 
129  Int_t c = GetBasicColor();
130 
131  // Segments
132  buffer.fSegs[ 0] = c ; buffer.fSegs[ 1] = 0 ; buffer.fSegs[ 2] = 1 ;
133  buffer.fSegs[ 3] = c+1 ; buffer.fSegs[ 4] = 1 ; buffer.fSegs[ 5] = 2 ;
134  buffer.fSegs[ 6] = c+1 ; buffer.fSegs[ 7] = 2 ; buffer.fSegs[ 8] = 3 ;
135  buffer.fSegs[ 9] = c ; buffer.fSegs[10] = 3 ; buffer.fSegs[11] = 0 ;
136  buffer.fSegs[12] = c+2 ; buffer.fSegs[13] = 4 ; buffer.fSegs[14] = 5 ;
137  buffer.fSegs[15] = c+2 ; buffer.fSegs[16] = 5 ; buffer.fSegs[17] = 6 ;
138  buffer.fSegs[18] = c+3 ; buffer.fSegs[19] = 6 ; buffer.fSegs[20] = 7 ;
139  buffer.fSegs[21] = c+3 ; buffer.fSegs[22] = 7 ; buffer.fSegs[23] = 4 ;
140  buffer.fSegs[24] = c ; buffer.fSegs[25] = 0 ; buffer.fSegs[26] = 4 ;
141  buffer.fSegs[27] = c+2 ; buffer.fSegs[28] = 1 ; buffer.fSegs[29] = 5 ;
142  buffer.fSegs[30] = c+1 ; buffer.fSegs[31] = 2 ; buffer.fSegs[32] = 6 ;
143  buffer.fSegs[33] = c+3 ; buffer.fSegs[34] = 3 ; buffer.fSegs[35] = 7 ;
144 
145  // Polygons
146  buffer.fPols[ 0] = c ; buffer.fPols[ 1] = 4 ; buffer.fPols[ 2] = 0 ;
147  buffer.fPols[ 3] = 9 ; buffer.fPols[ 4] = 4 ; buffer.fPols[ 5] = 8 ;
148  buffer.fPols[ 6] = c+1 ; buffer.fPols[ 7] = 4 ; buffer.fPols[ 8] = 1 ;
149  buffer.fPols[ 9] = 10 ; buffer.fPols[10] = 5 ; buffer.fPols[11] = 9 ;
150  buffer.fPols[12] = c ; buffer.fPols[13] = 4 ; buffer.fPols[14] = 2 ;
151  buffer.fPols[15] = 11 ; buffer.fPols[16] = 6 ; buffer.fPols[17] = 10 ;
152  buffer.fPols[18] = c+1 ; buffer.fPols[19] = 4 ; buffer.fPols[20] = 3 ;
153  buffer.fPols[21] = 8 ; buffer.fPols[22] = 7 ; buffer.fPols[23] = 11 ;
154  buffer.fPols[24] = c+2 ; buffer.fPols[25] = 4 ; buffer.fPols[26] = 0 ;
155  buffer.fPols[27] = 3 ; buffer.fPols[28] = 2 ; buffer.fPols[29] = 1 ;
156  buffer.fPols[30] = c+3 ; buffer.fPols[31] = 4 ; buffer.fPols[32] = 4 ;
157  buffer.fPols[33] = 5 ; buffer.fPols[34] = 6 ; buffer.fPols[35] = 7 ;
158 
159  buffer.SetSectionsValid(TBuffer3D::kRaw);
160  }
161  return buffer;
162 }
virtual ~TBRIK()
BRIK shape default destructor.
Definition: TBRIK.cxx:60
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:212
float Float_t
Definition: RtypesCore.h:53
return c
Float_t fDx
Definition: TBRIK.h:31
UInt_t NbPnts() const
Definition: TBuffer3D.h:82
int Int_t
Definition: RtypesCore.h:41
Double_t * fPnts
Definition: TBuffer3D.h:114
virtual const TBuffer3D & GetBuffer3D(Int_t reqSections) const
Get buffer 3D.
Definition: TBRIK.cxx:106
virtual void SetPoints(Double_t *points) const
Create BRIK points.
Definition: TBRIK.cxx:79
void SetSectionsValid(UInt_t mask)
Definition: TBuffer3D.h:67
Int_t * fPols
Definition: TBuffer3D.h:116
Int_t ShapeDistancetoPrimitive(Int_t numPoints, Int_t px, Int_t py)
Distance to primitive.
Definition: TShape.cxx:118
Bool_t fLocalFrame
Definition: TBuffer3D.h:92
point * points
Definition: X3DBuffer.c:20
This is the base class for all geometry shapes.
Definition: TShape.h:47
Bool_t SectionsValid(UInt_t mask) const
Definition: TBuffer3D.h:69
#define gSize3D
Definition: X3DBuffer.h:42
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.
Definition: TBuffer3D.cxx:359
Generic 3D primitive description class.
Definition: TBuffer3D.h:19
A box with faces perpendicular to the axes.
Definition: TBRIK.h:28
#define ClassImp(name)
Definition: Rtypes.h:279
double Double_t
Definition: RtypesCore.h:55
virtual void Sizeof3D() const
Return total X3D needed by TNode::ls (when called with option "x")
Definition: TBRIK.cxx:96
Int_t GetBasicColor() const
Get basic color.
Definition: TShape.cxx:242
Int_t * fSegs
Definition: TBuffer3D.h:115
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to a BRIK.
Definition: TBRIK.cxx:70
TBRIK()
BRIK shape default constructor.
Definition: TBRIK.cxx:39
void TransformPoints(Double_t *points, UInt_t NbPnts) const
Transform points (LocalToMaster)
Definition: TShape.cxx:191
char name[80]
Definition: TGX11.cxx:109
Float_t fDy
Definition: TBRIK.h:32
Float_t fDz
Definition: TBRIK.h:33