Mesh manipulation#

from vedo import dataurl, Mesh, Arrows, show, settings
settings.default_backend = "vtk"
# Load a mesh
mesh = Mesh(dataurl+"man.vtk").color("white")
mesh

vedo.mesh.Mesh
(....embl.es/examples/data/man.vtk)
bounds
(x/y/z)
-0.9169 ... 0.9169
-0.3300 ... 0.2617
-1.570 ... 1.685
center of mass (1.01e-10, 4.06e-11, 2.20e-11)
average size 0.911
nr. points / faces 24461 / 24459
cell data array MaterialIds
# Create a heavily decimated copy with about 200 points
# (to speed up the computation)
mesh_dec = mesh.clone().triangulate().decimate(n=200)
mesh_dec

vedo.mesh.Mesh
(....embl.es/examples/data/man.vtk)
bounds
(x/y/z)
-0.9070 ... 0.9041
-0.3287 ... 0.2765
-1.566 ... 1.691
center of mass (-3.62e-3, 0.0158, 0.0810)
average size 0.945
nr. points / faces 205 / 399
sources = [[0.9, 0.0, 0.2]]  # this point moves
targets = [[1.2, 0.0, 0.4]]  # ...to this.
for pt in mesh_dec.points():
    if pt[0] < 0.3:          # while these pts don't move
        sources.append(pt)   # (e.i. source = target)
        targets.append(pt)
# Warp the mesh
mesh_warped = mesh.clone().warp(sources, targets)
mesh_warped.c("blue").wireframe()

vedo.mesh.Mesh
(....embl.es/examples/data/man.vtk)
bounds
(x/y/z)
-0.9177 ... 1.173
-0.3300 ... 0.2617
-1.570 ... 1.684
center of mass (0.0237, 4.06e-11, 0.0158)
average size 0.935
nr. points / faces 24461 / 24459
cell data array MaterialIds
# Create the arrows representing the displacement
arrow = Arrows(sources, targets)

# Show the meshes and the arrow
show(mesh, mesh_warped, arrow, axes=1).close()