Hi!,
I have around 2000 hair like strands in 3d space. All of those strands are actually loaded from a single vtk file (size k) and the loaded polydata has number of points n.
When I use vtkPolyDataConnectivityFilter, I am able to successfully extract and visualize one strand separately. I tried the simple LargestRegion extraction and it is able to extract the largest strand and I was able to render it separately. However, when I query the number of points on the extracted data (filter output), I am getting n as the value. I tried to save the filter output (one strand), but the written file has the same size as that of the original 2000 strand data. Then I tried opening the saved file in paraview. It showed only one strand but the data behind(number of points) is as big as the original 2000. Is this a problem with the filter? If not, how can I solve this problem?
Probably the connectivity filter just deletes cells and leaves points untouched. This is often useful, because your point IDs remain the same as in the original data set. If you want to remove unused points then you can clean the polydata.
Dear Andras!, Thank you for your reply! I tried cleaning polydata. It removed some points but the math is still wrong. I tried something simple to verify this. My scene has now a sphere(#vertices=1024) and a torus(#vertices=640). I am getting a perfect total 1664 when querying number of points before applying vtkPolyDataConnectivityFilter. When I am using the connectivityFilter followed by a vtkCleanPolyDataFilter, I am getting the number of points as 1610 and 1610.
I used the following code to print the number of points. The loop runs two times and prints 1610.
for region in range(nregions):
conn.InitializeSpecifiedRegionList()
conn.AddSpecifiedRegion(region)
conn.Update()
p = vtk.vtkPolyData()
conn.DeleteSpecifiedRegion(region)
p.DeepCopy(conn.GetOutput())
cleanPolyData = vtk.vtkCleanPolyData()
cleanPolyData.SetInputData(p)
cleanPolyData.Update()
print("Number of points in surface", cleanPolyData.GetOutput().GetNumberOfPoints())
polydata_collection.append(p)
Even though the filter is doing great in separating and counting the disjoint surfaces, these extra point data is actually costing me memory. Am I missing something here.
Thanks in advance!
It’s hard to interpret the code, as the indentation is off. Make sure you quote Python code like this:
Please provide a complete example, starting from input data generation.
Hi Lassoan, I got it working now. The cleanPolyData Filter works as you mentioned. I will mark it as a solution. Thanks.