def morph(clm1, clm2, t, lmax):
    # interpolate linearly the two sets of sph harm. coeeficients
    clm = (1 - t) * clm1 + t * clm2
    grid_reco = clm.expand(lmax=lmax)  # cut "high frequency" components
    agrid_reco = grid_reco.to_array()
    pts = []
    for i, longs in enumerate(agrid_reco):
        ilat = grid_reco.lats()[i]
        for j, value in enumerate(longs):
            ilong = grid_reco.lons()[j]
            th = (90 - ilat) / 57.3
            ph = ilong / 57.3
            r = value + rbias
            p = np.array([sin(th) * cos(ph), sin(th) * sin(ph), cos(th)]) * r
            pts.append(p)
    return pts
Ejemplo n.º 2
0
def myloop(*event):
    global counts  # this is needed because counts is being modified:
    counts += 0.1

    # reference 'actor' is not modified so doesnt need to be global
    # (internal properties of the object are, but python doesn't know..)
    actor.pos([0, counts / 20, 0]).color(counts)  # move cube and change color

    rp = [u(-1, 1), u(0, 1), u(-1, 1)]  # a random position
    s = sphere(rp, r=0.05, c='blue 0.2')
    vp.render(s, resetcam=True)  # show() would cause exiting the loop

    # waste cpu time to slow down program
    for i in range(100000):
        sin(i)
    printc('#', end='')
Ejemplo n.º 3
0
def makeGrid(shape, N):
    rmax = 2.0  # line length
    agrid, pts = [], []
    for th in np.linspace(0, np.pi, N, endpoint=True):
        lats = []
        for ph in np.linspace(0, 2 * np.pi, N, endpoint=True):
            p = np.array([sin(th) * cos(ph), sin(th) * sin(ph), cos(th)]) * rmax
            intersections = shape.intersectWithLine([0, 0, 0], p)
            if len(intersections):
                value = mag(intersections[0])
                lats.append(value - rbias)
                pts.append(intersections[0])
            else:
                lats.append(rmax - rbias)
                pts.append(p)
        agrid.append(lats)
    agrid = np.array(agrid)
    actor = Points(pts, c="k", alpha=0.4, r=1)
    return agrid, actor
Ejemplo n.º 4
0
# Example usage of addTrail()
#
from vtkplotter import Plotter, sin

vp = Plotter(axes=6)

s = vp.sphere(c='green', res=24)
vp.cutPlane(s, [-0.9, 0, 0], showcut=True)  #cut left part of sphere

p = vp.point([1, 1, 1], r=12)

# add a trail to point p with maximum length 0.5 and 50 segments
p.addTrail(c='k', lw=3, maxlength=0.5, n=50)

for i in range(200):
    p.pos([-2 + i / 100., sin(i / 5.) / 15, 0])
    vp.render()
    vp.camera.Azimuth(-0.2)

vp.show(resetcam=0)
Ejemplo n.º 5
0
"""
Example usage of addTrail().
Add a trailing line to a moving object.
"""
print(__doc__)
from vtkplotter import Plotter, sin, Sphere, Point

vp = Plotter(axes=6, bg='white', interactive=0)

s = Sphere(c="green", res=24)
s.cutWithPlane([-0.9, 0, 0], showcut=True)  # cut left part of sphere

p = Point([1, 1, 1], r=12, c="k")

# add a trail to point p with maximum length 0.5 and 50 segments
p.addTrail(c="k", lw=3, maxlength=0.5, n=50)
vp += [s, p]

for i in range(200):
    p.pos([-2 + i / 100.0, sin(i / 5.0) / 15, 0])
    vp.show()
    vp.camera.Azimuth(-0.2)

vp.show(interactive=1)
Ejemplo n.º 6
0
shaft = vp.cylinder([[0,0,0],         [Lshaft,0,0]], r=.03, c='dg')
rotor = vp.cylinder([[Lshaft/2.2,0,0],[Lshaft/1.8,0,0]], r=R, texture='marble')
base  = vp.sphere([     0, 0, 0], c='dg', r=.03)
tip   = vp.sphere([Lshaft, 0, 0], c='dg', r=.03)
gyro  = vp.makeAssembly([shaft, rotor, base, tip]) # group relevant actors

pedestal = vp.box([0,-0.63,0], height=.1, length=.1, width=1, texture='wood5')
pedbase  = vp.box([0,-1.13,0], height=.5, length=.5, width=.05, texture='wood5')
pedpin   = vp.pyramid([0,-.08,0], axis=[0,1,0], s=.05, height=.12, texture='wood5')
formulas = vp.load('data/images/gyro_formulas.png', alpha=.9).scale(.003).pos([-1,-1,-1.1])

# ############################################################ the physics
pb = ProgressBar(0, 4, dt, c='b')
for i, t in enumerate(pb.range()):
    st, ct, sp, cp = sin(x[0]), cos(x[0]), sin(x[1]), cos(x[1])

    thetadot, phidot, psidot = v # unpack
    atheta = st*ct*phidot**2 + (M*g*r*st-I3*(psidot+phidot*ct)*phidot*st)/I1
    aphi = (I3/I1)*(psidot+phidot*ct)*thetadot/st - 2*ct*thetadot*phidot/st
    apsi = phidot*thetadot*st - aphi*ct
    a = vector(atheta, aphi, apsi)

    v += a*dt  # update velocities   
    x += v*dt  # update Lagrangian coordinates

    gaxis = (Lshaft+0.03)*vector(st*sp, ct, st*cp)
    # set orientation along gaxis and rotate it around its axis by psidot*t degrees
    gyro.orientation(gaxis, rotation=psidot*t*57.3) 
    if not i%200: # add trace and render all, every 200 iterations
        trace = vp.point(gaxis, r=3, c='r')
# 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)
Ejemplo n.º 8
0
def my_z(x, y):
    return sin(2 * x * y) * cos(3 * y) / 2
Ejemplo n.º 9
0
or as a reference to an external already existing function.
Red points indicate where the function does not exist.
'''
print(__doc__)
from vtkplotter import Plotter, fxy, sin, cos


def my_z(x, y):
    return sin(2 * x * y) * cos(3 * y) / 2


vp = Plotter(shape=(2, 2), sharecam=False, bg='snow')

# draw at renderer nr.0 the first actor, show it with a texture
# an existing function z(x,y) can be passed:
f1 = fxy(my_z)
vp.show(f1, at=0)

# c=None shows the original z-scalar color scale. No z-level lines.
f2 = fxy(lambda x, y: sin(x * y), c=None, zlevels=None, texture=None, wire=1)
vp.show(f2, at=1)

# red dots are shown where the function does not exist (y>x):
# if vp is set to verbose, sympy calculates derivatives and prints them:
f3 = fxy('sin(3*x)*log(x-y)/3')
vp.show(f3, at=2)

# specify x and y ranges and z vertical limits:
f4 = fxy('log(x**2+y**2 - 1)', x=[-2, 2], y=[-2, 2], zlimits=[-1, 1.5])
vp.show(f4, at=3, axes=2, interactive=1)
##########################################################
N = 100  # number of sample points on the unit sphere
lmax = 15  # maximum degree of the expansion
rmax = 2.0  # line length
rbias = 0.5  # subtract a constant average value
x0 = [0, 0, 0]  # set object at this position
##########################################################

vp = Plotter(shape=[1, 2], verbose=0, axes=0)
shape = vp.load('data/shapes/icosahedron.vtk').normalize().pos(x0).lineWidth(2)

agrid, pts = [], []
for th in np.linspace(0, np.pi, N, endpoint=True):
    lats = []
    for ph in np.linspace(0, 2 * np.pi, N, endpoint=True):
        p = np.array([sin(th) * cos(ph), sin(th) * sin(ph), cos(th)]) * rmax
        intersections = shape.intersectWithLine([0, 0, 0], p)  ### <--
        if len(intersections):
            value = mag(intersections[0])
            lats.append(value - rbias)
            pts.append(intersections[0])
        else:
            lats.append(rmax - rbias)
            pts.append(p)
    agrid.append(lats)
agrid = np.array(agrid)

vp.add(Points(pts, c='b', r=2))
vp.show(at=0)

############################################################
Ejemplo n.º 11
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')
Ejemplo n.º 12
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)