Observe modified segment

Hello community,
I am trying to add an observer to a segmentation node to keep track of any modifications to any segment (by modifications I mean manual changes to the contouring). The idea is to have a marker of any modifications so if the user changes subject (for which I have a QComboBox in my module), I can prompt the user to save before changing patients. This is to avoid any accidental subject changes and losing unsaved work.

I have been trying many different things. Something close is this:

segmentationNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLSegmentationNode') segmentationNode.AddObserver(segmentationNode.GetSegmentation().SegmentModified,onSegmentModified)

But this only activates onSegmentModified() when I add, remove, rename, change color of, etc… a Segment. What is the signal produced when the actual contouring changes? Is this something that can be done?
Thanks,
Eric

1 Like

SegmentModified event is invoked if segment metadata is modified. You need to observe MasterRepresentationModified or RepresentationModified to get notified about segmentation content changes. See list of events here.

4 Likes

Thank you!
This perfectly answers my question. And thank for the list of events!

Eric

1 Like