Now, I display a 2D image by the following code:
import vtk
img = vtk.vtkDICOMImageReader()
img.SetFileName('C:\\Users\\MLoong\\Desktop\\dicom_data\\Chang Cheng\\TOF\\IM_0174')
img.Update()
mapper = vtk.vtkImageMapper()
mapper.SetInputData(img.GetOutput())
actor = vtk.vtkActor2D()
actor.SetMapper(mapper)
ren = vtk.vtkRenderer()
ren.AddActor(actor)
ren.SetBackground(0.1, 0.2, 0.4)
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(400, 400)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
renWin.Render()
# iren.Start()
print(ren.GetActiveCamera().GetPosition())
# ren.GetActiveCamera().SetPosition([0, 0, 0.5]) ############ change the camera position
# ren.ResetCameraClippingRange()
# ren.UpdateLightsGeometryToFollowCamera()
renWin.Render()
iren.Start()
I print the camera position by print(ren.GetActiveCamera().GetPosition())
, and the position is [0, 0, 1].
And the result is:
Now, I want to change the camera position by:
...
print(ren.GetActiveCamera().GetPosition())
ren.GetActiveCamera().SetPosition([0, 0, 0.5])
ren.ResetCameraClippingRange()
ren.UpdateLightsGeometryToFollowCamera()
...
In my understanding, the camera is moved toward the object. Thus, the image should be zoom in. However, there is no change, and the result is:
What’s wrong with my code? Any suggestion is appreciated!