# Convert Vertex and Index Buffers to vtkPolyData for vtkDecimatePro

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

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