32 #ifdef G4VIS_BUILD_OI_DRIVER
37 #include <Inventor/SoPath.h>
38 #include <Inventor/SoNodeKitPath.h>
39 #include <Inventor/nodes/SoCoordinate3.h>
40 #include <Inventor/nodes/SoCoordinate4.h>
41 #include <Inventor/nodes/SoSeparator.h>
42 #include <Inventor/nodes/SoDrawStyle.h>
43 #include <Inventor/nodes/SoLightModel.h>
44 #include <Inventor/nodes/SoMaterial.h>
45 #include <Inventor/nodes/SoLineSet.h>
46 #include <Inventor/nodes/SoCube.h>
47 #include <Inventor/nodes/SoFont.h>
48 #include <Inventor/nodes/SoText2.h>
49 #include <Inventor/nodes/SoFaceSet.h>
50 #include <Inventor/nodes/SoNormal.h>
51 #include <Inventor/nodes/SoNormalBinding.h>
52 #include <Inventor/nodes/SoComplexity.h>
53 #include <Inventor/nodes/SoTranslation.h>
54 #include <Inventor/nodes/SoTransform.h>
55 #include <Inventor/nodes/SoResetTransform.h>
56 #include <Inventor/nodes/SoMatrixTransform.h>
58 #define USE_SOPOLYHEDRON
60 #ifndef USE_SOPOLYHEDRON
100 G4int G4OpenInventorSceneHandler::fSceneIdCount = 0;
102 G4OpenInventorSceneHandler::G4OpenInventorSceneHandler (
G4OpenInventor& system,
108 ,fCurrentSeparator(0)
109 ,fModelingSolid(false)
110 ,fReducedWireFrame(true)
112 ,fPreviewAndFull(true)
117 fRoot =
new SoSeparator;
119 fRoot->setName(
"Root");
121 fDetectorRoot =
new SoSeparator;
122 fDetectorRoot->setName(
"StaticRoot");
123 fRoot->addChild(fDetectorRoot);
125 fTransientRoot =
new SoSeparator;
126 fTransientRoot->setName(
"TransientRoot");
127 fRoot->addChild(fTransientRoot);
129 fCurrentSeparator = fTransientRoot;
132 G4OpenInventorSceneHandler::~G4OpenInventorSceneHandler ()
135 fStyleCache->unref();
138 void G4OpenInventorSceneHandler::ClearStore ()
140 fDetectorRoot->removeAllChildren();
141 fSeparatorMap.clear();
143 fTransientRoot->removeAllChildren();
146 void G4OpenInventorSceneHandler::ClearTransientStore ()
148 fTransientRoot->removeAllChildren();
154 void G4OpenInventorSceneHandler::PreAddSolid
161 GeneratePrerequisites();
167 void G4OpenInventorSceneHandler::BeginPrimitives
174 if (!fProcessingSolid) {
175 GeneratePrerequisites();
182 void G4OpenInventorSceneHandler::AddPrimitive (
const G4Polyline& line)
185 static G4bool warned =
false;
189 (
"G4OpenInventorSceneHandler::AddPrimitive (const G4Polyline&)",
191 "2D polylines not implemented. Ignored.");
203 G4int nPoints = line.size();
204 SbVec3f* pCoords =
new SbVec3f[nPoints];
206 for (
G4int iPoint = 0; iPoint < nPoints ; iPoint++) {
207 pCoords[iPoint].setValue((
float)line[iPoint].
x(),
208 (
float)line[iPoint].y(),
209 (
float)line[iPoint].
z());
215 SoCoordinate3 *polyCoords =
new SoCoordinate3;
216 polyCoords->point.setValues(0,nPoints,pCoords);
217 fCurrentSeparator->addChild(polyCoords);
222 SoDrawStyle* drawStyle = fStyleCache->getLineStyle();
223 fCurrentSeparator->addChild(drawStyle);
228 if (fpViewer->GetViewParameters().IsPicking()) LoadAtts(line, pLine);
231 pLine->numVertices.setValues(0,1,(
const long *)&nPoints);
233 pLine->numVertices.setValues(0,1,&nPoints);
236 fCurrentSeparator->addChild(pLine);
241 void G4OpenInventorSceneHandler::AddPrimitive (
const G4Polymarker& polymarker)
244 static G4bool warned =
false;
248 (
"G4OpenInventorSceneHandler::AddPrimitive (const G4Polymarker&)",
250 "2D polymarkers not implemented. Ignored.");
262 G4int pointn = polymarker.size();
263 if(pointn<=0)
return;
265 SbVec3f* points =
new SbVec3f[pointn];
266 for (
G4int iPoint = 0; iPoint < pointn ; iPoint++) {
267 points[iPoint].setValue((
float)polymarker[iPoint].
x(),
268 (
float)polymarker[iPoint].y(),
269 (
float)polymarker[iPoint].
z());
272 SoCoordinate3* coordinate3 =
new SoCoordinate3;
273 coordinate3->point.setValues(0,pointn,points);
274 fCurrentSeparator->addChild(coordinate3);
276 MarkerSizeType sizeType;
277 G4double screenSize = GetMarkerSize (polymarker, sizeType);
290 markerSet->numPoints = pointn;
293 if (fpViewer->GetViewParameters().IsPicking())
294 LoadAtts(polymarker, markerSet);
301 if (screenSize <= 5.) {
302 markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_5_5;
303 }
else if (screenSize <= 7.) {
304 markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_7_7;
306 markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_9_9;
310 if (screenSize <= 5.) {
312 markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_5_5;
314 markerSet->markerIndex = SoMarkerSet::CIRCLE_LINE_5_5;
316 }
else if (screenSize <= 7.) {
318 markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_7_7;
320 markerSet->markerIndex = SoMarkerSet::CIRCLE_LINE_7_7;
324 markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_9_9;
326 markerSet->markerIndex = SoMarkerSet::CIRCLE_LINE_9_9;
331 if (screenSize <= 5.) {
333 markerSet->markerIndex = SoMarkerSet::SQUARE_FILLED_5_5;
335 markerSet->markerIndex = SoMarkerSet::SQUARE_LINE_5_5;
337 }
else if (screenSize <= 7.) {
339 markerSet->markerIndex = SoMarkerSet::SQUARE_FILLED_7_7;
341 markerSet->markerIndex = SoMarkerSet::SQUARE_LINE_7_7;
345 markerSet->markerIndex = SoMarkerSet::SQUARE_FILLED_9_9;
347 markerSet->markerIndex = SoMarkerSet::SQUARE_LINE_9_9;
351 fCurrentSeparator->addChild(markerSet);
358 void G4OpenInventorSceneHandler::AddPrimitive (
const G4Text& text)
361 static G4bool warned =
false;
365 (
"G4OpenInventorSceneHandler::AddPrimitive (const G4Text&)",
367 "2D text not implemented. Ignored.");
379 const G4Colour&
c = GetTextColour (text);
381 fStyleCache->getMaterial((
float)c.GetRed(),
384 (float)(1-c.GetAlpha()));
385 fCurrentSeparator->addChild(material);
387 MarkerSizeType sizeType;
388 G4double size = GetMarkerSize (text, sizeType);
403 SoFont *g4Font =
new SoFont();
405 fCurrentSeparator->addChild(g4Font);
410 SoText2 *g4String =
new SoText2();
411 g4String->string.setValue(text.
GetText());
412 g4String->spacing = 2.0;
416 g4String->justification = SoText2::LEFT;
break;
418 g4String->justification = SoText2::CENTER;
break;
420 g4String->justification = SoText2::RIGHT;
break;
422 fCurrentSeparator->addChild(g4String);
428 void G4OpenInventorSceneHandler::AddPrimitive (
const G4Circle& circle) {
429 AddCircleSquare(G4OICircle, circle);
435 void G4OpenInventorSceneHandler::AddPrimitive (
const G4Square& square) {
436 AddCircleSquare(G4OISquare, square);
439 void G4OpenInventorSceneHandler::AddCircleSquare
440 (G4OIMarker markerType,
const G4VMarker& marker)
443 static G4bool warned =
false;
447 (
"G4OpenInventorSceneHandler::AddCircleSquare",
449 "2D circles and squares not implemented. Ignored.");
461 MarkerSizeType sizeType;
462 G4double screenSize = GetMarkerSize (marker, sizeType);
477 SbVec3f* points =
new SbVec3f[1];
478 points[0].setValue((
float)centre.
x(),
481 SoCoordinate3* coordinate3 =
new SoCoordinate3;
482 coordinate3->point.setValues(0,1,points);
483 fCurrentSeparator->addChild(coordinate3);
486 markerSet->numPoints = 1;
489 if (fpViewer->GetViewParameters().IsPicking()) LoadAtts(marker, markerSet);
492 switch (markerType) {
494 if (screenSize <= 5.) {
496 markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_5_5;
498 markerSet->markerIndex = SoMarkerSet::CIRCLE_LINE_5_5;
500 }
else if (screenSize <= 7.) {
502 markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_7_7;
504 markerSet->markerIndex = SoMarkerSet::CIRCLE_LINE_7_7;
508 markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_9_9;
510 markerSet->markerIndex = SoMarkerSet::CIRCLE_LINE_9_9;
515 if (screenSize <= 5.) {
517 markerSet->markerIndex = SoMarkerSet::SQUARE_FILLED_5_5;
519 markerSet->markerIndex = SoMarkerSet::SQUARE_LINE_5_5;
521 }
else if (screenSize <= 7.) {
523 markerSet->markerIndex = SoMarkerSet::SQUARE_FILLED_7_7;
525 markerSet->markerIndex = SoMarkerSet::SQUARE_LINE_7_7;
529 markerSet->markerIndex = SoMarkerSet::SQUARE_FILLED_9_9;
531 markerSet->markerIndex = SoMarkerSet::SQUARE_LINE_9_9;
536 fCurrentSeparator->addChild(markerSet);
544 void G4OpenInventorSceneHandler::AddPrimitive (
const G4Polyhedron& polyhedron)
549 static G4bool warned =
false;
553 (
"G4OpenInventorSceneHandler::AddPrimitive (const G4Polyhedron&)",
555 "2D polyhedra not implemented. Ignored.");
570 if (fpViewer->GetViewParameters().IsPicking())
571 LoadAtts(polyhedron, soPolyhedron);
573 SbString name =
"Non-geometry";
580 soPolyhedron->setName(sbName);
581 soPolyhedron->
solid.setValue(fModelingSolid);
583 fCurrentSeparator->addChild(soPolyhedron);
586 void G4OpenInventorSceneHandler::GeneratePrerequisites()
617 typedef std::vector<PVNodeID>
PVPath;
635 PVPath::const_reverse_iterator ri;
637 ri = ++drawnPVPath.rbegin();
638 if (ri != drawnPVPath.rend()) {
640 MotherVolume = ri->GetPhysicalVolume()->GetLogicalVolume();
650 SoSeparator* previewSeparator =
651 (SoSeparator*) detectorTreeKit->getPart(
"previewSeparator",
TRUE);
654 SoSeparator* fullSeparator =
655 (SoSeparator*) detectorTreeKit->getPart(
"fullSeparator",
TRUE);
665 fpViewer->GetApplicableVisAttributes (fpVisAttribs);
670 const double green = g4Col.
GetGreen ();
672 double transparency = 1 - g4Col.
GetAlpha();
676 GetDrawingStyle(pApplicableVisAttribs);
677 switch (drawing_style) {
679 fModelingSolid =
false;
684 fModelingSolid =
true;
688 SoMaterial* material =
689 fStyleCache->getMaterial((
float)red,
692 (
float)transparency);
693 detectorTreeKit->setPart(
"appearance.material",material);
695 SoLightModel* lightModel =
696 fModelingSolid ? fStyleCache->getLightModelPhong() :
697 fStyleCache->getLightModelBaseColor();
698 detectorTreeKit->setPart(
"appearance.lightModel",lightModel);
702 fSeparatorMap[pCurrentLV] = fullSeparator;
707 if (fSeparatorMap.find(MotherVolume) != fSeparatorMap.end()) {
710 fSeparatorMap[MotherVolume]->addChild(detectorTreeKit);
717 "ERROR: G4OpenInventorSceneHandler::GeneratePrerequisites: Mother "
718 << ri->GetPhysicalVolume()->GetName()
719 <<
':' << ri->GetCopyNo()
720 <<
" not previously encountered."
721 "\nShouldn't happen! Please report to visualization coordinator."
726 fDetectorRoot->addChild(detectorTreeKit);
730 fDetectorRoot->addChild(detectorTreeKit);
733 fCurrentSeparator = previewSeparator;
739 if (fSeparatorMap.find(MotherVolume) != fSeparatorMap.end()) {
740 fCurrentSeparator = fSeparatorMap[MotherVolume];
746 G4cout <<
"ERROR: G4OpenInventorSceneHandler::PreAddSolid: Mother "
747 << ri->GetPhysicalVolume()->GetName()
748 <<
':' << ri->GetCopyNo()
749 <<
" not previously encountered."
750 "\nShouldn't happen! Please report to visualization coordinator."
753 fCurrentSeparator = fDetectorRoot;
756 fCurrentSeparator = fDetectorRoot;
763 if (fReadyForTransients) {
764 fCurrentSeparator = fTransientRoot;
766 fCurrentSeparator = fDetectorRoot;
771 void G4OpenInventorSceneHandler::AddProperties(
const G4VisAttributes* visAtts)
775 fpViewer->GetApplicableVisAttributes (visAtts);
779 const double red = g4Col.
GetRed ();
780 const double green = g4Col.
GetGreen ();
781 const double blue = g4Col.
GetBlue ();
782 double transparency = 1 - g4Col.
GetAlpha();
786 GetDrawingStyle(pApplicableVisAttribs);
787 switch (drawing_style) {
789 fModelingSolid =
false;
794 fModelingSolid =
true;
799 G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pApplicableVisAttribs);
800 fReducedWireFrame = !isAuxEdgeVisible;
802 SoMaterial* material =
803 fStyleCache->getMaterial((
float)red,
806 (
float)transparency);
807 fCurrentSeparator->addChild(material);
809 SoLightModel* lightModel =
810 fModelingSolid ? fStyleCache->getLightModelPhong() :
811 fStyleCache->getLightModelBaseColor();
812 fCurrentSeparator->addChild(lightModel);
815 void G4OpenInventorSceneHandler::AddTransform(
const G4Point3D& translation)
819 fCurrentSeparator->addChild(fStyleCache->getResetTransform());
821 SoMatrixTransform* matrixTransform =
new SoMatrixTransform;
822 G4OpenInventorTransform3D oiTran
824 SbMatrix* sbMatrix = oiTran.GetSbMatrix();
826 const G4Vector3D scale = fpViewer->GetViewParameters().GetScaleFactor();
829 (SbVec3f((
float)scale.
x(),(float)scale.
y(),(float)scale.
z()));
830 sbMatrix->multRight(sbScale);
832 matrixTransform->matrix.setValue(*sbMatrix);
834 fCurrentSeparator->addChild(matrixTransform);
G4double GetAlpha() const
MarkerType GetMarkerType() const
virtual void BeginPrimitives(const G4Transform3D &objectTransformation)
virtual G4bool IsReplicated() const =0
const G4Colour & GetColour() const
G4Point3D GetPosition() const
const G4VisAttributes * GetVisAttributes() const
const std::vector< G4PhysicalVolumeNodeID > & GetDrawnPVPath() const
SoSFBool reducedWireFrame
G4GLOB_DLL std::ostream G4cout
G4double GetGreen() const
#define SoDetectorTreeKit
G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID
std::vector< PVNodeID > PVPath
G4int GetNoDaughters() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
virtual void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &)
virtual void setPreview(SbBool Flag)
FillStyle GetFillStyle() const
const G4String & GetName() const
G4LogicalVolume * GetCurrentLV() const
G4VPhysicalVolume * GetCurrentPV() const
G4int GetNoFacets() const