[vtkusers] New functionality: Observing events from class member functions

Jim Peterson jimcp at cox.net
Mon Oct 11 16:20:47 EDT 2010


David Doria wrote:
> Thanks to the hard work of Utkarsh and David Gobbi, we can now observe
> VTK events from class member functions!
>
> The idea is:
>
> class MyClass
> {
>   public:
>     void KeypressCallbackFunction(vtkObject* caller,
>                     long unsigned int eventId,
>                     void* callData )
>     {
>       std::cout << "Caught event in MyClass" << std::endl;
>     }
>
> };
>
> ... else where ...
>
> MyClass myClass;
> renderWindowInteractor->AddObserver(vtkCommand::KeyPressEvent,
> &myClass, &MyClass::KeypressCallbackFunction);
>
> (This in in contrast to the old method of creating a
> vtkCallbackCommand object and passing it a static class function,
> yuck!)
>
> A full demonstration can be found here:
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Interaction/ObserverMemberFunction
>
> Hopefully this new addition will improve the organization of everyones
> code. It certainly has with mine!
>   
This is excellent news, The callback structure is one of the reasons I 
gravitated to the Java interface in the first place. The Java callbacks 
do not have an equivalent of the void* data parameter, but since the 
callback in an instance object, My feeling is this parameter is rendered 
relatively unecessary.

Great work to all involved.

Jim



More information about the vtkusers mailing list