Then I want to pick the corresponding line close to the mouse picked point.
The mouse picked point can be get from:
int* clickpos = this->GetInteractor()->GetEventPosition();
vtkNew picker;
picker->Pick(clickpos[0], clickpos[1], 0, GetRenderer());
double *clickedcoord = picker->GetPickPosition();
Can you, please, post your code between two ```? Doing so prevents parts of your code being parsed as markdown syntax as well as making your code more readable.
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:
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.
vtkPolyData inherits FindCell() methods from vtkPointSet (which is an implementation of the pure virtual FindCell() defined in vtkDataSet - look in vtkDataSet for documentation about FindCell()). Using vtkPolyData::FindCell() will work for most applications and is reasonably fast.
However note that this is potentially a complex operation as there are different ways to “find cells” depending on your application. If you really want to hurt your brain, look into the vtkFindCellStrategy class and derived classes.
1- use vtkCellPicker
2- get picked cell then loop the edges
3- calculate distance between “clickedcoord” and each edge and find minimum
4- use minimum edge points to get ids from edge data using FindPoint function
5- use GetPointCells function on edge data to get cells of point 1 and 2 of the selected edge
6- the common cell id is the line id in your edge data