[vtkusers] help with interactor and MFC
Renaud Isabelle
renauisa at yahoo.fr
Fri Aug 19 09:39:41 EDT 2005
Hi,
It's me again...
Does anyone have an example that implements vtkRenderWindowInteractor, AddObserver and pick event with MFC? I would like to draw a circle where user clicks in the render window.
Isabelle
Renaud Isabelle <renauisa at yahoo.fr> a écrit :
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 ! _______________________________________________
This is the private VTK discussion list.
Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
---------------------------------
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/20050819/f4bf61e1/attachment.htm>
More information about the vtkusers
mailing list