Hello,
I tried modifying your long code example to automatically extract centerline curves using python. However, I found that the extracted centerline curves are not labelled in the 3D view, but only in the slice views:
Here is my code:
import vtk
import slicer
import ExtractCenterline
end_pts = slicer.util.loadMarkups("endpoints.json")
vessel_seg = slicer.util.loadSegmentation("segmentation.nii.gz")
segmentation = vessel_seg.GetSegmentation()
segmentation.SetConversionParameter("Smoothing factor", "0.1")
vessel_seg.CreateClosedSurfaceRepresentation() # This creates the 3D view
segmentID = segmentation.GetSegmentIdBySegmentName('Segment_1')
segmentVtkPolyData = vtk.vtkPolyData() # create empty vtkPolyData object
vessel_seg.GetClosedSurfaceRepresentation(segmentID, segmentVtkPolyData) # Get vtkPolyData representation of segment surface into segmentVtkPolyData variable
### Extract Centerline ###
extractLogic = ExtractCenterline.ExtractCenterlineLogic()
## Preprocess ##
inputSurfacePolyData = extractLogic.polyDataFromNode(vessel_seg, segmentID)
preprocessEnabled = True # (self._parameterNode.GetParameter("PreprocessInputSurface") == "true")
targetNumberOfPoints = 15000.0 # float(self._parameterNode.GetParameter("TargetNumberOfPoints"))
decimationAggressiveness = 4.0 #float(self._parameterNode.GetParameter("DecimationAggressiveness"))
subdivideInputSurface = False # (self._parameterNode.GetParameter("SubdivideInputSurface") == "true")
slicer.util.showStatusMessage(
"Preprocessing surface before centerline extraction..."
)
slicer.app.processEvents()
preprocessedPolyData = extractLogic.preprocess(
inputSurfacePolyData,
targetNumberOfPoints,
decimationAggressiveness,
subdivideInputSurface,
)
## Extract centerline ##
centerlineCurveNode = None
if centerlineCurveNode is None:
centerlineCurveNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsCurveNode", "Centerline curve")
slicer.util.showStatusMessage("Extracting centerline...")
slicer.app.processEvents() # force update
centerlinePolyData, voronoiDiagramPolyData = extractLogic.extractCenterline(
preprocessedPolyData, end_pts, curveSamplingDistance=0.001)
slicer.util.showStatusMessage(
"Generating curves and quantification results table..."
)
slicer.app.processEvents() # force update
centerlinePropertiesTableNode = None
extractLogic.createCurveTreeFromCenterline(
centerlinePolyData, centerlineCurveNode, centerlinePropertiesTableNode
)
if centerlineCurveNode.GetNumberOfControlPoints() == 2:
# Extraction had an error, likely due to too high decimation aggressiveness
# Try again
slicer.util.errorDisplay(
"Centerline generation failed, possibly due to decimationAggressiveness being too high."
)
Do you have any insights on what might be causing this display error? Moreover, how can I also generate the ‘Centerline Model’ (the model including all the centerline branches and usually displayed in green in the output from the ExtractCenterline extension)?
Many thanks in advance!
Rui