[vtkusers] picking an actor with vtkPropPicker
Lloyd Fenelon
lfenelon at bccrc.ca
Tue Jun 30 20:53:02 EDT 2009
Hi,
I would like to get the position of an actor when I
pick it in the screen with the mouse and "p".
I am using vtkPropPicker but the method getActor()
always returns NULL..I don't know what I missed in the code.
I tried with vtkPicker but I got the same results.
Here is the callback function and the main I am using to try picking:
class vtkMyCallback : public vtkCommand
{
public:
static vtkMyCallback *New()
{
return new vtkMyCallback;
}
void Delete()
{
delete this;
}
virtual void Execute(vtkObject *caller, unsigned long, void*)
{
vtkPropPicker* picker
= reinterpret_cast<vtkPropPicker*>(caller);
vtkSmartPointer<vtkActor> pickedActor
= vtkSmartPointer<vtkActor>::New();
pickedActor = picker->GetActor();
if ( pickedActor == NULL) cout << " nothing picked\n";
//double actorCoord[3] = {0.0};
//pickedActor->GetPosition(actorCoord);
//cout << actorCoord[0] << " \t" << actorCoord[1] << " \t" << actorCoord[2] << "\n";
}
};
int main()
{
vtkSphereSource *sphere = vtkSphereSource::New();
sphere->SetThetaResolution(10);
sphere->SetPhiResolution(5);
vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
sphereMapper->SetInputConnection(sphere->GetOutputPort());
vtkActor *sphere1 = vtkActor::New();
sphere1->SetMapper(sphereMapper);
sphere1->GetProperty()->SetColor(1,0,0);
vtkActor *sphere2 = vtkActor::New();
sphere2->SetMapper(sphereMapper);
sphere2->GetProperty()->SetColor(0,0,1);
sphere2->AddPosition(1.25,0,0);
vtkRenderer *ren1 = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren1);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
ren1->AddActor(sphere1);
ren1->AddActor(sphere2);
ren1->SetBackground(1, 1, 1);
renWin->SetSize(600, 400);
///////////////////////////////////////////////////////////////
// Picker
vtkSmartPointer<vtkPropPicker> picker
= vtkSmartPointer<vtkPropPicker>::New();
iren->SetPicker(picker);
vtkMyCallback* updateCoord = vtkMyCallback::New();
picker->AddObserver(vtkCommand::StartPickEvent, updateCoord);
///////////////////////////////////////////////////////////////
iren->Initialize();
iren->Start();
sphere->Delete();
sphereMapper->Delete();
sphere1->Delete();
sphere2->Delete();
ren1->Delete();
renWin->Delete();
iren->Delete();
return 0;
}
Thanks for your help
Lloyd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090630/d31472c8/attachment.htm>
More information about the vtkusers
mailing list