After running the following code, why does the statement print(f"Cluster {cluster_index} has {num_points} points.") output the coordinates of the 50 points from the first iteration again during the second iteration of the loop for cluster_index in range(num_clusters)?
code:
import vtk
import numpy as np
sphere1 = vtk.vtkSphereSource()
sphere1.SetCenter(0, 0, 0)
sphere1.SetRadius(1)
sphere1.Update()
sphere2 = vtk.vtkSphereSource()
sphere2.SetCenter(10, 0, 0)
sphere2.SetRadius(1)
sphere2.Update()
append_filter = vtk.vtkAppendPolyData()
append_filter.AddInputData(sphere1.GetOutput())
append_filter.AddInputData(sphere2.GetOutput())
append_filter.Update()
normals = vtk.vtkPolyDataNormals()
normals.SetInputData(append_filter.GetOutput())
normals.SetFeatureAngle(30.0)
normals.Update()
polydata = vtk.vtkPolyData()
polydata.SetPoints(append_filter.GetOutput().GetPoints())
cluster = vtk.vtkEuclideanClusterExtraction()
cluster.SetInputData(append_filter.GetOutput())
cluster.SetRadius(0.5)
cluster.SetExtractionModeToSpecifiedClusters()
cluster.Update()
num_clusters = cluster.GetNumberOfExtractedClusters()
for cluster_index in range(num_clusters):
cluster.AddSpecifiedCluster(cluster_index)
cluster.Update()
num_points = cluster.GetOutput().GetNumberOfPoints()
print(f"Cluster {cluster_index} has {num_points} points.")
for i in range(num_points):
coords = [0.0, 0.0, 0.0]
cluster.GetOutput().GetPoint(i, coords)
print(f"Point ID: {i}, Coordinates: {coords}")
why does the results of the second iteration contain the content of the first one?