[vtkusers] vtkcommand and events

David Doria daviddoria+vtk at gmail.com
Thu Nov 19 09:58:06 EST 2009


On Thu, Nov 19, 2009 at 8:09 AM, David Feng <dfeng at cs.unc.edu> wrote:
> I suspect that you're adding the observer to the wrong class, because I
> don't think renderers receive LeftButtonPressEvents.  You probably want to
> add your observer to the interactor style instead.
>
> David
>
> Radu Ilinca wrote:
>>
>> To: vtkedge at vtkedge.orgHi <mailto:vtkedge at vtkedge.orgHi> all !
>>  I am trying to catch the LeftButtonPressEvent event using the
>> observer/commannd architecture.  Code is pretty simmilar to the one in the
>> book where it catches the StartEvent (and the code works) but i try the
>> LeftButtonPressEvent.  Code below:
>>  class vtkMyCallback : public vtkCommand {
>> public: static vtkMyCallback *New() { return new vtkMyCallback; }
>> virtual void Execute( vtkObject *caller, unsigned long, void*) {
>> vtkRenderer *ren = reinterpret_cast<vtkRenderer*> (caller);
>> cout << "ana are mere " << endl;
>> }
>> };
>>   ... in the main ()  i have:
>>  vtkMyCallback *mycallback = vtkMyCallback::New();
>> ren1->AddObserver(vtkCommand::LeftButtonPressEvent, mycallback);
>>  I am using Visual Studio 2008 and WinXP
>>   The problem is that, I don't catch the event and actually the code never
>> enters the Execute function. Could someone tell me why ?
>>  Best,
>> Radu.
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
>

@David Feng
You are right on - I was adding the observer to the interactor style:
  RenderWindowInteractor->GetInteractorStyle()->AddObserver (
vtkCommand::LeftButtonPressEvent, ClickCallback );
when I should have been adding it to the interactor
  RenderWindowInteractor->AddObserver (
vtkCommand::LeftButtonPressEvent, ClickCallback );

This now works properly:
http://www.vtk.org/Wiki/Handle_mouse_events

@Anka -
You seem to be adding the observer to the style... I didn't make this
up, I must have seen it somewhere. Do some observers need to be
attached to the style and others directly to the interactor??

Thanks,

David



More information about the vtkusers mailing list