[vtkusers] VTK event handling

Mathieu Malaterre mathieu.malaterre at kitware.com
Wed Sep 1 09:56:52 EDT 2004


Payman,

	I believe this should work (*). Since I don't have much information 
about your c# lib, I assume it wrapped VTK.

(*)
http://public.kitware.com/pipermail/vtkusers/2004-January/071324.html

int main( int argc, char *argv[] )
{
   vtkConeSource *cone = vtkConeSource::New();

   vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
   coneMapper->SetInput( cone->GetOutput() );

   vtkActor *coneActor = vtkActor::New();
   coneActor->SetMapper( coneMapper );

   vtkRenderer *ren1= vtkRenderer::New();
   ren1->AddActor( coneActor );


   vtkRenderWindow *renWin = vtkRenderWindow::New();
   renWin->AddRenderer( ren1 );


   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
   iren->SetRenderWindow(renWin);

   vtkForwardCallback *forward = vtkForwardCallback::New();
   vtkBackwardCallback *backward = vtkBackwardCallback::New();
   iren->AddObserver(vtkCommand::MouseWheelForwardEvent, forward);
   iren->AddObserver(vtkCommand::MouseWheelBackwardEvent, backward);

   iren->Initialize();
   iren->Start();

   cone->Delete();
   coneMapper->Delete();
   coneActor->Delete();
   //forward->Delete();  //don't know which VTK version is used
   //backward->Delete(); //don't know which VTK version is used
   ren1->Delete();
   renWin->Delete();
   iren->Delete();

   return 0;
}


HTH
Mathieu

payman labbaf wrote:
> How can I catch VTK mouse events in my parent window which is in C# or 
> managed C++? At the moment vtk catches all the event but I want my 
> parent window to catch the events. I've tried disabling the event 
> handling in the interactor style; although the events were not fired by 
> VTK anymore but still I can't receive events in my parent window.
> I've been told a few ways to sort this out but I don't know which way is 
> the best.
> Here are some candidate solutions
>  
> 1- customising wnd_proc function and on receiving the favourite message 
> take necessary action such as notifying the parent window that message 
> was received.
>  
> 2- subclassing InteractorStyle.
> 3- passing a callback function pointer to vtkObserver.
>  
> Because I'm writing my application in managed code and using an 
> unmanaged library, all the above solutions will be difficult to 
> implement.  They need converting managed object to unmanaged and in one 
> case it involves converting a delegate(.Net type) to function pointer 
> (unmanaged c++ type) and vice versa. (oou la la)
>  
> I was wondring if anyone had faced this problem before or have any 
> opinion to sort this out. I still think there is an easier solution like 
> passing the parent window's handler (hwnd) to vtk so any events can be 
> caught in parent window.
>  
> Any help is appreciated in advance.
>  
>  
> 
> ------------------------------------------------------------------------
> *ALL-NEW Yahoo! Messenger* 
> <http://uk.rd.yahoo.com/evt=21626/*http://uk.messenger.yahoo.com>* - all 
> new features - even more fun!** *
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> This is the private VTK discussion list. 
> Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers






More information about the vtkusers mailing list