Dear all,
I wrote these to functions to convert between labelmap and model nodes. Is there a similar simple non-slicer solution e.g. using only itk and vtk?
def lbl2model(lblNode,lblName):
segNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
segNode.SetName(lblName)
slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(lblNode, segNode)
modelHNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLModelHierarchyNode")
slicer.modules.segmentations.logic().ExportAllSegmentsToModelHierarchy(segNode, modelHNode)
vColls = vtk.vtkCollection()
modelHNode.GetChildrenModelNodes(vColls)
modelNode = vColls.GetItemAsObject(0)
return modelNode
def model2lbl(modelNode,modelName,refNode):
segNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
segNode.SetName(modelName)
slicer.modules.segmentations.logic().ImportModelToSegmentationNode(modelNode,segNode)
labelmapVolumeNode =
slicer.mrmlScene.AddNewNodeByClass("vtkMRMLLabelMapVolumeNode")
labelmapVolumeNode.SetName(modelName)
ids = vtk.vtkStringArray()
segNode.GetDisplayNode().GetVisibleSegmentIDs(ids)
slicer.modules.segmentations.logic().ExportSegmentsToLabelmapNode(segNode, ids,labelmapVolumeNode, refNode)
return labelmapVolumeNode