Obtain STL information without exporting segment

Hi,

I have a Python script that works with .stl files. In order to speed things up in Slicer, I would like to get the information from the .stl file without having to export it. Is it possible?

Thanks :grinning:

I guess you mean you would want to export to file without exporting to model node. You can do that by-right-clicking “Export to files…” function (in drop-down menu of the green right-arrow button in Segment Editor).

This feature is avaiable in the method: slicer.vtkSlicerSegmentationsModuleLogic.ExportSegmentsClosedSurfaceRepresentationToFiles()

1 Like

Hi!

I have created this function from information of different forums to get vertices and faces of segmentation in Slicer directly as numpy arrays. It works thanks to the module pyvista.


def polydata(segmentation = 'Segmentation', segment = 'Segment_1'):
    segmentationNode = slicer.util.getNode(segmentation)
    segmentId = segmentationNode.GetSegmentation().GetSegmentIdBySegmentName(segment)
    
    superficie = vtk.vtkPolyData()
    slicer.vtkSlicerSegmentationsModuleLogic.GetSegmentClosedSurfaceRepresentation(segmentationNode, segmentId, superficie, True)
    
    return pyvista.PolyData(superficie)

Is this what you are looking for?

1 Like

That’s it!

Grazas :slight_smile: