[vtkusers] vtkRenderWindowInteractor and mouse events

Gib Bogle g.bogle at auckland.ac.nz
Thu Aug 15 12:43:04 EDT 2013


As I posted previously, I'm trying to find out how to suppress a behaviour of 
the interactor (which I observer using QVTKWidget) when viewing 2D images, i.e. 
with vtkInteractorStyleImage.  When the mouse is dragged with left button 
pressed the image intensities are changed.  I have not been able to locate where 
this is being done, so now I'm looking into catching MouseMove events when the 
left button is down.

I have been playing with code based on the CommandSubclass example. Using 
AddObserver() I can detect MouseMoveEvent and LeftButtonPressEvent, but 
interestingly not LeftButtonReleaseEvent. Here are the relevant code fragments:

class CommandSubclass2 : public vtkCommand
{
   public:
     vtkTypeMacro(CommandSubclass2, vtkCommand);

     static CommandSubclass2 *New()
     {
       return new CommandSubclass2;
     }

     void Execute(vtkObject *vtkNotUsed(caller), unsigned long vtkNotUsed(eventId),
                         void *vtkNotUsed(callData))
     {
//      std::cout << "timer callback" << std::endl;
       std::cout << "mouse callback" << std::endl;
     }
};

class CommandSubclass3 : public vtkCommand
{
   public:
     vtkTypeMacro(CommandSubclass3, vtkCommand);

     static CommandSubclass3 *New()
     {
       return new CommandSubclass3;
     }

     void Execute(vtkObject *vtkNotUsed(caller), unsigned long vtkNotUsed(eventId),
                         void *vtkNotUsed(callData))
     {
       std::cout << "left button pressed" << std::endl;
     }

};

class CommandSubclass4 : public vtkCommand
{
   public:
     vtkTypeMacro(CommandSubclass4, vtkCommand);

     static CommandSubclass4 *New()
     {
       return new CommandSubclass4;
     }

     void Execute(vtkObject *vtkNotUsed(caller), unsigned long vtkNotUsed(eventId),
                         void *vtkNotUsed(callData))
     {
       std::cout << "left button released" << std::endl;
     }

};

...

   vtkSmartPointer<CommandSubclass2> mouseCallback = 
vtkSmartPointer<CommandSubclass2>::New();
   renderWindowInteractor->AddObserver ( vtkCommand::MouseMoveEvent, 
mouseCallback );
   vtkSmartPointer<CommandSubclass3> leftButtonPressCallback = 
vtkSmartPointer<CommandSubclass3>::New();
   renderWindowInteractor->AddObserver ( vtkCommand::LeftButtonPressEvent, 
leftButtonPressCallback );
   vtkSmartPointer<CommandSubclass4> leftButtonReleaseCallback = 
vtkSmartPointer<CommandSubclass4>::New();
   renderWindowInteractor->AddObserver ( vtkCommand::LeftButtonReleaseEvent, 
leftButtonReleaseCallback );

Have I made a mistake that I can't see?  If not, should I be surprised by this?

Of course I'd be happy if someone could suggest another path to my destination.

Thanks
Gib

-- 
Dr. Gib Bogle
Senior Research Fellow
Auckland Bioengineering Institute
University of Auckland
New Zealand

http://www.bioeng.auckland.ac.nz

g.bogle at auckland.ac.nz
(64-9) 373-7599 Ext. 87030




More information about the vtkusers mailing list