[vtkusers] Doubt with point picker
Alex Malyushytskyy
alexmalvtk at gmail.com
Tue Aug 21 17:01:30 EDT 2012
Are you sure you do not get point on your sphere?
If you do not want it to happen you should set actor to be unpickable:
PickableOff( );
Alex
On Tue, Aug 21, 2012 at 3:32 AM, <imanolm at lsi.upc.edu> wrote:
> Hello,
>
> I'm trying to display a sphere lying on a triangle mesh. The user can move this
> sphere over the triangle mesh with the mouse.
>
> The user put the sphere over the mesh with a click. To get the point of the mesh
> clicked I use the following code:
> mPointPicker = vtkCellPicker::New();
> mPointPicker->Pick(mStyle->GetInteractor()->GetEventPosition()[0],
> mStyle->GetInteractor()->GetEventPosition()[1], 0,
> mStyle->GetInteractor()->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
>
> double p[3];
> p[0] = p[1] = p[2] = 0.;
> if (id_actor == (int)(mModel->getBoneActor()))
> mModel->getSkeletonMesh()->GetPoint(id, p);
> else if (id_actor == (int)(mModel->getLungsActor()))
> mModel->getLungsMesh()->GetPoint(id, p);
> else return;
>
> vtkSphereSource* sphereSource = vtkSphereSource::New();
> sphereSource->SetCenter(p[0], p[1], p[2]);
>
> With this code, the position of the sphere is ever well computed (It have never
> failed me...)
>
> The user can move the sphere over the mesh with a click and a movement of the
> mouse. To compute the temporal position (while the user is moving the sphere) I
> use the following code:
> double *pointPicker;
> mWorldPointPicker->Pick(mStyle->GetInteractor()->GetEventPosition()[0],
> mStyle->GetInteractor()->GetEventPosition()[1], 0,
> mQVTKWidget->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
> pointPicker = mWorldPointPicker->GetPickPosition();
> sphere->SetCenter(pointPicker[0],pointPicker[1],pointPicker[2]);
>
> I use that code, because with it I get better performance than with the other
> picker. But, as I get worse precision, when the user release the mouse button I
> use the following code to obtain the exact final position:
> mPointPicker->Pick(mStyle->GetInteractor()->GetEventPosition()[0],
> mStyle->GetInteractor()->GetEventPosition()[1], 0,
> mStyle->GetInteractor()->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
>
> double p[3];
> p[0] = p[1] = p[2] = 0.;
> if (id_actor == (int)(mModel->getBoneActor()))
> mModel->getSkeletonMesh()->GetPoint(idPicker, p);
> else if (id_actor == (int)(mModel->getLungsActor()))
> mModel->getLungsMesh()->GetPoint(idPicker, p);
> else return;
>
> sphere->SetCenter(p[0],p[1],p[2]);
>
>
> The problem is that although I use the same code than when the sphere is added,
> the position obtained is not correct. Sometimes after I move the sphere it is not
> well positioned. It is not on the surface, it have an empty space between the
> sphere and the surface...
>
> What am I doing wrong?
> There is any other call with more precision??
> Other actors in the renderer without visibility affect to this call?
>
> Thank you very much for helping me,
> --
> Imanol Muñoz i Pandiella.
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list