Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VtkViewer Class Reference

#include <G4VtkViewer.hh>

+ Inheritance diagram for G4VtkViewer:

Public Member Functions

 G4VtkViewer (G4VSceneHandler &, const G4String &name)
 
void Initialise () override
 
 ~G4VtkViewer () override
 
void SetView () override
 
void ClearView () override
 
void DrawView () override
 
void ShowView () override
 
void FinishView () override
 
void ExportScreenShot (G4String, G4String)
 
void ExportOBJScene (G4String)
 
void ExportVRMLScene (G4String)
 
void ExportVTPScene (G4String)
 
void ExportGLTFScene (G4String)
 
void ExportJSONRenderWindowScene (G4String)
 
void ExportVTPCutter (G4String fileName)
 
void ExportFormatStore (G4String fileName, G4String store)
 
void DrawShadows ()
 
void EnableShadows ()
 
void DisableShadows ()
 
void AddViewHUD ()
 
void EnableHUD ()
 
void DisableHUD ()
 
virtual void AddClipperPlaneWidget (const G4Plane3D &plane)
 
void EnableClipper (const G4Plane3D &plane, G4bool widget)
 
void DisableClipper ()
 
virtual void EnableClipperWidget ()
 
virtual void DisableClipperWidget ()
 
virtual void AddCutterPlaneWidget (const G4Plane3D &plane)
 
void EnableCutter (const G4Plane3D &plane, G4bool bWidget)
 
void DisableCutter (G4String name)
 
virtual void EnableCutterWidget ()
 
virtual void DisableCutterWidget ()
 
virtual void AddCameraOrientationWidget ()
 
virtual void EnableCameraOrientationWidget ()
 
virtual void DisableCameraOrientationWidget ()
 
void AddImageOverlay (const G4String &fileName, const G4double alpha, const G4double imageBottomLeft[2], const G4double worldBottomLeft[2], const G4double imageTopRight[2], const G4double worldTopRight[2], const G4double rot[3], const G4double trans[3])
 
void AddGeometryOverlay (const G4String &fileName, const G4double colour[3], const G4double alpha, const G4String &representation, const G4double scale[3], const G4double rotation[3], const G4double translation[3])
 
void Render ()
 
void StartInteractor ()
 
void Print ()
 
void SetPolyhedronPipeline (const G4String &t)
 
virtual void SetWidgetInteractor (vtkAbstractWidget *widget)
 
void ExportView ()
 
void SetGeant4View ()
 
- Public Member Functions inherited from G4VViewer
 G4VViewer (G4VSceneHandler &, G4int id, const G4String &name="")
 
virtual ~G4VViewer ()
 
virtual void ResetView ()
 
void RefreshView ()
 
std::vector< G4ThreeVectorComputeFlyThrough (G4Vector3D *)
 
SceneTreeSceneAccessSceneTreeScene ()
 
G4SceneTreeItemAccessSceneTree ()
 
void UpdateGUISceneTree ()
 
const G4StringGetName () const
 
const G4StringGetShortName () const
 
void SetName (const G4String &)
 
G4int GetViewId () const
 
G4VSceneHandlerGetSceneHandler () const
 
const G4ViewParametersGetViewParameters () const
 
const G4ViewParametersGetDefaultViewParameters () const
 
G4double GetKernelVisitElapsedTimeSeconds () const
 
virtual const std::vector< G4ModelingParameters::VisAttributesModifier > * GetPrivateVisAttributesModifiers () const
 
void SetViewParameters (const G4ViewParameters &vp)
 
void SetDefaultViewParameters (const G4ViewParameters &vp)
 
const G4VisAttributesGetApplicableVisAttributes (const G4VisAttributes *) const
 
void SetNeedKernelVisit (G4bool need)
 
void NeedKernelVisit ()
 
void ProcessView ()
 

Public Attributes

vtkNew< vtkTextActor > infoTextActor
 
vtkNew< vtkInfoCallbackinfoCallback
 
vtkNew< vtkGeant4Callbackgeant4Callback
 
vtkSmartPointer< vtkLight > light
 
vtkNew< vtkCamera > camera
 
vtkNew< vtkRenderer > renderer
 
vtkRenderWindow * _renderWindow
 
vtkRenderWindowInteractor * renderWindowInteractor
 

Protected Attributes

G4bool firstSetView = true
 
G4bool firstFinishView = true
 
G4double cameraDistance
 
vtkNew< vtkImplicitPlaneRepresentation > cutterPlaneRepresentation
 
vtkNew< vtkImplicitPlaneWidget2 > cutterPlaneWidget
 
vtkNew< vtkImplicitPlaneRepresentation > clipperPlaneRepresentation
 
vtkNew< vtkImplicitPlaneWidget2 > clipperPlaneWidget
 
vtkNew< vtkCameraOrientationWidget > camOrientWidget
 
bool bCutter = false
 
bool bClipper = false
 
bool bHud = false
 
bool bOrientation = false
 
- Protected Attributes inherited from G4VViewer
G4VSceneHandlerfSceneHandler
 
G4int fViewId
 
G4String fName
 
G4String fShortName
 
G4ViewParameters fVP
 
G4ViewParameters fDefaultVP
 
G4double fKernelVisitElapsedTimeSeconds = 999.
 
SceneTreeScene fSceneTreeScene
 
G4SceneTreeItem fSceneTree
 
G4bool fNeedKernelVisit
 

Additional Inherited Members

- Protected Member Functions inherited from G4VViewer
void SetTouchable (const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath)
 
void TouchableSetVisibility (const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath, G4bool visibility)
 
void TouchableSetColour (const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath, const G4Colour &)
 

Detailed Description

Definition at line 214 of file G4VtkViewer.hh.

Constructor & Destructor Documentation

◆ G4VtkViewer()

G4VtkViewer::G4VtkViewer ( G4VSceneHandler & sceneHandler,
const G4String & name )

Definition at line 81 of file G4VtkViewer.cc.

82 : G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name)
83{
84 vtkObject::GlobalWarningDisplayOff();
85
86 // Set default and current view parameters
87 fVP.SetAutoRefresh(true);
89}
G4int IncrementViewCount()
G4ViewParameters fDefaultVP
Definition G4VViewer.hh:258
G4ViewParameters fVP
Definition G4VViewer.hh:257
G4VViewer(G4VSceneHandler &, G4int id, const G4String &name="")
Definition G4VViewer.cc:49
void SetAutoRefresh(G4bool)

◆ ~G4VtkViewer()

G4VtkViewer::~G4VtkViewer ( )
override

Definition at line 149 of file G4VtkViewer.cc.

150{
151#ifdef G4VTKDEBUG
152 G4cout << "G4VtkViewer::~G4VtkViewer()" << G4endl;
153#endif
154}
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout

Member Function Documentation

◆ AddCameraOrientationWidget()

void G4VtkViewer::AddCameraOrientationWidget ( )
virtual

Definition at line 678 of file G4VtkViewer.cc.

679{
680 camOrientWidget->SetParentRenderer(renderer);
681 // Enable the widget.
682 camOrientWidget->Off();
683}
vtkNew< vtkCameraOrientationWidget > camOrientWidget
vtkNew< vtkRenderer > renderer

Referenced by DrawView().

◆ AddClipperPlaneWidget()

void G4VtkViewer::AddClipperPlaneWidget ( const G4Plane3D & plane)
virtual

Definition at line 552 of file G4VtkViewer.cc.

553{
554 vtkNew<vtkIPWCallback> clipperCallback;
555 auto& fVtkSceneHandler = dynamic_cast<G4VtkSceneHandler&>(fSceneHandler);
556 G4VtkStore& store = fVtkSceneHandler.GetStore();
557 clipperCallback->SetStore(&store);
558 clipperCallback->SetUpdatePipelineName("clipper", "clipper");
559
560 G4double bounds[6];
561 store.GetBounds(bounds);
562 auto vplane = G4Plane3DToVtkPlane(plane);
563 clipperPlaneRepresentation->SetPlaceFactor(
564 1.25); // This must be set prior to placing the widget.
565 clipperPlaneRepresentation->PlaceWidget(bounds);
566 clipperPlaneRepresentation->SetNormal(vplane->GetNormal());
567
568 vtkNew<vtkPropCollection> planeRepActors;
569 clipperPlaneRepresentation->GetActors(planeRepActors);
570 planeRepActors->InitTraversal();
571
574 clipperPlaneWidget->AddObserver(vtkCommand::InteractionEvent, clipperCallback);
575
576 clipperPlaneWidget->SetEnabled(0);
577}
double G4double
Definition G4Types.hh:83
vtkSmartPointer< vtkPlane > G4Plane3DToVtkPlane(const G4Plane3D &g4plane)
G4VSceneHandler & fSceneHandler
Definition G4VViewer.hh:253
void GetBounds(G4double maxBound[6])
virtual void SetWidgetInteractor(vtkAbstractWidget *widget)
vtkNew< vtkImplicitPlaneWidget2 > clipperPlaneWidget
vtkNew< vtkImplicitPlaneRepresentation > clipperPlaneRepresentation

Referenced by DrawView().

◆ AddCutterPlaneWidget()

void G4VtkViewer::AddCutterPlaneWidget ( const G4Plane3D & plane)
virtual

Definition at line 579 of file G4VtkViewer.cc.

580{
581 vtkNew<vtkIPWCallback> cutterCallback;
582 auto& fVtkSceneHandler = dynamic_cast<G4VtkSceneHandler&>(fSceneHandler);
583 G4VtkStore& store = fVtkSceneHandler.GetStore();
584 cutterCallback->SetStore(&store);
585 cutterCallback->SetUpdatePipelineName("cutter", "cutter");
586
587 G4double bounds[6];
588 store.GetBounds(bounds);
589 auto vplane = G4Plane3DToVtkPlane(plane);
590 cutterPlaneRepresentation->SetPlaceFactor(1.25); // This must be set prior to placing the widget.
591 cutterPlaneRepresentation->PlaceWidget(bounds);
592 cutterPlaneRepresentation->SetNormal(vplane->GetNormal());
593
596 cutterPlaneWidget->AddObserver(vtkCommand::InteractionEvent, cutterCallback);
597
598 cutterPlaneWidget->SetEnabled(0);
599}
vtkNew< vtkImplicitPlaneWidget2 > cutterPlaneWidget
vtkNew< vtkImplicitPlaneRepresentation > cutterPlaneRepresentation

Referenced by DrawView().

◆ AddGeometryOverlay()

void G4VtkViewer::AddGeometryOverlay ( const G4String & fileName,
const G4double colour[3],
const G4double alpha,
const G4String & representation,
const G4double scale[3],
const G4double rotation[3],
const G4double translation[3] )

Definition at line 729 of file G4VtkViewer.cc.

733{
734 auto transformation = G4Transform3D::Identity;
735 auto scal = G4Scale3D(scale[0], scale[1], scale[2]);
736 auto rotx = G4RotateX3D(rotation[0]);
737 auto roty = G4RotateY3D(rotation[1]);
738 auto rotz = G4RotateZ3D(rotation[2]);
739 auto tran = G4Translate3D(translation[0], translation[1], translation[2]);
740
741 transformation = tran * rotz * roty * rotx * scal * transformation;
742
743 auto& fVtkSceneHandler = dynamic_cast<G4VtkSceneHandler&>(fSceneHandler);
744 G4VtkStore& st = fVtkSceneHandler.GetTransientStore();
745
746
747 G4VtkVisContext vc = G4VtkVisContext(this, nullptr, false, transformation);
748 if (representation == "w")
750 else if (representation == "s")
752 vc.alpha = alpha;
753 vc.red = colour[0];
754 vc.green = colour[1];
755 vc.blue = colour[2];
756 st.AddNonG4ObjectPolydata(fileName, vc);
757}
HepGeom::RotateZ3D G4RotateZ3D
HepGeom::RotateX3D G4RotateX3D
HepGeom::RotateY3D G4RotateY3D
HepGeom::Translate3D G4Translate3D
HepGeom::Scale3D G4Scale3D
void AddNonG4ObjectPolydata(const G4String fileName, const G4VtkVisContext &vc)
G4ViewParameters::DrawingStyle fDrawingStyle
static DLL_API const Transform3D Identity

◆ AddImageOverlay()

void G4VtkViewer::AddImageOverlay ( const G4String & fileName,
const G4double alpha,
const G4double imageBottomLeft[2],
const G4double worldBottomLeft[2],
const G4double imageTopRight[2],
const G4double worldTopRight[2],
const G4double rot[3],
const G4double trans[3] )

Definition at line 695 of file G4VtkViewer.cc.

700{
701 auto xScale = (worldTopRight[0] - worldBottomLeft[0]) / (imageTopRight[0] - imageBottomLeft[0]);
702 auto yScale = -(worldTopRight[1] - worldBottomLeft[1]) / (imageTopRight[1] - imageBottomLeft[1]);
703
704 G4cout << xScale << " " << yScale << G4endl;
705 auto transformation = G4Transform3D::Identity;
706 auto scal = G4Scale3D(xScale, yScale, 1);
707 auto rotx = G4RotateX3D(rotation[0]/180*CLHEP::pi);
708 auto roty = G4RotateY3D(rotation[1]/180*CLHEP::pi);
709 auto rotz = G4RotateZ3D(rotation[2]/180*CLHEP::pi);
710 auto tranImg = G4Translate3D( -std::fabs(imageBottomLeft[0] + imageTopRight[0]) / 2.0,
711 -std::fabs(imageBottomLeft[1] + imageTopRight[1]) / 2.0,
712 0);
713 auto tran = G4Translate3D(translation[0],
714 translation[1],
715 translation[2]);
716
717 G4cout << translation[0] << " " << translation[1] << " " << translation[2] << G4endl;
718 transformation = tran * rotz * roty * rotx * scal * tranImg * transformation;
719
720 G4cout << transformation.dx() << " " << transformation.dy() << " " << transformation.dz() << G4endl;
721 auto& fVtkSceneHandler = dynamic_cast<G4VtkSceneHandler&>(fSceneHandler);
722 G4VtkStore& st = fVtkSceneHandler.GetTransientStore();
723
724 G4VtkVisContext vc = G4VtkVisContext(this, nullptr, false, transformation);
725 vc.alpha = alpha;
726 st.AddNonG4ObjectImage(fileName, vc);
727}
void AddNonG4ObjectImage(const G4String &fileName, const G4VtkVisContext &vc)

◆ AddViewHUD()

void G4VtkViewer::AddViewHUD ( )

Definition at line 538 of file G4VtkViewer.cc.

539{
540 // make sure text is always visible
542 infoTextActor->GetTextProperty()->SetColor(std::fmod(colour.GetRed() + 0.5, 1.0),
543 std::fmod(colour.GetGreen() + 0.5, 1.0),
544 std::fmod(colour.GetBlue() + 0.5, 1.0));
545 infoTextActor->GetTextProperty()->SetFontSize(20);
546 infoCallback->SetTextActor(infoTextActor);
547 renderer->AddObserver(vtkCommand::EndEvent, infoCallback);
548 renderer->AddActor(infoTextActor);
549 infoTextActor->SetVisibility(0);
550}
G4double GetBlue() const
Definition G4Colour.hh:154
G4double GetRed() const
Definition G4Colour.hh:152
G4double GetGreen() const
Definition G4Colour.hh:153
const G4Colour & GetBackgroundColour() const
vtkNew< vtkTextActor > infoTextActor
vtkNew< vtkInfoCallback > infoCallback

Referenced by DrawView().

◆ ClearView()

void G4VtkViewer::ClearView ( void )
overridevirtual

Implements G4VViewer.

Definition at line 234 of file G4VtkViewer.cc.

235{
236#ifdef G4VTKDEBUG
237 G4cout << "G4VtkViewer::ClearView()" << G4endl;
238#endif
239
240 auto& fVtkSceneHandler = dynamic_cast<G4VtkSceneHandler&>(fSceneHandler);
241 G4VtkStore& ts = fVtkSceneHandler.GetTransientStore();
242 ts.Clear();
243
244 G4VtkStore& s = fVtkSceneHandler.GetStore();
245 s.Clear();
246}
void Clear()

◆ DisableCameraOrientationWidget()

void G4VtkViewer::DisableCameraOrientationWidget ( )
virtual

Definition at line 690 of file G4VtkViewer.cc.

691{
692 camOrientWidget->Off();
693}

◆ DisableClipper()

void G4VtkViewer::DisableClipper ( )

Definition at line 632 of file G4VtkViewer.cc.

633{
634 auto& fVtkSceneHandler = dynamic_cast<G4VtkSceneHandler&>(fSceneHandler);
635 G4VtkStore& s = fVtkSceneHandler.GetStore();
636 s.RemoveClipper("clipper");
637}
void RemoveClipper(G4String name)

◆ DisableClipperWidget()

void G4VtkViewer::DisableClipperWidget ( )
virtual

Definition at line 644 of file G4VtkViewer.cc.

645{
646 clipperPlaneWidget->SetEnabled(0);
647}

◆ DisableCutter()

void G4VtkViewer::DisableCutter ( G4String name)

Definition at line 660 of file G4VtkViewer.cc.

661{
662 auto& fVtkSceneHandler = dynamic_cast<G4VtkSceneHandler&>(fSceneHandler);
663 G4VtkStore& s = fVtkSceneHandler.GetStore();
664 s.RemoveCutter("cutter");
665}
void RemoveCutter(G4String name)

◆ DisableCutterWidget()

void G4VtkViewer::DisableCutterWidget ( )
virtual

Definition at line 673 of file G4VtkViewer.cc.

674{
675 cutterPlaneWidget->SetEnabled(0);
676}

◆ DisableHUD()

void G4VtkViewer::DisableHUD ( )

Definition at line 616 of file G4VtkViewer.cc.

617{
618 infoTextActor->SetVisibility(0);
619}

◆ DisableShadows()

void G4VtkViewer::DisableShadows ( )

Definition at line 606 of file G4VtkViewer.cc.

607{
608 renderer->SetUseShadows(0);
609}

◆ DrawShadows()

void G4VtkViewer::DrawShadows ( )

Definition at line 282 of file G4VtkViewer.cc.

283{
284 _renderWindow->SetMultiSamples(0);
285
286 vtkNew<vtkShadowMapPass> shadows;
287 vtkNew<vtkSequencePass> seq;
288
289 vtkNew<vtkRenderPassCollection> passes;
290 passes->AddItem(shadows->GetShadowMapBakerPass());
291 passes->AddItem(shadows);
292 seq->SetPasses(passes);
293
294 vtkNew<vtkCameraPass> cameraP;
295 cameraP->SetDelegatePass(seq);
296
297 // tell the renderer to use our render pass pipeline
298 auto glrenderer = dynamic_cast<vtkOpenGLRenderer*>(renderer.GetPointer());
299 glrenderer->SetPass(cameraP);
300}
vtkRenderWindow * _renderWindow

◆ DrawView()

void G4VtkViewer::DrawView ( )
overridevirtual

Implements G4VViewer.

Definition at line 248 of file G4VtkViewer.cc.

249{
250#ifdef G4VTKDEBUG
251 G4cout << "G4VtkViewer::DrawView()" << G4endl;
252#endif
253
254 // First, a view should decide when to re-visit the G4 kernel.
255 // Sometimes it might not be necessary, e.g., if the scene is stored
256 // in a graphical database (e.g., OpenGL's display lists) and only
257 // the viewing angle has changed. But graphics systems without a
258 // graphical database will always need to visit the G4 kernel.
259
260 NeedKernelVisit(); // Default is - always visit G4 kernel.
261
262 // Note: this routine sets the fNeedKernelVisit flag of *all* the
263 // views of the scene.
264
265 ProcessView(); // The basic logic is here.
266
267 // Add HUD
268 AddViewHUD();
269
270 // Add clipper and cutter widgets
271 auto g4p = G4Plane3D();
274
275 // Add camera orientation widget
277
278 // ...before finally...
279 FinishView(); // Flush streams and/or swap buffers.
280}
HepGeom::Plane3D< G4double > G4Plane3D
Definition G4Plane3D.hh:34
void ProcessView()
Definition G4VViewer.cc:108
void NeedKernelVisit()
Definition G4VViewer.cc:81
void FinishView() override
virtual void AddClipperPlaneWidget(const G4Plane3D &plane)
virtual void AddCameraOrientationWidget()
virtual void AddCutterPlaneWidget(const G4Plane3D &plane)
void AddViewHUD()

◆ EnableCameraOrientationWidget()

void G4VtkViewer::EnableCameraOrientationWidget ( )
virtual

Definition at line 685 of file G4VtkViewer.cc.

686{
687 camOrientWidget->On();
688}

◆ EnableClipper()

void G4VtkViewer::EnableClipper ( const G4Plane3D & plane,
G4bool widget )

Definition at line 621 of file G4VtkViewer.cc.

622{
623 auto& fVtkSceneHandler = dynamic_cast<G4VtkSceneHandler&>(fSceneHandler);
624 G4VtkStore& s = fVtkSceneHandler.GetStore();
625 G4String name = G4String("clipper");
626 s.AddClipper(name, plane);
627 if (bWidget) {
629 }
630}
virtual void EnableClipperWidget()
const char * name(G4int ptype)

◆ EnableClipperWidget()

void G4VtkViewer::EnableClipperWidget ( )
virtual

Reimplemented in G4VtkQtViewer.

Definition at line 639 of file G4VtkViewer.cc.

640{
641 clipperPlaneWidget->SetEnabled(1);
642}

Referenced by EnableClipper(), and G4VtkQtViewer::EnableClipperWidget().

◆ EnableCutter()

void G4VtkViewer::EnableCutter ( const G4Plane3D & plane,
G4bool bWidget )

Definition at line 649 of file G4VtkViewer.cc.

650{
651 auto& fVtkSceneHandler = dynamic_cast<G4VtkSceneHandler&>(fSceneHandler);
652 G4VtkStore& s = fVtkSceneHandler.GetStore();
653 G4String name = G4String("cutter");
654 s.AddCutter(name, plane);
655 if (bWidget) {
657 }
658}
virtual void EnableCutterWidget()

◆ EnableCutterWidget()

void G4VtkViewer::EnableCutterWidget ( )
virtual

Definition at line 667 of file G4VtkViewer.cc.

668{
669 G4cout << "enable cutter widget" << G4endl;
670 cutterPlaneWidget->SetEnabled(1);
671}

Referenced by EnableCutter().

◆ EnableHUD()

void G4VtkViewer::EnableHUD ( )

Definition at line 611 of file G4VtkViewer.cc.

612{
613 infoTextActor->SetVisibility(1);
614}

◆ EnableShadows()

void G4VtkViewer::EnableShadows ( )

Definition at line 601 of file G4VtkViewer.cc.

602{
603 renderer->SetUseShadows(1);
604}

◆ ExportFormatStore()

void G4VtkViewer::ExportFormatStore ( G4String fileName,
G4String store )

Definition at line 493 of file G4VtkViewer.cc.

494{
495 vtkSmartPointer<vtkRenderWindow> tempRenderWindow;
496 vtkNew<vtkRenderer> tempRenderer;
497 tempRenderWindow = vtkSmartPointer<vtkRenderWindow>::New();
498 tempRenderWindow->AddRenderer(tempRenderer);
499
500 auto& fVtkSceneHandler = dynamic_cast<G4VtkSceneHandler&>(fSceneHandler);
501
502 if (storeName == "transient") {
503 G4VtkStore& store = fVtkSceneHandler.GetTransientStore();
504 store.AddToRenderer(tempRenderer);
505 }
506 else {
507 G4VtkStore& store = fVtkSceneHandler.GetStore();
508 store.AddToRenderer(tempRenderer);
509 }
510
511 if (fileName.find("obj") != std::string::npos) {
512 vtkNew<vtkOBJExporter> exporter;
513 exporter->SetRenderWindow(tempRenderWindow);
514 exporter->SetFilePrefix(fileName.c_str());
515 exporter->Write();
516 }
517 else if (fileName.find("vrml") != std::string::npos) {
518 vtkNew<vtkVRMLExporter> exporter;
519 exporter->SetRenderWindow(tempRenderWindow);
520 exporter->SetFileName(fileName.c_str());
521 exporter->Write();
522 }
523 else if (fileName.find("vtp") != std::string::npos) {
524 vtkNew<vtkSingleVTPExporter> exporter;
525 exporter->SetRenderWindow(tempRenderWindow);
526 exporter->SetFileName(fileName.c_str());
527 exporter->Write();
528 }
529 else if (fileName.find("gltf") != std::string::npos) {
530 vtkNew<vtkGLTFExporter> exporter;
531 exporter->SetRenderWindow(tempRenderWindow);
532 exporter->SetFileName(fileName.c_str());
533 exporter->InlineDataOn();
534 exporter->Write();
535 }
536}
void AddToRenderer(vtkRenderer *renderer)

◆ ExportGLTFScene()

void G4VtkViewer::ExportGLTFScene ( G4String fileName)

Definition at line 412 of file G4VtkViewer.cc.

412 {
414 exporter->SetRenderWindow(_renderWindow);
415 exporter->SetFileName((fileName+".gltf").c_str());
416 exporter->InlineDataOn();
417 exporter->Write();
418}

◆ ExportJSONRenderWindowScene()

void G4VtkViewer::ExportJSONRenderWindowScene ( G4String )

Definition at line 420 of file G4VtkViewer.cc.

420 {
423 exporter->SetRenderWindow(_renderWindow);
424 exporter->SetSerializer(serializer);
425 exporter->Write();
426}

◆ ExportOBJScene()

void G4VtkViewer::ExportOBJScene ( G4String path)

Definition at line 388 of file G4VtkViewer.cc.

389{
391 exporter->SetRenderWindow(_renderWindow);
392 exporter->SetFilePrefix(path.c_str());
393 exporter->Write();
394}

◆ ExportScreenShot()

void G4VtkViewer::ExportScreenShot ( G4String path,
G4String format )

Definition at line 342 of file G4VtkViewer.cc.

343{
344 vtkImageWriter* imWriter = nullptr;
345
346 if (format == "bmp") {
347 imWriter = vtkBMPWriter::New();
348 }
349 else if (format == "jpg") {
350 imWriter = vtkJPEGWriter::New();
351 }
352 else if (format == "pnm") {
353 imWriter = vtkPNMWriter::New();
354 }
355 else if (format == "png") {
356 imWriter = vtkPNGWriter::New();
357 }
358 else if (format == "tiff") {
359 imWriter = vtkTIFFWriter::New();
360 }
361 else if (format == "ps") {
362 imWriter = vtkPostScriptWriter::New();
363 }
364 else {
365 return;
366 }
367
368 _renderWindow->Render();
369
372 winToImage->SetInput(_renderWindow);
373 winToImage->SetScale(1);
374 if (format == "ps") {
375 winToImage->SetInputBufferTypeToRGB();
376 winToImage->ReadFrontBufferOff();
377 winToImage->Update();
378 }
379 else {
380 winToImage->SetInputBufferTypeToRGBA();
381 }
382
383 imWriter->SetFileName((path + "." + format).c_str());
384 imWriter->SetInputConnection(winToImage->GetOutputPort());
385 imWriter->Write();
386}

◆ ExportView()

void G4VtkViewer::ExportView ( )
inline

Definition at line 281 of file G4VtkViewer.hh.

281{};

◆ ExportVRMLScene()

void G4VtkViewer::ExportVRMLScene ( G4String path)

Definition at line 396 of file G4VtkViewer.cc.

397{
399 exporter->SetRenderWindow(_renderWindow);
400 exporter->SetFileName((path + ".vrml").c_str());
401 exporter->Write();
402}

◆ ExportVTPCutter()

void G4VtkViewer::ExportVTPCutter ( G4String fileName)

Definition at line 428 of file G4VtkViewer.cc.

429{
430 auto& fVtkSceneHandler = dynamic_cast<G4VtkSceneHandler&>(fSceneHandler);
431 G4VtkStore& s = fVtkSceneHandler.GetStore();
432
433 // create new renderer
434 vtkNew<vtkRenderer> tempRenderer;
435
436 // loop over pipelines
437 auto separate = s.GetSeparatePipeMap();
438 for (const auto& i : separate) {
439 i.second->GetActor();
440 auto children = i.second->GetChildPipelines();
441 for (auto child : children) {
442 if (child->GetTypeName() == "G4VtkCutterPipeline") {
443 auto childCutter = dynamic_cast<G4VtkCutterPipeline*>(child);
444 tempRenderer->AddActor(childCutter->GetActor());
445 }
446 }
447 }
448
449 auto tensor = s.GetTensorPipeMap();
450 for (const auto& i : tensor) {
451 i.second->GetActor();
452 auto children = i.second->GetChildPipelines();
453 for (auto child : children) {
454 if (child->GetTypeName() == "G4VtkCutterPipeline") {
455 auto childCutter = dynamic_cast<G4VtkCutterPipeline*>(child);
456 tempRenderer->AddActor(childCutter->GetActor());
457 }
458 }
459 }
460
461 auto append = s.GetAppendPipeMap();
462 for (const auto& i : append) {
463 i.second->GetActor();
464 auto children = i.second->GetChildPipelines();
465 for (auto child : children) {
466 if (child->GetTypeName() == "G4VtkCutterPipeline") {
467 auto childCutter = dynamic_cast<G4VtkCutterPipeline*>(child);
468 tempRenderer->AddActor(childCutter->GetActor());
469 }
470 }
471 }
472
473 auto baked = s.GetBakePipeMap();
474 for (const auto& i : baked) {
475 i.second->GetActor();
476 auto children = i.second->GetChildPipelines();
477 for (auto child : children) {
478 if (child->GetTypeName() == "G4VtkCutterPipeline") {
479 auto childCutter = dynamic_cast<G4VtkCutterPipeline*>(child);
480 tempRenderer->AddActor(childCutter->GetActor());
481 }
482 }
483 }
484
485 vtkNew<vtkRenderWindow> tempRenderWindow;
486 tempRenderWindow->AddRenderer(tempRenderer);
487 vtkNew<vtkSingleVTPExporter> exporter;
488 exporter->SetRenderWindow(tempRenderWindow);
489 exporter->SetFileName(fileName.c_str());
490 exporter->Write();
491}
std::map< std::size_t, std::shared_ptr< G4VtkPolydataPipeline > > & GetSeparatePipeMap()

◆ ExportVTPScene()

void G4VtkViewer::ExportVTPScene ( G4String path)

Definition at line 404 of file G4VtkViewer.cc.

405{
407 exporter->SetRenderWindow(_renderWindow);
408 exporter->SetFileName((path + ".vtp").c_str());
409 exporter->Write();
410}

◆ FinishView()

void G4VtkViewer::FinishView ( void )
overridevirtual

Reimplemented from G4VViewer.

Definition at line 322 of file G4VtkViewer.cc.

323{
324#ifdef G4VTKDEBUG
325 G4cout << "G4VtkViewer::FinishView()" << G4endl;
326#endif
327
328 auto& fVtkSceneHandler = dynamic_cast<G4VtkSceneHandler&>(fSceneHandler);
329 fVtkSceneHandler.Modified();
330
331 _renderWindow->GetInteractor()->Initialize();
332 _renderWindow->Render();
333
334 if (firstFinishView) {
335 firstFinishView = false;
336 }
337 else {
338 _renderWindow->GetInteractor()->Start();
339 }
340}
G4bool firstFinishView

Referenced by DrawView().

◆ Initialise()

void G4VtkViewer::Initialise ( )
overridevirtual

Reimplemented from G4VViewer.

Definition at line 91 of file G4VtkViewer.cc.

92{
93 _renderWindow = vtkRenderWindow::New();
94 renderWindowInteractor = vtkRenderWindowInteractor::New();
95
96#ifdef G4VTKDEBUG
97 G4cout << "G4VtkViewer::G4VtkViewer" << G4endl;
98 G4cout << "G4VtkViewer::G4VtkViewer> " << fVP.GetWindowSizeHintX() << " "
100 G4cout << "G4VtkViewer::G4VtkViewer> " << fVP.GetWindowLocationHintX() << " "
102#endif
103
104 // Need windowSizeX/Y - obtain from _renderWindow?
105 G4int screenSizeX = _renderWindow->GetScreenSize()[0];
106 G4int screenSizeY = _renderWindow->GetScreenSize()[1];
107 G4int positionX = fVP.GetWindowLocationHintX();
109 positionX = screenSizeX + positionX - fVP.GetWindowSizeHintX();
110 }
111 G4int positionY = fVP.GetWindowLocationHintY();
113 positionY = screenSizeY + positionY - fVP.GetWindowSizeHintY();
114 }
115 _renderWindow->SetPosition(positionX, positionY);
116#ifdef __APPLE__
117 // Adjust window size for Apple to make it correspond to OpenGL.
118 // Maybe it's OpenGL that shoud be adjusted.
119 const G4double pixelFactor = 2.;
120#else
121 const G4double pixelFactor = 1.;
122#endif
123 _renderWindow->SetSize(pixelFactor * fVP.GetWindowSizeHintX(),
124 pixelFactor * fVP.GetWindowSizeHintY());
125 _renderWindow->SetWindowName("Vtk viewer");
126
127 _renderWindow->AddRenderer(renderer);
128 renderWindowInteractor->SetRenderWindow(_renderWindow);
129
130 // TODO proper camera parameter settings
131 camera->SetPosition(0, 0, 1000);
132 camera->SetFocalPoint(0, 0, 0);
133 renderer->SetActiveCamera(camera);
134
135 // Hidden line removal
136 renderer->SetUseHiddenLineRemoval(0);
137
138 // Shadows
139 renderer->SetUseShadows(0);
140
141 // Set callback to match VTK parameters to Geant4
142 geant4Callback->SetGeant4ViewParameters(&fVP);
143 renderer->AddObserver(vtkCommand::EndEvent, geant4Callback);
144
146 renderWindowInteractor->SetInteractorStyle(style);
147}
int G4int
Definition G4Types.hh:85
G4int GetWindowLocationHintX() const
unsigned int GetWindowSizeHintX() const
G4bool IsWindowLocationHintXNegative() const
G4bool IsWindowLocationHintYNegative() const
G4int GetWindowLocationHintY() const
unsigned int GetWindowSizeHintY() const
vtkNew< vtkCamera > camera
vtkNew< vtkGeant4Callback > geant4Callback
vtkRenderWindowInteractor * renderWindowInteractor

Referenced by G4VtkOffscreenViewer::Initialise().

◆ Print()

void G4VtkViewer::Print ( )

Definition at line 759 of file G4VtkViewer.cc.

760{
761 cutterPlaneRepresentation->VisibilityOff();
762
763 G4cout << "Number of VTK props> " << renderer->GetNumberOfPropsRendered() << G4endl;
764 G4cout << "Number of VTK actors> " << renderer->GetActors()->GetNumberOfItems() << G4endl;
765 auto& fVtkSceneHandler = dynamic_cast<G4VtkSceneHandler&>(fSceneHandler);
766 G4VtkStore& s = fVtkSceneHandler.GetStore();
767 G4VtkStore& st = fVtkSceneHandler.GetTransientStore();
768 s.Print();
769 st.Print();
770}
void Print()

◆ Render()

void G4VtkViewer::Render ( )
inline

Definition at line 270 of file G4VtkViewer.hh.

270{_renderWindow->Render();}

◆ SetGeant4View()

void G4VtkViewer::SetGeant4View ( )
inline

Definition at line 282 of file G4VtkViewer.hh.

282{};

◆ SetPolyhedronPipeline()

void G4VtkViewer::SetPolyhedronPipeline ( const G4String & t)

Definition at line 772 of file G4VtkViewer.cc.

773{
774 // Get the scene handler
775 auto& fVtkSceneHandler = dynamic_cast<G4VtkSceneHandler&>(fSceneHandler);
776 fVtkSceneHandler.SetPolyhedronPipeline(type);
777}
void SetPolyhedronPipeline(const G4String &str)

◆ SetView()

void G4VtkViewer::SetView ( )
overridevirtual

Implements G4VViewer.

Definition at line 156 of file G4VtkViewer.cc.

157{
158#ifdef G4VTKDEBUG
159 G4cout << "G4VtkViewer::SetView()" << G4endl;
160#endif
161 // background colour
162 const G4Colour backgroundColour = fVP.GetBackgroundColour();
163 renderer->SetBackground(backgroundColour.GetRed(), backgroundColour.GetGreen(),
164 backgroundColour.GetBlue());
165
166 // target and camera positions
168 if (radius <= 0.) {
169 radius = 1.;
170 }
171
173 G4Point3D viewpointDirection = fVP.GetViewpointDirection();
174 G4Point3D targetPosition = fVP.GetCurrentTargetPoint();
175 G4double zoomFactor = fVP.GetZoomFactor();
176 G4double fieldHalfAngle = fVP.GetFieldHalfAngle();
177
178 G4Point3D cameraPosition = targetPosition + viewpointDirection.unit() /zoomFactor * cameraDistance;
179
180 vtkCamera* activeCamera = renderer->GetActiveCamera();
181 activeCamera->SetFocalPoint(targetPosition.x(), targetPosition.y(), targetPosition.z());
182 activeCamera->SetViewAngle(2*fieldHalfAngle / CLHEP::pi * 180);
183 activeCamera->SetPosition(cameraPosition.x(), cameraPosition.y(), cameraPosition.z());
184 activeCamera->SetParallelScale(cameraDistance / zoomFactor);
185
186 if (fieldHalfAngle == 0) {
187 activeCamera->SetParallelProjection(1);
188 }
189 else {
190 activeCamera->SetParallelProjection(0);
191 }
192
193 // need to set camera distance and parallel scale on first set view
194 if (firstSetView) {
195 geant4Callback->SetVtkInitialValues(cameraDistance, cameraDistance);
196 activeCamera->SetParallelScale(cameraDistance);
197 firstSetView = false;
198 }
199
200 // camera up direction
201 const G4Vector3D upVector = fVP.GetUpVector();
202 renderer->GetActiveCamera()->SetViewUp(upVector.x(), upVector.y(), upVector.z());
203
204 // Light
205 const G4Vector3D lightDirection = fVP.GetLightpointDirection();
206 G4bool lightsMoveWithCamera = fVP.GetLightsMoveWithCamera();
207 G4Vector3D lightPosition = targetPosition + lightDirection.unit() * cameraDistance;
208
209 vtkLightCollection* currentLights = renderer->GetLights();
210 if (currentLights->GetNumberOfItems() != 0) {
211 auto currentLight = dynamic_cast<vtkLight*>(currentLights->GetItemAsObject(0));
212 if (currentLight != nullptr) {
213 currentLight->SetPosition(lightPosition.x(), lightPosition.y(), lightPosition.z());
214 if (lightsMoveWithCamera) {
215 currentLight->SetLightTypeToCameraLight();
216 }
217 else {
218 currentLight->SetLightTypeToSceneLight();
219 }
220 }
221 }
222
223 // cut away
224 if (fVP.IsCutaway()) {
225 G4cout << "Add cutaway planes" << G4endl;
226 }
227
228 // section
229 if (fVP.IsSection()) {
230 G4cout << "Add section" << G4endl;
231 }
232}
bool G4bool
Definition G4Types.hh:86
virtual const G4VisExtent & GetExtent() const
G4double GetCameraDistance(G4double radius) const
G4bool IsCutaway() const
const G4Vector3D & GetLightpointDirection() const
const G4Vector3D & GetViewpointDirection() const
G4bool IsSection() const
const G4Point3D & GetCurrentTargetPoint() const
G4double GetFieldHalfAngle() const
G4double GetZoomFactor() const
const G4Vector3D & GetUpVector() const
G4bool GetLightsMoveWithCamera() const
G4double GetExtentRadius() const
G4double cameraDistance
G4bool firstSetView
BasicVector3D< T > unit() const

◆ SetWidgetInteractor()

void G4VtkViewer::SetWidgetInteractor ( vtkAbstractWidget * widget)
virtual

Reimplemented in G4VtkQtViewer.

Definition at line 779 of file G4VtkViewer.cc.

780{
781 widget->SetInteractor(_renderWindow->GetInteractor());
782}

Referenced by AddClipperPlaneWidget(), and AddCutterPlaneWidget().

◆ ShowView()

void G4VtkViewer::ShowView ( void )
overridevirtual

Reimplemented from G4VViewer.

Definition at line 302 of file G4VtkViewer.cc.

303{
304#ifdef G4VTKDEBUG
305 G4cout << "G4VtkViewer::ShowView()" << G4endl;
306#endif
307
308 infoTextActor->GetTextProperty()->SetFontSize(28);
310
311 // make sure text is always visible
312 infoTextActor->GetTextProperty()->SetColor(std::fmod(colour.GetRed() + 0.5, 1.0),
313 std::fmod(colour.GetGreen() + 0.5, 1.0),
314 std::fmod(colour.GetBlue() + 0.5, 1.0));
315 infoTextActor->GetTextProperty()->SetFontSize(20);
316 infoCallback->SetTextActor(infoTextActor);
317 renderer->AddObserver(vtkCommand::EndEvent, infoCallback);
318 geant4Callback->SetGeant4ViewParameters(&fVP);
319 renderer->AddObserver(vtkCommand::EndEvent, geant4Callback);
320}

◆ StartInteractor()

void G4VtkViewer::StartInteractor ( )
inline

Definition at line 271 of file G4VtkViewer.hh.

271 {
272 G4cout << "StartInteractor" << G4endl;
273 _renderWindow->GetInteractor()->Start();}

Member Data Documentation

◆ _renderWindow

◆ bClipper

bool G4VtkViewer::bClipper = false
protected

Definition at line 307 of file G4VtkViewer.hh.

◆ bCutter

bool G4VtkViewer::bCutter = false
protected

Definition at line 306 of file G4VtkViewer.hh.

◆ bHud

bool G4VtkViewer::bHud = false
protected

Definition at line 308 of file G4VtkViewer.hh.

◆ bOrientation

bool G4VtkViewer::bOrientation = false
protected

Definition at line 309 of file G4VtkViewer.hh.

◆ camera

vtkNew<vtkCamera> G4VtkViewer::camera

Definition at line 288 of file G4VtkViewer.hh.

Referenced by Initialise().

◆ cameraDistance

G4double G4VtkViewer::cameraDistance
protected

Definition at line 296 of file G4VtkViewer.hh.

Referenced by SetView().

◆ camOrientWidget

vtkNew<vtkCameraOrientationWidget> G4VtkViewer::camOrientWidget
protected

◆ clipperPlaneRepresentation

vtkNew<vtkImplicitPlaneRepresentation> G4VtkViewer::clipperPlaneRepresentation
protected

Definition at line 301 of file G4VtkViewer.hh.

Referenced by AddClipperPlaneWidget().

◆ clipperPlaneWidget

vtkNew<vtkImplicitPlaneWidget2> G4VtkViewer::clipperPlaneWidget
protected

◆ cutterPlaneRepresentation

vtkNew<vtkImplicitPlaneRepresentation> G4VtkViewer::cutterPlaneRepresentation
protected

Definition at line 298 of file G4VtkViewer.hh.

Referenced by AddCutterPlaneWidget(), and Print().

◆ cutterPlaneWidget

vtkNew<vtkImplicitPlaneWidget2> G4VtkViewer::cutterPlaneWidget
protected

Definition at line 299 of file G4VtkViewer.hh.

Referenced by AddCutterPlaneWidget(), DisableCutterWidget(), and EnableCutterWidget().

◆ firstFinishView

G4bool G4VtkViewer::firstFinishView = true
protected

Definition at line 295 of file G4VtkViewer.hh.

Referenced by FinishView().

◆ firstSetView

G4bool G4VtkViewer::firstSetView = true
protected

Definition at line 294 of file G4VtkViewer.hh.

Referenced by SetView().

◆ geant4Callback

vtkNew<vtkGeant4Callback> G4VtkViewer::geant4Callback

Definition at line 286 of file G4VtkViewer.hh.

Referenced by G4VtkQtViewer::Initialise(), Initialise(), SetView(), and ShowView().

◆ infoCallback

vtkNew<vtkInfoCallback> G4VtkViewer::infoCallback

Definition at line 285 of file G4VtkViewer.hh.

Referenced by AddViewHUD(), and ShowView().

◆ infoTextActor

vtkNew<vtkTextActor> G4VtkViewer::infoTextActor

Definition at line 284 of file G4VtkViewer.hh.

Referenced by AddViewHUD(), DisableHUD(), EnableHUD(), and ShowView().

◆ light

vtkSmartPointer<vtkLight> G4VtkViewer::light

Definition at line 287 of file G4VtkViewer.hh.

◆ renderer

◆ renderWindowInteractor

vtkRenderWindowInteractor* G4VtkViewer::renderWindowInteractor

Definition at line 291 of file G4VtkViewer.hh.

Referenced by Initialise().


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