Can't set Scissors parameter

Hello,

I am trying to access the Scissors effect from Segment Editor in my scripted module. When I run print(slicer.mrmlScene.GetFirstNodeByClass(“vtkMRMLSegmentEditorNode”)), I see that Scissors.Operation:EraseInside. I would like for the operation to be EraseOutside.

My code is:

segmentEditorWidget.setActiveEffectByName(“Scissors”)
effect = segmentEditorWidget.activeEffect()
effect.setParameter(“Operation”, “Erase Outside”)

I have also tried “EraseOutside” and 1 (since it’s a radio button), but none of these have changed the value of Operation. I looked at the source code for the scissors effect and I can’t figure out why this isn’t working. Any help would be appreciated. Thanks.

I didn’t change my code at all but suddenly effect.setParameter(“Operation”, “EraseOutside”) started working.

Another question: I want to trigger an event after the scissor cuts. I have tried adding an observer to the segment like so:
self.observerTag = self.segmentationNode.GetSegmentation().GetSegment(addedSegmentID).AddObserver(‘ModifiedEvent’, self.printStatus)

This seems to trigger when I apply a threshold but not when I cut with the scissors, I think since there isn’t an onApply() method for the Scissors effect. What would be the best way to trigger an event after a cutting occurs?

Thanks for any advice.

You can add an observer to segment changes. In your callback function you can check if the Scissors effect is active.

Why do you need to trigger an action after Scissors is used?

I’m trying to develop a streamlined method for determining breast volume from MRI. After scissoring I want to advance the program.

I’m having another issue that is related to the initial topic. I’m trying to use the Margin effect and I can’t seem to get it to Shrink instead of Grow. My code is:

    self.segmentEditorWidget.setActiveEffectByName("Margin")
    effect = self.segmentEditorWidget.activeEffect()
    effect.setParameter('Operation', 'Shrink')
    effect.self().onApply()

However, the margin grows instead of shrinks. What is unusual is when I print the SegmentEditorNode I see “Margin.Operation:Shrink” yet the margin is clearly growing. Any advice?

I’ve added documentation for all segment editor effect parameters. See Margin effect parameters here: https://slicer.readthedocs.io/en/latest/developer_guide/modules/segmenteditor.html#margin

I thought I was cheating when I set MarginSizeMm negative but I see now that is the proper way. Thanks!

1 Like