Thanks again for the previous help. I am now able to get cell identifiers for triangles on the surface mesh and color them / their neighbors.
I have no issues when the markup point is outside the mesh or on the exterior surface, but I am unsuccessful when the markup is slightly inside the surface mesh. I have experimented with hollowing out the segmentation before generating the model, but that has not solved the issue.
Based on my experiments, it looks like the surface mesh is not only on the surface. If this is the case, is there a way to always/only get triangles on the exterior surface using cell.FindClosestPoint? The 1st image below identifies a cell with two internal vertices as the closest cell to MarkupsFiducial_1.
Additionally, is the mesh not actually a triangle mesh? Each cell has a 4th vertex which seems to be internal to the surface (2nd image below).
I apologize if the screenshots are difficult to interpret in 2D. Let me know if I can clarify anything.
Here is the code I used to identify cells and vertices:
meshModelNode = slicer.util.getNode('Model_1')
selectionArray, cell = initializeMeshArray(meshModelNode)
markupsNode = slicer.util.getNode('MarkupsFiducial')
markupPoints = slicer.util.arrayFromMarkupsControlPoints(markupsNode)
markupIndex = 0
markupPoint = markupPoints[markupIndex]
# find the closest cell to markupPoint
closestPoint = [0.0, 0.0, 0.0]
cellObj = vtk.vtkGenericCell()
cellId = vtk.mutable(0)
subId = vtk.mutable(0)
dist2 = vtk.mutable(0.0)
cell.FindClosestPoint(markupPoint, closestPoint, cellObj, cellId, subId, dist2)
# find the number of vertices for the cell (output is 4)
# find the vertex RAS coordinates
np.array(cellObj.GetPoints().GetData().GetTuple(0) + cellObj.GetPoints().GetData().GetTuple(1) + cellObj.GetPoints().GetData().GetTuple(2) + cellObj.GetPoints().GetData().GetTuple(3)).reshape(4,3)
# output is array([[ 43.90499878, 9.22570038, -78.88699341],
[ 44.46899414, 9.83119965, -79.45799255],
[ 44.1309967 , 8.99890137, -79.11399841],
[ 43.90499878, 9.22570038, -79.48599243]])