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

#include <SoTrap.h>

+ Inheritance diagram for SoTrap:

Public Member Functions

 SoTrap ()
 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 pDz
 half-length along Z
 
SoSFFloat pTheta
 Polar angle of the line joining the centres of the faces at -/+pDz.
 
SoSFFloat pPhi
 
SoSFFloat pDy1
 Half-length along y of the face at -pDz.
 
SoSFFloat pDx1
 Half-length along x of the side at y=-pDy1 of the face at -pDz.
 
SoSFFloat pDx2
 Half-length along x of the side at y=+pDy1 of the face at -pDz.
 
SoSFFloat pDy2
 Half-length along y of the face at +pDz.
 
SoSFFloat pDx3
 Half-length along x of the side at y=-pDy2 of the face at +pDz.
 
SoSFFloat pDx4
 Half-length along x of the side at y=+pDy2 of the face at +pDz.
 
SoSFFloat pAlp1
 
SoSFFloat pAlp2
 
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 ~SoTrap ()
 Destructor, required.
 

Detailed Description

Definition at line 81 of file SoTrap.h.

Constructor & Destructor Documentation

◆ SoTrap()

SoTrap::SoTrap ( )

Constructor, required.

Definition at line 62 of file SoTrap.cc.

62 {
63 // This statement is required
64 SO_NODE_CONSTRUCTOR(SoTrap);
65
66 // Data fields are initialized like this:
67 SO_NODE_ADD_FIELD(pDz, (1.0));
68 SO_NODE_ADD_FIELD(pTheta, (0.0));
69 SO_NODE_ADD_FIELD(pPhi, (0.0));
70 SO_NODE_ADD_FIELD(pDy1, (1.0));
71 SO_NODE_ADD_FIELD(pDx1, (1.0));
72 SO_NODE_ADD_FIELD(pDx2, (1.0));
73 SO_NODE_ADD_FIELD(pDy2, (1.0));
74 SO_NODE_ADD_FIELD(pDx3, (1.0));
75 SO_NODE_ADD_FIELD(pDx4, (1.0));
76 SO_NODE_ADD_FIELD(pAlp1, (0.0));
77 SO_NODE_ADD_FIELD(pAlp2, (0.0));
78 SO_NODE_ADD_FIELD(alternateRep, (NULL));
79 children = new SoChildList(this);
80}
Definition: SoTrap.h:81

◆ ~SoTrap()

SoTrap::~SoTrap ( )
protectedvirtual

Destructor, required.

Definition at line 83 of file SoTrap.cc.

83 {
84 delete children;
85}

Member Function Documentation

◆ clearAlternateRep()

void SoTrap::clearAlternateRep ( )
virtual

We better be able to clear it, too!

Definition at line 409 of file SoTrap.cc.

409 {
410 alternateRep.setValue(NULL);
411}
SoSFNode alternateRep
Alternate rep - required.
Definition: SoTrap.h:145

◆ computeBBox()

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

compute bounding Box, required

Definition at line 252 of file SoTrap.cc.

252 {
253 float pDx= pDx1.getValue(),pDy=pDy1.getValue();
254
255 if (pDx2.getValue() > pDx) pDx = pDx2.getValue();
256 if (pDx3.getValue() > pDx) pDx = pDx3.getValue();
257 if (pDx4.getValue() > pDx) pDx = pDx4.getValue();
258 if (pDy2.getValue() > pDy) pDy = pDy2.getValue();
259 float TthetaCphi = FTAN(pTheta.getValue())*FCOS(pPhi.getValue());
260 float TthetaSphi = FTAN(pTheta.getValue())*FSIN(pPhi.getValue());
261 float Xalp = FFABS(std::tan(pAlp1.getValue())*pDy1.getValue());
262 float Xalp2 = FFABS(std::tan(pAlp2.getValue())*pDy2.getValue());
263 if (Xalp< Xalp2) Xalp=Xalp2;
264 pDx += FFABS(TthetaCphi*pDz.getValue());
265 pDx += Xalp;
266 pDy += FFABS(TthetaSphi*pDz.getValue());
267
268
269 center.setValue(0,0,0);
270 box.setBounds(SbVec3f(-pDx,-pDy,-pDz.getValue()),
271 SbVec3f( pDx, pDy, pDz.getValue()));
272}
#define FFABS(x)
Definition: SbMath.h:51
#define FCOS(x)
Definition: SbMath.h:40
#define FSIN(x)
Definition: SbMath.h:41
#define FTAN(x)
Definition: SbMath.h:44
SoSFFloat pDx2
Half-length along x of the side at y=+pDy1 of the face at -pDz.
Definition: SoTrap.h:118
SoSFFloat pDz
half-length along Z
Definition: SoTrap.h:97
SoSFFloat pAlp2
Definition: SoTrap.h:140
SoSFFloat pDx4
Half-length along x of the side at y=+pDy2 of the face at +pDz.
Definition: SoTrap.h:130
SoSFFloat pDy1
Half-length along y of the face at -pDz.
Definition: SoTrap.h:110
SoSFFloat pAlp1
Definition: SoTrap.h:135
SoSFFloat pTheta
Polar angle of the line joining the centres of the faces at -/+pDz.
Definition: SoTrap.h:101
SoSFFloat pDx3
Half-length along x of the side at y=-pDy2 of the face at +pDz.
Definition: SoTrap.h:126
SoSFFloat pDx1
Half-length along x of the side at y=-pDy1 of the face at -pDz.
Definition: SoTrap.h:114
SoSFFloat pPhi
Definition: SoTrap.h:106
SoSFFloat pDy2
Half-length along y of the face at +pDz.
Definition: SoTrap.h:122

◆ generateAlternateRep()

void SoTrap::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 398 of file SoTrap.cc.

398 {
399
400 // This routine sets the alternate representation to the child
401 // list of this mode.
402
403 if (children->getLength() == 0) generateChildren();
404 updateChildren();
405 alternateRep.setValue((SoSeparator *) ( *children)[0]);
406}

◆ generatePrimitives()

void SoTrap::generatePrimitives ( SoAction *  action)
protectedvirtual

Generate Primitives, required.

Definition at line 100 of file SoTrap.cc.

100 {
101 // This variable is used to store each vertex
102 SoPrimitiveVertex pv;
103
104 // Access the stat from the action
105 SoState *state = action->getState();
106
107 // See if we have to use a texture coordinate function,
108 // rather than generating explicit texture coordinates.
109 SbBool useTexFunction=
110 (SoTextureCoordinateElement::getType(state) ==
111 SoTextureCoordinateElement::FUNCTION);
112
113 // If we need to generate texture coordinates with a function,
114 // we'll need an SoGLTextureCoordinateElement. Otherwise, we'll
115 // set up the coordinates directly.
116 const SoTextureCoordinateElement *tce = NULL;
117 SbVec4f texCoord;
118 if (useTexFunction) {
119 tce = SoTextureCoordinateElement::getInstance(state);
120 }
121 else {
122 texCoord[2] = 0.0;
123 texCoord[3] = 1.0;
124 }
125 SbVec3f point, normal;
126
127
128 //////////////////////////////////////////
129 //----------------------------------------
130#define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz) \
131 point.setValue(x,y,z); \
132 normal.setValue(nx,ny,nz); \
133 if (useTexFunction) { \
134 texCoord=tce->get(point,normal); \
135 } \
136 else { \
137 texCoord[0]=s; \
138 texCoord[1]=t; \
139 } \
140 pv.setPoint(point); \
141 pv.setNormal(normal); \
142 pv.setTextureCoords(texCoord); \
143 shapeVertex(&pv);
144 //----------------------------------------
145 //////////////////////////////////////////
146
147 const int NPOINTS=8, NFACES=6, NINDICES = NFACES*5;
148 int indices[NINDICES] = {3,2,1,0, SO_END_FACE_INDEX, //z back.
149 4,5,6,7, SO_END_FACE_INDEX, //z front.
150 0,1,5,4, SO_END_FACE_INDEX, //y up.
151 1,2,6,5, SO_END_FACE_INDEX, //x left.
152 2,3,7,6, SO_END_FACE_INDEX, //y down.
153 3,0,4,7, SO_END_FACE_INDEX}; //x right.
154
155 // points for the eight vertices
156 float TthetaCphi = FTAN(pTheta.getValue())*FCOS(pPhi.getValue());
157 float TthetaSphi = FTAN(pTheta.getValue())*FSIN(pPhi.getValue());
158 float Talp1 = FTAN(pAlp1.getValue());
159 float Talp2 = FTAN(pAlp2.getValue());
160
161 float points[NPOINTS][3];
162 points[0][0] = pDx2.getValue()+pDy1.getValue()*Talp1;
163 points[0][1] = pDy1.getValue();
164 points[0][2] = -pDz.getValue();
165
166 points[1][0] = -pDx2.getValue()+pDy1.getValue()*Talp1;
167 points[1][1] = pDy1.getValue();
168 points[1][2] = -pDz.getValue();
169
170 points[2][0] = -pDx1.getValue()-pDy1.getValue()*Talp1;
171 points[2][1] = -pDy1.getValue();
172 points[2][2] = -pDz.getValue();
173
174 points[3][0] = pDx1.getValue()-pDy1.getValue()*Talp1;
175 points[3][1] = -pDy1.getValue();
176 points[3][2] = -pDz.getValue();
177
178 points[4][0] = pDx4.getValue()+pDy2.getValue()*Talp2;
179 points[4][1] = pDy2.getValue();
180 points[4][2] = pDz.getValue();
181
182 points[5][0] = -pDx4.getValue()+pDy2.getValue()*Talp2;
183 points[5][1] = pDy2.getValue();
184 points[5][2] = pDz.getValue();
185
186 points[6][0] = -pDx3.getValue()-pDy2.getValue()*Talp2;
187 points[6][1] = -pDy2.getValue();
188 points[6][2] = pDz.getValue();
189
190 points[7][0] = pDx3.getValue()-pDy2.getValue()*Talp2;
191 points[7][1] = -pDy2.getValue();
192 points[7][2] = pDz.getValue();
193
194 int i;
195 for (i=0;i<4;i++) {
196 points[i][0] -= pDz.getValue()*TthetaCphi;
197 points[i][1] -= pDz.getValue()*TthetaSphi;
198 }
199 for (i=4;i<8;i++) {
200 points[i][0] += pDz.getValue()*TthetaCphi;
201 points[i][1] += pDz.getValue()*TthetaSphi;
202 }
203
204 SbVec3f normals[NFACES];
205 int nf;
206 for (nf=0;nf<NFACES;nf++) {
207 int j0 = indices[5*nf + 0];
208 int j1 = indices[5*nf + 1];
209 int j2 = indices[5*nf + 2];
210 SbVec3f p0(points[j0][0],points[j0][1],points[j0][2]);
211 SbVec3f p1(points[j1][0],points[j1][1],points[j1][2]);
212 SbVec3f p2(points[j2][0],points[j2][1],points[j2][2]);
213 normals[nf] = (p1-p0).cross(p2-p0);
214 normals[nf].normalize();
215 }
216
217 float x,y,z;
218 int index;
219 for (nf=0;nf<NFACES;nf++) {
220 beginShape(action,TRIANGLE_FAN);
221 index = indices[nf * 5];
222 x = points[index][0];
223 y = points[index][1];
224 z = points[index][2];
225 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
226 index = indices[nf * 5 + 1];
227 x = points[index][0];
228 y = points[index][1];
229 z = points[index][2];
230 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
231 index = indices[nf * 5 + 2];
232 x = points[index][0];
233 y = points[index][1];
234 z = points[index][2];
235 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
236 index = indices[nf * 5 + 3];
237 x = points[index][0];
238 y = points[index][1];
239 z = points[index][2];
240 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
241 endShape();
242 }
243}
#define GEN_VERTEX(pv, x, y, z, s, t, nx, ny, nz)

◆ getChildren()

SoChildList * SoTrap::getChildren ( ) const
protectedvirtual

GetChildList, required whenever the class has hidden children.

Definition at line 246 of file SoTrap.cc.

246 {
247 return children;
248}

◆ initClass()

void SoTrap::initClass ( )
static

Class Initializer, required.

Definition at line 89 of file SoTrap.cc.

89 {
90 // This statement is required.
91 static bool first = true;
92 if (first) {
93 first = false;
94 SO_NODE_INIT_CLASS(SoTrap,SoShape,"Shape");
95 }
96}

Referenced by G4OpenInventor::InitNodes().

Member Data Documentation

◆ alternateRep

SoSFNode SoTrap::alternateRep

Alternate rep - required.

Definition at line 145 of file SoTrap.h.

Referenced by clearAlternateRep(), and generateAlternateRep().

◆ pAlp1

SoSFFloat SoTrap::pAlp1

Angle with respect to the y axis from the centre of the side at y=-pDy1 to the centre at y=+pDy1 of the face at -pDz

Definition at line 135 of file SoTrap.h.

Referenced by computeBBox(), and generatePrimitives().

◆ pAlp2

SoSFFloat SoTrap::pAlp2

Angle with respect to the y axis from the centre of the side at y=-pDy2 to the centre at y=+pDy2 of the face at +pDz

Definition at line 140 of file SoTrap.h.

Referenced by computeBBox(), and generatePrimitives().

◆ pDx1

SoSFFloat SoTrap::pDx1

Half-length along x of the side at y=-pDy1 of the face at -pDz.

Definition at line 114 of file SoTrap.h.

Referenced by computeBBox(), and generatePrimitives().

◆ pDx2

SoSFFloat SoTrap::pDx2

Half-length along x of the side at y=+pDy1 of the face at -pDz.

Definition at line 118 of file SoTrap.h.

Referenced by computeBBox(), and generatePrimitives().

◆ pDx3

SoSFFloat SoTrap::pDx3

Half-length along x of the side at y=-pDy2 of the face at +pDz.

Definition at line 126 of file SoTrap.h.

Referenced by computeBBox(), and generatePrimitives().

◆ pDx4

SoSFFloat SoTrap::pDx4

Half-length along x of the side at y=+pDy2 of the face at +pDz.

Definition at line 130 of file SoTrap.h.

Referenced by computeBBox(), and generatePrimitives().

◆ pDy1

SoSFFloat SoTrap::pDy1

Half-length along y of the face at -pDz.

Definition at line 110 of file SoTrap.h.

Referenced by computeBBox(), and generatePrimitives().

◆ pDy2

SoSFFloat SoTrap::pDy2

Half-length along y of the face at +pDz.

Definition at line 122 of file SoTrap.h.

Referenced by computeBBox(), and generatePrimitives().

◆ pDz

SoSFFloat SoTrap::pDz

half-length along Z

Definition at line 97 of file SoTrap.h.

Referenced by computeBBox(), and generatePrimitives().

◆ pPhi

SoSFFloat SoTrap::pPhi

Azimuthal angle of the line joing the centre of the face at -pDz to the centre of the face at +pDz

Definition at line 106 of file SoTrap.h.

Referenced by computeBBox(), and generatePrimitives().

◆ pTheta

SoSFFloat SoTrap::pTheta

Polar angle of the line joining the centres of the faces at -/+pDz.

Definition at line 101 of file SoTrap.h.

Referenced by computeBBox(), and generatePrimitives().


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