Skip to content

Instantly share code, notes, and snippets.

@pieper
Created June 3, 2022 20:57
Show Gist options
  • Save pieper/e4ca5e4c753c5ed6c61656d25b93402c to your computer and use it in GitHub Desktop.
Save pieper/e4ca5e4c753c5ed6c61656d25b93402c to your computer and use it in GitHub Desktop.
Load a ply point cloud in Slicer
"""
filePath = "/Users/pieper/slicer/latest/SlicerMorph/loadPointCloud.py"
modelPath = "/opt/tmp/georeferenced_model.vtk"
exec(open(filePath).read())
"""
modelNode = slicer.util.loadModel(modelPath)
modelArray = slicer.util.arrayFromModelPoints(modelNode)
pointSource = vtk.vtkPointSource()
pointSource.SetNumberOfPoints(len(modelArray))
pointSource.Update()
pointPolyData = pointSource.GetOutputDataObject(0)
modelPolyData = modelNode.GetPolyData()
pointPolyData.GetPoints().DeepCopy(modelPolyData.GetPoints())
pointPolyData.GetPointData().DeepCopy(modelPolyData.GetPointData())
modelNode.SetAndObservePolyData(pointPolyData)
modelDisplayNode = modelNode.GetDisplayNode()
modelDisplayNode.SetRepresentation(modelDisplayNode.PointsRepresentation)
modelDisplayNode.SetPointSize(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment