Looping Over Segmentation Algorithm Targets Wrong Segment

We have got our segmentation algorithm working! Now we are looping over it to allow doctors to segment multiple vertebrae. Whenever we run our code in a for loop, the seed around the second point, F-2(purple in the diagram on the yellow slice), works. However, when we run the effect function, the algorithm works perfectly fine but adds the segmented piece to the first segmentation. Does anyone have any ideas why?

We think the issue is in these lines of code when looping:

segmentationNode.AddSegmentFromClosedSurfaceRepresentation(lumbarSeed.GetOutput(), “Lumbar-” + str(x+1), [random(), random(), random()])
segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
segmentEditorWidget.setMRMLScene(slicer.mrmlScene)
segmentEditorNode = slicer.vtkMRMLSegmentEditorNode()
slicer.mrmlScene.AddNode(segmentEditorNode)
segmentEditorWidget.setMRMLSegmentEditorNode(segmentEditorNode)
segmentEditorWidget.setSegmentationNode(segmentationNode)
segmentEditorWidget.setMasterVolumeNode(masterVolumeNode)

1 Like

This is exactly how the effect is supposed to work: incrementally add more parts to the current segment with each click.

If you want to create a separate segment for each click then create and select a new segment before each click.

1 Like

We also looked in the class reference linked below but we did not find anything.

https://apidocs.slicer.org/master/classqMRMLSegmentEditorWidget.html#a07f1984ccaea1b8e49245d4b79be4382