collapsing the triangle edges with a threshold already does a pretty decent job… a very unsophisticated test here:
import numpy as np
from vedo import *
txu = 'SMPL_sampleTex_m.jpg'
threshold = 4.0
mesh1 = Mesh('guy.vtk', c='w').texture(txu)
grad = mesh1.gradient("tcoords")
ugrad, vgrad = np.split(grad, 2, axis=1)
ugradm, vgradm = mag(ugrad), mag(vgrad)
gradm = np.log(ugradm*ugradm + vgradm*vgradm)
largegrad_ids = np.arange(len(grad))[gradm>threshold]
# collapse triangles that have large gradient
uvmap = mesh1.getPointArray('tcoords')
points = mesh1.points()
for f in mesh1.faces():
if np.isin(f, largegrad_ids).all():
id1, id2, id3 = f
uv1, uv2, uv3 = uvmap[f]
d12 = mag(uv1-uv2)
d23 = mag(uv2-uv3)
d31 = mag(uv3-uv1)
idm = np.argmin([d12, d23, d31])
if idm == 0: # d12, collapse segment12 to pt3
points[id1] = points[id2] = points[id3]
elif idm == 1:
points[id2] = points[id3] = points[id1]
mesh1.points(points) # move points
mesh2 = mesh1.clone().cmap('jet', gradm).addScalarBar()
show(mesh1, mesh2, N=2, axes=1)
I’ll also give a try to the PLY reader, thanks for the hints!