# Convert Vertex and Index Buffers to vtkPolyData for vtkDecimatePro

**URL:** https://discourse.vtk.org/t/convert-vertex-and-index-buffers-to-vtkpolydata-for-vtkdecimatepro/4057
**Category:** Support
**Created:** [August 24, 2020, 10:51am UTC](https://discourse.vtk.org/t/convert-vertex-and-index-buffers-to-vtkpolydata-for-vtkdecimatepro/4057 "2020-08-24T10:51:57Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Robin](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/r/e5b9ba/32.png) [@Robin](https://discourse.vtk.org/u/Robin)
#### Post date: [August 24, 2020, 10:51am UTC](https://discourse.vtk.org/t/convert-vertex-and-index-buffers-to-vtkpolydata-for-vtkdecimatepro/4057/1 "2020-08-24T10:51:58Z")

</div>

Hello,

I’m trying to decimate a mesh using vtkDecimatePro. The mesh is represented as a vertex list with a list of indices referencing the corresponding vertices.  
E.g:  
Vertices: {0f, 0f, 0f}, {1f, 0f, 0f}, {0f, 1f, 0f}, {1f, 1f, 0f}  
Indices:0, 1, 2, 1, 3, 2  
Which should result in a quad consisting of two triangles.

When I try to use the vtkDecimatePro Algorithm it says “DecimatePro does not accept polygons that are not triangles.”

I looked through the source of VTK and it turns out that my Polygons are not Homogenous:  
Line 188 in vtkDecimatePro.cxx:  
const vtkIdType cellSize = input-\>GetPolys()-\>IsHomogeneous();

Every advice how to convert my data into a vtk compatible data format that I can use with the vtkDecimatePro algorithm is appreciated.

What I tried to do is the following:

```
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
	vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();

	cells->InsertNextCell(indexCount);
	for (int i = 0; i < indexCount / 3; ++i) {
            //Add every Vertex to the Points-List
		points->InsertNextPoint(
                vertices[indices[i * 3 + 0]], 
                vertices[indices[i * 3 + 1]], 
                vertices[indices[i * 3 + 2]]);
            //Specify that the next entry is a triangle (?)
		cells->InsertNextCell(3);
		cells->InsertCellPoint(i * 3 + 0);
		cells->InsertCellPoint(i * 3 + 1);
		cells->InsertCellPoint(i * 3 + 2);
	}

	vtkSmartPointer<vtkPolyData> polydata =
		vtkSmartPointer<vtkPolyData>::New();
	polydata->SetPoints(points);
	polydata->SetPolys(cells);
vtkSmartPointer<vtkDecimatePro> decimate = vtkSmartPointer<vtkDecimatePro>::New();
decimate->SetInputData(polydata);
decimate->SetTargetReduction(0.1f);
decimate->PreserveTopologyOn();
decimate->Update();
```

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [August 24, 2020, 3:36pm UTC](https://discourse.vtk.org/t/convert-vertex-and-index-buffers-to-vtkpolydata-for-vtkdecimatepro/4057/2 "2020-08-24T15:36:21Z")

</div>

Your code looks good to me. I would recommend to step with your debugger into `IsHomogeneous` to see what kind of inhomogeneity it finds.
