[vtkusers] vtkRenderWindowInteractor() in addition to other kind of interactors

Andreas Pedroni anpedroni at gmail.com
Tue Nov 13 03:07:10 EST 2018

Thank you very much for reaching out!

I got actually one step further and could implement and understand the EventTimer as in the Python animation example. However, instead of updating the position or any other property of an actor I would like to update the texture of a plane to play a video on this plane. To do this I would need to pass more than just the actor (as in the https://www.vtk.org/Wiki/VTK/Examples/Python/Animation <https://www.vtk.org/Wiki/VTK/Examples/Python/Animation>) to the vtkTimerCallback() and update it by the timercount. I think I need to pass the VideoCapture (cap) object, and execute everything after „while cap.isOpened():“ I am new to object oriented programming and I don’t see how to pass more than the actor object to the vtkTimerCallback() class. Below is a code snippet to show how I map the texture on the plane repeatedly to play a video, but without being able to interact with the 3D scene. 

Best and thanks for any help!

import vtk
import cv2
from vtk.util import numpy_support

VIDEOPATH= "/Users/apedroni/AnacondaProjects/objecttracking/ressources/MRI-Video/Videos/20180816-133303.mp4"

def setup3dScene(frame):

    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    vtkArray = numpy_support.numpy_to_vtk(frame.reshape((-1, 3), order='F'), deep=False)

    # Create a vtkImage Object. This is filled with the vtkArray data later
    vtkImage = vtk.vtkImageData()
    vtkImage.SetDimensions(720, 1280, 1)
    vtkImage.SetSpacing(720, 1280, 1)
    vtkImage.SetOrigin(720, 1280, 0)
    # create the Texture for a plane
    atext = vtk.vtkTexture()

    # The Screen where the movie is mapped onto
    plane = vtk.vtkPlaneSource()
    planeMapper = vtk.vtkPolyDataMapper()
    planeActor = vtk.vtkActor()
    planeActor.SetScale(0.5625, 1, 1)
    planeActor.SetOrientation(180, 180, 90)

    # set up the renderer and the window
    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()


    iren = vtk.vtkRenderWindowInteractor()
    ren.SetBackground(0.1, 1, 0.4)
    renWin.SetSize(1500, 1500)


    return vtkImage, renWin, iren

#1 set up the 3D scene
#2 Open CV2 Video Capture and update the actors in the 3D scene

# Create a video capture object to read videos
cap = cv2.VideoCapture(VIDEOPATH)
success, frame = cap.read()

vtkImage, renWin, iren = setup3dScene(frame)

while cap.isOpened():
    # read video
    videoOk, frame = cap.read()
    if not videoOk:

    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    vtkArray = numpy_support.numpy_to_vtk(frame.reshape((-1, 3), order='F'), deep=False)


> Am 12.11.2018 um 09:52 schrieb Andaharoo <Andx_roo at live.com>:
> How are you updating your data? There is a timer you can add to the
> interactors that you can use for updating things whilst keeping the
> interactors working.  https://www.vtk.org/Wiki/VTK/Examples/Python/Animation
> <https://www.vtk.org/Wiki/VTK/Examples/Python/Animation>  
> --
> Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
> _______________________________________________
> Powered by www.kitware.com
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Search the list archives at: http://markmail.org/search/?q=vtkusers
> Follow this link to subscribe/unsubscribe:
> https://public.kitware.com/mailman/listinfo/vtkusers

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20181113/8c1c1b63/attachment.html>

More information about the vtkusers mailing list