slic/include
diff -u -r1.1 -r1.2
--- VRML2Writer.hh 7 Jul 2009 21:39:19 -0000 1.1
+++ VRML2Writer.hh 9 Jul 2009 18:24:36 -0000 1.2
@@ -11,6 +11,7 @@
class G4VPhysicalVolume;
class G4Box;
class G4VSolid;
+class G4Polyhedron;
// TODO: correct indentation level
// TODO: transforms are REVERSED; up the hierarchy instead of down!
@@ -30,7 +31,8 @@
void processPhysicalVolume(G4VPhysicalVolume*);
void processVisualization(G4VPhysicalVolume*);
void processSolid(G4VSolid*);
- void processBox(G4Box*);
+ void processBox(G4Box*);
+ void processPolyhedron(G4Polyhedron*);
void writeLine(const std::string&);
void indent();
void unindent();
slic/src
diff -u -r1.2 -r1.3
--- VRML2Writer.cc 8 Jul 2009 22:16:22 -0000 1.2
+++ VRML2Writer.cc 9 Jul 2009 18:24:36 -0000 1.3
@@ -1,3 +1,4 @@
+// $Header: /cvs/lcd/slic/src/VRML2Writer.cc,v 1.3 2009/07/09 18:24:36 jeremy Exp $
#include "VRML2Writer.hh"
// stl
@@ -10,14 +11,13 @@
#include "G4LogicalVolume.hh"
#include "G4VisAttributes.hh"
#include "G4Box.hh"
+#include "G4Polyhedron.hh"
#include "G4RotationMatrix.hh"
#include "G4ThreeVector.hh"
#include "G4RotationMatrix.hh"
+#include "G4Point3D.hh"
#include "globals.hh"
-// clhep
-//#include <CLHEP/Vector/ThreeVector.h>
-
namespace slic
{
@@ -59,6 +59,7 @@
writeLine("children [");
indent();
+ // shape node
writeLine("Shape {");
indent();
processVisualization(pv);
@@ -83,7 +84,6 @@
writeLine(ss.str());
// rotation
-
const G4RotationMatrix* rot = pv->GetRotation();
CLHEP::Hep3Vector axis(0,0,0);
double angle = 0;
@@ -126,10 +126,14 @@
void VRML2Writer::processSolid(G4VSolid* solid)
{
- if (dynamic_cast<G4Box*>(solid) != 0)
+ if (solid->GetEntityType() == "G4Box")
{
processBox((G4Box*)solid);
}
+ else
+ {
+ processPolyhedron(solid->GetPolyhedron());
+ }
}
void VRML2Writer::processBox(G4Box* box)
@@ -146,6 +150,56 @@
writeLine("}");
}
+ // code taken from Geant4....
+ // G4MVRL2SceneHandlerFunc.icc - G4VRML2SCENEHANDLER::AddPrimitive(const G4Polyhedron& polyhedron)
+ void VRML2Writer::processPolyhedron(G4Polyhedron* polyhedron)
+ {
+ writeLine("geometry IndexedFaceSet {");
+ indent();
+ writeLine("coord Coordinate {");
+ indent();
+ writeLine("point [");
+ indent();
+
+ int i, j;
+ for (i = 1, j = polyhedron->GetNoVertices(); j; j--, i++)
+ {
+ G4Point3D point = polyhedron->GetVertex(i);
+ std::stringstream ss;
+ ss << point.x() / m << " " << point.y() / m << " " << point.z() / m;
+ writeLine(ss.str());
+ }
+ unindent();
+ writeLine("]"); // point
+ unindent();
+ writeLine("}"); // coord
+
+ writeLine("coordIndex [");
+ indent();
+
+ // facet loop
+ int f;
+ for (f = polyhedron->GetNoFacets(); f; f--)
+ {
+ // edge loop
+ bool notLastEdge;
+ int index = -1, edgeFlag = 1;
+ std::stringstream ss;
+ do {
+ notLastEdge = polyhedron->GetNextVertexIndex(index, edgeFlag);
+ ss << index - 1 << ", ";
+ } while (notLastEdge);
+ ss << "-1, ";
+ writeLine(ss.str());
+ }
+
+ unindent();
+ writeLine("]");
+ writeLine("solid FALSE");
+ unindent();
+ writeLine("}"); // IndexFaceSet
+ }
+
void VRML2Writer::writeLine(const std::string& text)
{
for (int i=0; i<_indentLevel; i++)