Is it possible to rotate an object in real time using a method other than clicking on the screen?

I started using VTK the other day, and now I’m mainly working on the code for the tutorial.
I would like to use VTK to rotate an object by specifying the rotation angle from the GUI, or to read the sensor value and rotate the object as in the real world.

However, the vtkRenderWindowInteractor makes other operations impossible, and it was also impossible to change the PolyData value from another thread.

For example, in the last part of this example, I tried to change the following without using the vtkRenderWindowInteractor.

    # render the image
    renWin.Render()

    renderer.ResetCamera()
    renderer.GetActiveCamera().Elevation(-30)
    renderer.GetActiveCamera().Roll(-20)
    renderer.ResetCameraClippingRange()
    renWin.Render()
    # --- change from here ---
    # iren.Start()  # delete

    # add
    z = 0
    While True:
	plane.SetCenter(0, 0, z)
	z+=0.01
	renWin.Render()

I know this is obviously wrong (in fact, this code didn’t work), but I didn’t know what other code I could use to implement the functionality.
Is there any other way to implement this kind of operation?

Also, I thought about using animation, but I don’t think it would be possible to implement the movement I have in mind, which is to change the direction of rotation according to the sensor value.

Any suggestion is appreciated!

This works for me when I replace the line plane.SetCenter(0,0,z) with planeActor.SetPosition(0,0,z).

In VTK, our Source isn’t situated in the world coordinates yet, so to achieve this rotation we need to move it’s Actor, which is the representation of our source within the rendered world.

This thread has more on the distinction between SetCenter and SetPosition. The code may be in javascript, but the same VTK principles apply there.

Thank you!
Following your advice, I was able to reflect the sensor value on the screen in real time by using actor.SetPosition and combining it with TimerEvent of vtkRenderWindowInteractor!

1 Like