Coloring individual triangles in triangulated surface model of segmentation

Hi Everyone,

I am wondering if it is possible to color individual triangles in the triangulated surface model of a segmentation? In other words, when I click “w” in Slicer and I see my segmentation as a triangulated mesh, can I color individual triangles.


Operating system: OSX
Slicer version: 4.10.2

There is an example in the script repository does exactly this:

Thank you very much for the quick response. I am taking a look through the example and will post if I have any questions


1 Like

Thanks again for the pointer, I got the code to work (I had to switch to 4.11 for the “arrayFromMarkupsControlPoints” functionality).

I am playing around with SegmentMesher and the Models module, but am having difficulty reducing the mesh to just be the actual segmented object as opposed to a rectangle encompassing it. Is there any way to get the mesh to actually be on the airway like in the second image (obtained by pressing ‘w’ in the 3D view).


A background mesh is often very useful because you can simulate embedding of the object in another material, but if you don’t need then then enable “Cleaver remove background mesh” option in Advanced section.

Thank you, that’s exactly what I was looking for

1 Like

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]])

I am guessing that triangles are 3D objects in the mesh, hence the 4th vertex, which would be the answer to my second question from the previous post. If that’s true, my updated question is if its possible to only consider the 2D triangle objects that reside on the exterior surface?

Segment mesher creates a volumetric mesh, so you have tetrahedral elements (defined by 4 points). You get a surface mesh (with triangle elements) when you exporting the segment to a model using Segmentations module.

perfect, thank you very much