will do the trick. The problem is that when I call that I get:
MemoryError: std::bad_alloc: bad allocation
It looks like the label map I get inside my effect on an empty segment has zero dimensions:
label_map = self.scriptedEffect.maskLabelmap()
I assume that would be the case even if there were something in the segment already and I was drawing outside of the bounds of that mask?
Is there a way to create a mask that isn’t zero length from an empty segment? Or how should I be going about the task of drawing these vtkPolygons into a segment? I’d like to be able to have the system draw these in and then let the user clean them up a bit in one workflow.
I wasn’t able to make this work but came up with a different approach. I figured I’d post this for the next person that is tearing their hair out over this.
First, get the points out of the vtkPolygons:
return [list(vtk_polygon.GetPoints().GetPoint(i)) for i in
Then save those points as Markups:
def save_markup_points(markup_name, points):
markupsNode = slicer.mrmlScene.GetFirstNodeByName(markup_name)
if markupsNode is None:
markupsNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsFiducialNode")
for pt in points:
This indicates that you might have tried to use the legacy Editor module. It will be probably removed from Slicer5, so I would recommend not to rely on it anymore.
The approach that you described should work nicely for convex (or slightly concave) shapes. You don’t need to create a temporary markups module, you can use a lower level API - vtkSlicerMarkupsToModelClosedSurfaceGeneration - to generate vtkPolyData from vtkPoints.
If you need to work with concave shapes then you can save your planar contours in a polydata and set it in a segmentation node as “planar contour” representation. Segmentation infrastructure automatically converts it to all other representations (binary labelmap, closed surface, ribbon, etc.) as needed. The converters are provided by SlicerRT extension (since this planar contour representation is still quite commonly used for radiotherapy and not used much elsewhere), so you will need to install this extension.