Camera operation do not work

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!

Hi, Zhang,

Can you, please, change your code to this:

?

Does it have an effect?

regards,

Paulo

Thank you for your reply. But ren.GetActiveCamera().SetPosition([1, 1, 0.5]) has no effect on the final result. So confuzed~~~

Can you try translating the focal point by the same delta x and delta y in addition to setting position? e.g. SetFocalPoint (1, 1, 0.0)

I modify the code as:


ren.GetActiveCamera().SetPosition([0, 0, 0.5])   ############ change the camera position
ren.GetActiveCamera().SetFocalPoint ([10, 10, 0.0])

And the result is:

I think there is no change.

Hello,

Please, take a look at this example: https://vtk.org/Wiki/VTK/Examples/Cxx/Images/InteractWithImage . It features the operations on a 2D image you are trying like pan and zoom.

regards,

Paulo