VMTK SlicerExtension Multiprocessing

Hi,

I have a python pipeline that utilizes several functions, such as ExtractCenterline and ClipVessel, from the SlicerExtension-VMTK (GitHub - vmtk/SlicerExtension-VMTK) for analyzing vessel segmentation. Since I need to process each segment in the segmentation, I am interested in using multiprocessing to speed up the analysis.

I’ve tried using SlicerParallelProcessing (GitHub - pieper/SlicerParallelProcessing: Slicer modules for running subprocesses to operate on data in parallel), but it doesn’t seem to work, possibly due to the presence of vtkMRMLNode in SlicerExtension-VMTK.

Is there any suggestion or other method to implement multiprocessing in this context?
BTW, I am working with SlicerJupyter and the Slicer 5.6 environment.

Thank you so much!

Best,
Tracy

By default the SlicerParallelProcessing just launches PythonSlicer which is the same python shell as Slicer but without the modules or extensions.

You should be able to create a subshell that has all the paths defined so that VMTK logic libraries are included and can be used. Perhaps lauchConsoleProcess, but I haven’t tried.

Hi Pieper,

Thanks for your advice.

I’m encountering an issue (which I believe is related to the environment) when trying to use launchConsoleProcess.

Here is the command

command = [
‘PythonSlicer’, ‘test_script.py’, # The Python interpreter and the script name
‘–segmentationName’, ‘segment_merge.nii.gz’,
‘–segmentName’, ‘Segment_1’,
‘–centerlineName’, ‘test’,
‘–point’, ‘145.66666666666666, 315.3333333333333, 301.6666666666667’ # Second 3D coordinate
]

process = slicer.util.launchConsoleProcess(command)
slicer.util.logProcessOutput(process)

When I use ‘python3’ as the executable, I get the error:
ModuleNotFoundError: No module named numpy
Additionally, all the SlicerExtension-VMTK modules seem to be missing.

On the other hand, if I use ‘PythonSlicer’, I encounter this error:
FileNotFoundError: [Errno 2] No such file or directory: ‘PythonSlicer’

Do you have any suggestions for resolving these issues?
If you need any further information, please let me know.
Thanks a lot.

Best,
Tracy

Try launchConsoleProcess(["PythonSlicer"], useStartupEnvironment=False)

Thanks for quick reply.

However, I face some other error (vtkMRMLNode)
Please refer to the attached image.

Here is my function if useful
def centerline_extraction(segmentationName, segmentName, centerlineName, points=None):

segmentationNode = slicer.util.getNode(segmentationName)
segmentID = segmentationNode.GetSegmentation().GetSegmentIdBySegmentName(segmentName)

# Init the VMTK ExtracCenterline class
extractLogic = ExtractCenterline.ExtractCenterlineLogic()

# Preprocess the surface
inputSurfacePolyData = extractLogic.polyDataFromNode(segmentationNode, segmentID)
targetNumberOfPoints = 5000.0
decimationAggressiveness = 3.5
subdivideInputSurface = False
preprocessedPolyData = extractLogic.preprocess(inputSurfacePolyData, targetNumberOfPoints, decimationAggressiveness, subdivideInputSurface)

endPointsMarkupsNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsFiducialNode", "Centerline endpoints")
if not np.any(points):
    # Auto-detect the endpoints      
    networkPolyData = extractLogic.extractNetwork(preprocessedPolyData, endPointsMarkupsNode)
    startPointPosition=None
    endpointPositions = extractLogic.getEndPoints(networkPolyData, startPointPosition)
    endPointsMarkupsNode.RemoveAllMarkups()
    for position in endpointPositions:
      endPointsMarkupsNode.AddControlPoint(vtk.vtkVector3d(position))

else:
    assert points.shape[1] == 3
    # Self define start and end points
    endPointsMarkupsNode.RemoveAllMarkups()
    for p in points:
        endPointsMarkupsNode.AddControlPoint(vtk.vtkVector3d(p))
    
        #endPointsMarkupsNode.AddControlPoint(vtk.vtkVector3d(points[-1]))

# Extract the centerline
curveName = centerlineName+"Curve"
modelName = centerlineName+"Model"

centerlineCurveNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsCurveNode", curveName)

centerlinePolyData, voronoiDiagramPolyData = extractLogic.extractCenterline(preprocessedPolyData, endPointsMarkupsNode)
centerlinePropertiesTableNode = None
extractLogic.createCurveTreeFromCenterline(centerlinePolyData, centerlineCurveNode, centerlinePropertiesTableNode)

centerlineModelNode = slicer.modules.models.logic().AddModel(centerlinePolyData)
centerlineModelNode.SetName(modelName)

return centerlineCurveNode, centerlineModelNode

PythonSlicer is more just a python shell and not a full instance of Slicer. Maybe for what you want you can use Slicer --no-main-window. Since it runs the application you’ll need to explicitly exit() when you are done processing.

Dear Steve Pieper,
My writing is not belong to this conversation. Could you kindly review and approve my post request? I am new to the community and currently seeking assistance. Thank you for your time and understanding.