[vtkusers] help with interactor and MFC

John Platt jcplatt at lineone.net
Fri Aug 19 19:27:39 EDT 2005


Hi Isabelle,

 

As far as I can see, the pick events are fired by the Pick() method of
the interactor’s picker. If you want to observe these events, you must
add the observers to the picker, not the interactor. You must also
arrange for the Pick() method to be called.

 

As a start, in the check for LeftButtonPressEvent, call Pick() with the
current mouse event position and then get the point id -

 

         int x = interactor->GetEventPosition()[0];

         int y = interactor->GetEventPosition()[1];

         vtkPointPicker* picker = interactor->GetPicker(); 

         picker->Pick( (double)x, (double)y, 0, renderer );

         int pointId = picker->GetPointId();

 

and print the point Id using the TRACE macro. If you cannot get the
LeftButtonPressEvent, see the recent thread on “handle right mouse
click”.

 

I have drawn various 2D shapes, by first creating a polydata object, and
then, as each point is clicked, add the point as a vertex to the
polydata. The polydata is set as input to vtkGlyph2DMapper (very similar
to vtkTextMapper). This mapper takes vtkGlyphSource2D as a source and
copies the specified shape (diamond, circle, square etc.) to each of the
points in the polydata. The mapper then feeds a single vtkActor2D.
Something like 


 

   vtkGlyphSource2D* vtkGlyphSource = vtkGlyphSource2D::New();

   vtkGlyphSource->SetGlyphTypeToCircle();

   m_vtkGlyphMapper = vtkGlyph2DMapper::New();

   m_vtkGlyphMapper->SetInput( m_vtkInputPolyData );

   m_vtkGlyphMapper->SetSource( vtkGlyphSource->GetOutput() );

   vtkGlyphSource->Delete();

   m_vtkGlyphActor = vtkActor2D::New();

   m_vtkGlyphActor->SetMapper( m_vtkGlyphMapper );

 

I can let you have the mapper if you think it would be helpful.

 

John.

 

-----Original Message-----
From: vtkusers-bounces+jcplatt=lineone.net at vtk.org
[mailto:vtkusers-bounces+jcplatt=lineone.net at vtk.org] On Behalf Of
Renaud Isabelle
Sent: 18 August 2005 16:32
To: vtkusers at public.kitware.com
Subject: [vtkusers] help with interactor and MFC

 

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
<http://us.rd.yahoo.com/messenger/mail_taglines/default/*http:/fr.messen
ger.yahoo.com>  le ici ! 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20050820/ee180ebf/attachment.htm>


More information about the vtkusers mailing list