Exemplo n.º 1
0
coords1 = a1.coordinates()
pts1 = vp.points(coords1, r=4, c='g', legend='#points = ' + str(len(coords1)))
vp.show([a1, pts1], at=0)

a2 = a1.subdivide(method=0)  # Increasing the number of points of the mesh
coords2 = a2.coordinates()
pts2 = vp.points(coords2, r=1, legend='#points = ' + str(len(coords2)))
vp.show([a2, pts2], at=1, interactive=True)

########################################################################################
# Draw a bunch of simple objects on separate parts of the rendering window:
# split window to best accomodate 9 renderers
vp = Plotter(N=9, title='basic shapes')
vp.sharecam = False  # each object can be moved independently
vp.show(at=0, actors=vp.arrow([0, 0, 0], [1, 1, 1]), legend='arrow')
vp.show(at=1, actors=vp.line([0, 0, 0], [1, 1, 1]), legend='line')
vp.show(at=2, actors=vp.points([[0, 0, 0], [1, 1, 1]]), legend='points')
vp.show(at=3, actors=vp.text('Hello!'))
vp.show(at=4, actors=vp.sphere())
vp.show(at=5, actors=vp.cube(), legend='cube')
vp.show(at=6, actors=vp.ring(), legend='ring')
vp.show(at=7, actors=vp.helix(), legend='helix')
vp.show(at=8, actors=vp.cylinder(), legend='cylinder', interactive=1)

########################################################################################
# Draw a bunch of objects from various mesh formats. Loading is automatic.
vp = Plotter(shape=(3, 3),
             title='mesh formats')  # split window in 3 rows and 3 columns
vp.sharecam = False  # each object can be moved independently
vp.show('data/beethoven.ply', at=0, c=0, axes=0,
        ruler=1)  # dont show axes, add a ruler
Exemplo n.º 2
0
def d_dt(psi):  # find Psi(t+dt)-Psi(t) /dt with 4th order Runge-Kutta method
    k1 = f(psi)
    k2 = f(psi + dt / 2 * k1)
    k3 = f(psi + dt / 2 * k2)
    k4 = f(psi + dt * k3)
    return (k1 + 2 * k2 + 2 * k3 + k4) / 6


vp = Plotter(interactive=0, axes=2, verbose=0)
vp.xtitle = ''
vp.ytitle = 'Psi^2(x,t)'
vp.ztitle = ''

bck = vp.load('data/images/schrod.png').scale(0.012).pos([0, 0, -.5])
barrier = vp.line(list(zip(x, V * 15)), c='dr', lw=3)

lines = []
for j in range(200):
    for i in range(500):
        Psi += d_dt(Psi) * dt  # integrate for a while

    A = np.real(Psi * np.conj(Psi)) * 1.5  # psi squared, probability(x)
    coords = list(zip(x, A))
    Aline = vp.line(coords, c='db', tube=True, lw=.08)
    vp.show([Aline, barrier, bck])
    lines.append(Aline)

# now show the same lines along z representing time
vp.clear()
vp.camera.Elevation(20)
Exemplo n.º 3
0
vp = Plotter(title='The Double Slit Experiment', axes=0, verbose=0, bg='black')

screen = vp.grid(pos=[0,0,-D], sx=0.1, sy=0.1, resx=200, resy=50)
screen.wire(False) # show it as a solid plane (not as wireframe)

k  = 0.0 + 1j * 2*pi/lambda1 # complex wave number
norm = len(slits)*5e+5
amplitudes = []

for i, x in enumerate(screen.coordinates()):
    psi = 0
    for s in slits:
        r = mag(x-s)
        psi += exp( k * r )/r
    psi2 = real( psi * conj(psi) ) # psi squared
    amplitudes.append(psi2)
    screen.point(i, x+[0,0, psi2/norm]) # elevate grid in z

screen.pointColors(amplitudes, cmap='hot')

vp.points(array(slits)*200, c='w')    # slits scale magnified by factor 200

vp.grid(sx=0.1, sy=0.1, resx=6, resy=6, c='white/.1') # add some annotation
vp.line([0,0,0], [0,0,-D], c='white/.1')
vp.text("source plane", pos=[-.05,-.053,0], s=.002, c='gray')
vp.text('detector plane D = '+str(D)+' m', pos=[-.05,-.053,-D], s=.002, c='gray')

vp.show(zoom=1.1)


Exemplo n.º 4
0
from vtkplotter import Plotter, arange, exp

c = 2.9979246e+8
k = 1.3806485e-23  # boltzmann constant
h = 6.6260700e-34  # planck constant


def planck(l, T):
    a = 2 * h * c**2
    b = h * c / (l * k * T)
    return a / (l**5 * (exp(b) - 1)) * 1e-13  # Planck formula


vp = Plotter(interactive=0, verbose=0, bg='k', axes=0)
vp.infinity = True  # view from infinity (axes are kept orthogonal)
vp.xtitle = ''
vp.ytitle = 'Intensity'
vp.ztitle = 'Temperature'
vp.load('data/images/light.jpg').scale(.00118).pos([.72, -.11, .14])

wavelengths = arange(400, 700, 10) * 1e-9
intensities = []
for T in range(3000, 9000, 50):
    I = planck(wavelengths, T)
    coords = list(zip(wavelengths * 2e+6, I * 0.02, [T * 5e-5] * len(I)))
    lineact = vp.line(coords, lw=4, alpha=.5)
    lineact.pointColors(wavelengths * 2e+6, cmap='jet')
    vp.show(elevation=.1, azimuth=0.1)

vp.show(axes=1, interactive=1)
Exemplo n.º 5
0
def d_dt(psi):  # find Psi(t+dt)-Psi(t) /dt with 4th order Runge-Kutta method
    k1 = f(psi)
    k2 = f(psi + dt / 2 * k1)
    k3 = f(psi + dt / 2 * k2)
    k4 = f(psi + dt * k3)
    return (k1 + 2 * k2 + 2 * k3 + k4) / 6


vp = Plotter(interactive=0, axes=2, verbose=0)
vp.xtitle = ''
vp.ytitle = 'Psi^2(x,t)'
vp.ztitle = ''

bck = vp.load('data/images/schrod.png').scale(0.012).pos([0, 0, -.5])
barrier = vp.line(list(zip(x, V * 15)), c='dr', lw=3)

lines = []
for j in range(200):
    for i in range(500):
        Psi += d_dt(Psi) * dt  # integrate for a while

    A = np.real(Psi * np.conj(Psi)) * 1.5  # psi squared, probability(x)
    coords = list(zip(x, A, [0] * len(x)))
    Aline = vp.tube(coords, c='db', r=.08)
    vp.show([Aline, barrier, bck])
    lines.append(Aline)

# now show the same lines along z representing time
vp.clear()
vp.camera.Elevation(20)
Exemplo n.º 6
0
# Green histogram is the distribution of residuals from the fitting.
# Red histogram is the distribution of the curvatures (1/r**2).
# Fitted radius can be accessed from attribute actor.radius

from __future__ import division, print_function
from vtkplotter import Plotter
from vtkplotter.analysis import fitSphere

vp = Plotter(verbose=0, axes=0)

# load mesh and increase by a lot (N=2) the nr of surface vertices
s = vp.load('data/shapes/cow.vtk').alpha(0.3).subdivide(N=2)

reds, invr = [], []
for i, p in enumerate(s.coordinates()):
    if i % 1000: continue  # skip most points
    pts = s.closestPoint(p, N=16)  # find the N closest points to p
    sph = fitSphere(pts, alpha=0.05)  # find the fitting sphere
    if sph is None:
        continue  # may fail if all points sit on a plane
    vp.actors.append(sph)
    vp.points(pts)
    vp.line(sph.info['center'], p, lw=2)
    reds.append(sph.info['residue'])
    invr.append(1 / sph.info['radius']**2)

vp.histogram(reds, title='residue', bins=12, c='g', corner=3)
vp.histogram(invr, title='1/r**2', bins=12, c='r', corner=4)

vp.show()
Exemplo n.º 7
0
# time goes from 0 to 90 hours
pb = ProgressBar(0, 50, step=0.1, c=1)
for t in pb.range():
    msg = '[Nb,Ng,Nr,t] = '
    vp.actors = []  # clean up the list of actors

    for colony in colonies:

        newcells = []
        for cell in colony.cells:

            if cell.dieAt(t): continue
            if cell.divideAt(t):
                newc = cell.split()  # make daughter cell
                vp.line(cell.pos, newc.pos, c='k', lw=3, alpha=.5)
                newcells.append(newc)
            newcells.append(cell)
        colony.cells = newcells

        pts = [c.pos for c in newcells]  # draw all points at once
        vp.points(pts, c=colony.color, r=5, alpha=.80)  # nucleus
        vp.points(pts, c=colony.color, r=15, alpha=.05)  # halo
        msg += str(len(colony.cells)) + ','

    pb.print(msg + str(int(t)))
    vp.show(resetcam=0)

# draw the oriented ellipsoid that contains 50% of the cells
for colony in colonies:
    pts = [c.pos for c in colony.cells]