Please have a look for the following code:
import vtkmodules.all as vtk
polyData = vtk.vtkPolyData()
polyData.SetPoints(vtk.vtkPoints())
polyData.SetVerts(vtk.vtkCellArray())
polyData.GetPoints().InsertNextPoint(1, 1, 1)
polyData.GetVerts().InsertNextCell(1)
polyData.GetVerts().InsertCellPoint(0)
polyData.GetPoints().Modified()
polyData.GetVerts().Modified()
polyData.Modified()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(polyData)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetColor(255, 255, 0)
actor.GetProperty().SetPointSize(10) ################### point size
def mousemove(iren, event):
pos = iren.GetEventPosition()
picker = vtk.vtkCellPicker()
picker.SetTolerance(0.01)
picker.Pick(pos[0], pos[1], 0, render)
actor = picker.GetProp3D()
if actor == None:
print('no actor')
else:
print('pick actor')
render = vtk.vtkRenderer()
render.AddActor(actor)
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(render)
renWin.Render()
iren = vtk.vtkRenderWindowInteractor()
iren.AddObserver('MouseMoveEvent', mousemove)
iren.SetRenderWindow(renWin)
iren.Initialize()
iren.Start()
In the above code, I can pick the point as I expect. However, when I change the point size to 50:
actor.GetProperty().SetPointSize(50)
I find that I can pick the actor only when the cursor move inside the red rectangle in the following picture.
I think it is because the vtkCellPicker
do not conside the point size. Am I correct?
I have read the source code of vtkCellPicker
and vtkPicker
, and I actually do not find where the vtkCellPicker
conside the point size or line width.
Or is there something wrong with my test code?