# vtkvoroni2d doesn't work probably

**URL:** https://discourse.vtk.org/t/vtkvoroni2d-doesnt-work-probably/10478
**Category:** Support
**Created:** [January 17, 2023, 9:53am UTC](https://discourse.vtk.org/t/vtkvoroni2d-doesnt-work-probably/10478 "2023-01-17T09:53:27Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![AndreAhmed](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andreahmed/32/6061_2.png) [@AndreAhmed](https://discourse.vtk.org/u/AndreAhmed)
#### Post date: [January 17, 2023, 9:53am UTC](https://discourse.vtk.org/t/vtkvoroni2d-doesnt-work-probably/10478/1 "2023-01-17T09:53:28Z")

</div>

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

 ![image](https://discourse.vtk.org/uploads/default/original/2X/9/9af64b845be1d5be3d3b92c77312ea537c53bb35.png)

```auto

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();

```

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [January 17, 2023, 12:53pm UTC](https://discourse.vtk.org/t/vtkvoroni2d-doesnt-work-probably/10478/2 "2023-01-17T12:53:07Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![AndreAhmed](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andreahmed/32/6061_2.png) [@AndreAhmed](https://discourse.vtk.org/u/AndreAhmed)
#### Post date: [January 17, 2023, 1:20pm UTC](https://discourse.vtk.org/t/vtkvoroni2d-doesnt-work-probably/10478/3 "2023-01-17T13:20:35Z")

</div>

@will.schroeder  
Have attached the polydata\_grid  
[final\_.obj](https://discourse.vtk.org/uploads/short-url/otSd3A8RbKiPwGboB5W1ho2zpIB.obj) (42.6 KB)

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [January 17, 2023, 2:19pm UTC](https://discourse.vtk.org/t/vtkvoroni2d-doesnt-work-probably/10478/4 "2023-01-17T14:19:14Z")

</div>

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

 ![image.png](https://discourse.vtk.org/uploads/default/original/2X/9/974392ee58e0d14e13d3426f419328a716971793.png)

---

<div class="post-metadata">

### Author: ![AndreAhmed](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andreahmed/32/6061_2.png) [@AndreAhmed](https://discourse.vtk.org/u/AndreAhmed)
#### Post date: [January 17, 2023, 2:25pm UTC](https://discourse.vtk.org/t/vtkvoroni2d-doesnt-work-probably/10478/5 "2023-01-17T14:25:01Z")

</div>

@will.schroeder can you please share the code ?

---

<div class="post-metadata">

### Author: ![AndreAhmed](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andreahmed/32/6061_2.png) [@AndreAhmed](https://discourse.vtk.org/u/AndreAhmed)
#### Post date: [January 17, 2023, 2:30pm UTC](https://discourse.vtk.org/t/vtkvoroni2d-doesnt-work-probably/10478/6 "2023-01-17T14:30:00Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [January 17, 2023, 2:43pm UTC](https://discourse.vtk.org/t/vtkvoroni2d-doesnt-work-probably/10478/7 "2023-01-17T14:43:14Z")

</div>

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](https://discourse.vtk.org/uploads/short-url/fD2WKFWnlJWg97Y2Hr1VJGMhUST.py) (3.6 KB)

[points.vtk](https://discourse.vtk.org/uploads/short-url/wSkBxNgFfrrXp8yfFiq8Azoanb9.vtk) (29.9 KB)

---

<div class="post-metadata">

### Author: ![AndreAhmed](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andreahmed/32/6061_2.png) [@AndreAhmed](https://discourse.vtk.org/u/AndreAhmed)
#### Post date: [January 17, 2023, 3:39pm UTC](https://discourse.vtk.org/t/vtkvoroni2d-doesnt-work-probably/10478/8 "2023-01-17T15:39:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [January 18, 2023, 11:42am UTC](https://discourse.vtk.org/t/vtkvoroni2d-doesnt-work-probably/10478/9 "2023-01-18T11:42:33Z")

</div>

vtkTriangleFilter will transform general polygons into triangles.
