Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
SoTubs Class Reference

#include <SoTubs.h>

+ Inheritance diagram for SoTubs:

Public Member Functions

 SoTubs ()
 Constructor, required.
 
virtual void generateAlternateRep ()
 
virtual void clearAlternateRep ()
 We better be able to clear it, too!
 

Static Public Member Functions

static void initClass ()
 Class Initializer, required.
 

Public Attributes

SoSFFloat pRMin
 Inside radius of the tube.
 
SoSFFloat pRMax
 Outside radius of the tube.
 
SoSFFloat pDz
 Half-length in Z.
 
SoSFFloat pSPhi
 Starting angle, in radians.
 
SoSFFloat pDPhi
 Delta-angle, in radians.
 
SoSFNode alternateRep
 Alternate rep - required.
 

Protected Member Functions

virtual void computeBBox (SoAction *action, SbBox3f &box, SbVec3f &center)
 compute bounding Box, required
 
virtual void generatePrimitives (SoAction *action)
 Generate Primitives, required.
 
virtual SoChildList * getChildren () const
 GetChildList, required whenever the class has hidden children.
 
virtual ~SoTubs ()
 Destructor, required.
 

Detailed Description

Definition at line 71 of file SoTubs.h.

Constructor & Destructor Documentation

◆ SoTubs()

SoTubs::SoTubs ( )

Constructor, required.

Definition at line 61 of file SoTubs.cc.

61 {
62
63
64 // This statement is required
65 SO_NODE_CONSTRUCTOR(SoTubs);
66
67 // Data fields are initialized like this:
68 SO_NODE_ADD_FIELD(pRMin, (0));
69 SO_NODE_ADD_FIELD(pRMax, (1));
70 SO_NODE_ADD_FIELD(pDz, (10));
71 SO_NODE_ADD_FIELD(pSPhi, (0));
72 SO_NODE_ADD_FIELD(pDPhi, ((float)(2*M_PI)));
73 SO_NODE_ADD_FIELD(alternateRep, (NULL));
74 children = new SoChildList(this);
75}
#define M_PI
Definition SbMath.h:33

◆ ~SoTubs()

SoTubs::~SoTubs ( )
protectedvirtual

Destructor, required.

Definition at line 78 of file SoTubs.cc.

78 {
79 delete children;
80}

Referenced by ~SoTubs().

Member Function Documentation

◆ clearAlternateRep()

void SoTubs::clearAlternateRep ( )
virtual

We better be able to clear it, too!

Definition at line 469 of file SoTubs.cc.

469 {
470 alternateRep.setValue(NULL);
471}
SoSFNode alternateRep
Alternate rep - required.
Definition SoTubs.h:101

Referenced by clearAlternateRep().

◆ computeBBox()

void SoTubs::computeBBox ( SoAction * action,
SbBox3f & box,
SbVec3f & center )
protectedvirtual

compute bounding Box, required

Definition at line 256 of file SoTubs.cc.

256 {
257 SbVec3f vmin(-pRMax.getValue(),-pRMax.getValue(),-pDz.getValue()),
258 vmax( pRMax.getValue(), pRMax.getValue(), pDz.getValue());
259 center.setValue(0,0,0);
260 box.setBounds(vmin,vmax);
261}
SoSFFloat pDz
Half-length in Z.
Definition SoTubs.h:89
SoSFFloat pRMax
Outside radius of the tube.
Definition SoTubs.h:85

Referenced by computeBBox().

◆ generateAlternateRep()

void SoTubs::generateAlternateRep ( )
virtual

Generate AlternateRep, required. Generating an alternate representation must be done upon users request. It allows an Inventor program to read back the file without requiring this code to be dynamically linked. If the users expects that this code will be dynamically linked, he need not invoke this method.

Definition at line 458 of file SoTubs.cc.

458 {
459
460 // This routine sets the alternate representation to the child
461 // list of this mode.
462
463 if (children->getLength() == 0) generateChildren();
464 updateChildren();
465 alternateRep.setValue((SoSeparator *) ( *children)[0]);
466}

Referenced by generateAlternateRep().

◆ generatePrimitives()

void SoTubs::generatePrimitives ( SoAction * action)
protectedvirtual

Generate Primitives, required.

Definition at line 94 of file SoTubs.cc.

94 {
95 // This variable is used to store each vertex
96 SoPrimitiveVertex pv;
97
98 // Access the stat from the action
99 SoState *state = action->getState();
100
101 // See if we have to use a texture coordinate function,
102 // rather than generating explicit texture coordinates.
103 SbBool useTexFunction=
104 (SoTextureCoordinateElement::getType(state) ==
105 SoTextureCoordinateElement::FUNCTION);
106
107 // If we need to generate texture coordinates with a function,
108 // we'll need an SoGLTextureCoordinateElement. Otherwise, we'll
109 // set up the coordinates directly.
110 const SoTextureCoordinateElement* tce = NULL;
111 SbVec4f texCoord;
112 if (useTexFunction) {
113 tce = SoTextureCoordinateElement::getInstance(state);
114 }
115 else {
116 texCoord[2] = 0.0;
117 texCoord[3] = 1.0;
118 }
119 SbVec3f point, normal;
120
121
122 ///////////////////////////////////////////////////////
123 //-----------------------------------------------------
124#define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz) \
125 point.setValue((float)(x),(float)(y),(float)(z)); \
126 normal.setValue((float)(nx),(float)(ny),(float)(nz)); \
127 if (useTexFunction) { \
128 texCoord=tce->get(point,normal); \
129 } else { \
130 texCoord[0]=(float)(s); \
131 texCoord[1]=(float)(t); \
132 } \
133 pv.setPoint(point); \
134 pv.setNormal(normal); \
135 pv.setTextureCoords(texCoord); \
136 shapeVertex(&pv);
137 //-----------------------------------------------------
138 ///////////////////////////////////////////////////////
139
140 int NPHI = (int)(2+22*std::fabs(pDPhi.getValue()/(2.0*M_PI)));
141 double deltaPhi = pDPhi.getValue()/NPHI, phi0 = pSPhi.getValue(),phi1=phi0+pDPhi.getValue();
142 double rMax=pRMax.getValue(),rMin=pRMin.getValue();
143 double zMax=pDz.getValue(),zMin=-zMax;
144 double cosPhi0=std::cos(phi0), sinPhi0=std::sin(phi0);
145 double cosPhi1=std::cos(phi1), sinPhi1=std::sin(phi1);
146 double cosDeltaPhi=std::cos(deltaPhi),sinDeltaPhi=std::sin(deltaPhi);
147 //
148 // The outer surface!
149 //
150 int i;
151 double sinPhi,cosPhi;
152 beginShape(action,TRIANGLE_STRIP);
153 sinPhi=sinPhi0;
154 cosPhi=cosPhi0;
155 for (i = 0; i<=NPHI; i++) {
156 GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMax,0.0,0.0,cosPhi,sinPhi,0);
157 GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMin,1.0,1.0,cosPhi,sinPhi,0);
158 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
159 }
160 endShape();
161 //
162 // The inner surface!
163 //
164 if(rMin!=0.F) {
165 beginShape(action,TRIANGLE_STRIP);
166 sinPhi=sinPhi0;
167 cosPhi=cosPhi0;
168 for (i = 0; i<=NPHI; i++) {
169 GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMax,0.0,0.0,-cosPhi,-sinPhi,0);
170 GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMin,1.0,1.0,-cosPhi,-sinPhi,0);
171 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
172 }
173 endShape();
174 }
175 if (std::fabs(deltaPhi)<2.0*M_PI) {
176 //
177 // The end
178 //
179 beginShape(action,TRIANGLE_STRIP);
180 sinPhi=sinPhi0;
181 cosPhi=cosPhi0;
182 GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMax,0.0,0.0,sinPhi,-cosPhi,0);
183 GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMin,1.0,1.0,sinPhi,-cosPhi,0);
184 GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMax,1.0,0.0,sinPhi,-cosPhi,0);
185 GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMin,0.0,1.0,sinPhi,-cosPhi,0);
186 endShape();
187 //
188 // The other end
189 //
190 beginShape(action,TRIANGLE_STRIP);
191 sinPhi=sinPhi1;
192 cosPhi=cosPhi1;
193 GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi, zMax,0.0,0.0,-sinPhi,+cosPhi,0);
194 GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi, zMin,1.0,1.0,-sinPhi,+cosPhi,0);
195 GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi, zMax,1.0,0.0,-sinPhi,+cosPhi,0);
196 GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi, zMin,0.0,1.0,-sinPhi,+cosPhi,0);
197 endShape();
198 }
199 //
200 // The outer surface at z=+PDZ
201 //
202 if(rMin==0.F) {
203 beginShape(action,TRIANGLE_FAN);
204 sinPhi=sinPhi0;
205 cosPhi=cosPhi0;
206 GEN_VERTEX(pv,0,0,zMax,0.0,0.0,0,0,1);
207 for (i = 0; i<=NPHI; i++) {
208 GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMax,1.0,1.0,0,0,1);
209 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
210 }
211 endShape();
212 //
213 // The outer surface at z=-PDZ
214 //
215 beginShape(action,TRIANGLE_FAN);
216 sinPhi=sinPhi0;
217 cosPhi=cosPhi0;
218 GEN_VERTEX(pv,0,0,zMin,0.0,0.0,0,0,-1);
219 for (i = 0; i<=NPHI; i++) {
220 GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMin,1.0,1.0,0,0,-1);
221 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
222 }
223 endShape();
224 } else {
225 beginShape(action,TRIANGLE_STRIP);
226 sinPhi=sinPhi0;
227 cosPhi=cosPhi0;
228 for (i = 0; i<=NPHI; i++) {
229 GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMax,0.0,0.0,0,0,1);
230 GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMax,1.0,1.0,0,0,1);
231 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
232 }
233 endShape();
234 //
235 // The outer surface at z=-PDZ
236 //
237 beginShape(action,TRIANGLE_STRIP);
238 sinPhi=sinPhi0;
239 cosPhi=cosPhi0;
240 for (i = 0; i<=NPHI; i++) {
241 GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMin,0.0,0.0,0,0,-1);
242 GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMin,1.0,1.0,0,0,-1);
243 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
244 }
245 endShape();
246 }
247}
#define GEN_VERTEX(pv, x, y, z, s, t, nx, ny, nz)
SoSFFloat pDPhi
Delta-angle, in radians.
Definition SoTubs.h:97
SoSFFloat pSPhi
Starting angle, in radians.
Definition SoTubs.h:93
SoSFFloat pRMin
Inside radius of the tube.
Definition SoTubs.h:81

Referenced by generatePrimitives().

◆ getChildren()

SoChildList * SoTubs::getChildren ( ) const
protectedvirtual

GetChildList, required whenever the class has hidden children.

Definition at line 250 of file SoTubs.cc.

250 {
251 return children;
252}

Referenced by getChildren().

◆ initClass()

void SoTubs::initClass ( )
static

Class Initializer, required.

Definition at line 84 of file SoTubs.cc.

84 {
85 // This statement is required.
86 static bool first = true;
87 if (first) {
88 first = false;
89 SO_NODE_INIT_CLASS(SoTubs,SoShape,"Shape");
90 }
91}

Referenced by initClass().

Member Data Documentation

◆ alternateRep

SoSFNode SoTubs::alternateRep

Alternate rep - required.

Definition at line 101 of file SoTubs.h.

Referenced by clearAlternateRep(), and generateAlternateRep().

◆ pDPhi

SoSFFloat SoTubs::pDPhi

Delta-angle, in radians.

Definition at line 97 of file SoTubs.h.

Referenced by generatePrimitives().

◆ pDz

SoSFFloat SoTubs::pDz

Half-length in Z.

Definition at line 89 of file SoTubs.h.

Referenced by computeBBox(), and generatePrimitives().

◆ pRMax

SoSFFloat SoTubs::pRMax

Outside radius of the tube.

Definition at line 85 of file SoTubs.h.

Referenced by computeBBox(), and generatePrimitives().

◆ pRMin

SoSFFloat SoTubs::pRMin

Inside radius of the tube.

Definition at line 81 of file SoTubs.h.

Referenced by generatePrimitives().

◆ pSPhi

SoSFFloat SoTubs::pSPhi

Starting angle, in radians.

Definition at line 93 of file SoTubs.h.

Referenced by generatePrimitives().


The documentation for this class was generated from the following files: