I had a problem trying to run multiple rendering windows in a Python VTK application that I am writing. The application is an attempt to visualize a three-dimensional model in two separate representations for a stereo application (i.e. left render and right render), but I have a problem updating cameras of each window at the same time. Currently, I have two almost identical pipelines, each with its own vtkCamera , vtkRenderWindow , vtkRenderer and vtkRenderWindowInteractor , with the only difference being that the right camera is positioned 30 units on the X axis.
Each of the interactive windows of the rendering window is updated using the vtkRenderWindowInteractor.AddObserver() method, which calls a simple function to reset the cameras to their original position and orientation. The biggest problem is that it only seems to be happening in one window at a time, in particular the window is in focus at that time. It is as if the interactor timer just went off after the interactor loses focus. In addition, when I hold the mouse (and thus move the camera around), the rendered image starts to βdriftβ, returning to a more or less correct position, although I hard-coded the coordinates in the function.
Obviously, I am very new to VTK, and a lot of what is happening is rather confusing since there is so much hiding in the backend, so it would be surprising to get some help on this. My code is below. Thanks guys!
from vtk import* from parse import * import os import time, signal, threading def ParseSIG(signum, stack): print signum return class vtkGyroCallback(): def __init__(self): pass def execute(self, obj, event):
EDIT:
On further viewing, it seems that TimerEvents do not shoot more than once in a row after MouseClickEvent, and I have no idea why.
EDIT 2: Scratch that they work most accurately according to some test outputs built into the code. I changed the code to accept user input for calling self.leftCam.SetPosition() in the self.leftCam.SetPosition() method (thus, replacing the hardcoded parameters "10, 40, 100" with three input variables), then passed the output of the script, which it just displays three random values ββin my main program. What was about to happen was to have a rendering window that would constantly change position. Instead, nothing happens until I click on the screen, after which the expected functionality starts. All the time, the timer events are still triggered and the inputs are still being received, but the cameras refuse to update until the mouse event occurs within their window. What a deal?
EDIT 3: I dug something else and found that in the vtkObject::InvokeEvent() method, which is called inside each interaction event, there is a focus loop that overlaps all the observers that are not related to the object in focus. I'm going to investigate if there is a way to remove focus so that instead it bypasses this focus cycle and goes into an unfocused cycle that processes unfocused objects.