marcomusy / vedo

A python module for scientific analysis of 3D data based on VTK and Numpy
https://vedo.embl.es
MIT License
1.98k stars 257 forks source link

collapse_edges() not preserving celldata #1007

Closed marcomusy closed 5 months ago

marcomusy commented 5 months ago

I have a similar issue:

I have a mesh with custom data per face, stored in mesh.celldata["mydata"] I now iteratively collapse edges of the mesh and call mesh.clean() after each iteration to update topology (a slightly modified version of vedo.Mesh.collapse_edges()). While mesh.clean() correctly removes faces, e.g. when a triangle edge is collapsed, it does not update the celldata array. Is there any way to update the celldata, or e.g. get a map from input to output cells when calling mesh.clean()?

NB: the trick to move "mydata" to pointdata before mesh.clean() and then back does not work, because I do not want to interpolate "mydata".

Originally posted by @raphaelsulzer in https://github.com/marcomusy/vedo/issues/992#issuecomment-1881098489

marcomusy commented 5 months ago

Hi @raphaelsulzer this works for me

pip install -U git+https://github.com/marcomusy/vedo.git

then

from vedo import *
np.random.seed(2)
grid1 = Grid().add_gaussian_noise(0.8).triangulate().lw(1)
grid1.celldata['scalar'] = grid1.cell_centers[:,1]
grid2 = grid1.clone().collapse_edges(0.1)
show(grid1, grid2, N=2, axes=1)

Screenshot from 2024-01-08 16-40-30

raphaelsulzer commented 5 months ago

After updating with pip install -U git+https://github.com/marcomusy/vedo.git it works like a charm. I guess I had an old version installed.

Thank you so much for the quick response and for your work on this library in general. It is a really great tool!