31#include "vtkRendererCollection.h"
32#include "vtkLightCollection.h"
34#include "vtkWindowToImageFilter.h"
35#include "vtkImageWriter.h"
36#include "vtkBMPWriter.h"
37#include "vtkJPEGWriter.h"
38#include "vtkPNGWriter.h"
39#include "vtkPNMWriter.h"
40#include "vtkTIFFWriter.h"
41#include "vtkPostScriptWriter.h"
42#include "vtkOBJExporter.h"
43#include "vtkVRMLExporter.h"
44#include "vtkSingleVTPExporter.h"
46#include "vtkShadowMapPass.h"
47#include "vtkShadowMapBakerPass.h"
48#include "vtkSequencePass.h"
49#include "vtkCameraPass.h"
50#include "vtkRenderPass.h"
51#include "vtkRenderPassCollection.h"
53#include "vtkOpenGLRenderer.h"
56 :
G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name)
58 vtkObject::GlobalWarningDisplayOff();
105 camera->SetPosition(0, 0, 1000);
106 camera->SetFocalPoint(0, 0, 0);
116 vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
117 vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
139 targetPoint + viewpointDirection.
unit() * cameraDistance;
140 renderer->GetActiveCamera()->SetFocalPoint(targetPoint.
x(),
143 renderer->GetActiveCamera()->SetPosition(cameraPosition.
x(),
146 renderer->GetActiveCamera()->SetParallelScale(cameraDistance);
151 geant4Callback->SetVtkInitialValues(cameraDistance, cameraDistance);
152 firstSetView =
false;
158 vtkCamera* activeCamera =
renderer->GetActiveCamera();
159 if(fieldHalfAngle == 0) {
160 activeCamera->SetParallelProjection(1);
161 activeCamera->SetParallelScale(activeCamera->GetParallelScale()/zoomFactor);
164 activeCamera->SetParallelProjection(0);
165 activeCamera->SetViewAngle(2*fieldHalfAngle/
M_PI*180);
166 activeCamera->SetPosition(cameraPosition.
x()/zoomFactor,
167 cameraPosition.
y()/zoomFactor,
168 cameraPosition.
z()/zoomFactor);
176 renderer->GetActiveCamera()->SetViewUp(upVector.
x(),
184 targetPoint + lightDirection.
unit() * cameraDistance;
186 vtkLightCollection* currentLights =
renderer->GetLights();
187 if (currentLights->GetNumberOfItems() != 0)
189 auto currentLight =
dynamic_cast<vtkLight*
>(currentLights->GetItemAsObject(0));
192 currentLight->SetPosition(lightPosition.
x(),
195 if (lightsMoveWithCamera)
196 {currentLight->SetLightTypeToCameraLight();}
198 {currentLight->SetLightTypeToSceneLight();}
206 vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
207 vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
212 vtkSmartPointer<vtkInteractorStyleTerrain> style =
213 vtkSmartPointer<vtkInteractorStyleTerrain>::New();
220 vtkActorCollection *actors =
renderer->GetActors();
221 vtkActor *actor = actors->GetLastActor();
225 G4cout <<
"G4VtkViewer::ClearView() remove actor " << actor <<
G4endl;
228 actor = actors->GetLastActor();
231 vtkPropCollection *props =
renderer->GetViewProps();
232 vtkProp *prop = props->GetLastProp();
236 G4cout <<
"G4VtkViewer::ClearView() remove prop " << prop <<
G4endl;
239 prop = props->GetLastProp();
268 std::fmod(colour.
GetGreen() + 0.5, 1.0),
269 std::fmod(colour.
GetBlue() + 0.5, 1.0));
280 vtkNew<vtkShadowMapPass> shadows;
281 vtkNew<vtkSequencePass> seq;
283 vtkNew<vtkRenderPassCollection> passes;
284 passes->AddItem(shadows->GetShadowMapBakerPass());
285 passes->AddItem(shadows);
286 seq->SetPasses(passes);
288 vtkNew<vtkCameraPass> cameraP;
289 cameraP->SetDelegatePass(seq);
292 vtkOpenGLRenderer* glrenderer =
dynamic_cast<vtkOpenGLRenderer*
>(
renderer.GetPointer());
293 glrenderer->SetPass(cameraP);
311 std::fmod(colour.
GetGreen() + 0.5, 1.0),
312 std::fmod(colour.
GetBlue() + 0.5, 1.0));
334 vtkImageWriter *imWriter =
nullptr;
336 if(format ==
"bmp") {
337 imWriter = vtkBMPWriter::New();
339 else if (format ==
"jpg") {
340 imWriter = vtkJPEGWriter::New();
342 else if (format ==
"pnm") {
343 imWriter = vtkPNMWriter::New();
345 else if (format ==
"png") {
346 imWriter = vtkPNGWriter::New();
348 else if (format ==
"tiff") {
349 imWriter = vtkTIFFWriter::New();
351 else if (format ==
"ps") {
352 imWriter = vtkPostScriptWriter::New();
355 imWriter = vtkPNGWriter::New();
360 vtkSmartPointer<vtkWindowToImageFilter> winToImage = vtkSmartPointer<vtkWindowToImageFilter>::New();
362 winToImage->SetScale(1);
365 winToImage->SetInputBufferTypeToRGB();
366 winToImage->ReadFrontBufferOff();
367 winToImage->Update();
370 {winToImage->SetInputBufferTypeToRGBA();}
372 imWriter->SetFileName((path+
"."+format).c_str());
373 imWriter->SetInputConnection(winToImage->GetOutputPort());
379 vtkSmartPointer<vtkRenderWindow> _rw1 = vtkSmartPointer<vtkRenderWindow>::New();
380 _rw1->AddRenderer(
_renderWindow->GetRenderers()->GetFirstRenderer());
381 vtkSmartPointer<vtkOBJExporter> exporter = vtkSmartPointer<vtkOBJExporter>::New();
382 exporter->SetRenderWindow(_rw1);
383 exporter->SetFilePrefix(path.c_str());
389 vtkSmartPointer<vtkRenderWindow> _rw1 = vtkSmartPointer<vtkRenderWindow>::New();
390 _rw1->AddRenderer(
_renderWindow->GetRenderers()->GetFirstRenderer());
391 vtkSmartPointer<vtkVRMLExporter> exporter = vtkSmartPointer<vtkVRMLExporter>::New();
392 exporter->SetRenderWindow(_rw1);
393 exporter->SetFileName((path+
".vrml").c_str());
399 vtkSmartPointer<vtkRenderWindow> _rw1 = vtkSmartPointer<vtkRenderWindow>::New();
400 _rw1->AddRenderer(
_renderWindow->GetRenderers()->GetFirstRenderer());
401 vtkSmartPointer<vtkSingleVTPExporter> exporter = vtkSmartPointer<vtkSingleVTPExporter>::New();
402 exporter->SetRenderWindow(_rw1);
403 exporter->SetFileName((path+
".vtp").c_str());
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
RotationStyle GetRotationStyle() const
G4int GetWindowLocationHintY() const
unsigned int GetWindowSizeHintY() const
G4bool GetLightsMoveWithCamera() const
G4double GetExtentRadius() const
vtkNew< vtkCamera > camera
void ExportVRMLScene(G4String)
vtkNew< vtkGeant4Callback > geant4Callback
void ExportScreenShot(G4String, G4String)
vtkNew< vtkTextActor > infoTextActor
vtkRenderWindowInteractor * renderWindowInteractor
G4VtkViewer(G4VSceneHandler &, const G4String &name)
vtkNew< vtkInfoCallback > infoCallback
vtkNew< vtkRenderer > renderer
void ExportVTPScene(G4String)
void ExportOBJScene(G4String)
vtkRenderWindow * _renderWindow
BasicVector3D< T > unit() const