vtkvoroni2d doesn't work probably

I’m trying to generate a grid of voroni2D, here is the code, and the output, is really weird


int i = 0;
	while (i < 1000)
	{
		float pt_x = rand_FloatRange(0, 1);
		float pt_y = rand_FloatRange(0, 1);
		points_voronoi->InsertPoint(i, pt_x, pt_y, 0);
		
		i++;
	}
	points_voronoi->InsertNextPoint(0.0, 0.0, 0);
	points_voronoi->InsertNextPoint(1, 0.0, 0);
	points_voronoi->InsertNextPoint(1, 1, 0);

	points_voronoi->InsertNextPoint(0.0, 1, 0);

	vtkNew<vtkPolyData> polydata_grid;
	polydata_grid->SetPoints(points_voronoi);


	vornoi_2d = vtkSmartPointer<vtkVoronoi2D>::New();
	vornoi_2d->SetInputData(polydata_grid);
	vornoi_2d->SetPointOfInterest(-1);
	vornoi_2d->SetGenerateVoronoiFlower(1);
	vornoi_2d->SetMaximumNumberOfTileClips(3000);
	//vornoi_2d->GetLocator()->SetNumberOfPointsPerBucket(2);
	vornoi_2d->Update();

	vtkNew<vtkPolyData> polydata;

	// Add the points and quads to the dataset
	polydata->SetPoints(polydata_grid->GetPoints());
	polydata->SetPolys(vornoi_2d->GetOutput()->GetPolys());
	vtkNew<vtkOBJWriter> plyWriter;

	plyWriter->SetFileName("final_.obj");
	plyWriter->SetInputData(polydata);
	plyWriter->Write();

I’ll take a look. It would greatly help if you could write out the polydata_grid into a file and send it, since you are generating random coordinates which I probably can’t duplicate. Also, disable GenerateVoronoiFlower which is meant for debugging purposes.

@will.schroeder
Have attached the polydata_grid
final_.obj (42.6 KB)

Works for me (see image). I am wondering if the plyWriter assumes that the input is triangles. The output of voronoi is convex polygons.

@will.schroeder can you please share the code ?

why do I need to triangulate ? can’t I just output a voroni mesh ? I can’t use VTK visualization, so I need to ouput the voroni 2d mesh into something.

v.py is a hacked version of a test script, no guarantee that it is anywhere near good code. Your points were converted to legacy VTK format so I could more easily read them.

v.py (3.6 KB)

points.vtk (29.9 KB)

@will.schroeder Do you know a solution If I want to save 2D voroni into obj,stl file ?

vtkTriangleFilter will transform general polygons into triangles.