Dear people,
Recently I migrated code from VTK 8.1 to 9.1. Giving or taking minor changes (mostly related to deprecated API), most of VTK code stayed the same. However, the behavior of vtkPropPicker::GetPickPosition()
has changed. It now returns the wrong world pick coordinates. Here’s the code (it was fine in VTK 8.1):
// Get pick position in 2D screen coordinates.
int* clickPos = this->GetInteractor()->GetEventPosition();
// Get the 3D object under the 2D screen coordinates (ray casting).
vtkSmartPointer<vtkPropPicker> picker = vtkSmartPointer<vtkPropPicker>::New();
picker->Pick(clickPos[0], clickPos[1], 0, this->GetDefaultRenderer());
// Get the picked location in world coordinates.
double* pos = picker->GetPickPosition();
The XYZ value in the pos
array is used to place a small red sphere in the scene to serve as a pick maker. In VTK 8.1, the pick marker appeared exactly where the user picked. In VTK 9.1, the pick marker is placed on a plane orthogonal to the camera, which is incorrect. The figure below shows a 2D grid at Z=0 facing the camera:
Picking anywere results in the correct reported position Z=0 and, consequently, the pick marker is placed correctly on the grid.
Now, if I rotate the scene and proceed to picking, the method returns the wrong pick position in world coordinates, above or below the plane, even though the picked cell is correct:
After testing a few times, the conclusion is that the returned world coordinates lies in the intersection point of the pick ray and some plane orthogonal to the camera, not on the geometry of the picked actor. It seems to me that the picking logic is applying the reverse rotation transform applied to scene when computing the world picked position.
Thanks in advance,
Paulo