[vtkusers] Problem with getting pointId after Picking operation!!!
Łukasz Tutaj
ltutaj at wp.pl
Mon Oct 10 16:40:25 EDT 2005
Hi vtk Users,
In my work display medical images (DICOM). I want to choose a point
on a screen and then I want to get pointId of this point. I use in this
case vtkPointPicker.I have a problem in getting pointId after picking
operation. I always get pointId = -1. However some pick event take place
because I get good coordinates of event position. I don't know what is
wrong. In my opinion this piece of code I have written should work. But
it doesn't. Could someone look at it and tell me what is wrong? Please.
Here is this code.
class vtkMyCallback : public vtkCommand
{
public:
int x, y;
static vtkMyCallback *New() { return new vtkMyCallback; }
virtual void Execute(vtkObject *caller, unsigned long, void*)
{
vtkRenderWindowInteractor *iren =
reinterpret_cast<vtkRenderWindowInteractor*>(caller);
x = iren->GetEventPosition()[0];
y = iren->GetEventPosition()[1];
vtkPointPicker *picker = (vtkPointPicker *)iren->GetPicker();
int pointId = picker->GetPointId();
cout << "(" << x << ", " << y << ") " << pointId << endl;
}
};
int main()
{
vtkRenderer *ren = vtkRenderer::New();
vtkRenderWindow *renwin = vtkRenderWindow::New();
renwin->AddRenderer(ren);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renwin);
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);
renwin->Render();
vtkPointPicker *picker = vtkPointPicker::New();
picker->SetTolerance(0.00001);
iren->SetPicker(picker);
vtkMyCallback *mo1 = vtkMyCallback::New();
iren->AddObserver(vtkCommand::EndPickEvent,mo1);
iren->Start();
iren->RemoveObserver(mo1);
iren->Initialize();
iren->Start();
mo1->Delete();
...
....
return 0;
}
More information about the vtkusers
mailing list