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

#include <SoBox.h>

+ Inheritance diagram for SoBox:

Public Member Functions

 SoBox ()
 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 fDx
 Half-length along X.
 
SoSFFloat fDy
 Half-length along Y.
 
SoSFFloat fDz
 Half-length along Z.
 
SoSFNode alternateRep
 Alternate rep - for use by users without HEPVis shared objects.
 

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 ~SoBox ()
 Destructor, required.
 

Detailed Description

Definition at line 63 of file SoBox.h.

Constructor & Destructor Documentation

◆ SoBox()

SoBox::SoBox ( )

Constructor, required.

Definition at line 58 of file SoBox.cc.

58 {
59 // This statement is required
60 SO_NODE_CONSTRUCTOR(SoBox);
61
62 // Data fields are initialized like this:
63 SO_NODE_ADD_FIELD(fDx, (1.0));
64 SO_NODE_ADD_FIELD(fDy, (1.0));
65 SO_NODE_ADD_FIELD(fDz, (1.0));
66 SO_NODE_ADD_FIELD(alternateRep, (NULL));
67 children = new SoChildList(this);
68}
Definition: SoBox.h:63

◆ ~SoBox()

SoBox::~SoBox ( )
protectedvirtual

Destructor, required.

Definition at line 71 of file SoBox.cc.

71 {
72 delete children;
73}

Member Function Documentation

◆ clearAlternateRep()

void SoBox::clearAlternateRep ( )
virtual

We better be able to clear it, too!

Definition at line 278 of file SoBox.cc.

278 {
279 alternateRep.setValue(NULL);
280}
SoSFNode alternateRep
Alternate rep - for use by users without HEPVis shared objects.
Definition: SoBox.h:85

◆ computeBBox()

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

compute bounding Box, required

Definition at line 227 of file SoBox.cc.

227 {
228 SbVec3f vmin(-fDx.getValue(),-fDy.getValue(),-fDz.getValue()),
229 vmax( fDx.getValue(), fDy.getValue(), fDz.getValue());
230 center.setValue(0,0,0);
231 box.setBounds(vmin,vmax);
232}
SoSFFloat fDx
Half-length along X.
Definition: SoBox.h:73
SoSFFloat fDy
Half-length along Y.
Definition: SoBox.h:77
SoSFFloat fDz
Half-length along Z.
Definition: SoBox.h:81

◆ generateAlternateRep()

void SoBox::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 267 of file SoBox.cc.

267 {
268
269 // This routine sets the alternate representation to the child
270 // list of this mode.
271
272 if (children->getLength() == 0) generateChildren();
273 updateChildren();
274 alternateRep.setValue((SoSeparator *) ( *children)[0]);
275}

◆ generatePrimitives()

void SoBox::generatePrimitives ( SoAction *  action)
protectedvirtual

Generate Primitives, required.

Definition at line 88 of file SoBox.cc.

88 {
89 // This variable is used to store each vertex
90 SoPrimitiveVertex pv;
91
92 // Access the stat from the action
93 SoState *state = action->getState();
94
95 // See if we have to use a texture coordinate function,
96 // rather than generating explicit texture coordinates.
97 SbBool useTexFunction=
98 (SoTextureCoordinateElement::getType(state) ==
99 SoTextureCoordinateElement::FUNCTION);
100
101 // If we need to generate texture coordinates with a function,
102 // we'll need an SoGLTextureCoordinateElement. Otherwise, we'll
103 // set up the coordinates directly.
104 const SoTextureCoordinateElement *tce = NULL;
105 SbVec4f texCoord;
106 if (useTexFunction) {
107 tce = SoTextureCoordinateElement::getInstance(state);
108 }
109 else {
110 texCoord[2] = 0.0;
111 texCoord[3] = 1.0;
112 }
113 SbVec3f point, normal;
114
115
116 //////////////////////////////////////////
117 //----------------------------------------
118#define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz) \
119 point.setValue(x,y,z); \
120 normal.setValue(nx,ny,nz); \
121 if (useTexFunction) { \
122 texCoord=tce->get(point,normal); \
123 } \
124 else { \
125 texCoord[0]=s; \
126 texCoord[1]=t; \
127 } \
128 pv.setPoint(point); \
129 pv.setNormal(normal); \
130 pv.setTextureCoords(texCoord); \
131 shapeVertex(&pv);
132 //----------------------------------------
133 //////////////////////////////////////////
134
135 const int NPOINTS=8, NFACES=6, NINDICES = NFACES*5;
136 int indices[NINDICES] = {3,2,1,0, SO_END_FACE_INDEX, //z back.
137 4,5,6,7, SO_END_FACE_INDEX, //z front.
138 0,1,5,4, SO_END_FACE_INDEX, //y up.
139 1,2,6,5, SO_END_FACE_INDEX, //x left.
140 2,3,7,6, SO_END_FACE_INDEX, //y down.
141 3,0,4,7, SO_END_FACE_INDEX}; //x right.
142
143
144 // points for the eight vertices
145 float points[NPOINTS][3];
146 points[0][0] = fDx.getValue();
147 points[0][1] = fDy.getValue();
148 points[0][2] = -fDz.getValue();
149
150 points[1][0] = -fDx.getValue();
151 points[1][1] = fDy.getValue();
152 points[1][2] = -fDz.getValue();
153
154 points[2][0] = -fDx.getValue();
155 points[2][1] = -fDy.getValue();
156 points[2][2] = -fDz.getValue();
157
158 points[3][0] = fDx.getValue();
159 points[3][1] = -fDy.getValue();
160 points[3][2] = -fDz.getValue();
161
162 points[4][0] = fDx.getValue();
163 points[4][1] = fDy.getValue();
164 points[4][2] = fDz.getValue();
165
166 points[5][0] = -fDx.getValue();
167 points[5][1] = fDy.getValue();
168 points[5][2] = fDz.getValue();
169
170 points[6][0] = -fDx.getValue();
171 points[6][1] = -fDy.getValue();
172 points[6][2] = fDz.getValue();
173
174 points[7][0] = fDx.getValue();
175 points[7][1] = -fDy.getValue();
176 points[7][2] = fDz.getValue();
177
178 float normals[NFACES][3];
179 //z back.
180 normals[0][0] = 0 ; normals[0][1] = 0; normals [0][2] = -1;
181 //z front.
182 normals[1][0] = 0 ; normals[1][1] = 0; normals [1][2] = 1;
183 //y up.
184 normals[2][0] = 0 ; normals[2][1] = 1; normals [2][2] = 0;
185 //x left.
186 normals[3][0] = -1 ; normals[3][1] = 0; normals [3][2] = 0;
187 //y down.
188 normals[4][0] = 0 ; normals[4][1] = -1; normals [4][2] = 0;
189 //x right.
190 normals[5][0] = 1 ; normals[5][1] = 0; normals [5][2] = 0;
191
192 float x,y,z;
193 int index;
194 for (int nf=0;nf<NFACES;nf++) {
195 beginShape(action,TRIANGLE_FAN);
196 index = indices[nf * 5];
197 x = points[index][0];
198 y = points[index][1];
199 z = points[index][2];
200 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
201 index = indices[nf * 5 + 1];
202 x = points[index][0];
203 y = points[index][1];
204 z = points[index][2];
205 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
206 index = indices[nf * 5 + 2];
207 x = points[index][0];
208 y = points[index][1];
209 z = points[index][2];
210 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
211 index = indices[nf * 5 + 3];
212 x = points[index][0];
213 y = points[index][1];
214 z = points[index][2];
215 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
216 endShape();
217 }
218}
#define GEN_VERTEX(pv, x, y, z, s, t, nx, ny, nz)

◆ getChildren()

SoChildList * SoBox::getChildren ( ) const
protectedvirtual

GetChildList, required whenever the class has hidden children.

Definition at line 221 of file SoBox.cc.

221 {
222 return children;
223}

◆ initClass()

void SoBox::initClass ( )
static

Class Initializer, required.

Definition at line 77 of file SoBox.cc.

77 {
78 // This statement is required.
79 static bool first = true;
80 if (first) {
81 first = false;
82 SO_NODE_INIT_CLASS(SoBox,SoShape,"Shape");
83 }
84}

Referenced by G4OpenInventor::InitNodes().

Member Data Documentation

◆ alternateRep

SoSFNode SoBox::alternateRep

Alternate rep - for use by users without HEPVis shared objects.

Definition at line 85 of file SoBox.h.

Referenced by clearAlternateRep(), and generateAlternateRep().

◆ fDx

SoSFFloat SoBox::fDx

Half-length along X.

Definition at line 73 of file SoBox.h.

Referenced by computeBBox(), and generatePrimitives().

◆ fDy

SoSFFloat SoBox::fDy

Half-length along Y.

Definition at line 77 of file SoBox.h.

Referenced by computeBBox(), and generatePrimitives().

◆ fDz

SoSFFloat SoBox::fDz

Half-length along Z.

Definition at line 81 of file SoBox.h.

Referenced by computeBBox(), and generatePrimitives().


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