I’m new to creating modules and my programming skills are rather basic, so I encountered problems in loading segmentation from subdirectories, and in exporting and saving the mesh models.
The first issue looks like following: I want to load segmentations named ‘_repair.seg.nrrd’ from multiple subdirectories. What I got so far is:
TypeError: ExportAllSegmentsToModelHierarchy argument 1: method requires a VTK object.
I would be really grateful for your help, as I lack knowledge to fix this (probably really trivial) problem. I have a next piece of code that looks as below. However, I don’t even know if it works, because of the previous error I mentioned.
# Make sure surface mesh cells are consistently oriented
surfaceMesh = MasterModelNode.GetClosedSurfaceRepresentation(segmentID)
normals = vtk.vtkPolyDataNormals()
surfaceMesh = normals.GetOutput()
# Save as PLY file
writer = vtk.vtkSTLWriter()
#### name should be: name of segmentation .ply
file_new = dir_path + "/" + filename + "/" + whichOP + "/CT/" + filename + segmentName + ".ply"
writer.SetFileName(file_new) # set file name
# Clean up
segmentEditorWidget = None
So I used slicer.util.loadSegmentation(filename, returnNode=False) as you suggested but the error remains - ‘method requires a VTK object’.
Also I need to export the mesh surface as .ply file.
Is it possible that I miss a line about a node, like getNode(‘Segmentation’)?