Hello, I want to implement my own event loop using a vtkGenericRenderWindowInteractor instance. I couldn’t find any examples where the event loop is implemented.
The code should have the following structure:
#include <vtkGenericRenderWindowInteractor.h>
vtkNew<vtkGenericRenderWindowInteractor> interactor;
// custom event
int renderEvent = vtkCommand::UserEvent + 1;
function processData()
{
// do some data processing
// when finished, update the visualization
interactor->InvokeEvent(renderEvent); // invoke custom event to render the scene
}
int main()
{
// initialize the visualization
// ...
// Start the interactor without blocking the execution
interactor->Start();
// Event loop
while (true)
{
processData(); // do some data processing and update the scene when finished
// invoke mouse events for interactions with the scene
// ...
}
}
However, I have several questions.
First, if the execution of processData() takes 1 second, would the interactor be unresponsive during that time? If yes, can this be solved by calling processData() in a separate thread with a flag that checks if the previous call was finished before processData() is called again?
Second, how can I enable the same events of a vtkRenderWindowInteractor instance in a vtkGenericRenderWindowInteractor instance, i.e., the mouse events such as rotating, etc.?
Thank you for your response. Unfortunately, I forgot to mention that I’m still using VTK 8. It seems like ProcessEvents() is not available in VTK 8. Is there a workaround or an alternative method?
Ah yeah. Anyways, it should still use an event loop whether it exposes it or not. So what you can do is depending on the system you’re targeting, or both. Copy vtkWin32RenderWindowInteractor or vtkXRenderWindowInteractor. Rename them to vtkWin32RenderWindowInteractor2 or something & use it instead.
If we pop open vtkWin32RenderWindowInteractor we can see,
It’s also worth mentioning mentioning whatever data you are wanting to process. You could setup a timer event which would be invoked by VTK every Nms (outside of rendering, ie: done in sequence).