Manually trigger vtkCommand

Hello,

I want to create an interactive live visualization of data which I’m streaming from a hardware device. Instead of using a repeating vtkCommand::TimerEvent, I would like to trigger the update manually once the data has been received.

Currently, I’m using the following basic approach

vtkPlotCustom *plot = new vtkPlotCustom(); // A simple wrapper class for the initialization and update of the plot
plot->init(); // Initialize the visualization. Here, I cannot start the vtkRenderWindowInteractor as it will block the application.
while (true) {
    receiveData(); // receive data from hardware device
    plot->update(); // Call Modified() on the utilized arrays and Render() on the vtkRenderWindow instance
}

With my approach, I’m facing two issues:

  1. I cannot start the vtkRenderWindowInteractor as it will block the application
  2. Even without the interactor, the plot is not updating everytime I receive data. I’m using the vtkPolyDataMapper and I tried calling Modified() on every single vtk component that I’m using. However, if I replace the infinite loop with a for loop, only the first and last frame (sometimes only the last frame) will be shown. How do I force the vtkRenderWindow to redraw everytime?

Does anyone have an idea how to solve the issues? I couldn’t find anything in the examples.

If you build a VTK-based application then you normally rely on the widget toolkit (such as Qt) to manage your event loop. If you are new to all this then I would recommend to choose a VTK-based customizable and extensible application framework that already that has interface for receiving real-time data from external devices and use that as the basis of your application instead of redeveloping everything from scratch. I know that 3D Slicer can interface with a wide range of imaging and position tracking systems, sensors, etc. (see for example www.slicerigt.org) but probably ParaView has some external hardware interfaces, too.

What kind of data the hardware device is streaming - 2D/3D images, position tracking, surface scan,…? What is your application domain - medical imaging, robotics,…?

Thank you, I will have a look at the widget toolkits.

However, if I just want to trigger the re-rendering event externally while the VTK interactor is running, shouldn’t it be easier to realize that than using Qt or any other widget toolkit? These toolkits are relying on the VTK commands as well, aren’t they?

Yes, if you use Qt then you still use vtkCommand objects. However, you don’t use VTK timer events.

If you don’t like Qt because it is big then you may use lightweight widget toolkits, such as fltk or wxWidgets (I haven’t looked at these for many years but probably they are still around).