Hi all,
I am attempting to automate a volume resampling process using the reslice
function. The issue I am encountering is that the resampling process takes a few seconds (approximately 20 seconds), and I need the code to wait until this process finishes. To address this, I have implemented the waitUntilReslice
function. However, I seem to be encountering problems with the resampling status; it never changes to “Completed,” regardless of how long I wait. It consistently remains in the “Completing” state.
Following the resampling process, I also need to adjust the window level. However, I am encountering a “NoneType” error for the “reslicedVolumeNode.” Does anyone have any suggestions on how I can resolve this issue?
Code:
def waitUntilReslice(timeout, res, period=0.25):
mustend = time.time() + timeout
while time.time() < mustend:
if (res.GetStatusString() == 'Completed') or \
(res.GetStatusString() == 'Completing'): # I want to use only "Completed"
print(res.GetStatusString())
return True
time.sleep(period)
return False
def reslice(volumeNode, resolution=0.25, name='resliced'):
global res
reslicedVolumeNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLScalarVolumeNode", name)
parameters = {
"outputPixelSpacing":"{:},{:},{:}".format(*[resolution]*3),
"InputVolume":volumeNode.GetID(),
"interpolationMode":'bspline',
"referenceVolume": volumeNode.GetID(),
"OutputVolume":reslicedVolumeNode.GetID()}
res = slicer.cli.run(slicer.modules.resamplescalarvolume, None, parameters)
waitUntilReslice(60, res)
# reslicedVolumeNode = slicer.util.getNode(name)
if(not reslicedVolumeNode == None):
reslicedVolumeNode.GetDisplayNode().SetAutoWindowLevel(0)
reslicedVolumeNode.GetDisplayNode().SetWindowLevel(800,100)
return reslicedVolumeNode
Thanks,
Belén