[vtkusers] SphereWidget InteractionEvent not triggered?

Alex Malyushytskyy alexmalvtk at gmail.com
Thu Mar 7 14:11:52 EST 2013


David,

On top of previous changes you need add an observer for event(s) you
are interested.
SphereWidget does it only for :
vtkCommand::MouseMoveEvent,
 vtkCommand::LeftButtonPressEvent,
vtkCommand::LeftButtonReleaseEvent,
vtkCommand::RightButtonPressEvent,
vtkCommand::RightButtonReleaseEvent,

In order to to it in event handler you already have You can do it in
constructor in the referred example

MySphereWidget::MySphereWidget()
{
  this->EventCallbackCommand->SetCallback( MySphereWidget::ProcessEvents );
  this->AddObserver(vtkCommand::InteractionEvent, this->EventCallbackCommand);
  this->AddObserver(vtkCommand::StartInteractionEvent,
this->EventCallbackCommand);
}

A side note.
Keep in mind that previous change is also required - somebody still
needs to create InteractionEvent, etc.
Normally this is done in  vtkSphereWidget::ProcessEvents or more
precisely in the functions it calls

Example is  OnLeftButtonUp().
If you changed behavior of such function and call it directly from
MySphereWidget::ProcessEvents
So You should skip calling vtkSphereWidget::ProcessEvents in case  of
vtkCommand::LeftButtonPressEvent
or it will be called twice (in current implementation)

    case vtkCommand::LeftButtonPressEvent:
      std::cout << "LeftButtonPressEvent" << std::endl;
      self->OnLeftButtonDown();
      return; /// make sure parent process event is not called
      break;
    }

Since currently in your new example you call parent class
implementation of OnLeftButtonDown, it will invoke required by
interaction
process event, but if you want to change widget behavior you will be
responsible to invoke  appropriate events.

For example if you new implementation of OnLeftButtonDown still want
to start some interaction it should be doing something like:

  this->EventCallbackCommand->SetAbortFlag(1);
  this->StartInteraction();
  this->InvokeEvent(vtkCommand::StartInteractionEvent,NULL);
  this->Interactor->Render();


Alex

On Thu, Mar 7, 2013 at 6:14 AM, David Doria <daviddoria at gmail.com> wrote:
> On Wed, Mar 6, 2013 at 7:16 PM, Alex Malyushytskyy <alexmalvtk at gmail.com> wrote:
>> Call
>>  vtkSphereWidget::ProcessEvents( object,  event, clientdata, calldata);
>>
>> at the end of MySphereWidget::ProcessEvents . You will probably need
>> also probably  remove vtkNotUsed macro if you do it exactly as I wrote
>> above.
>>
>> What happens?
>> As far as I understand your widget gets mouse move event and depending
>> on previous widget state process it.
>> During such processing new notification might be generated, but you do
>> not do any processing on mouse move,
>> so who is going to create them?
>>
>> So you either process MouseMoveEvent yourself and create such events
>> yourself or let vtkSphereWidget do it the way it does.
>>
>> Hope this helps,
>>    Alex
>
> Alex,
>
> I don't think I follow. If I call vtkSphereWidget::ProcessEvents from
> MySphereWidget::ProcessEvents, that doesn't seem like it will allow me
> to handle the events any differently in MySphereWidget::ProcessEvents?
> I tried what yo suggested anyway, and it still does not output
> "InteractionEvent" or "StartInteractionEvent". Would you take a look
> at the updated version?
>
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Widgets/SphereWidgetEvents
>
> David



More information about the vtkusers mailing list