26#ifdef G4VIS_BUILD_OI_DRIVER
39#include <Inventor/SbBox.h>
40#include <Inventor/actions/SoAction.h>
41#include <Inventor/SoPrimitiveVertex.h>
42#include <Inventor/elements/SoTextureCoordinateElement.h>
43#include <Inventor/nodes/SoSeparator.h>
46#define SbMinimum(a,b) ((a)<(b)?a:b)
47#define SbMaximum(a,b) ((a)>(b)?a:b)
66 static bool first =
true;
80 SO_NODE_ADD_FIELD(solid,(
TRUE));
81 SO_NODE_ADD_FIELD(reducedWireFrame,(
TRUE));
82 SO_NODE_ADD_FIELD(alternateRep,(NULL));
93 SO_NODE_ADD_FIELD(solid,(
TRUE));
94 SO_NODE_ADD_FIELD(reducedWireFrame,(
TRUE));
95 SO_NODE_ADD_FIELD(alternateRep,(NULL));
103:fPolyhedron(aPolyhedron)
108 SO_NODE_ADD_FIELD(solid,(
TRUE));
109 SO_NODE_ADD_FIELD(reducedWireFrame,(
TRUE));
110 SO_NODE_ADD_FIELD(alternateRep,(NULL));
127 if(!fPolyhedron)
return;
130 SoState *state = aAction->getState();
131 SbBool useTexFunction =
132 (SoTextureCoordinateElement::getType(state) ==
133 SoTextureCoordinateElement::FUNCTION);
134 const SoTextureCoordinateElement *tce = NULL;
135 SbVec4f texCoord(0.,0.,0.,0.);
136 if (useTexFunction) {
137 tce = SoTextureCoordinateElement::getInstance(state);
144 SoPrimitiveVertex pv;
145 SbVec3f point, normal;
148#define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz) \
149 point.setValue(x,y,z); \
150 normal.setValue(nx,ny,nz); \
151 if (useTexFunction) { \
152 texCoord=tce->get(point,normal); \
157 pv.setPoint(point); \
158 pv.setNormal(normal); \
159 pv.setTextureCoords(texCoord); \
167 HVNormal3D unitNormal;
170 beginShape(aAction,POLYGON);
184 }
while (notLastEdge);
186 }
while (notLastFace);
188 SoPrimitiveVertex pvb,pve;
189 pve.setTextureCoords(texCoord);
190 pvb.setTextureCoords(texCoord);
193 beginShape(aAction,POLYGON);
200 HVNormal3D unitNormal;
204 normal.setValue(unitNormal[0],unitNormal[1],unitNormal[2]);
208 int prevEdgeFlag = edgeFlag;
210 SbBool firstEdge =
TRUE;
217 pvb.setNormal(normal);
218 point.setValue(vertex[0],vertex[1],vertex[2]);
223 prevEdgeFlag = edgeFlag;
225 if(edgeFlag!=prevEdgeFlag) {
227 pvb.setNormal(normal);
228 point.setValue(vertex[0],vertex[1],vertex[2]);
231 pve.setNormal(normal);
232 point.setValue(vertex[0],vertex[1],vertex[2]);
234 invokeLineSegmentCallbacks(aAction,&pvb,&pve);
236 prevEdgeFlag = edgeFlag;
239 pve.setNormal(normal);
240 point.setValue(vertex[0],vertex[1],vertex[2]);
242 invokeLineSegmentCallbacks(aAction,&pvb,&pve);
248 }
while (notLastEdge);
249 }
while (notLastFace);
262 if(!fPolyhedron)
return;
264 SbVec3f vmin(-1,-1,-1);
265 SbVec3f vmax( 1, 1, 1);
266 aBox.setBounds(vmin,vmax);
267 aCenter.setValue(0,0,0);
270 float xmn = 0,ymn = 0,zmn = 0;
271 float xmx = 0,ymx = 0,zmx = 0;
272 float xct = 0,yct = 0,zct = 0;
278 HVNormal3D unitNormal;
285 point.setValue(vertex[0],vertex[1],vertex[2]);
287 xct = xmx = xmn = point[0];
288 yct = ymx = ymn = point[1];
289 zct = zmx = zmn = point[2];
307 }
while (notLastEdge);
308 }
while (notLastFace);
309 SbVec3f vmin(xmn,ymn,zmn);
310 SbVec3f vmax(xmx,ymx,zmx);
311 aBox.setBounds(vmin,vmax);
313 aCenter.setValue(0,0,0);
315 aCenter.setValue(xct/count,yct/count,zct/count);
319#include <Inventor/nodes/SoNormalBinding.h>
320#include <Inventor/nodes/SoNormal.h>
321#include <Inventor/nodes/SoCoordinate3.h>
322#include <Inventor/nodes/SoIndexedFaceSet.h>
323#include <Inventor/nodes/SoIndexedLineSet.h>
330 if(!fPolyhedron)
return;
336 SoSeparator* separator =
new SoSeparator;
338 SoNormalBinding* normalBinding =
new SoNormalBinding;
339 normalBinding->value = SoNormalBinding::PER_FACE;
340 separator->addChild(normalBinding);
342 SoCoordinate3* coordinate3 =
new SoCoordinate3;
343 separator->addChild(coordinate3);
344 SoNormal* normal =
new SoNormal;
345 separator->addChild(normal);
346 SoIndexedFaceSet* indexedFaceSet =
new SoIndexedFaceSet;
347 separator->addChild(indexedFaceSet);
352 SbVec3f* normals =
new SbVec3f[nface];
354 SbVec3f* points =
new SbVec3f[nvert];
355 int32_t* coords =
new int32_t[nvert+1];
364 HVNormal3D unitNormal;
375 points[ipoint].setValue(vertex[0],vertex[1],vertex[2]);
376 coords[ipoint] = icoord + ipoint;
378 }
while (notLastEdge);
381 coords[ipoint] = SO_END_FACE_INDEX;
382 coordinate3->point.setValues(icoord,ipoint,points);
385 normals[inormal].setValue(unitNormal[0],unitNormal[1],unitNormal[2]);
388 indexedFaceSet->coordIndex.setValues(iindex,(ipoint+1),coords);
391 }
while (notLastFace);
393 normal->vector.setValues(0,inormal,normals);
403 SoSeparator* separator =
new SoSeparator;
408 int nedge = nvert * 3;
409 int npoint = nedge*2;
410 SbVec3f* points =
new SbVec3f[npoint];
411 int ncoord = nedge*3;
412 int32_t* coords =
new int32_t[ncoord];
414 SbVec3f pvb(0.,0.,0.), pve(0.,0.,0.);
422 HVNormal3D unitNormal;
434 int prevEdgeFlag = edgeFlag;
436 SbBool firstEdge =
TRUE;
443 pvb.setValue(vertex[0],vertex[1],vertex[2]);
447 prevEdgeFlag = edgeFlag;
449 if(edgeFlag!=prevEdgeFlag) {
451 pvb.setValue(vertex[0],vertex[1],vertex[2]);
453 pve.setValue(vertex[0],vertex[1],vertex[2]);
455 if((ipoint+1)>=npoint) {
456 int new_npoint = 2 * npoint;
457 SbVec3f* new_points =
new SbVec3f[new_npoint];
458 for(
int i=0;i<npoint;i++) new_points[i] = points[i];
464 if((icoord+2)>=ncoord) {
465 int new_ncoord = 2 * ncoord;
466 int32_t* new_coords =
new int32_t[new_ncoord];
467 for(
int i=0;i<ncoord;i++) new_coords[i] = coords[i];
473 points[ipoint+0] = pvb;
474 points[ipoint+1] = pve;
475 coords[icoord+0] = ipoint + 0;
476 coords[icoord+1] = ipoint + 1;
477 coords[icoord+2] = SO_END_LINE_INDEX;
482 prevEdgeFlag = edgeFlag;
485 pve.setValue(vertex[0],vertex[1],vertex[2]);
487 if((ipoint+1)>=npoint) {
488 int new_npoint = 2 * npoint;
489 SbVec3f* new_points =
new SbVec3f[new_npoint];
490 for(
int i=0;i<npoint;i++) new_points[i] = points[i];
496 if((icoord+2)>=ncoord) {
497 int new_ncoord = 2 * ncoord;
498 int32_t* new_coords =
new int32_t[new_ncoord];
499 for(
int i=0;i<ncoord;i++) new_coords[i] = coords[i];
505 points[ipoint+0] = pvb;
506 points[ipoint+1] = pve;
507 coords[icoord+0] = ipoint + 0;
508 coords[icoord+1] = ipoint + 1;
509 coords[icoord+2] = SO_END_LINE_INDEX;
519 }
while (notLastEdge);
520 }
while (notLastFace);
522 SoCoordinate3* coordinate3 =
new SoCoordinate3;
523 coordinate3->point.setValues(0,ipoint,points);
524 separator->addChild(coordinate3);
526 SoIndexedLineSet* indexedLineSet =
new SoIndexedLineSet;
527 indexedLineSet->coordIndex.setValues(0,icoord,coords);
528 separator->addChild(indexedLineSet);
556 SoShape::doAction(aAction);
#define SO_ALTERNATEREP_DO_ACTION(aAction)
virtual void generateAlternateRep()
SoSFBool reducedWireFrame
virtual void computeBBox(SoAction *, SbBox3f &, SbVec3f &)
virtual ~Geant4_SoPolyhedron()
virtual void generatePrimitives(SoAction *)
virtual void doAction(SoAction *)
virtual void clearAlternateRep()
G4bool GetNextVertex(G4Point3D &vertex, G4int &edgeFlag) const
G4int GetNoFacets() const
G4bool GetNextUnitNormal(G4Normal3D &normal) const
G4int GetNoVertices() const