Exemplo n.º 1
0
"""Create a set of transparencies
which can be passed to method cmap()"""
from vedo import Mesh, show, dataurl

mesh = Mesh(dataurl + "beethoven.ply")

# pick y coordinates of vertices and use them as scalars
scals = mesh.points()[:, 1]

# define opacities in the range of the scalar,
# at min(scals) alpha is 0.1,
# at max(scals) alpha is 0.9:
alphas = [0.1, 0.1, 0.3, 0.4, 0.9]

mesh.cmap("copper", scals, alpha=alphas)
# print(mesh.getPointArray('PointScalars')) # retrieve scalars

show(mesh, __doc__, axes=9).close()
Exemplo n.º 2
0
"""Share the same color map
across different meshes"""
from vedo import Mesh, show, dataurl

#####################################
man1 = Mesh(dataurl + "man.vtk")
scals = man1.points()[:, 2] * 5 + 27  # pick z coordinates [18->34]
man1.cmap("rainbow", scals, vmin=18, vmax=44)

#####################################
man2 = Mesh(dataurl + "man.vtk")
scals = man2.points()[:, 2] * 5 + 37  # pick z coordinates [28->44]
man2.cmap("rainbow", scals, vmin=18, vmax=44).addScalarBar()

show([(man1, __doc__), man2], N=2, elevation=-40, axes=11)
Exemplo n.º 3
0
"""Manually build a mesh from points and faces"""
from vedo import Mesh, printc, show

verts = [(50,50,50), (70,40,50), (50,40,80), (80,70,50)]
faces = [(0,1,2), (2,1,3), (1,0,3)]
# (the first triangle face is formed by vertex 0, 1 and 2)

# Build the polygonal Mesh object:
mesh = Mesh([verts, faces])
mesh.backColor('violet').lineColor('tomato').lineWidth(2)
labs = mesh.labels('id').c('black')

# retrieve them as numpy arrays
printc('points():\n', mesh.points(), c=3)
printc('faces(): \n', mesh.faces(),  c=3)

show(mesh, labs, __doc__, viewup='z', axes=1).close()
Exemplo n.º 4
0
"""Thin Plate Spline transformations describe a nonlinear warp
transform defined by a set of source and target landmarks.
Any point on the mesh close to a source landmark will
be moved to a place close to the corresponding target landmark.
The points in between are interpolated using Bookstein's algorithm"""
from vedo import Mesh, Points, show, dataurl
import numpy as np

np.random.seed(1)

mesh = Mesh(dataurl + "shuttle.obj").c('silver')

# pick 4 random points
indxs = np.random.randint(0, mesh.N(), 4)
pts = mesh.points()[indxs]

# and move them randomly by a little
ptsource, pttarget = [], []
for ptold in pts:
    ptnew = ptold + np.random.rand(3) * 0.2
    ptsource.append(ptold)
    pttarget.append(ptnew)
    # print(ptold,'->',ptnew)

warped = mesh.clone().thinPlateSpline(ptsource, pttarget).color("b", 0.4)

apts = Points(ptsource, r=15, c="r")

show(mesh, warped, apts, __doc__, viewup="z", axes=1)
Exemplo n.º 5
0
"""
print(__doc__)
from vedo import Plotter, Mesh, dataurl

# these are the some matplotlib color maps
maps = [
    "afmhot",
    "binary",
    "bone",
    "cool",
    "coolwarm",
    "copper",
    "gist_earth",
    "gray",
    "hot",
    "jet",
    "rainbow",
    "winter",
]

mug = Mesh(dataurl + "mug.ply")
scalars = mug.points()[:, 1]  # let y-coord be the scalar

plt = Plotter(N=len(maps))

for i, key in enumerate(maps):  # for each available color map name
    imug = mug.clone(deep=False).cmap(key, scalars, n=5)
    plt.show(imug, key, at=i)

plt.show().interactive().close()
Exemplo n.º 6
0
"""Manually build a mesh from points and faces"""
from vedo import Mesh, printc, show

verts = [(50, 50, 50), (70, 40, 50), (50, 40, 80), (80, 70, 50)]
faces = [(0, 1, 2), (2, 1, 3), (1, 0, 3)]
# (the first triangle face is formed by vertex 0, 1 and 2)

# Build the polygonal Mesh object:
m = Mesh([verts, faces])
m.backColor('violet').lineColor('tomato').lineWidth(2)

# retrieve them as numpy arrays
printc('points():\n', m.points(), c=3)
printc('faces(): \n', m.faces(), c=3)

show(m, __doc__, viewup='z', axes=8)