pyvista / pyvista-support

[moved] Please head over to the Discussions tab of the PyVista repository
https://github.com/pyvista/pyvista/discussions
60 stars 4 forks source link

how to use decimate function? #379

Closed ghazalbangash closed 3 years ago

ghazalbangash commented 3 years ago

Hi there i want to reduce the triangles of my mesh and tried using decimate function but it doesnt seem to bring any change in the number of cells of my mesh here is my code:

import pyvista as pv   
mesh = pv.read("bunny.stl")
mesh = pv.PolyData(mesh)
p = pv.Plotter()

p.add_mesh(mesh,show_edges=True,color=True)
print(mesh.n_cells)
dec_sphere = mesh.decimate(0.5, volume_preservation=True)
print(mesh.n_cells)

am i using it wrong?cause i have the same issue using subdivide

akaszynski commented 3 years ago

Hello,

There's a minor problem with your example. Since you're not updating the mesh in-place, you have to use the returned value of decimate:

import pyvista as pv
from pyvista import examples
bunny = examples.download_bunny()
dec_bunny = bunny.decimate(0.9)

p = pv.Plotter(shape=(2, 1))
p.add_mesh(bunny, show_edges=True)
p.camera_position = 'xy'
p.camera.zoom(2)
p.subplot(1, 0)
p.add_mesh(dec_bunny, show_edges=True)
p.camera_position = 'xy'
p.camera.zoom(2)
p.show()

tmp

ghazalbangash commented 3 years ago

thanks a lot :D