I am scripting a module in 3D Slicer using python and the script worked on Slicer 4.10 but now that I’ve updated to the new version 4.11 part of the script is not working. Specifically, a part where I create a handle for a keychain and it is added to the new keychain image. Here is the part I think is not working, which is the call to meshtolabelmap. I don’t know if the new version of python is different with the function call parameters or what it is. I’ve included some surrounding code to give some insight into what is going on. The tempDirectory “saves” has the handle path but the file itself is empty. Again, this worked on Slicer 4.10 with the exact same code.
handle = makeHandle()
handleNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLModelNode', "handle")
handleNode.SetAndObservePolyData(handle)
handleNode.CreateDefaultDisplayNodes()
handleNode.CreateDefaultStorageNode()
path = slicer.util.tempDirectory("saves")
handlePath = path + "/handle.nrrd"
handleParams = {'reference' : blankVolumeNode.GetID(), 'mesh' : handleNode.GetID(), 'labelMap': handleBLM.GetID(), 'value' : 255}
process = slicer.cli.run(slicer.modules.meshtolabelmap, None, handleParams, wait_for_completion=True)
slicer.util.saveNode(handleBLM,handlePath)
############################################
############################################
# Save surfaces and then load via simpleITK
############################################
############################################
left = sitk.ReadImage(sitkUtils.GetSlicerITKReadWriteAddress(leftBLM.GetName()))
right = sitk.ReadImage(sitkUtils.GetSlicerITKReadWriteAddress(rightBLM.GetName()))
handleVol = sitk.ReadImage(sitkUtils.GetSlicerITKReadWriteAddress(handleBLM.GetName()))
############################################
############################################
# Use simpleITK to combine, smooth and fill holes
############################################
############################################
orFilter = sitk.OrImageFilter()
brain = orFilter.Execute(right,left)
or2Filter = sitk.OrImageFilter()
keychain = or2Filter.Execute(brain,handleVol)
I’ve added the make handle function as well just incase (even though it creates a handle and shows it in slicer).
def makeHandle():
fn = vtk.vtkParametricTorus()
fn.SetRingRadius((rightBound-leftBound)/5)
fn.SetCrossSectionRadius((rightBound-leftBound)/15)
#vtk.FlipNormalsOn()
source = vtk.vtkParametricFunctionSource()
source.SetParametricFunction(fn)
source.Update()
trans = vtk.vtkTransform()
trans.RotateX(90)
trans.Translate(midline,topBound + handleShift,halfway)
# vtk generate normals
# communicate with SLACK
rotate = vtk.vtkTransformPolyDataFilter()
rotate.SetTransform(trans)
rotate.SetInputConnection(source.GetOutputPort())
rotate.Update()
return rotate.GetOutput()