# Decimation

**URL:** https://discourse.vtk.org/t/decimation/2763
**Category:** Support
**Created:** [March 5, 2020, 6:13pm UTC](https://discourse.vtk.org/t/decimation/2763 "2020-03-05T18:13:19Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![steersteer](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@steersteer](https://discourse.vtk.org/u/steersteer)
#### Post date: [March 5, 2020, 6:13pm UTC](https://discourse.vtk.org/t/decimation/2763/1 "2020-03-05T18:13:19Z")

</div>

Hi,

I’m trying to decimate a mesh because I have far too many triangles for the mesh to be useable.

 ![Annotation 2020-03-05 175928](https://discourse.vtk.org/uploads/default/original/2X/e/e0363402e6c436aa1643e4cce00c9a3700771671.png) ![Annotation 2020-03-05 175955](https://discourse.vtk.org/uploads/default/original/2X/7/70a8cfd6304c606dddbbb9afba73c8be16b27c7b.png)  
So far I have been using:

```
def Decimation(meshname):
    reader = vtk.vtkSTLReader()
    reader.SetFileName(meshname)
    reader.Update()
    polydata = reader.GetOutput()

    print("Before ",meshname, " decimation\n"
      "-----------------\n"
      "There are " + str(polydata.GetNumberOfPoints()) + "points.\n"
      "There are " + str(polydata.GetNumberOfPolys()) + "polygons.\n")

    decimate = vtkDecimatePro()
    decimate.SetInputData(polydata)
    decimate.SetTargetReduction(.90)
    decimate.PreserveTopologyOn()
    decimate.Update()

    decimatedPoly = vtkPolyData()
    decimatedPoly.ShallowCopy(decimate.GetOutput())

    print("After ",meshname, " decimation \n"
          "-----------------\n"
          "There are " + str(decimatedPoly.GetNumberOfPoints()) + "points.\n"
          "There are " + str(decimatedPoly.GetNumberOfPolys()) + "polygons.\n")

    stlWriter = vtkSTLWriter()
    stlWriter.SetFileName(meshname)
    stlWriter.SetFileTypeToBinary()
    stlWriter.SetInputConnection(decimate.GetOutputPort())
    stlWriter.Write()

Decimation("Output\\Meshes\\Tmesh.stl")
Decimation("Output\\Meshes\\Cmesh.stl")

```

This seems to work though the resultant mesh is very ugly:

 ![Annotation 2020-03-05 180950](https://discourse.vtk.org/uploads/default/original/2X/c/c2d49026878bae64d209a233195756e5f7590ce1.png)

Is there a way to make the mesh more consistent?

---

<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: [March 6, 2020, 4:59am UTC](https://discourse.vtk.org/t/decimation/2763/2 "2020-03-06T04:59:30Z")

</div>

Do you like vtkQuadricDecimation results better?
