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!