43#include <vtk3DSImporter.h>
44#include <vtkBMPWriter.h>
45#include <vtkIVExporter.h>
46#include <vtkImageWriter.h>
47#include <vtkImplicitPlaneRepresentation.h>
48#include <vtkImplicitPlaneWidget2.h>
49#include <vtkJPEGWriter.h>
50#include <vtkLightCollection.h>
51#include <vtkOBJExporter.h>
52#include <vtkOBJImporter.h>
53#include <vtkGLTFExporter.h>
54#include <vtkOOGLExporter.h>
55#include <vtkJSONRenderWindowExporter.h>
56#include <vtkVtkJSSceneGraphSerializer.h>
58#include <vtkPNGWriter.h>
59#include <vtkPNMWriter.h>
60#include <vtkPOVExporter.h>
61#include <vtkPostScriptWriter.h>
62#include <vtkRIBExporter.h>
63#include <vtkRendererCollection.h>
64#include <vtkSingleVTPExporter.h>
65#include <vtkTIFFWriter.h>
66#include <vtkVRMLExporter.h>
67#include <vtkVRMLImporter.h>
68#include <vtkWindowToImageFilter.h>
69#include <vtkX3DExporter.h>
73#include <vtkCameraPass.h>
74#include <vtkOpenGLRenderer.h>
75#include <vtkRenderPass.h>
76#include <vtkRenderPassCollection.h>
77#include <vtkSequencePass.h>
78#include <vtkShadowMapBakerPass.h>
79#include <vtkShadowMapPass.h>
82 :
G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name)
84 vtkObject::GlobalWarningDisplayOff();
131 camera->SetPosition(0, 0, 1000);
132 camera->SetFocalPoint(0, 0, 0);
136 renderer->SetUseHiddenLineRemoval(0);
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());
186 if (fieldHalfAngle == 0) {
187 activeCamera->SetParallelProjection(1);
190 activeCamera->SetParallelProjection(0);
202 renderer->GetActiveCamera()->SetViewUp(upVector.
x(), upVector.
y(), upVector.
z());
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();
218 currentLight->SetLightTypeToSceneLight();
241 G4VtkStore& ts = fVtkSceneHandler.GetTransientStore();
286 vtkNew<vtkShadowMapPass> shadows;
287 vtkNew<vtkSequencePass> seq;
289 vtkNew<vtkRenderPassCollection> passes;
290 passes->AddItem(shadows->GetShadowMapBakerPass());
291 passes->AddItem(shadows);
292 seq->SetPasses(passes);
294 vtkNew<vtkCameraPass> cameraP;
295 cameraP->SetDelegatePass(seq);
298 auto glrenderer =
dynamic_cast<vtkOpenGLRenderer*
>(
renderer.GetPointer());
299 glrenderer->SetPass(cameraP);
313 std::fmod(colour.
GetGreen() + 0.5, 1.0),
314 std::fmod(colour.
GetBlue() + 0.5, 1.0));
344 vtkImageWriter* imWriter =
nullptr;
346 if (format ==
"bmp") {
347 imWriter = vtkBMPWriter::New();
349 else if (format ==
"jpg") {
350 imWriter = vtkJPEGWriter::New();
352 else if (format ==
"pnm") {
353 imWriter = vtkPNMWriter::New();
355 else if (format ==
"png") {
356 imWriter = vtkPNGWriter::New();
358 else if (format ==
"tiff") {
359 imWriter = vtkTIFFWriter::New();
361 else if (format ==
"ps") {
362 imWriter = vtkPostScriptWriter::New();
373 winToImage->SetScale(1);
374 if (format ==
"ps") {
375 winToImage->SetInputBufferTypeToRGB();
376 winToImage->ReadFrontBufferOff();
377 winToImage->Update();
380 winToImage->SetInputBufferTypeToRGBA();
383 imWriter->SetFileName((path +
"." + format).c_str());
384 imWriter->SetInputConnection(winToImage->GetOutputPort());
392 exporter->SetFilePrefix(path.c_str());
400 exporter->SetFileName((path +
".vrml").c_str());
408 exporter->SetFileName((path +
".vtp").c_str());
415 exporter->SetFileName((fileName+
".gltf").c_str());
416 exporter->InlineDataOn();
424 exporter->SetSerializer(serializer);
434 vtkNew<vtkRenderer> tempRenderer;
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") {
444 tempRenderer->AddActor(childCutter->GetActor());
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") {
456 tempRenderer->AddActor(childCutter->GetActor());
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") {
468 tempRenderer->AddActor(childCutter->GetActor());
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") {
480 tempRenderer->AddActor(childCutter->GetActor());
485 vtkNew<vtkRenderWindow> tempRenderWindow;
486 tempRenderWindow->AddRenderer(tempRenderer);
487 vtkNew<vtkSingleVTPExporter> exporter;
488 exporter->SetRenderWindow(tempRenderWindow);
489 exporter->SetFileName(fileName.c_str());
496 vtkNew<vtkRenderer> tempRenderer;
498 tempRenderWindow->AddRenderer(tempRenderer);
502 if (storeName ==
"transient") {
503 G4VtkStore& store = fVtkSceneHandler.GetTransientStore();
507 G4VtkStore& store = fVtkSceneHandler.GetStore();
511 if (fileName.find(
"obj") != std::string::npos) {
512 vtkNew<vtkOBJExporter> exporter;
513 exporter->SetRenderWindow(tempRenderWindow);
514 exporter->SetFilePrefix(fileName.c_str());
517 else if (fileName.find(
"vrml") != std::string::npos) {
518 vtkNew<vtkVRMLExporter> exporter;
519 exporter->SetRenderWindow(tempRenderWindow);
520 exporter->SetFileName(fileName.c_str());
523 else if (fileName.find(
"vtp") != std::string::npos) {
524 vtkNew<vtkSingleVTPExporter> exporter;
525 exporter->SetRenderWindow(tempRenderWindow);
526 exporter->SetFileName(fileName.c_str());
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();
543 std::fmod(colour.
GetGreen() + 0.5, 1.0),
544 std::fmod(colour.
GetBlue() + 0.5, 1.0));
554 vtkNew<vtkIPWCallback> clipperCallback;
556 G4VtkStore& store = fVtkSceneHandler.GetStore();
557 clipperCallback->SetStore(&store);
558 clipperCallback->SetUpdatePipelineName(
"clipper",
"clipper");
568 vtkNew<vtkPropCollection> planeRepActors;
570 planeRepActors->InitTraversal();
581 vtkNew<vtkIPWCallback> cutterCallback;
583 G4VtkStore& store = fVtkSceneHandler.GetStore();
584 cutterCallback->SetStore(&store);
585 cutterCallback->SetUpdatePipelineName(
"cutter",
"cutter");
626 s.AddClipper(name, plane);
654 s.AddCutter(name, plane);
701 auto xScale = (worldTopRight[0] - worldBottomLeft[0]) / (imageTopRight[0] - imageBottomLeft[0]);
702 auto yScale = -(worldTopRight[1] - worldBottomLeft[1]) / (imageTopRight[1] - imageBottomLeft[1]);
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,
717 G4cout << translation[0] <<
" " << translation[1] <<
" " << translation[2] <<
G4endl;
718 transformation = tran * rotz * roty * rotx * scal * tranImg * transformation;
720 G4cout << transformation.dx() <<
" " << transformation.dy() <<
" " << transformation.dz() <<
G4endl;
722 G4VtkStore& st = fVtkSceneHandler.GetTransientStore();
735 auto scal =
G4Scale3D(scale[0], scale[1], scale[2]);
739 auto tran =
G4Translate3D(translation[0], translation[1], translation[2]);
741 transformation = tran * rotz * roty * rotx * scal * transformation;
744 G4VtkStore& st = fVtkSceneHandler.GetTransientStore();
748 if (representation ==
"w")
750 else if (representation ==
"s")
754 vc.
green = colour[1];
767 G4VtkStore& st = fVtkSceneHandler.GetTransientStore();
HepGeom::Plane3D< G4double > G4Plane3D
vtkSmartPointer< vtkPlane > G4Plane3DToVtkPlane(const G4Plane3D &g4plane)
G4GLOB_DLL std::ostream G4cout
G4double GetGreen() const
virtual const G4VisExtent & GetExtent() const
G4VSceneHandler & fSceneHandler
G4ViewParameters fDefaultVP
G4int GetWindowLocationHintX() const
void SetAutoRefresh(G4bool)
G4double GetCameraDistance(G4double radius) const
unsigned int GetWindowSizeHintX() const
const G4Colour & GetBackgroundColour() const
const G4Vector3D & GetLightpointDirection() const
const G4Vector3D & GetViewpointDirection() const
const G4Point3D & GetCurrentTargetPoint() const
G4double GetFieldHalfAngle() const
G4double GetZoomFactor() const
const G4Vector3D & GetUpVector() const
G4bool IsWindowLocationHintXNegative() const
G4bool IsWindowLocationHintYNegative() const
G4int GetWindowLocationHintY() const
unsigned int GetWindowSizeHintY() const
G4bool GetLightsMoveWithCamera() const
G4double GetExtentRadius() const
void SetPolyhedronPipeline(const G4String &str)
std::map< std::size_t, std::shared_ptr< G4VtkPolydataPipeline > > & GetSeparatePipeMap()
void AddNonG4ObjectImage(const G4String &fileName, const G4VtkVisContext &vc)
void AddToRenderer(vtkRenderer *renderer)
void RemoveCutter(G4String name)
void GetBounds(G4double maxBound[6])
void RemoveClipper(G4String name)
void AddNonG4ObjectPolydata(const G4String fileName, const G4VtkVisContext &vc)
vtkNew< vtkCamera > camera
vtkNew< vtkCameraOrientationWidget > camOrientWidget
void DisableCutter(G4String name)
void ExportVRMLScene(G4String)
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])
vtkNew< vtkImplicitPlaneWidget2 > cutterPlaneWidget
vtkNew< vtkGeant4Callback > geant4Callback
void Initialise() override
void SetPolyhedronPipeline(const G4String &t)
void ExportScreenShot(G4String, G4String)
void FinishView() override
void ExportGLTFScene(G4String)
vtkNew< vtkTextActor > infoTextActor
virtual void SetWidgetInteractor(vtkAbstractWidget *widget)
virtual void AddClipperPlaneWidget(const G4Plane3D &plane)
vtkRenderWindowInteractor * renderWindowInteractor
vtkNew< vtkImplicitPlaneRepresentation > cutterPlaneRepresentation
void ExportJSONRenderWindowScene(G4String)
virtual void EnableClipperWidget()
G4VtkViewer(G4VSceneHandler &, const G4String &name)
virtual void AddCameraOrientationWidget()
void ExportFormatStore(G4String fileName, G4String store)
void EnableClipper(const G4Plane3D &plane, G4bool widget)
virtual void AddCutterPlaneWidget(const G4Plane3D &plane)
virtual void EnableCameraOrientationWidget()
vtkNew< vtkInfoCallback > infoCallback
virtual void DisableCutterWidget()
virtual void DisableCameraOrientationWidget()
vtkNew< vtkImplicitPlaneWidget2 > clipperPlaneWidget
vtkNew< vtkRenderer > renderer
void EnableCutter(const G4Plane3D &plane, G4bool bWidget)
void ExportVTPScene(G4String)
vtkNew< vtkImplicitPlaneRepresentation > clipperPlaneRepresentation
virtual void DisableClipperWidget()
void ExportOBJScene(G4String)
void ClearView() override
virtual void EnableCutterWidget()
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])
vtkRenderWindow * _renderWindow
void ExportVTPCutter(G4String fileName)
G4ViewParameters::DrawingStyle fDrawingStyle
BasicVector3D< T > unit() const