I am currently writing a custom segment editor effect. There are two cases:
- When a segment already has contents (e.g. from a thresholding step) I would like to modify the segment based on those contents.
- My effect also works on newly generated segments.
The first case works. For the latter case, in the UI I do this:
- Make sure that the master volume is correctly set
- Add a new Segment
- Click the Apply button of my effect
In code, I have:
segmentEditorNode = self.scriptedEffect.parameterSetNode() segmentationNode = segmentEditorNode.GetSegmentationNode() currentSegmentId = segmentEditorNode.GetSelectedSegmentID()
- Then, I call
self.scriptedEffect.defaultModifierLabelmap(), which I thought would initialize the labelmap to the geometry of the master volume (via
bool qMRMLSegmentEditorWidgetPrivate::resetModifierLabelmapToDefault()), however
- the call to
segmentArray = slicer.util.arrayFromSegmentInternalBinaryLabelmap(segmentationNode, currentSegmentId)fails with:
Traceback (most recent call last): File "D:/Misc/TestProjects/SegmentationTest/SegmentationTest/SegmentationTest/Lib/SegmentEditorEffect.py", line 152, in onApply segmentArray = slicer.util.arrayFromSegmentInternalBinaryLabelmap(segmentationNode, currentSegmentId) File "D:\Apps\Slicer 4.11.0-2020-02-26\bin\Python\slicer\util.py", line 1201, in arrayFromSegmentInternalBinaryLabelmap narray = vtk.util.numpy_support.vtk_to_numpy(vimage.GetPointData().GetScalars()).reshape(nshape) File "D:\Apps\Slicer 4.11.0-2020-02-26\bin\Lib\site-packages\vtkmodules\util\numpy_support.py", line 216, in vtk_to_numpy typ = vtk_array.GetDataType() AttributeError: 'NoneType' object has no attribute 'GetDataType'
What do I have to do to determine whether a segment already has contents, and, if not, to correctly initialize it according to the geometry of the master volume?
Thanks again for your help!