I’m looking for a way, to register a class member function as a callback to a vtkCallbackCommand like that:
class foo
{
public:
void bar(vtkObject* caller, unsigned long eId, void* clientData, void* callerData);
}
Foo::Foo()
{
auto callbackCommand = vtkSmartPointer<vtkCallbackCommand>::New();
callbackCommand->SetCallback(bar);
this->AddObserver(vtkCommand::<event-name>, callbackCommand);
}
Using vtkCallbackCommand I get an error like:
argument of type void (foo::*)(vtkObject *, unsigned long, void *, void *) is incompatible with parameter of type void (*)(vtkObject *caller, unsigned long eid, void *clientdata, void *calldata)
I believe the issue here is that the bar function needs an object to be invoked on. If you change the bar function such that it is a static function it should work. If you need bar to be a non static function you can pass the object it should be invoked on via the clientData pointer. Here is an explanation for that: https://vtk.org/Wiki/VTK/Tutorials/Callbacks
Ok, that’s what I thought so too. But i indeed need a non-static function to be the callback.
The clientData is the way to go here I think … I hoped there would be a “cleaner” way already implemented in VTK, as ParaView seems to have that functionality.
The callback is able to run the member function, which enables me to use member variables aswell, without setting clientData of the AddObserver() call from my initial post.