Using vtk for python, when using vtkDecimatePolylineFilter, the output has the same number of points (and lines) as the input.
Here below a minimal example supposed decimate from 30 to 10 points (target reduction of 0.667). But there is still 30 points in the output.
Am I using this filter wrong?
Thanks
import vtk
import numpy as np
# Create example data with 30 points and 30 lines
n = 30
n_down = 10
points = vtk.vtkPoints()
for i in range(int(n/2)):
t = (4*i-n)/n
points.InsertNextPoint(t, np.cos(t), 0)
for i in range(int(n/2)):
t = -(4*i-n)/n
points.InsertNextPoint(t, -np.cos(t), 0)
lines = vtk.vtkCellArray()
for i in range(n-1):
line = vtk.vtkLine()
line.GetPointIds().SetId(0, i)
line.GetPointIds().SetId(1, i + 1)
lines.InsertNextCell(line)
line.GetPointIds().SetId(0, i + 1)
line.GetPointIds().SetId(1, 0)
lines.InsertNextCell(line)
poly = vtk.vtkPolyData()
poly.SetPoints(points)
poly.SetLines(lines)
# Decimation
down_factor = (n - n_down) / n
decimator = vtk.vtkDecimatePolylineFilter()
decimator.SetInputData(poly)
decimator.SetTargetReduction(down_factor)
decimator.Update()
poly_down = decimator.GetOutput()
# Check number of points and lines in the downsampled poly
print(f"Original Number of Points: {poly.GetNumberOfPoints()}")
print(f"Original Number of Lines: {poly.GetNumberOfLines()}")
print(f"Downsampled Number of Points: {poly_down.GetNumberOfPoints()}")
print(f"Downsampled Number of Lines: {poly_down.GetNumberOfLines()}")
Original Number of Points: 30
Original Number of Lines: 30
Downsampled Number of Points: 30
Downsampled Number of Lines: 30