-
Notifications
You must be signed in to change notification settings - Fork 521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support rendering point clouds #7646
Comments
@dzenanz, in my view there are two aspects to consider in this issue: 1) Representing clouds of pointsYou are correct. When a model does not have cells, it won't be rendered. This happens even if you try to set the representation to def addSingleVertexTopology(modelNodeName):
# Get the model node by name
modelNode = slicer.util.getNode(modelNodeName)
if not modelNode:
print("Model node not found.")
return
# Access the polydata of the model
polyData = modelNode.GetPolyData()
if not polyData:
print("No polydata found in the model node.")
return
# Ensure there are points to work with
if polyData.GetNumberOfPoints() == 0:
print("The model has no points.")
return
# Create a vtkPolyVertex that includes all points
polyVertex = vtk.vtkPolyVertex()
polyVertex.GetPointIds().SetNumberOfIds(polyData.GetNumberOfPoints())
for i in range(polyData.GetNumberOfPoints()):
polyVertex.GetPointIds().SetId(i, i)
# Create a new vtkCellArray and add the single polyVertex to it
vertices = vtk.vtkCellArray()
vertices.InsertNextCell(polyVertex)
# Update the verts in polyData to only include the single polyVertex
polyData.SetVerts(vertices)
# Notify the model node and its display node, if any, to update
modelNode.Modified()
displayNode = modelNode.GetDisplayNode()
if displayNode:
displayNode.Modified()
def removeCellsFromModelNode(modelNodeName):
# Get the model node by name
modelNode = slicer.util.getNode(modelNodeName)
if modelNode is None:
print("Model node not found.")
return
# Get the polydata from the model node
polyData = modelNode.GetPolyData()
if polyData is None:
print("No polydata found in the model node.")
return
# Create a new vtkPolyData object without cells
newPolyData = vtk.vtkPolyData()
newPolyData.SetPoints(polyData.GetPoints()) # Copy points to the new polydata
# Update the model node with the new polydata
modelNode.SetAndObservePolyData(newPolyData)
print("All cells have been removed from the model.") 2 Utilities to extract/create clouds of pointsMaybe we could add a new |
@RafaelPalomar I forgot to share another function I created (a poor-man's version of your): def addVerticesToPolyData(pointCloudName):
"""Add vertices to specified polydata to make the point cloud visible"""
pc = slicer.util.getNode(pointCloudName)
polydata = pc.GetPolyData()
vertices = vtk.vtkCellArray()
cell_ids = [0]
for i in range(polydata.GetPoints().GetNumberOfPoints()):
cell_ids[0] = i
vertices.InsertNextCell(1, cell_ids)
polydata.SetVerts(vertices) |
Is your feature request related to a problem? Please describe.
Loading a .ply file as a model works, but nothing is rendered.
Describe the solution you'd like
When a model has points, bot no cells (vertices, lines, polygons, tetrahedra), some implicit vertices (one per point) should be assumed, so that a point cloud is rendered. Ideally, there would be a button in the user interface to toggle this on/off.
Describe alternatives you've considered
As a workaround, I have come up with a function below, based on this code. It works, but it is pretty hacky and substantially slower (due to ~15x increase in number of vertices).
Additional context
samplePointCloud.zip
The text was updated successfully, but these errors were encountered: