How to pick a cell from vtkPolyData by coordinate

Hello,

I suggest you to study this example: https://kitware.github.io/vtk-examples/site/Cxx/PolyData/CellLocator/

In VTK context, a cell is any composition of vtkPoints, which is a sort of atomic object. The simplest cell type is a vertex which is composed by a single “atom”. Other cell types include:
image

I belive you want to query the cell of type VTK_LINE(3) or VTK_POLY_LINE(4) that is near clickedcoord[0], clickedcoord[1], clickedcoord[2]. So you can set either 3 or 4 as the subId parameter of the FindClosestPoint() method in the example above.

NOTICE VTK 9: If you’re using VTK 9, be aware that the conversion to world coordinates in picking operations has a standing bug: vtkPropPicker in VTK 9.1 is now returning wrong world coordinates. . I submitted a merge request with a possible solution here: https://gitlab.kitware.com/vtk/vtk/-/merge_requests/9125 . If you experience this bug and can’t wait for a solution to make it downstream, you can patch VTK yourself (like I did) as described here: VTK 9: the pick marker is not positioned on the picked location, instead it is now placed in a plane orthogonal to the camera. · Issue #273 · PauloCarvalhoRJ/gammaray · GitHub.

take care,

Paulo