I was wondering how to get the segmentationNode from segment name.
With version 4.5.0, I was using the subject hierarchy function:
modelLogic = slicer.vtkSlicerSegmentationsModuleLogic()
segmentSH = slicer.util.getNode(segmentName)
segmentationNode=modelLogic.GetSegmentationNodeForSegmentSubjectHierarchyNode(segmentSH)
But with version 4.10.1, subject hierarchy doesn’t seem to exist anymore?
Subject hierarchy has been completely reimplemented since that version. This specific operation is not obvious in the new system, but here is how you can do it:
itemName = 'What you are looking for'
shn = slicer.vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNode(slicer.mrmlScene)
sc = shn.GetSceneItemID()
items = vtk.vtkIdList()
shn.GetItemChildren(sc, items, True)
for i in xrange(items.GetNumberOfIds()):
name = shn.GetItemName(items.GetId(i))
if name == itemName:
foundItem = items.GetId(i)
break
parentItem = shn.GetItemParent(foundItem)
parentNode = shn.GetItemDataNode(parentItem)
But it doesn’t seem to work for if there is more than one segmentation.
What I want to do is : from segments (DICOM RTstruct), with the slicerRT extension, I do bool. operation -intersection/expansion - of segments in new segmentation and I want to get the segmentation node for all the segments (original and newly created in new segmentation) based on their segment name.
For example:
‘structure1’ -> vtkMRMLSegmentationNode1
‘Expanded_5_5_5_structure1’ -> vtkMRMLSegmentationNode2