I would like to ask a question on VTK operations. I have one VTK file and I want to get many images, each taken from a different angle to create a movie of that image.
I have created the following codes (see below). The problem is that although different coordinates will rotate the image to the angles that I want, the zooming is a bit off. So images on some angles appear to be "zoomed in", but other images with different angles appear to be "zoomed out".
I am not sure how should I set all the images to have the same "zooming" scale. Help will be much appreciated. Thank you.
def rotateSave(data, coordinates, filename):
### Set up things
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(data)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
### Translate and Rotate
center_x, center_y, center_z = actor.GetCenter()
ren.AddActor(actor)
w = vtk.vtkTransform()
w.Translate(-center_x, -center_y, -center_z)
w.RotateX(coordinates[0])
w.RotateZ(coordinates[2])
actor.SetUserTransform(w)
### Save
renWin.Render()
w2if = vtk.vtkWindowToImageFilter()
w2if.SetInput(renWin)
w2if.Update()
writer = vtk.vtkPNGWriter()
writer.SetFileName(filename.png)
writer.SetInputData(w2if.GetOutput())
writer.Write()
return
In order to set all the images to have the same "zooming" scale, you could reset the camera in the renderer, something like this:
(...)
### Save
ren.ResetCamera()
renWin.Render()
w2if = vtk.vtkWindowToImageFilter()
(...)
Or if you want you can always change the zooming factor:
ren.GetActiveCamera().Zoom(1.2) #increase zoom
ren.GetActiveCamera().Zoom(0.8) #decrease zoom
Please check the vtkCamera
( https://www.vtk.org/doc/nightly/html/classvtkCamera.html ) class, it has some examples.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.