I want to extract xyz co-ordinates of point cloud of a segment created in Slicer. I have tried saving a segment as a .ply file and then opened the same in Meshlab and saved it as a .xyz file to get the physical co-ordinates of all the points. That works. I wanted to know if there is a direct way to get the co-ordinates of points directly from 3D Slicer?
Yes, you can access the coordinates directly. For example, this code snippet gives you point coordinates in a numpy array:
segmentationNode=getNode('Segmentation') segmentId = segmentationNode.GetSegmentation().GetNthSegmentID(0) segmentPolyData=segmentationNode.GetClosedSurfaceRepresentation(segmentId) import vtk.util.numpy_support pointData = segmentPolyData.GetPoints().GetData() pointCoordinates = vtk.util.numpy_support.vtk_to_numpy(pointData)
Connectivity between points is very important, as often it is very difficult to accurately reconstruct a surface from just the point cloud. So, in general, I would recommend to export the full mesh (triangle cell point IDs as well), and not just points coordinates.