Exemplo n.º 1
0
"""
Mirror a mesh along one of the Cartesian axes.

Hover mouse to see original and mirrored.
"""
from vtkplotter import Plotter, Text, datadir

vp = Plotter(axes=2)

myted1 = vp.load(datadir+"teddy.vtk").flag('original')

myted2 = myted1.clone().mirror("y").pos([0, 3, 0]).c("green").flag('mirrored')

vp.show(myted1, myted2, Text(__doc__), viewup="z")
Exemplo n.º 2
0
################################################# RBF
from scipy.interpolate import Rbf

x, y, z = sources[:, 0], sources[:, 1], sources[:, 2]
dx, dy, dz = deltas[:, 0], deltas[:, 1], deltas[:, 2]

itrx = Rbf(x, y, z, dx)  # Radial Basis Function interpolator:
itry = Rbf(x, y, z, dy)  #  interoplate the deltas in each separate
itrz = Rbf(x, y, z, dz)  #  cartesian dimension

positions_x = itrx(xr, yr, zr) + xr
positions_y = itry(xr, yr, zr) + yr
positions_z = itrz(xr, yr, zr) + zr
positions_rbf = np.vstack([positions_x, positions_y, positions_z])

warped_rbf = Points(positions_rbf, r=2).alpha(0.4).color("lg").pointSize(10)
allarr_rbf = Arrows(apos.points(), warped_rbf.points())

arr = Arrows(sources, sources + deltas)

vp2 = Plotter(N=2, pos=(200, 300), verbose=0, bg='bb')
vp2.camera = vp.camera  # share the same camera with previous Plotter
vp2.show(apos,
         warped_rbf,
         src,
         trs,
         arr,
         Text2D("Radial Basis Function"),
         at=0)
vp2.show(allarr_rbf, at=1, interactive=1)
Exemplo n.º 3
0
# The difference between one time point and the next is shown as
# a blue component.
#
from __future__ import division, print_function
from vtkplotter import vector, Plotter, ProgressBar
import numpy as np

# Load (with numpy) an existing set of mesh points and a list
# of scalars that represent the concentration of a substance
mesh, conc, cgradfac = np.load('data/turing_data.npy', encoding='latin1')
conc = conc / 1000.  # normalize concentrations read from file
nc, n = conc.shape  # nc= nr. of time points, n= nr. of vertices

# Create the Plotter instance and position the camera.
# (values can be copied in the code by pressing C in the rendering window)
vp = Plotter(verbose=0, axes=0, interactive=0, size=(700, 700))
vp.camera.SetPosition(962, -239, 1034)
vp.camera.SetFocalPoint(0.0, 0.0, 10.0)
vp.camera.SetViewUp(-0.693, -0.479, 0.539)

pb = ProgressBar(0, nc, c='g')  # a green progress bar
for t1 in pb.range():  # for each time point
    t2 = t1 + 1
    if t1 == nc - 1: t2 = t1  # avoid index overflow with last time point

    vp.actors = []  # clean up the list of actors at each iteration
    vp.cylinder([0, 0, -15], r=260, height=10, texture='marble', res=60)
    vp.cylinder([0, 0, 10], r=260, height=50, wire=1, c='gray', res=60)

    pts, cols = [], []
    for i, p in enumerate(mesh):  # for each vertex in the mesh
Exemplo n.º 4
0
# Example use of addTrail() and updateTrail()
#
from vtkplotter import Plotter, sin

vp = Plotter(axes=1, interactive=0)

c = vp.cube()
vp.cutPlane(c, [-0.4, 0, 0])  #cut away the left face

s = vp.sphere([1, 1, 1], r=.03, c='db')

# add a trail to last created actor with max 50 segments
vp.addTrail(c='k', lw=3, maxlength=.5, n=50)

for i in range(200):
    s.pos([-2. + i / 100., sin(i / 5.) / 10., 0]).updateTrail()
    vp.render()
    vp.camera.Azimuth(-.3)

vp.show(interactive=1)
Exemplo n.º 5
0
#!/usr/bin/env python
#
# Usage example of fitLine() and fitPlane()
#
# Draw a line in 3D that fits a cloud of 20 points,
# also show the first set of 20 points and fit a plane to them
#
from __future__ import division, print_function
import numpy as np
from vtkplotter import Plotter
from vtkplotter.analysis import fitLine, fitPlane

# declare the class instance
vp = Plotter(verbose=0, title='linear fitting')

# draw 500 fit lines superimposed and very transparent
for i in range(500):

    x = np.linspace(-2, 5, 20)  # generate each time 20 points
    y = np.linspace(1, 9, 20)
    z = np.linspace(-5, 3, 20)
    data = np.array(list(zip(x, y, z)))
    data += np.random.normal(size=data.shape) * 0.8  # add gauss noise

    l = fitLine(data, lw=4, alpha=0.03)  # fit a line
    vp.actors.append(l)

# 'data' still contains the last iteration points
vp.points(data, r=10, c='red', legend='random points')

# the first fitted slope direction is stored in actor.slope and actor.normal