I am using VTK in my project, and I need to get the world point from a display point.
I find three method: vtkPropPicker
, vtkCellPicker
, vtkCoordinate
. But I find they return different world point for the same display point.
The test code is:
import vtk
cone = vtk.vtkConeSource()
cone.SetCenter(150, 150, 0)
cone.SetHeight(100)
cone.SetRadius(50)
cone.Update()
coneMapper = vtk.vtkPolyDataMapper()
coneMapper.SetInputData(cone.GetOutput())
coneMapper.Update()
coneActor = vtk.vtkActor()
coneActor.SetMapper(coneMapper)
ren = vtk.vtkRenderer()
ren.AddActor(coneActor)
ren.SetBackground(0.1, 0.2, 0.4)
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(400, 400)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
renWin.Render()
X = 100
Y = 100
picker = vtk.vtkPropPicker()
picker.Pick(X, Y, 0, ren)
pickerWorld = picker.GetPickPosition()
print('world point from vtkPropPicker: ', pickerWorld)
picker = vtk.vtkCellPicker()
picker.Pick(X, Y, 0, ren)
cellWorld = picker.GetPickPosition()
print('world point from vtkCellPicker: ', cellWorld)
coordinate = vtk.vtkCoordinate()
coordinate.SetCoordinateSystemToDisplay()
coordinate.SetValue(X, Y)
coorWorld = coordinate.GetComputedWorldValue(ren)
print('world point from vtkCoordinate: ', coorWorld)
And the result is:
world point from vtkPropPicker: (108.0365506828649, 108.0365506828649, 7.141902959080343)
world point from vtkCellPicker: (108.0089599111793, 108.0089599111793, 6.935962635578974)
world point from vtkCoordinate: (119.0534474476644, 119.0534474476644, 89.37313989502613)
We can see: for the same display point (100, 100), vtkPropPicker
, vtkCellPicker
, vtkCoordinate
return different world point.
It really make me crazy!!
Any suggestion is appreciated!