vp = Plotter(shape=[2, 2], verbose=0, axes=3, interactive=0)

shape1 = Sphere(alpha=0.2)
shape2 = vp.load('data/shapes/icosahedron.vtk').normalize().lineWidth(1)

agrid1, actorpts1 = makeGrid(shape1, N)
vp.show(at=0, actors=[shape1, actorpts1])

agrid2, actorpts2 = makeGrid(shape2, N)
vp.show(at=1, actors=[shape2, actorpts2])
vp.camera.Zoom(1.2)
vp.interactive = False

clm1 = pyshtools.SHGrid.from_array(agrid1).expand()
clm2 = pyshtools.SHGrid.from_array(agrid2).expand()
# clm1.plot_spectrum2d() # plot the value of the sph harm. coefficients
# clm2.plot_spectrum2d()

for t in arange(0, 1, 0.005):
    act21 = Points(morph(clm2, clm1, t, lmax), c='r', r=4)
    act12 = Points(morph(clm1, clm2, t, lmax), c='g', r=4)
    vp.show(at=2,
            actors=act21,
            resetcam=0,
            legend='time: ' + str(int(t * 100)))
    vp.show(at=3, actors=act12)
    vp.camera.Azimuth(2)

vp.show(interactive=1)
Пример #2
0
# Can simulate the 'Arago spot', the bright point at the center of
#  a circular object shadow (https://en.wikipedia.org/wiki/Arago_spot).
#
from numpy import conj, real, pi, array, sin, cos, exp
from vtkplotter import Plotter, arange, mag, grid, line

#########################################
lambda1 = 680e-9  # red wavelength 680nm
width = 10e-6  # slit width in m
D = 0.1  # screen distance in m
#########################################

# create the slits as a set of individual coherent point-like sources
n = 10  # nr of elementary sources in slit (to control precision).
slit1 = list(zip([0] * n,
                 arange(0, n) * width / n,
                 [0] * n))  # source points inside slit 1
slit2 = list(slit1 + array([1e-5, 0, 0]))  # a shifted copy of slit 1
slits = slit1 + slit2
#slits += list(slit1 + array([-2e-5, 1e-5, 0]))      # add an other copy of slit 1
#slits = [(cos(x)*4e-5, sin(x)*4e-5, 0) for x in arange(0,2*pi, .1)] # Arago spot
#slits = grid(sx=1e-4, sy=1e-4, resx=9, resy=9).coordinates() # a square lattice

vp = Plotter(title='The Double Slit Experiment', axes=0, verbose=0, bg='black')

screen = vp.add(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 = []
Пример #3
0
# Example on how to specify a color for each individual cell
# or point of an actor's mesh.
# Last example also shows the usage of addScalarBar3D().
#
from vtkplotter import Plotter, arange

vp = Plotter(N=3)

##################################### addPointScalars
man1 = vp.load('data/shapes/man.vtk')
Np = man1.N()  # nr. of vertices
scals = arange(0, 1, 1. / Np)  # coloring by index nr of vertex
man1.addPointScalars(scals, 'mypointscalars')  # add a vtkArray to actor
#print(man1.scalars('mypointscalars')) # info can be retrieved this way
vp.show(man1, at=0, elevation=-60)
vp.addScalarBar()  # add a scalarbar to last drawn actor

##################################### pointColors
man2 = vp.load('data/shapes/man.vtk')
scals = man2.coordinates()[:, 1] + 37  # pick y coordinates of vertices

man2.pointColors(scals, cmap='bone', vmin=36.2, vmax=36.7)  # right dark arm
vp.show(man2, at=1, axes=0, legend='pointColors')
vp.addScalarBar(horizontal=True)

##################################### cellColors
man3 = vp.load('data/shapes/man.vtk')
scals = man3.cellCenters()[:, 2] + 37  # pick z coordinates of cells
man3.cellColors(scals, cmap='afmhot')
#print(man3.scalars('cellColors_afmhot')) # info can be retrieved this way
Пример #4
0
# Example on how to specify a color for each individual cell
# or point of an actor's mesh.
# Last example shows the usage of addScalarBar3D().
# Needs matplotlib.
from vtkplotter import Plotter, arange

vp = Plotter(shape=(1, 3), size='fullscreen')

#####################################
man1 = vp.load('data/shapes/man.vtk')
Np = man1.N()  # nr. of vertices
pscals = arange(0, 1, 1. / Np)  # coloring will be by index nr of the vertex
man1.pointScalars(pscals, 'mypointscalars')  # add a vtkArray to actor
#print(man1.scalars('mypointscalars')) # info can be retrieved this way
vp.show(man1, at=0, axes=1)
vp.addScalarBar()  # add a scalarbar to last drawn actor

#####################################
man2 = vp.load('data/shapes/man.vtk')
pscals = man2.coordinates()[:, 1] + 37  # pick y coordinates of vertices
man2.pointColors(pscals, cmap='bone')  # use a colormap to associate a color
#print(man2.scalars('pointColors_bone')) # info can be retrieved this way
vp.show(man2, at=1, axes=0, legend='pointColors')
vp.addScalarBar(horizontal=True)

#####################################
man3 = vp.load('data/shapes/man.vtk')
cscals = man3.cellCenters()[:, 2] + 37  # pick z coordinates of cells
man3.cellColors(cscals, cmap='afmhot')

# add some oriented 3D text
Пример #5
0
Rb = screen_w/32        # Radius of the big sphere
Rs = Rb*0.43            # Radius of small spheres
Ms=(Rs/Rb)**3           # Mass of the small spheres (Mbig=1)
Dt = 0.03               # Time step

LBox=(screen_w/2,screen_h/2) # Size of the box = 2LBox[0].2LBox[1]
Lb0 = LBox[0]-Rb
Lb1 = LBox[1]-Rb
Ls0 = LBox[0]-Rs
Ls1 = LBox[1]-Rs

# Create the arrays with the initial positions of the spheres.
# Start with the big sphere at the center, then put the small
# spheres at random selected from a grid of possible positions.
ListPos=[(0,0)]
PossiblePos=[(x,y) for x in arange(-LBox[0]+2*Rs,LBox[0]-2*Rs,2.2*Rs)
             for y in arange(-LBox[1]+2*Rs,LBox[1]-2*Rs,2.2*Rs)
             if x*x+y*y > Rb+Rs]
             
if Nsp > len(PossiblePos)+1: Nsp = len(PossiblePos)+1

for s in range(Nsp-1):
    n = random.randint(0, len(PossiblePos)-1)
    ListPos.append(PossiblePos[n])
    del PossiblePos[n] 
Pos = np.array(ListPos)

# Create an array with all the radius and a list with all the masses
Radius = np.concatenate( (np.array([Rb]), np.array([Rs]*(Nsp-1))) )
Mass=[1.0]+[Ms]*(Nsp-1)
Пример #6
0
Rs = Rb * 0.43  # Radius of small spheres
Ms = (Rs / Rb)**3  # Mass of the small spheres (Mbig=1)
Dt = 0.03  # Time step

LBox = (screen_w / 2, screen_h / 2)  # Size of the box = 2LBox[0].2LBox[1]
Lb0 = LBox[0] - Rb
Lb1 = LBox[1] - Rb
Ls0 = LBox[0] - Rs
Ls1 = LBox[1] - Rs

# Create the arrays with the initial positions of the spheres.
# Start with the big sphere at the center, then put the small
# spheres at random selected from a grid of possible positions.
ListPos = [(0, 0)]
PossiblePos = [(x, y)
               for x in arange(-LBox[0] + 2 * Rs, LBox[0] - 2 * Rs, 2.2 * Rs)
               for y in arange(-LBox[1] + 2 * Rs, LBox[1] - 2 * Rs, 2.2 * Rs)
               if x * x + y * y > Rb + Rs]

if Nsp > len(PossiblePos) + 1: Nsp = len(PossiblePos) + 1

for s in range(Nsp - 1):
    n = random.randint(0, len(PossiblePos) - 1)
    ListPos.append(PossiblePos[n])
    del PossiblePos[n]
Pos = np.array(ListPos)

# Create an array with all the radius and a list with all the masses
Radius = np.concatenate((np.array([Rb]), np.array([Rs] * (Nsp - 1))))
Mass = [1.0] + [Ms] * (Nsp - 1)
# The input actor's polydata is modified by the method
# so more than one pass is possible.
# If showNLines>0 an actor is built demonstrating the
# details of the regression for some random points
#
from __future__ import division, print_function
from vtkplotter import Plotter, arange, sin, cos, sqrt
from vtkplotter.analysis import smoothMLS1D
import numpy as np

N = 9  # nr. of iterations

# build some initial cloud of noisy points along a line
#pts = [ (sin(6*x), sin(2*x)/(x+1), cos(9*x)) for x in arange(0,1, .001)]
#pts = [ (0, sin(x), cos(x)) for x in arange(0,6, .002) ]
pts = [(sqrt(x), sin(x), x / 10) for x in arange(0, 16, .01)]

pts += np.random.randn(len(pts), 3) / 10  # add noise
np.random.shuffle(pts)  # make sure points are not ordered

vp = Plotter(N=N, axes=5)
a = vp.points(pts)
vp.show(a, at=0, legend='cloud')

for i in range(1, N):
    a = a.clone().color(i)
    smoothMLS1D(a, f=0.2)

    # at last iteration make sure points are separated by tol
    if i == N - 1:
        a.clean(tol=.01)
Пример #8
0
model.add(Dense(neurons, activation="relu"))
model.add(Dense(neurons, activation="relu"))
model.add(Dense(1, activation="sigmoid"))

model.compile(optimizer="rmsprop", loss="mse", metrics=["mae"])

model.fit(datalist, scalars, epochs=50, batch_size=64)

predicted_scalars = model.predict(datalist)

model.summary()

idx = 0
vispred = np.zeros([n, n, n])
for i, x in enumerate(ls):
    for j, y in enumerate(ls):
        for k, z in enumerate(ls):
            vispred[i, j, k] = predicted_scalars[idx]
            idx += 1

v1 = Volume(visdata)
v2 = Volume(vispred)

s1 = v1.isosurface(threshold=[t for t in arange(0, 1, 0.1)])
s1.alpha(0.5)

s2 = v2.isosurface(threshold=[t for t in arange(0, 1, 0.1)])
s2.alpha(0.5)

show([[v1, s1], s2], N=2, axes=8)
Пример #9
0
 (as source are in scale, too small to be seen, they are magnified x200).
Can simulate the 'Arago spot', the bright point at the center of 
 a circular object shadow (https://en.wikipedia.org/wiki/Arago_spot).
'''
from numpy import conj, real, pi, array, sin, cos, exp
from vtkplotter import Plotter, arange, mag, Grid, Line, Points, Text

#########################################
lambda1 = 680e-9   # red wavelength 680nm
width   = 10e-6    # slit width in m
D       = 0.1      # screen distance in m
#########################################

# create the slits as a set of individual coherent point-like sources
n = 10 # nr of elementary sources in slit (to control precision).
slit1 = list(zip([0]*n, arange(0,n)*width/n, [0]*n)) # source points inside slit 1
slit2 = list(slit1 + array([1e-5, 0,0]))             # a shifted copy of slit 1
slits = slit1 + slit2  
#slits += list(slit1 + array([-2e-5, 1e-5, 0]))      # add an other copy of slit 1
#slits = [(cos(x)*4e-5, sin(x)*4e-5, 0) for x in arange(0,2*pi, .1)] # Arago spot
#slits = Grid(sx=1e-4, sy=1e-4, resx=9, resy=9).coordinates() # a square lattice

vp = Plotter(title='The Double Slit Experiment', axes=0, verbose=0, bg='black')

screen = vp.add(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 = []
Пример #10
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)
Пример #11
0
model.add(Dense(neurons, activation="relu"))
model.add(Dense(neurons, activation="relu"))
model.add(Dense(1, activation="sigmoid"))

model.compile(optimizer="rmsprop", loss="mse", metrics=["mae"])

model.fit(datalist, scalars, epochs=50, batch_size=64)

predicted_scalars = model.predict(datalist)

model.summary()

idx = 0
vispred = np.zeros([n, n, n])
for i, x in enumerate(ls):
    for j, y in enumerate(ls):
        for k, z in enumerate(ls):
            vispred[i, j, k] = predicted_scalars[idx]
            idx += 1

v1 = Volume(visdata)
v2 = Volume(vispred)

s1 = isosurface(v1, threshold=[t for t in arange(0, 1, 0.1)])
s1.alpha(0.5)

s2 = isosurface(v2, threshold=[t for t in arange(0, 1, 0.1)])
s2.alpha(0.5)

show([[v1, s1], s2], N=2, axes=8, bg="w", depthpeeling=1)
Пример #12
0
# Form a surface by joining two lines.
#
from vtkplotter import Plotter, arange, sin, cos

vp = Plotter()

l1 = [ [sin(x),     cos(x),      x/2] for x in arange(0,9, .1)]
l2 = [ [sin(x)+0.2, cos(x)+x/15, x/2] for x in arange(0,9, .1)]

vp.tube(l1, c='g', r=0.02)
vp.tube(l2, c='b', r=0.02)

vp.ribbon(l1, l2, alpha=.2, res=(200,5), legend='ruled surf').wire(1)

vp.show(viewup='z')
Пример #13
0
model.add(Dense(neurons, activation="relu"))
model.add(Dense(neurons, activation="relu"))
model.add(Dense(1, activation="sigmoid"))

model.compile(optimizer="rmsprop", loss="mse", metrics=["mae"])

model.fit(datalist, scalars, epochs=50, batch_size=64)

predicted_scalars = model.predict(datalist)

model.summary()

idx = 0
vispred = np.zeros([n, n, n])
for i, x in enumerate(ls):
    for j, y in enumerate(ls):
        for k, z in enumerate(ls):
            vispred[i, j, k] = predicted_scalars[idx]
            idx += 1

v1 = Volume(visdata)
v2 = Volume(vispred)

s1 = isosurface(v1.image, threshold=[t for t in arange(0, 1, 0.1)])
s1.alpha(0.5)

s2 = isosurface(v2.image, threshold=[t for t in arange(0, 1, 0.1)])
s2.alpha(0.5)

show([[v1, s1], s2], N=2, axes=8, bg="w", depthpeeling=1)
Пример #14
0
#Create a map of transparencies which can be passed
# to method pointColors()
#
from vtkplotter import Plotter, arange

vp = Plotter(axes=6)  # type 6 marks bounding box corners

act = vp.load('data/beethoven.ply')

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

# make a range of transparencies from bottom (0) to top (1)
alphas = arange(0, 1, 1. / len(pscals))

act.pointColors(pscals, alpha=alphas, cmap='copper')

vp.show(act)