vtkRenderWindowInteractor::CreateRepeatingTimer stops during interaction

Hello VTK Community.

When creating a repeating timer with a callback function, here a very simple case:

void timerFunc(vtkObject* caller, unsigned long eid, void* clientdata, void* calldata);
 
// Somewhere in main()
int main(int argc, char* argv) 
{
   ...
   auto renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
   auto interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
   auto interactorStyle = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();

   interactor->SetStyle(interactorStyle);
   renderWindow->SetInteractor(interactor);

   // initialize renderer and load some data into renderwindow
   ...

   auto timerCallback = vtkSmartPointer<vtkCallbackCommand>::New();
   timerCallback->SetCallback(timerFunc);
   interactor->AddObserver(vtkCommand::TimerEvent, timerCallback);

   interactor->Initialize();
   interactor->CreateRepeatingTimer(1000);
   interactor->Start();
}


// timerFunc
void timerFunc(vtkObject* caller, unsigned long eid, void* clientdata, void* calldata)
{
    std::cout << "Timer event" << std::endl;
}

Now when running the code, the console shows repeating outputs of the Timer event string as expected.

As soon as I interact with the scene, the timer event is not triggered anymore. Furthermore, if I move the camera of the scene and then stop (without releasing the left mouse button), the camera keeps rotating.

Is the stopping of the repeating timer during interaction considered normal behavior or am I doing something wrong?

Considering the on-going rotation after mouse stop - is this a bug?

Hello, Phillip,

Please, take a look at this example: https://kitware.github.io/vtk-examples/site/Cxx/Utilities/Timer/ .

I hope this helps,

Paulo

Hello @Paulo_Carvalho

The example you referred to has the same “problem” as I described above.
When you start the example project the timer counter increases and outputs the current count in the console.
Now try to interact with the black window - if you click inside the window, holding the left mouse button will stop the timer events. Releasing the mouse button will continue the timer outputs.

I’m looking for a way so that the mouse interaction will not interfere with the timer events.

I see. I’ve had that kind of problem before, but with programming GUIs (Java Swing and Qt). One way around that is to add a call similar to Qt’s QCoreApplication::processEvents(). This call yields execution for processing other events that are in the queue.

That would imply making a similar call (I don’t know the VTK’s equivalent to QCoreApplication::processEvents(), if there is such thing) in one of the event handlers of a custom subclass of vtkInteractorStyle class of your own design.

What GUI API are you using? GLUT, gtk, Motif, Qt?

Hello @Paulo_Carvalho

In my application I’m not using any GUI API. I’m completely offscreen.
I’m using the concept of the vtkGenericRenderWindowInteractor emulating custom mouse events, which are received from a web client (browser) running an Anuglar application. It’s a fairly complex structure, too much to be explained in detail here. But for short, this is the interaction pipeline:

Client → Mouse Interaction → WebSocket Event → C# backend → PInvoke → Create event for vtkGenericRenderWindowInteractor → Render to Offscreen buffer

For my use-case, I’ve come to the conclusion, that I won’t bother with the stopped timer anymore, as I’ve moved away from that approach to achieve my goals.