Generated points are not reduced when sampling spacing increases

2D Interior Area.vtp (83.3 KB)
I want to generate points from the above vtp file, I don’t know how to choose the suitable distance parameter, when I increase the distance it works at the beginning, but the points generated are not reduce when reach the 11166 number, as the picture below shows. this number is too big for me.


here is my code:

void sampleFromPolylineTest()
{
	
	vtkNew<vtkXMLPolyDataReader> reader;
	reader->SetFileName("2D Interior Area.vtp");
	reader->Update();

	double bounds[6];
	reader->GetOutput()->GetBounds(bounds);
	double range[3];
	for (int i = 0; i < 3; ++i)
	{
		range[i] = bounds[2 * i + 1] - bounds[2 * i];
	}
	std::cout << "Range: " << range[0] << ", " << range[1] << ", " << range[2]
		<< std::endl;
	std::cout << "# of original points: " << reader->GetOutput()->GetNumberOfPoints()
		<< std::endl;
	vtkNew<vtkPolyDataPointSampler> sample;
	sample->SetInputData(reader->GetOutput());
	double distance = 150.0;
	sample->SetDistance(distance);
	sample->GenerateEdgePointsOff();
	sample->GenerateVertexPointsOff();
	/*sample->GenerateVerticesOff();
	sample->GenerateInteriorPointsOff();*/
	sample->SetPointGenerationModeToRandom();
	sample->Update();
	std::cout << "# of points after sampling: " << distance << ";"
		<< sample->GetOutput()->GetNumberOfPoints() << std::endl;

	vtkNew<vtkXMLPolyDataWriter> writer;
	writer->SetFileName("sample.vtp");
	writer->SetDataModeToBinary();
	writer->SetCompressionLevel(9);
	writer->SetInputData(sample->GetOutput());
	writer->Write();
}

Very grateful for your help!

Point sampling filter is for generating additional points. I don’t think it can reduce the number of points - see documentation.

Poisson dusk sampler can also add random samples (see Selecting random points of a PolyData (Stratified sampling)) but I don’t think it can reduce the number of points (simplify the mesh) either.

There are decimation filters in VTK that you can use to reduce the number of points, but the result is not uniform, but it will strive to preserve all details with less points, so sampling will be sparse in flat regions.

Unfortunately, VTK currently does not have a filter for uniform resampling, but you can use the ACVD algorithm for that, for example using the pyacvd package.

I have posted a feature request here for making ACVD available in VTK - hopefully eventually it will be added at some point.