35#include <Inventor/SoPath.h>
36#include <Inventor/SoNodeKitPath.h>
37#include <Inventor/nodes/SoCoordinate3.h>
38#include <Inventor/nodes/SoCoordinate4.h>
39#include <Inventor/nodes/SoSeparator.h>
40#include <Inventor/nodes/SoDrawStyle.h>
41#include <Inventor/nodes/SoLightModel.h>
42#include <Inventor/nodes/SoMaterial.h>
43#include <Inventor/nodes/SoLineSet.h>
44#include <Inventor/nodes/SoCube.h>
45#include <Inventor/nodes/SoFont.h>
46#include <Inventor/nodes/SoText2.h>
47#include <Inventor/nodes/SoFaceSet.h>
48#include <Inventor/nodes/SoNormal.h>
49#include <Inventor/nodes/SoNormalBinding.h>
50#include <Inventor/nodes/SoComplexity.h>
51#include <Inventor/nodes/SoTranslation.h>
52#include <Inventor/nodes/SoTransform.h>
53#include <Inventor/nodes/SoResetTransform.h>
54#include <Inventor/nodes/SoMatrixTransform.h>
56#define USE_SOPOLYHEDRON
58#ifndef USE_SOPOLYHEDRON
102G4int G4OpenInventorSceneHandler::fSceneIdCount = 0;
111,fModelingSolid(false)
112,fReducedWireFrame(true)
114,fPreviewAndFull(true)
119 fRoot =
new SoSeparator;
121 fRoot->setName(
"Root");
123 fDetectorRoot =
new SoSeparator;
124 fDetectorRoot->setName(
"StaticRoot");
125 fRoot->addChild(fDetectorRoot);
127 fTransientRoot =
new SoSeparator;
128 fTransientRoot->setName(
"TransientRoot");
129 fRoot->addChild(fTransientRoot);
131 fCurrentSeparator = fTransientRoot;
137 fStyleCache->unref();
142 fDetectorRoot->removeAllChildren();
143 fSeparatorMap.clear();
145 fTransientRoot->removeAllChildren();
150 fTransientRoot->removeAllChildren();
163 GeneratePrerequisites();
177 GeneratePrerequisites();
187 static G4bool warned =
false;
191 (
"G4OpenInventorSceneHandler::AddPrimitive (const G4Polyline&)",
193 "2D polylines not implemented. Ignored.");
206 SbVec3f* pCoords =
new SbVec3f[nPoints];
208 for (
G4int iPoint = 0; iPoint < nPoints ; ++iPoint) {
209 pCoords[iPoint].setValue((
G4float)line[iPoint].x(),
217 SoCoordinate3 *polyCoords =
new SoCoordinate3;
218 polyCoords->point.setValues(0,nPoints,pCoords);
219 fCurrentSeparator->addChild(polyCoords);
224 SoDrawStyle* drawStyle = fStyleCache->getLineStyle();
225 fCurrentSeparator->addChild(drawStyle);
233 pLine->numVertices.setValues(0,1,(
const G4long *)&nPoints);
235 pLine->numVertices.setValues(0,1,&nPoints);
238 fCurrentSeparator->addChild(pLine);
246 static G4bool warned =
false;
250 (
"G4OpenInventorSceneHandler::AddPrimitive (const G4Polymarker&)",
252 "2D polymarkers not implemented. Ignored.");
265 if(pointn<=0)
return;
267 SbVec3f* points =
new SbVec3f[pointn];
268 for (
G4int iPoint = 0; iPoint < pointn ; ++iPoint) {
269 points[iPoint].setValue((
G4float)polymarker[iPoint].x(),
270 (
G4float)polymarker[iPoint].y(),
271 (
G4float)polymarker[iPoint].z());
274 SoCoordinate3* coordinate3 =
new SoCoordinate3;
275 coordinate3->point.setValues(0,pointn,points);
276 fCurrentSeparator->addChild(coordinate3);
292 markerSet->numPoints = pointn;
303 if (screenSize <= 5.) {
305 }
else if (screenSize <= 7.) {
312 if (screenSize <= 5.) {
318 }
else if (screenSize <= 7.) {
333 if (screenSize <= 5.) {
339 }
else if (screenSize <= 7.) {
353 fCurrentSeparator->addChild(markerSet);
363 static G4bool warned =
false;
367 (
"G4OpenInventorSceneHandler::AddPrimitive (const G4Text&)",
369 "2D text not implemented. Ignored.");
382 SoMaterial* material =
387 fCurrentSeparator->addChild(material);
405 SoFont *g4Font =
new SoFont();
407 fCurrentSeparator->addChild(g4Font);
412 SoText2 *g4String =
new SoText2();
413 g4String->string.setValue(text.
GetText());
414 g4String->spacing = 2.0;
418 g4String->justification = SoText2::LEFT;
break;
420 g4String->justification = SoText2::CENTER;
break;
422 g4String->justification = SoText2::RIGHT;
break;
424 fCurrentSeparator->addChild(g4String);
431 AddCircleSquare(G4OICircle, circle);
438 AddCircleSquare(G4OISquare, square);
441void G4OpenInventorSceneHandler::AddCircleSquare
442(G4OIMarker markerType,
const G4VMarker& marker)
445 static G4bool warned =
false;
449 (
"G4OpenInventorSceneHandler::AddCircleSquare",
451 "2D circles and squares not implemented. Ignored.");
479 SbVec3f* points =
new SbVec3f[1];
480 points[0].setValue((
G4float)centre.
x(),
483 SoCoordinate3* coordinate3 =
new SoCoordinate3;
484 coordinate3->point.setValues(0,1,points);
485 fCurrentSeparator->addChild(coordinate3);
488 markerSet->numPoints = 1;
494 switch (markerType) {
496 if (screenSize <= 5.) {
502 }
else if (screenSize <= 7.) {
517 if (screenSize <= 5.) {
523 }
else if (screenSize <= 7.) {
538 fCurrentSeparator->addChild(markerSet);
551 static G4bool warned =
false;
555 (
"G4OpenInventorSceneHandler::AddPrimitive (const G4Polyhedron&)",
557 "2D polyhedra not implemented. Ignored.");
575 SbString name =
"Non-geometry";
582 soPolyhedron->setName(sbName);
583 soPolyhedron->
solid.setValue(fModelingSolid);
585 fCurrentSeparator->addChild(soPolyhedron);
592void G4OpenInventorSceneHandler::GeneratePrerequisites()
623 using PVPath = std::vector<PVNodeID>;
641 PVPath::const_reverse_iterator ri;
643 ri = ++drawnPVPath.rbegin();
644 if (ri != drawnPVPath.rend()) {
646 MotherVolume = ri->GetPhysicalVolume()->GetLogicalVolume();
656 SoSeparator* previewSeparator =
657 (SoSeparator*) detectorTreeKit->getPart(
"previewSeparator",
TRUE);
658 previewSeparator->renderCaching = SoSeparator::OFF;
660 SoSeparator* fullSeparator =
661 (SoSeparator*) detectorTreeKit->getPart(
"fullSeparator",
TRUE);
662 fullSeparator->renderCaching = SoSeparator::OFF;
683 switch (drawing_style) {
685 fModelingSolid =
false;
690 fModelingSolid =
true;
693 fModelingSolid =
false;
697 SoMaterial* material =
698 fStyleCache->getMaterial((
G4float)red,
702 detectorTreeKit->setPart(
"appearance.material",material);
704 SoLightModel* lightModel =
705 fModelingSolid ? fStyleCache->getLightModelPhong() :
706 fStyleCache->getLightModelBaseColor();
707 detectorTreeKit->setPart(
"appearance.lightModel",lightModel);
711 fSeparatorMap[pCurrentLV] = fullSeparator;
716 if (fSeparatorMap.find(MotherVolume) != fSeparatorMap.end()) {
719 fSeparatorMap[MotherVolume]->addChild(detectorTreeKit);
726 "ERROR: G4OpenInventorSceneHandler::GeneratePrerequisites: Mother "
727 << ri->GetPhysicalVolume()->GetName()
728 <<
':' << ri->GetCopyNo()
729 <<
" not previously encountered."
730 "\nShouldn't happen! Please report to visualization coordinator."
735 fDetectorRoot->addChild(detectorTreeKit);
739 fDetectorRoot->addChild(detectorTreeKit);
742 fCurrentSeparator = previewSeparator;
748 if (fSeparatorMap.find(MotherVolume) != fSeparatorMap.end()) {
749 fCurrentSeparator = fSeparatorMap[MotherVolume];
755 G4warn <<
"ERROR: G4OpenInventorSceneHandler::PreAddSolid: Mother "
756 << ri->GetPhysicalVolume()->GetName()
757 <<
':' << ri->GetCopyNo()
758 <<
" not previously encountered."
759 "\nShouldn't happen! Please report to visualization coordinator."
762 fCurrentSeparator = fDetectorRoot;
765 fCurrentSeparator = fDetectorRoot;
773 fCurrentSeparator = fTransientRoot;
775 fCurrentSeparator = fDetectorRoot;
780void G4OpenInventorSceneHandler::AddProperties(
const G4VisAttributes* visAtts)
796 switch (drawing_style) {
798 fModelingSolid =
false;
803 fModelingSolid =
true;
806 fModelingSolid =
false;
812 fReducedWireFrame = !isAuxEdgeVisible;
814 SoMaterial* material =
815 fStyleCache->getMaterial((
G4float)red,
819 fCurrentSeparator->addChild(material);
821 SoLightModel* lightModel =
822 fModelingSolid ? fStyleCache->getLightModelPhong() :
823 fStyleCache->getLightModelBaseColor();
824 fCurrentSeparator->addChild(lightModel);
827void G4OpenInventorSceneHandler::AddTransform(
const G4Point3D& translation)
831 fCurrentSeparator->addChild(fStyleCache->getResetTransform());
833 SoMatrixTransform* matrixTransform =
new SoMatrixTransform;
836 SbMatrix* sbMatrix = oiTran.GetSbMatrix();
842 sbMatrix->multRight(sbScale);
844 matrixTransform->matrix.setValue(*sbMatrix);
846 fCurrentSeparator->addChild(matrixTransform);
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
#define SoDetectorTreeKit
#define HEPVis_SoMarkerSet
G4double GetAlpha() const
G4double GetGreen() const
std::size_t GetNoDaughters() const
const G4String & GetName() const
void AddPrimitive(const G4Polyline &line)
virtual ~G4OpenInventorSceneHandler()
void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &visAttribs)
void AddCompound(const G4Mesh &)
G4OpenInventorSceneHandler(G4OpenInventor &system, const G4String &name="")
void ClearTransientStore()
void BeginPrimitives(const G4Transform3D &objectTransformation)
const std::vector< G4PhysicalVolumeNodeID > & GetDrawnPVPath() const
G4VPhysicalVolume * GetCurrentPV() const
G4LogicalVolume * GetCurrentLV() const
MarkerType GetMarkerType() const
FillStyle GetFillStyle() const
G4Point3D GetPosition() const
virtual G4bool IsReplicated() const =0
void LoadAtts(const G4Visible &, G4AttHolder *)
const G4Colour & GetTextColour(const G4Text &)
G4Transform3D fObjectTransformation
G4double GetMarkerSize(const G4VMarker &, MarkerSizeType &)
virtual void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &)
const G4VisAttributes * fpVisAttribs
G4bool fReadyForTransients
G4ViewParameters::DrawingStyle GetDrawingStyle(const G4VisAttributes *)
virtual void BeginPrimitives(const G4Transform3D &objectTransformation=G4Transform3D())
G4bool GetAuxEdgeVisible(const G4VisAttributes *)
void StandardSpecialMeshRendering(const G4Mesh &)
const G4VisAttributes * GetApplicableVisAttributes(const G4VisAttributes *) const
const G4ViewParameters & GetViewParameters() const
const G4Vector3D & GetScaleFactor() const
const G4Colour & GetColour() const
const G4VisAttributes * GetVisAttributes() const
SoSFBool reducedWireFrame
G4int GetNoFacets() const
virtual void setPreview(SbBool Flag)