Geant4-11
Public Member Functions | Static Public Member Functions | Data Fields | Protected Member Functions | Private Member Functions | Private Attributes
SoBox Class Reference

#include <SoBox.h>

Inheritance diagram for SoBox:

Public Member Functions

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

Static Public Member Functions

static void initClass ()
 Class Initializer, required. More...
 

Data Fields

SoSFNode alternateRep
 Alternate rep - for use by users without HEPVis shared objects. More...
 
SoSFFloat fDx
 Half-length along X. More...
 
SoSFFloat fDy
 Half-length along Y. More...
 
SoSFFloat fDz
 Half-length along Z. More...
 

Protected Member Functions

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

Private Member Functions

void generateChildren ()
 
 SO_NODE_HEADER (SoBox)
 
void updateChildren ()
 

Private Attributes

SoChildList * children
 ChildList. Required whenever the class has hidden children.
More...
 

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
SoChildList * children
ChildList. Required whenever the class has hidden children.
Definition: SoBox.h:152
SoSFFloat fDx
Half-length along X.
Definition: SoBox.h:73
SoSFNode alternateRep
Alternate rep - for use by users without HEPVis shared objects.
Definition: SoBox.h:85
SoSFFloat fDy
Half-length along Y.
Definition: SoBox.h:77
SoSFFloat fDz
Half-length along Z.
Definition: SoBox.h:81

◆ ~SoBox()

SoBox::~SoBox ( )
protectedvirtual

Destructor, required.

Definition at line 71 of file SoBox.cc.

71 {
72 delete children;
73}

References children.

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}

References alternateRep.

◆ 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}

References fDx, fDy, and fDz.

◆ 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();
274 alternateRep.setValue((SoSeparator *) ( *children)[0]);
275}
void generateChildren()
Definition: SoBox.cc:251
void updateChildren()
Definition: SoBox.cc:238

References alternateRep, children, generateChildren(), and updateChildren().

◆ generateChildren()

void SoBox::generateChildren ( )
private

Generate Children. Used to create the hidden children. Required whenever the node has hidden children.

Definition at line 251 of file SoBox.cc.

251 {
252
253 // A box consists of a set of scale factors and a
254 // cube.
255
256 assert(children->getLength() ==0);
257 SoSeparator *sep = new SoSeparator();
258 SoScale *scale = new SoScale();
259 SoCube *cube = new SoCube();
260
261 sep->addChild(scale);
262 sep->addChild(cube);
263 children->append(sep);
264}

References children.

Referenced by generateAlternateRep().

◆ 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
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 //----------------------------------------
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)
static double normal(HepRandomEngine *eptr)
Definition: RandPoisson.cc:79

References geant4_check_module_cycles::action, fDx, fDy, fDz, GEN_VERTEX, and CLHEP::normal().

◆ 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}

References children.

◆ initClass()

void SoBox::initClass ( void  )
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().

◆ SO_NODE_HEADER()

SoBox::SO_NODE_HEADER ( SoBox  )
private

◆ updateChildren()

void SoBox::updateChildren ( )
private

Used to modify hidden children when a data field is changed. Required whenever the class has hidden children.

Definition at line 238 of file SoBox.cc.

238 {
239
240
241 // Redraw the G4Box....
242
243 assert(children->getLength()==1);
244 SoSeparator *sep = (SoSeparator *) ( *children)[0];
245 SoScale *scale = (SoScale *)( sep->getChild(0));
246 //SoCube *cube = (SoCube *)( sep->getChild(1));
247 scale->scaleFactor.setValue(fDx.getValue(), fDy.getValue(), fDz.getValue());
248}

References children, fDx, fDy, and fDz.

Referenced by generateAlternateRep().

Field 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().

◆ children

SoChildList* SoBox::children
private

ChildList. Required whenever the class has hidden children.

Definition at line 152 of file SoBox.h.

Referenced by generateAlternateRep(), generateChildren(), getChildren(), updateChildren(), and ~SoBox().

◆ fDx

SoSFFloat SoBox::fDx

Half-length along X.

Definition at line 73 of file SoBox.h.

Referenced by computeBBox(), generatePrimitives(), and updateChildren().

◆ fDy

SoSFFloat SoBox::fDy

Half-length along Y.

Definition at line 77 of file SoBox.h.

Referenced by computeBBox(), generatePrimitives(), and updateChildren().

◆ fDz

SoSFFloat SoBox::fDz

Half-length along Z.

Definition at line 81 of file SoBox.h.

Referenced by computeBBox(), generatePrimitives(), and updateChildren().


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