[vtkusers] help with interactor and MFC

Renaud Isabelle renauisa at yahoo.fr
Thu Aug 18 11:32:17 EDT 2005


Hi guys, 
 
I have to implement user interaction with my renderwindow in MFC: 
 
user picks points on the displayed medical image and notices them with spheres. I saw that I have to use vtkHandleMessage2 with vtkWin32RenderWindowInteractor to handle a left button mouse click and interactor->AddObserver() to call a function to handle it. 
 
But now, I see that vtkPointPicker exists and that is doing the same thing. I am really a bit confused with all the options. Here is what I did:
 
  interactor->SetRenderWindow(m_RenderWindow);
  interactor->SetInteractorStyle(NULL);
 
  vtkPointPicker *picker = vtkPointPicker::New();
  interactor->SetPicker(picker);
  
  vtkMyCallback* how_execute = vtkMyCallback::New();
  interactor->AddObserver( vtkCommand::LeftButtonPressEvent, how_execute );
  interactor->AddObserver( vtkCommand::EndPickEvent,  how_execute);
  
  interactor->SetInstallMessageProc(false);
  interactor->Initialize();
 
LRESULT CMyView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
 // TODO: Add your specialized code here and/or call the base class
 switch ( message )
 {
 case WM_LBUTTONDOWN:
  if ( this->interactor->GetInitialized() )
  {
   return vtkHandleMessage2(this->m_hWnd, message, wParam, lParam, this->interactor);
  }
  break;
 }
 return CFormView::WindowProc(message, wParam, lParam);
}
 
class vtkMyCallback : public vtkCommand
{
public:
  static vtkMyCallback *New()  { return new vtkMyCallback; }
  
  virtual void Execute(vtkObject *caller, unsigned long eventId, void*)
    {
      vtkRenderWindowInteractor* interactor = reinterpret_cast<vtkRenderWindowInteractor*>(caller);
      
     if(eventId == vtkCommand::LeftButtonPressEvent)
     {  
          int point[2];
          interactor->GetEventPosition(point);
          m_viewer->SelectPoint(point[0],point[1]);
   }
 
   if(eventId == vtkCommand::EndPickEvent)
   {  
          vtkPointPicker* picker = (vtkPointPicker*) interactor->GetPicker();
          if(picker->GetPointId() != -1)
         {
            float* position = picker->GetPickPosition();
            m_sphereActor->SetPosition(position);
         }
   }
}
 
- This seems not to work. I think that I have to choose between handling one of the event: LeftButtonPressEvent or EndPickEvent. But I don't know what is the best option. Could someone tell me what is best? 
 
- Btw, my purpose is to add a circle on each point that user picked. Do I have to handle a array of vtkSphereSource to display so many spheres?
 
Thanks for replyiong, guys,
 
Isabelle

		
---------------------------------
 Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger
 Téléchargez le ici !  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20050818/9ed27b56/attachment.htm>


More information about the vtkusers mailing list