Beispiel #1
0
"""Setting illumination properties:
ambient, diffuse, specular, specularPower, specularColor.
"""
from vedo import Plotter, Mesh, dataurl

plt = Plotter(axes=1)

ambient, diffuse, specular = 0.1, 0., 0.
specularPower, specularColor = 20, 'white'

apple = Mesh(dataurl + 'apple.ply').normalize().c('gold')

for i in range(8):
    s = apple.clone().pos((i % 4) * 2.2, int(i < 4) * 3, 0)

    #s.phong()
    s.flat()

    # modify the default with specific values
    s.lighting('default', ambient, diffuse, specular, specularPower,
               specularColor)
    #ambient += 0.125
    diffuse += 0.125
    specular += 0.125

    plt += s

plt += __doc__
plt.show().close()
Beispiel #2
0
"""Identify and fill holes of an input mesh.
Holes are identified by locating boundary edges, linking them
together into loops, and then triangulating the resulting loops."""
from vedo import Mesh, show, dataurl

a = Mesh(dataurl+"bunny.obj").lw(0.1).bc('red')

# size = approximate limit to the size of the hole to be filled.
b = a.clone().pos(.2,0,0).fillHoles(size=0.1)
b.color("lb").bc('green').legend("filled mesh")

show(a, b, __doc__, elevation=-70).close()
Beispiel #3
0
m1 = Mesh([verts1, faces]).c('g').lw(4).wireframe()
m2 = Mesh([verts2, faces]).c('b').lw(4).wireframe()

a1 = precision(m1.area(), 3) + " \mum\^2"
a2 = precision(m2.area(), 3) + " \mum\^2"

vig1 = m1.vignette('Triangle 1\nA=' + a1,
                   point=(2.1, 0.7),
                   s=0.012,
                   offset=(-0.3, 0.04))
vig2 = m2.vignette('Triangle 2\nA=' + a2,
                   point=(1.9, 0.4),
                   s=0.012,
                   offset=(0.2, -0.2))

m3 = m1.clone().wireframe(False).c('tomato').lw(0)

zax = (0, 0, 1)
v0, v1, v2 = np.insert(np.array(verts2), 2, 0, axis=1)

m3.cutWithPlane(origin=v0, normal=np.cross(zax, v1 - v0))
if m3.NPoints():
    m3.cutWithPlane(origin=v1, normal=np.cross(zax, v2 - v1))
if m3.NPoints():
    m3.cutWithPlane(origin=v2, normal=np.cross(zax, v0 - v2))
vig3 = m3.vignette('Overlap polygon\nA=' + precision(m3.area(), 3),
                   point=(2.2, 0.6),
                   s=0.012)

show(m1, m2, m3, vig1, vig2, vig3, __doc__, axes=1, size=(800, 600),
     zoom=1.3).close()
Beispiel #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)
Beispiel #5
0
"""Insert 2D and 3D scalarbars
in the rendering scene"""
from vedo import Mesh, dataurl, show

shape = Mesh(dataurl + "lamp.vtk")

ms = []
cmaps = ("jet", "PuOr", "viridis")
for i in range(3):
    s = shape.clone(deep=False).pos(0, i * 2.2, 0)
    # colorize mesh
    scals = s.points()[:, 2]
    s.cmap(cmaps[i], scals)
    ms.append(s)

# add 2D scalar bar to first mesh
ms[0].addScalarBar(title="my scalarbar\nnumber #0")  #2D

# add 3D scalar bars
ms[1].addScalarBar3D(c="k", title="scalarbar #1", sy=3)

sc = ms[2].addScalarBar3D(
    pos=(1, 0, -5),
    c="k",
    sy=2.8,  # change y-size
    title="A viridis 3D\nscalarbar to play with",
    titleFont='Quikhand',
    titleXOffset=-2,  # offset of labels
    titleSize=1.5)
sc.scalarbar.rotateX(90)  # make it vertical
Beispiel #6
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()