[vtkusers] Doubt with point picker

imanolm at lsi.upc.edu imanolm at lsi.upc.edu
Tue Aug 21 06:32:24 EDT 2012


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.




More information about the vtkusers mailing list