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

#include <SoTrd.h>

Inheritance diagram for SoTrd:

Public Member Functions

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

Static Public Member Functions

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

Data Fields

SoSFNode alternateRep
 Alternate rep - required. More...
 
SoSFFloat fDx1
 half-length of x, at -fDz More...
 
SoSFFloat fDx2
 half-length of x, at +fDz More...
 
SoSFFloat fDy1
 half-length of y, at -fDz More...
 
SoSFFloat fDy2
 half-length of y, at +fDz 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 ~SoTrd ()
 Destructor, required. More...
 

Private Member Functions

void generateChildren ()
 
 SO_NODE_HEADER (SoTrd)
 This is required. More...
 
void updateChildren ()
 

Private Attributes

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

Detailed Description

Definition at line 62 of file SoTrd.h.

Constructor & Destructor Documentation

◆ SoTrd()

SoTrd::SoTrd ( )

Constructor, required.

Definition at line 67 of file SoTrd.cc.

67 {
68 // This statement is required
69 SO_NODE_CONSTRUCTOR(SoTrd);
70 // Data fields are initialized like this:
71 SO_NODE_ADD_FIELD(fDx1,(1.0));
72 SO_NODE_ADD_FIELD(fDx2,(1.0));
73 SO_NODE_ADD_FIELD(fDy1,(1.0));
74 SO_NODE_ADD_FIELD(fDy2,(1.0));
75 SO_NODE_ADD_FIELD(fDz,(1.0));
76 SO_NODE_ADD_FIELD(alternateRep,(NULL));
77 children = new SoChildList(this);
78}
Definition: SoTrd.h:62
SoSFFloat fDx2
half-length of x, at +fDz
Definition: SoTrd.h:79
SoChildList * children
ChildList. Required whenever the class has hidden children.
Definition: SoTrd.h:167
SoSFFloat fDy2
half-length of y, at +fDz
Definition: SoTrd.h:89
SoSFFloat fDy1
half-length of y, at -fDz
Definition: SoTrd.h:84
SoSFNode alternateRep
Alternate rep - required.
Definition: SoTrd.h:99
SoSFFloat fDx1
half-length of x, at -fDz
Definition: SoTrd.h:74
SoSFFloat fDz
half-length along Z
Definition: SoTrd.h:94

References alternateRep, children, fDx1, fDx2, fDy1, fDy2, and fDz.

◆ ~SoTrd()

SoTrd::~SoTrd ( )
protectedvirtual

Destructor, required.

Definition at line 80 of file SoTrd.cc.

80 {
81 delete children;
82}

References children.

Member Function Documentation

◆ clearAlternateRep()

void SoTrd::clearAlternateRep ( )
virtual

We better be able to clear it, too!

Definition at line 343 of file SoTrd.cc.

343 {
344 alternateRep.setValue(NULL);
345}

References alternateRep.

◆ computeBBox()

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

compute bounding Box, required

Definition at line 230 of file SoTrd.cc.

230 {
231 float fDx= fDx1.getValue(),fDy=fDy1.getValue();
232
233 if (fDx2.getValue() > fDx) fDx = fDx2.getValue();
234 if (fDy2.getValue() > fDy) fDy = fDy2.getValue();
235
236 SbVec3f vmin(-fDx,-fDy,-fDz.getValue()),
237 vmax( fDx, fDy, fDz.getValue());
238
239 center.setValue(0,0,0);
240 box.setBounds(vmin,vmax);
241}

References fDx1, fDx2, fDy1, fDy2, and fDz.

◆ generateAlternateRep()

void SoTrd::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 332 of file SoTrd.cc.

332 {
333
334 // This routine sets the alternate representation to the child
335 // list of this mode.
336
337 if (children->getLength() == 0) generateChildren();
339 alternateRep.setValue((SoSeparator *) ( *children)[0]);
340}
void generateChildren()
Definition: SoTrd.cc:308
void updateChildren()
Definition: SoTrd.cc:247

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

◆ generateChildren()

void SoTrd::generateChildren ( )
private

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

Definition at line 308 of file SoTrd.cc.

308 {
309
310 // This routines creates one SoSeparator, one SoCoordinate3, and
311 // one SoLineSet, and puts it in the child list. This is done only
312 // once, whereas redrawing the position of the coordinates occurs each
313 // time an update is necessary, in the updateChildren routine.
314
315 assert(children->getLength() ==0);
316 SoSeparator *sep = new SoSeparator();
317 SoCoordinate3 *theCoordinates = new SoCoordinate3();
318 SoNormal *theNormals = new SoNormal();
319 SoNormalBinding *theNormalBinding = new SoNormalBinding();
320 SoIndexedFaceSet *theFaceSet = new SoIndexedFaceSet();
321 //
322 // This line costs some in render quality! but gives speed.
323 //
324 sep->addChild(theCoordinates);
325 sep->addChild(theNormals);
326 sep->addChild(theNormalBinding);
327 sep->addChild(theFaceSet);
328 children->append(sep);
329}

References children.

Referenced by generateAlternateRep().

◆ generatePrimitives()

void SoTrd::generatePrimitives ( SoAction *  action)
protectedvirtual

Generate Primitives, required.

Definition at line 84 of file SoTrd.cc.

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

◆ getChildren()

SoChildList * SoTrd::getChildren ( ) const
protectedvirtual

GetChildList, required whenever the class has hidden children.

Definition at line 224 of file SoTrd.cc.

224 {
225 return children;
226}

References children.

◆ initClass()

void SoTrd::initClass ( void  )
static

Class Initializer, required.

Definition at line 59 of file SoTrd.cc.

59 {
60 static bool first = true;
61 if (first) {
62 first = false;
63 SO_NODE_INIT_CLASS(SoTrd,SoShape,"Shape");
64 }
65}

Referenced by G4OpenInventor::InitNodes().

◆ SO_NODE_HEADER()

SoTrd::SO_NODE_HEADER ( SoTrd  )
private

This is required.

◆ updateChildren()

void SoTrd::updateChildren ( )
private

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

Definition at line 247 of file SoTrd.cc.

247 {
248
249
250 // Redraw the G4Trd....
251
252 assert(children->getLength()==1);
253 SoSeparator *sep = (SoSeparator *) ( *children)[0];
254 SoCoordinate3 *theCoordinates = (SoCoordinate3 *) ( sep->getChild(0));
255 SoNormal *theNormals = (SoNormal *) ( sep->getChild(1));
256 SoNormalBinding *theNormalBinding = (SoNormalBinding *) ( sep->getChild(2));
257 SoIndexedFaceSet *theFaceSet = (SoIndexedFaceSet *) ( sep->getChild(3));
258
259 const int NPOINTS=8, NFACES=6, NINDICES = NFACES*5;
260 float points[NPOINTS][3];
261 float normals[NFACES][3]= {{0,0,-1}, {0,0,1}, {0,1,0}, {-1, 0, 0}, {0, -1, 0}, {1,0,0}};
262
263 // Indices for the eight faces
264#ifdef INVENTOR2_0
265 static long
266#else
267 static int32_t
268#endif
269 indices[NINDICES] = {3,2,1,0, SO_END_FACE_INDEX, // bottom
270 4,5,6,7, SO_END_FACE_INDEX, // top
271 0,1,5,4, SO_END_FACE_INDEX,
272 1,2,6,5, SO_END_FACE_INDEX,
273 2,3,7,6, SO_END_FACE_INDEX,
274 3,0,4,7, SO_END_FACE_INDEX};
275
276
277 // points for the eight vertices
278 points[0][0] = fDx1.getValue(); points[0][1] = fDy1.getValue(); points[0][2] = -fDz.getValue();
279 points[1][0] = -fDx1.getValue(); points[1][1] = fDy1.getValue(); points[1][2] = -fDz.getValue();
280 points[2][0] = -fDx1.getValue(); points[2][1] = -fDy1.getValue(); points[2][2] = -fDz.getValue();
281 points[3][0] = fDx1.getValue(); points[3][1] = -fDy1.getValue(); points[3][2] = -fDz.getValue();
282 points[4][0] = fDx2.getValue(); points[4][1] = fDy2.getValue(); points[4][2] = fDz.getValue();
283 points[5][0] = -fDx2.getValue(); points[5][1] = fDy2.getValue(); points[5][2] = fDz.getValue();
284 points[6][0] = -fDx2.getValue(); points[6][1] = -fDy2.getValue(); points[6][2] = fDz.getValue();
285 points[7][0] = fDx2.getValue(); points[7][1] = -fDy2.getValue(); points[7][2] = fDz.getValue();
286
287 float t1 = FATAN((fDx2.getValue()-fDx1.getValue())/(2*fDz.getValue()));
288 float t2 = FATAN((fDy2.getValue()-fDy1.getValue())/(2*fDz.getValue()));
289 float st1 = FSIN(t1);
290 float st2 = FSIN(t2);
291 float ct1 = FCOS(t1);
292 float ct2 = FCOS(t2);
293
294 normals[0][0] = 0 ; normals[0][1] = 0; normals [0][2] = -1;
295 normals[1][0] = 0 ; normals[1][1] = 0; normals [1][2] = 1;
296 normals[2][0] = 0 ; normals[2][1] = ct2; normals [2][2] = -st2;
297 normals[3][0] = -ct1; normals[3][1] = 0; normals [3][2] = -st1;
298 normals[4][0] = 0 ; normals[4][1] = -ct2; normals [4][2] = -st2;
299 normals[5][0] = ct1; normals[5][1] = 0; normals [5][2] = -st1;
300
301 for (int np=0;np<NPOINTS;np++) theCoordinates->point.set1Value(np,points[np][0],points[np][1],points[np][2]);
302 theFaceSet->coordIndex.setValues(0,NINDICES,indices);
303 for (int nf=0;nf<NFACES;nf++) theNormals->vector.set1Value(nf,normals[nf][0],normals[nf][1],normals[nf][2]);
304 theNormalBinding->value=SoNormalBinding::PER_FACE;
305}

References children, FATAN, FCOS, fDx1, fDx2, fDy1, fDy2, fDz, and FSIN.

Referenced by generateAlternateRep().

Field Documentation

◆ alternateRep

SoSFNode SoTrd::alternateRep

Alternate rep - required.

Definition at line 99 of file SoTrd.h.

Referenced by clearAlternateRep(), generateAlternateRep(), and SoTrd().

◆ children

SoChildList* SoTrd::children
private

ChildList. Required whenever the class has hidden children.

Definition at line 167 of file SoTrd.h.

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

◆ fDx1

SoSFFloat SoTrd::fDx1

half-length of x, at -fDz

Definition at line 74 of file SoTrd.h.

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

◆ fDx2

SoSFFloat SoTrd::fDx2

half-length of x, at +fDz

Definition at line 79 of file SoTrd.h.

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

◆ fDy1

SoSFFloat SoTrd::fDy1

half-length of y, at -fDz

Definition at line 84 of file SoTrd.h.

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

◆ fDy2

SoSFFloat SoTrd::fDy2

half-length of y, at +fDz

Definition at line 89 of file SoTrd.h.

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

◆ fDz

SoSFFloat SoTrd::fDz

half-length along Z

Definition at line 94 of file SoTrd.h.

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


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