Get cell data of a mesh at selected point positions

Hi Andras,
I have data points and want to map it on a brain mesh to get the cell values of brain mesh at data points. how can I do it. any suggestions?

Thank you

Regards,
Saima Safdar

You can use a vtkCellLocator to get closest point to each data point and then get the cell value from cell ID as shown in this example: https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_scalar_values_at_surface_of_a_model

Hi Andras,
I am using the findcell based on fiducial points to select the cells but there are less number of cells selected as compared to fiducial points. I need all cells for each fiducial and nearby cells as well of the mesh. How would i be able to get this. any idea.

Thank you

Regards,
Saima Safdar

as in the image below you can see only few cells are selected.

The script that I’ve linked above works very robustly for me. If you can save your scene in a .mrb file, upload it somewhere, and post the link then I can have a look at it.

Hi Andras,
I uploaded it on googledrive. here is the link.

https://drive.google.com/drive/folders/1WFGnfJRLm65MxF99JzKdnnvGyPLRhO-u?usp=sharing

Regards,
Saima Safdar

Thanks, the scene file helped. The main issue was that the points were not on the surface of the model and the locator’s FindCell method required points to be on the surface (it uses 0 tolerance value for finding a cell).

I’ve updated the example script to find the closest cell and also updated the example to not recreate the selection array if it already exists (so that the code runs correctly even if you run it on a mesh where you’ve used it on already).

Hi Andras,
Thank you so much. Andras what should I do if I need to select the other neighbouring cells in between the selected cells.

Thankyou

Regards,
Saima Safdar

See this example: https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/CellPointNeighbors/

Hi Andras,
how can i use this within slicer. what will be the steps.

I am so sorry if I am asking a simple question because I do not understand how i am going to use it within slicer.

Thank you

Regards,
Saima Safdar

Look at the example to see what VTK classes and what methods of that classes are used to get cell neighbors.

Hi Andras,
I was trying to do what you said. the program below is used to extract neighbouring cells relevant to a single cell for example; 2978 is the cell id of one of the cells in the mesh and it gets its cell point ids and based on the cell point ids it gets the neighouring cells. but my program is crashing. could you please tell me what is wrong what I am doing.

actually problem starts with line “trianglefilter.GetOutput().GetCellNeighbors(2978, idList, neighbourcells)`”" the second argument requires a vtk object. I am passing the vtklist object but dont understand what to do. Could you please advice what am i doing wrong.
Thanks

modelNode = slicer.util.getNode(inputVolume.GetID())
m = modelNode.GetMesh()

trianglefilter = vtk.vtkTriangleFilter()

trianglefilter.SetInputData(m)
trianglefilter.Update()

cellPointIds = vtk.vtkIdList()

trianglefilter.GetOutput().GetCellPoints(2978, cellPointIds)

for i in range(0,3):
    print(cellPointIds.GetId(i))
    
neighbourcells = vtk.vtkIdList()

idList = vtk.vtkIdList()
idList.SetNumberOfIds(3)
idList.SetId(0,1552)

> trianglefilter.GetOutput().GetCellNeighbors(2978, idList, neighbourcells)

print(neighbourcells.GetNumberOfIds())

I figured out my mistake. Thank you andras.

Regards,
Saima Safdar

1 Like