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

David Doria daviddoria at gmail.com
Mon Oct 11 15:28:34 EDT 2010


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!

Thanks,

David



More information about the vtkusers mailing list