[vtkusers] Problem with vtkPointPicker
Łukasz Tutaj
ltutaj at wp.pl
Wed Oct 5 18:16:52 EDT 2005
Hi vtk Users.
I want to know the pointId of picked point. I wrote some test program
but it doesn't work, m_picker->Pick(...) method returns 0 (nothing was
picked) and pointId is -1. I don't know why it doesn't work. Could
anyone help me?
Thanks in advance.
Łukasz Tutaj
Here is my source code:
#include <vtkDICOMImageReader.h>
#include <vtkPointPicker.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkImageMapper.h>
#include <vtkActor2D.h>
#include <vtkCommand.h>
// Callback for the interaction
class vtkMyCallback : public vtkCommand
{
public:
vtkPointPicker * m_picker;
vtkRenderer *m_ren;
int x, y;
static vtkMyCallback *New()
{ return new vtkMyCallback; }
virtual void Execute(vtkObject *caller, unsigned long, void*)
{
double *ptActual, *ptMapped;
vtkRenderWindowInteractor *iren =
reinterpret_cast<vtkRenderWindowInteractor*>(caller);
x = iren->GetEventPosition()[0];
y = iren->GetEventPosition()[1];
int succed = m_picker->Pick(x, y, 0, m_ren);
int pointId = m_picker->GetPointId();
m_picker->GetPickedPositions();
cout << "(" << x << ", " << y << ") " << succed << " " <<
pointId << endl;
}
void SetPicker(vtkPointPicker *picker)
{
m_picker = picker;
}
void SetRenderer(vtkRenderer *ren)
{
m_ren = ren;
}
};
int main()
{
vtkRenderWindow *renwin = vtkRenderWindow::New();
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
vtkRenderer *ren = vtkRenderer::New();
vtkPointPicker *picker = vtkPointPicker::New();
iren->SetPicker(picker);
renwin->AddRenderer(ren);
renwin->SetInteractor(iren);
vtkDICOMImageReader *reader = vtkDICOMImageReader::New();
reader->SetFileName("D:\\PRACA MAGISTERSKA\\dane381\\46009361");
vtkImageMapper *mapper = vtkImageMapper::New();
mapper->SetInput(reader->GetOutput());
mapper->SetColorWindow(300);
mapper->SetColorLevel(40);
vtkActor2D *actor = vtkActor2D::New();
actor->SetMapper(mapper);
ren->AddActor2D(actor);
renwin->SetSize(512,512);
vtkMyCallback *mo1 = vtkMyCallback::New();
mo1->SetPicker(picker);
mo1->SetRenderer(ren);
iren->AddObserver(vtkCommand::LeftButtonPressEvent,mo1);
mo1->Delete();
iren->Initialize();
iren->Start();
return 0;
}
More information about the vtkusers
mailing list