# how to resolve the issue in vtkEuclideanClusterExtraction?

**URL:** https://discourse.vtk.org/t/how-to-resolve-the-issue-in-vtkeuclideanclusterextraction/14477
**Category:** Support
**Tags:** python
**Created:** [August 25, 2024, 3:31pm UTC](https://discourse.vtk.org/t/how-to-resolve-the-issue-in-vtkeuclideanclusterextraction/14477 "2024-08-25T15:31:00Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![erya123](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/e/dec6dc/32.png) [@erya123](https://discourse.vtk.org/u/erya123)
#### Post date: [August 25, 2024, 3:31pm UTC](https://discourse.vtk.org/t/how-to-resolve-the-issue-in-vtkeuclideanclusterextraction/14477/1 "2024-08-25T15:31:00Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [August 26, 2024, 1:49pm UTC](https://discourse.vtk.org/t/how-to-resolve-the-issue-in-vtkeuclideanclusterextraction/14477/2 "2024-08-26T13:49:59Z")

</div>

Hello,

Please, enclose your code between a ```python and a ```. This improves readability a lot.

best,

PC
