Get Mesh Cell and Modify

for mesh cell 1 …, end of mesh <== executing all of the mesh

  1. Get each mesh cell(below first picture) of all the mesh cells in the volume
  2. Modify each cell value(color)


referral script code^^

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)

Let us know if you have any questions.

I will do it by myself and let sample code shared in this page^^

2 Likes

I found below when executing python script

https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_scalar_values_at_surface_of_a_model

You have set a segmentation node into modelNode variable. As the name suggests, a model node is expected. You can create model nodes from segmentations by exporting segments to model nodes (this creates surface meshes) or by using Segment Mesher extension (this creates volumetric mesh).

I did mesh from Segment Mesher^^

when i call modelNode.GetMesh()

cellScalars = modelNode.GetMesh().GetCellData()

it seemed to be there’s no attribute ‘GetMesh’
or python script can find ‘GetMesh’ function

You can run print(modelNode) in the Python console to see if the object is indeed a model node.

I seemed to be real node

“modelNode” is a vtkMRMLSegmentationNode, so it is not a model node. Segmentation node is an input to model generators. You can create model nodes from segmentations by exporting segments to model nodes (this creates surface meshes) or by using Segment Mesher extension (this creates volumetric mesh).

Thanks Adras, I have time so now analysis all of the slicer source code for accumulated and structured knowledges. I think slicer has positive contribution to the medical imaging and communication (like DICOM Concept). Always thinking your slicer community member’s hard working and Voluntary commitment :slight_smile:

1 Like