vtkPolyDataConnectivityFilter bug?

Hi,

Why Case 2a, Case 2b and Case 2c do not have the same number of points? Is this a bug?

Example below:

# points
points = vtk.vtkPoints()
points.InsertNextPoint(0, 0, 10)
points.InsertNextPoint(2, 0, 5)
points.InsertNextPoint(0, 0, 0)
points.InsertNextPoint(14, 5, -5)
points.InsertNextPoint(40, 0, 12)
targetPoint = (10, -4, 8)
points.InsertNextPoint(targetPoint)

# create a polydata object
polyData = vtk.vtkPolyData()
polyData.SetPoints(points)
# for every control point create a sphere
sphereSource = vtk.vtkSphereSource()
sphereSource.SetRadius(1.0)
sphereSource.SetThetaResolution(16)
sphereSource.SetPhiResolution(16)
sphereSource.Update()
spheres = vtk.vtkGlyph3D()
spheres.SetInputData(polyData)
spheres.SetSourceConnection(sphereSource.GetOutputPort())
spheres.Update()
nPts = spheres.GetOutput().GetNumberOfPoints()
nCells = spheres.GetOutput().GetNumberOfCells()
print("")
print("Case 1")
print("Spheres")
print("nPts: {nPts}, nCells: {nCells}".format(nPts=nPts, nCells=nCells))
print("")

# only one sphere
oneSphere = vtk.vtkPolyDataConnectivityFilter()
oneSphere.SetInputData(spheres.GetOutput())
oneSphere.SetExtractionModeToClosestPointRegion()
oneSphere.SetClosestPoint(targetPoint)
oneSphere.Update()
nPts = oneSphere.GetOutput().GetNumberOfPoints()
nCells = oneSphere.GetOutput().GetNumberOfCells()
print("Case 2a")
print("Closest point region (i.e. one sphere)")
print("nPts: {nPts}, nCells: {nCells}".format(nPts=nPts, nCells=nCells))
print("")

# should only be one sphere (i.e. less points, less cells)
spheresOneByOne = vtk.vtkPolyDataConnectivityFilter()
spheresOneByOne.SetInputData(spheres.GetOutput())
spheresOneByOne.SetExtractionModeToSpecifiedRegions()
spheresOneByOne.InitializeSpecifiedRegionList()
spheresOneByOne.AddSpecifiedRegion(1)
spheresOneByOne.Update()
nPts = spheresOneByOne.GetOutput().GetNumberOfPoints()
nCells = spheresOneByOne.GetOutput().GetNumberOfCells()
print("Case 2b")
print("2nd region (i.e. one sphere)")
print("nPts: {nPts}, nCells: {nCells}".format(nPts=nPts, nCells=nCells))
print("")

# should only be one sphere (i.e. less points, less cells)
spheresOneByOne_2ndTry = vtk.vtkPolyDataConnectivityFilter()
spheresOneByOne_2ndTry.SetInputData(spheres.GetOutput())
spheresOneByOne_2ndTry.SetExtractionModeToSpecifiedRegions()
spheresOneByOne_2ndTry.InitializeSpecifiedRegionList()
spheresOneByOne_2ndTry.DeleteSpecifiedRegion(0)
spheresOneByOne_2ndTry.AddSpecifiedRegion(1)
spheresOneByOne_2ndTry.DeleteSpecifiedRegion(2)
spheresOneByOne_2ndTry.DeleteSpecifiedRegion(3)
spheresOneByOne_2ndTry.DeleteSpecifiedRegion(4)
spheresOneByOne_2ndTry.DeleteSpecifiedRegion(5)
spheresOneByOne_2ndTry.Update()
nPts = spheresOneByOne_2ndTry.GetOutput().GetNumberOfPoints()
nCells = spheresOneByOne_2ndTry.GetOutput().GetNumberOfCells()
print("Case 2c")
print("explicit 2nd region (i.e. one sphere)")
print("nPts: {nPts}, nCells: {nCells}".format(nPts=nPts, nCells=nCells))
print("")

Thank you

This subsequent filter solves the problem:

cleanPolyData = vtk.vtkCleanPolyData()
cleanPolyData.SetInputData(spheresOneByOne.GetOutput())
cleanPolyData.Update()
nPts = cleanPolyData.GetOutput().GetNumberOfPoints()
nCells = cleanPolyData.GetOutput().GetNumberOfCells()
print("Case 3")
print("Cleaned (i.e. one sphere)")
print("nPts: {nPts}, nCells: {nCells}".format(nPts=nPts, nCells=nCells))
print("")