示例#1
0
    def _make_root(self, rootpath):
        """
            Creates a root mesh by merging the mesh corresponding to each neuron,
            then saves it as an obj file at rootpath
        """
        raise NotImplementedError(f"Create root method not supported yet, sorry")

        print(f"Creating root mesh for atlas {self.atlas_name}")
        temp_scene = Scene(atlas=Celegans, add_root=False,
                        display_inset=False,
                        atlas_kwargs=dict(data_folder=self.data_folder))

        temp_scene.add_neurons(self.neurons_names)
        temp_scene.render(interactive=False)
        temp_scene.close()

        root = merge(*temp_scene.actors['neurons']).clean().cap()
        # root = mesh2Volume(root, spacing=(0.02, 0.02, 0.02)).isosurface()

        points = Points(root.points()).smoothMLS2D(f=0.8).clean(tol=0.005)

        root =  recoSurface(points, dims=100, radius=0.2)


        # Save
        write(root, rootpath)
        
        del temp_scene
        return root
示例#2
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
示例#3
0
    def learn(self, n_epoch=10000, sigma=(0.25, 0.01), lrate=(0.5, 0.01)):

        t = np.linspace(0, 1, n_epoch)
        lrate = lrate[0] * (lrate[1] / lrate[0])**t
        sigma = sigma[0] * (sigma[1] / sigma[0])**t
        I = np.random.randint(0, len(self.samples), n_epoch)
        self.samples = self.samples[I]
        pts = Points(self.samples, r=2)
        doc = Text(__doc__)

        pb = ProgressBar(0, n_epoch)
        for i in pb.range():
            pb.print("epochs")
            # Get random sample
            data = self.samples[i]

            # Get index of nearest node (minimum distance)
            winner = np.argmin(((self.codebook - data)**2).sum(axis=-1))

            # Gaussian centered on winner
            G = np.exp(-self.distance[winner]**2 / sigma[i]**2)

            # Move nodes towards sample according to Gaussian
            self.codebook -= lrate[i] * G[...,
                                          np.newaxis] * (self.codebook - data)

            # Draw network
            if i > 500 and not i % 20 or i == n_epoch - 1:
                x, y, z = [self.codebook[:, i].reshape(n, n) for i in range(3)]
                grd = Grid(resx=n - 1,
                           resy=n - 1).wire(False).lw(0.5).bc('lightblue')
                for i in range(n):
                    for j in range(n):
                        grd.setPoint(i * n + j, (x[i, j], y[i, j], z[i, j]))
                show(doc,
                     pts,
                     grd,
                     axes=6,
                     bg='w',
                     azimuth=2,
                     interactive=False)

        return [self.codebook[:, i].reshape(n, n) for i in range(3)]
示例#4
0
 and align them using the Iterative Closest Point algorithm.
'''
from __future__ import division
from random import uniform as u
from vtkplotter import Plotter, align, Arrow, Text, Points

vp = Plotter(shape=[1, 2], verbose=0, axes=2, bg='w')

N1 = 15  # number of points of first set
N2 = 15  # number of points of second set
x = 1.  # add some randomness

pts1 = [(u(0, x), u(0, x), u(0, x) + i) for i in range(N1)]
pts2 = [(u(0, x) + 3, u(0, x) + i / 2 + 2, u(0, x) + i + 1) for i in range(N2)]

act1 = Points(pts1, r=8, c='b').legend('source')
act2 = Points(pts2, r=8, c='r').legend('target')

vp.show([act1, act2], at=0)

# find best alignment between the 2 sets of Points, e.i. find
# how to move act1 to best match act2
alpts1 = align(act1, act2).coordinates()
vp.add(Points(alpts1, r=8, c='b'))

for i in range(N1):  # draw arrows to see where points end up
    vp.add(Arrow(pts1[i], alpts1[i], c='k', s=0.007, alpha=.1))

vp.add(Text(__doc__, c='k'))
vp.show(at=1, interactive=1)
示例#5
0
"""
Example for delaunay2D() and cellCenters() functions.
"""
print(__doc__)

from vtkplotter import Plotter, delaunay2D, Points, datadir

vp = Plotter(shape=(1, 2), interactive=0)

d0 = vp.load(datadir + "250.vtk").rotateY(-90).legend("original mesh")

coords = d0.points()  # get the coordinates of the mesh vertices
# Build a mesh starting from points in space
#  (points must be projectable on the XY plane)
d1 = delaunay2D(coords, mode='fit')
d1.color("r").wireframe(True).legend("delaunay mesh")

cents = d1.cellCenters()
ap = Points(cents).legend("cell centers")

vp.show(d0, d1, at=0)  # NB: d0 and d1 are slightly different
vp.show(d1, ap, at=1, interactive=1)
示例#6
0
The points in between are interpolated using Bookstein's algorithm.
'''
from vtkplotter import Plotter, thinPlateSpline, Points, Text
import numpy as np
np.random.seed(1)

vp = Plotter(verbose=0)

act = vp.load('data/shuttle.obj')

# pick 4 random points
indxs = np.random.randint(0, act.N(), 4)

# and move them randomly by a little
ptsource, pttarget = [], []
for i in indxs:
    ptold = act.getPoint(i)
    ptnew = ptold + np.random.rand(3) * 0.2
    act.setPoint(i, ptnew)
    ptsource.append(ptold)
    pttarget.append(ptnew)
    # print(ptold,'->',ptnew)

warped = thinPlateSpline(act, ptsource, pttarget)
warped.alpha(0.4).color('b')
# print(warped.info['transform']) # saved here.

apts = Points(ptsource, r=15, c='r')

vp.show([act, warped, apts, Text(__doc__)], viewup='z')
X, Y, Z = np.mgrid[0:10:n, 0:10:n, 0:10:n]
xr, yr, zr = X.ravel(), Y.ravel(), Z.ravel()
positions = np.vstack([xr, yr, zr])

sources = [
    (5, 8, 5),
    (8, 5, 5),
    (5, 2, 5),
]
deltas = [
    (1, 1, .2),
    (1, 0, -.8),
    (1, -1, .2),
]

apos = Points(positions, r=2)

#for p in apos.coordinates(): ####### Uncomment to fix some points.
#    if abs(p[2]-5) > 4.999:  # differences btw RBF and thinplate
#        sources.append(p)    # will become much smaller.
#        deltas.append(np.zeros(3))
sources = np.array(sources)
deltas = np.array(deltas)

src = Points(sources, c='r', r=12)
trs = Points(sources + deltas, c='v', r=12)
arr = Arrows(sources, sources + deltas)

################################################# Thin Plate Splines
warped = thinPlateSpline(apos, sources, sources + deltas)
warped.alpha(0.4).color('lg').pointSize(10)
"""
from __future__ import division, print_function
from vtkplotter import Plotter, colorMap, smoothMLS2D, Points, Spheres, Text
import numpy as np

vp1 = Plotter(shape=(1, 4), axes=4, bg="w")

act = vp1.load("data/shapes/bunny.obj").normalize().subdivide()
act.color("k").alpha(0.05).wire(True)
pts = act.coordinates(copy=True)  # pts is a copy of the points not a reference
pts += (np.random.randn(len(pts), 3) / 40
        )  # add noise, will not mess up the original points

#################################### smooth cloud with MLS
# build the points actor
s0 = Points(pts, c="blue", r=3).legend("point cloud")
vp1.show(s0, at=0)

s1 = s0.clone().color("dg")  # a dark green copy of s0

# project s1 points into a smooth surface of points
# return a demo actor showing 30 regressions at random points
mls1 = smoothMLS2D(s1, f=0.5, showNPlanes=30)  # first pass
vp1.show(mls1, at=1, legend="first pass")

mls2 = smoothMLS2D(s1, f=0.3, showNPlanes=30)  # second pass
vp1.show(mls2, at=2, legend="second pass")

mls3 = smoothMLS2D(s1, f=0.1)  # third pass
vp1.show(s1, at=3, legend="third pass", zoom=1.3)
示例#9
0
This make a simultaneus fit in 4D (space+time).
smoothMLS3D method returns a vtkActor where points
are color coded in bins of fitted time.
Data itself can suggest a meaningful time separation
based on the spatial distribution of points.
The nr neighbours in the local 4D fitting must be specified.
'''
from vtkplotter import Plotter, Sphere, smoothMLS3D, Points, Text

vp = Plotter(N=2, axes=0, bg='w')

# generate uniform points on sphere (tol separates points by 2% of actor size)
cc = Sphere(res=200).clean(tol=0.02).coordinates()

a, b, noise = .2, .4, .1  # some random warping paramenters, and noise factor
sets = []
for i in range(5):  # generate a time sequence of 5 shapes
    cs = cc + a * i * cc**2 + b * i * cc**3  # warp sphere in weird ways
    # set absolute time of points actor, and add 1% noise on positions
    ap = Points(cs, c=i, alpha=0.5).addGaussNoise(1.0).time(0.2 * i)
    sets.append(ap)

vp.show(Text(__doc__, c='k'), at=0)
vp.show(sets, at=0, zoom=1.4)  # show input clouds as func(time)

asse = smoothMLS3D(sets, neighbours=50)

vp.addScalarBar3D(asse, at=1, pos=(-2, 0, -1))  # color indicates fitted time

vp.show(asse, at=1, zoom=1.4, axes=4, interactive=1)
Example shows how to share the same vtkCamera
between different Plotter windows.
"""
from vtkplotter import Plotter, Points, Arrows, show, Text2D
import numpy as np

ls = np.linspace(0, 10, 8)
X, Y, Z = np.meshgrid(ls, ls, ls)
xr, yr, zr = X.ravel(), Y.ravel(), Z.ravel()
positions = np.vstack([xr, yr, zr])

sources = [(5, 8, 5), (8, 5, 5), (5, 2, 5)]
deltas = [(1, 1, 0.2), (1, 0, -0.8), (1, -1, 0.2)]

apos = Points(positions, r=2)

# for p in apos.points(): ####### Uncomment to fix some points.
#    if abs(p[2]-5) > 4.999:  # differences btw RBF and thinplate
#        sources.append(p)    # will become much smaller.
#        deltas.append(np.zeros(3))
sources = np.array(sources)
deltas = np.array(deltas)

src = Points(sources, c="r", r=12)
trs = Points(sources + deltas, c="v", r=12)
arr = Arrows(sources, sources + deltas)

################################################# Thin Plate Splines
warped = apos.clone().thinPlateSpline(sources, sources + deltas)
warped.alpha(0.4).color("lg").pointSize(10)
示例#11
0
'''
from __future__ import division, print_function
from random import uniform as u

from vtkplotter import Plotter, procrustes, Text, Points

vp = Plotter(shape=[1, 2], verbose=0, axes=2, sharecam=0, bg='w')

N = 15  # number of points
x = 1.  # add some randomness

pts1 = [(u(0, x), u(0, x), u(0, x)+i) for i in range(N)]
pts2 = [(u(0, x)+3, u(0, x)+i/2+2, u(0, x)+i+1) for i in range(N)]
pts3 = [(u(0, x)+4, u(0, x)+i/4-3, u(0, x)+i-2) for i in range(N)]

act1 = Points(pts1, c='r').legend('set1')
act2 = Points(pts2, c='g').legend('set2')
act3 = Points(pts3, c='b').legend('set3')

vp.show([act1, act2, act3], at=0)

# find best alignment among the n sets of Points,
# return an Assembly formed by the aligned sets
aligned = procrustes([act1, act2, act3])

# print(aligned.info['transform'])

vp.show([aligned, Text(__doc__)], at=1, interactive=1)


示例#12
0
import numpy as np
from vtkplotter import Plotter, fitLine, fitPlane, Points, Text

# 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

    vp += fitLine(data).lw(4).alpha(0.03)  # fit a line

# 'data' still contains the last iteration points
vp += Points(data, r=10, c="yellow")

# the first fitted slope direction is stored
# in actor.info['slope] and actor.info['normal]
print("Line Fit slope = ", vp.actors[0].info["slope"])

plane = fitPlane(data)  # fit a plane
print("Plan Fit normal=", plane.info["normal"])

vp += [plane, Text(__doc__)]

vp.show(axes=1)
示例#13
0
"""Generate 3 random sets of points and align
them using Procrustes method.
"""
from __future__ import division, print_function
from random import uniform as u

from vtkplotter import Plotter, alignProcrustes, Points

vp = Plotter(shape=[1, 2], axes=2, sharecam=0)

N = 15  # number of points
x = 1.0  # add some randomness

pts1 = [(u(0, x), u(0, x), u(0, x) + i) for i in range(N)]
pts2 = [(u(0, x) + 3, u(0, x) + i / 2 + 2, u(0, x) + i + 1) for i in range(N)]
pts3 = [(u(0, x) + 4, u(0, x) + i / 4 - 3, u(0, x) + i - 2) for i in range(N)]

vpts1 = Points(pts1, c="r").legend("set1")
vpts2 = Points(pts2, c="g").legend("set2")
vpts3 = Points(pts3, c="b").legend("set3")

vp.show(vpts1, vpts2, vpts3, __doc__, at=0)

# find best alignment among the n sets of Points,
# return an Assembly object formed by the aligned sets
aligned = alignProcrustes([vpts1, vpts2, vpts3])

# print(aligned.info['transform'])

vp.show(aligned, at=1, interactive=1)
示例#14
0
    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=0.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=0.80)   # nucleus
        vp += Points(pts, c=colony.color, r=15, alpha=0.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]
    a = pcaEllipsoid(pts, pvalue=0.5, pcaAxes=0)
    a.color(colony.color).alpha(0.3)
    a.legend("1/rate=" + str(colony.cells[0].tdiv) + "h")
    vp += a
vp.show(resetcam=0, interactive=1)
示例#15
0
"""
Colorize a large cloud of points by passing
colors and transparencies in the format (R,G,B,A)
"""
print(__doc__)
from vtkplotter import Points
import numpy as np
import time

N = 1000000

pts = np.random.rand(N, 3)
RGB = pts * 255
Alpha = pts[:, 2] * 255
RGBA = np.c_[RGB, Alpha]  # concatenate

print("clock starts")
t0 = time.clock()

# passing c in format (R,G,B,A) is ~50x faster
pts = Points(pts, r=2, c=RGBA)  #fast
#pts = Points(pts, r=2, c=pts, alpha=pts[:, 2]) #slow

t1 = time.clock()
print("----> elapsed time:", t1 - t0, "seconds for N:", N)

pts.show(bg="white", axes=True)
示例#16
0
Example shows how to share the same vtkCamera
between different Plotter windows.
"""
from vtkplotter import Plotter, thinPlateSpline, Points, Arrows, show, Text
import numpy as np

ls = np.linspace(0, 10, 8)
X, Y, Z = np.meshgrid(ls, ls, ls)
xr, yr, zr = X.ravel(), Y.ravel(), Z.ravel()
positions = np.vstack([xr, yr, zr])

sources = [(5, 8, 5), (8, 5, 5), (5, 2, 5)]
deltas = [(1, 1, 0.2), (1, 0, -0.8), (1, -1, 0.2)]

apos = Points(positions, r=2)

# for p in apos.getPoints(): ####### Uncomment to fix some points.
#    if abs(p[2]-5) > 4.999:  # differences btw RBF and thinplate
#        sources.append(p)    # will become much smaller.
#        deltas.append(np.zeros(3))
sources = np.array(sources)
deltas = np.array(deltas)

src = Points(sources, c="r", r=12)
trs = Points(sources + deltas, c="v", r=12)
arr = Arrows(sources, sources + deltas)

################################################# Thin Plate Splines
warped = thinPlateSpline(apos, sources, sources + deltas)
warped.alpha(0.4).color("lg").pointSize(10)
示例#17
0
        ph = np.deg2rad(long)
        p = spher2cart(agrid_reco[j][i], th, ph)
        pts1.append(p)
        ll.append((lat, long))

radii = agrid_reco.T.ravel()
n = 500j
lnmin, lnmax = np.array(ll).min(axis=0), np.array(ll).max(axis=0)
grid = np.mgrid[lnmax[0]:lnmin[0]:(n), lnmin[1]:lnmax[1]:(n + 1j)]
grid_x, grid_y = grid
agrid_reco_finer = griddata(ll, radii, (grid_x, grid_y), method='cubic')

pts2 = []
for i, long in enumerate(
        np.linspace(0, 360, num=agrid_reco_finer.shape[1], endpoint=False)):
    for j, lat in enumerate(
            np.linspace(90, -90, num=agrid_reco_finer.shape[0],
                        endpoint=True)):
        th = np.deg2rad(90 - lat)
        ph = np.deg2rad(long)
        p = spher2cart(agrid_reco_finer[j][i], th, ph)
        pts2.append(p)

act1 = Points(pts1, r=5, c="b", alpha=1)
act1_col = Points(pts1colored, r=8, c="k", alpha=0.5)
act2 = Points(pts2, r=3, c="r", alpha=0.5)
act2.clean(0.01)  # impose point separation of 1% of the bounding box size

comment = Text('spherical harmonics\nexpansion of order ' + str(lmax))
show(act2, comment, at=1, interactive=True)
示例#18
0
vp = Plotter(shape=[2, 2], axes=3, interactive=0)

shape1 = Sphere(alpha=0.2)
shape2 = vp.load(datadir + "icosahedron.vtk").normalize().lineWidth(1)

agrid1, actorpts1 = makeGrid(shape1, N)

vp.show(shape1, actorpts1, at=0)

agrid2, actorpts2 = makeGrid(shape2, N)
vp.show(shape2, actorpts2, at=1)

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(act21, at=2, resetcam=0)
    vp.show(act12, at=3)
    vp.camera.Azimuth(2)

vp.show(interactive=1)
示例#19
0
"""
2D histogram with hexagonal binning.
"""
print(__doc__)
from vtkplotter import Plotter, histogram2D, Points, Latex
import numpy as np

vp = Plotter(axes=1, verbose=0, bg="w")
vp.xtitle = "x gaussian, s=1.0"
vp.ytitle = "y gaussian, s=1.5"
vp.ztitle = "dN/dx/dy"

N = 20000
x = np.random.randn(N) * 1.0
y = np.random.randn(N) * 1.5

histo = histogram2D(x, y, c="dr", bins=15, fill=False)

pts = Points([x, y, np.zeros(N)], c="black", alpha=0.1)

f = r'f(x, y)=A \exp \left(-\left(\frac{\left(x-x_{o}\right)^{2}}{2 \sigma_{x}^{2}}+\frac{\left(y-y_{o}\right)^{2}}{2 \sigma_{y}^{2}}\right)\right)'

formula = Latex(f, c='k', s=2).rotateZ(90).pos(5, -2, 1)

vp.show(histo, pts, formula, viewup="z")
示例#20
0
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 = []

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.setPoint(i, x+[0,0, psi2/norm]) # elevate grid in z

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

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

vp.add(Grid(sx=0.1, sy=0.1, resx=6, resy=6, c='w', alpha=.1)) # add some annotation
vp.add(Line([0,0,0], [0,0,-D], c='w', alpha=.1))
vp.add(Text('source plane', pos=[-.05,-.053,0], s=.002, c='gray'))
vp.add(Text('detector plane D = '+str(D)+' m', pos=[-.05,-.053,-D], s=.002, c='gray'))
vp.add(Text(__doc__, c='gray'))

vp.show(zoom=1.1)


示例#21
0
'''
Draw the PCA (Principal Component Analysis) ellipsoid that contains  
50% of a cloud of Points, then check if points are inside the surface.
Extra info is stored in actor.info['sphericity'], 'va', 'vb', 'vc'.
'''
from vtkplotter import Plotter, pcaEllipsoid, Points, Text
import numpy as np

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

pts = np.random.randn(500, 3)  # random gaussian point cloud

act = pcaEllipsoid(pts, pvalue=0.5, pcaAxes=1)

ipts = act.getActor(0).insidePoints(pts)  # act is a vtkAssembly
opts = act.getActor(0).insidePoints(pts, invert=True)
vp.add(Points(ipts, c='g'))
vp.add(Points(opts, c='r'))

print('inside  points #', len(ipts))
print('outside points #', len(opts))
print('sphericity :', act.info['sphericity'])

vp.add([act, Text(__doc__)])

vp.show()
示例#22
0
import numpy as np

dt = 0.002
y = (25.0, -10.0, -7.0)  # Starting point (initial condition)
pts, cols = [], []

for t in np.linspace(0, 20, int(20 / dt)):
    # Integrate a funny differential equation
    dydt = np.array([
        -8 / 3.0 * y[0] + y[1] * y[2], -10.0 * (y[1] - y[2]),
        -y[1] * y[0] + 28.0 * y[1] - y[2]
    ])
    y = y + dydt * dt

    c = np.clip([np.linalg.norm(dydt) * 0.005], 0, 1)[0]  # color by speed
    cols.append([c, 0, 1 - c])
    pts.append(y)

from vtkplotter import Plotter, Line, Point, Points, settings
settings.renderPointsAsSpheres = False  # render points as squares

scene = Plotter(title="Lorenz attractor", axes=1, verbose=0, bg="w")
scene += Point(y, r=10, c="g")  # end point
scene += Points(pts, r=3, c=cols)
scene += Line(pts).off().addShadow(x=3)  # only show shadow, not line
scene += Line(pts).off().addShadow(z=-30)
scene.show(viewup='z')
示例#23
0
'''
Voronoi in 3D with Voro++ library.
'''
from vtkplotter import voronoi3D, Points, show
import numpy as np

#from vtkplotter import settings
#settings.voro_path = '/g/sharpeba/software/bin'

N = 2000
nuclei = np.random.rand(N, 3) - (0.5, 0.5, 0.5)
ncl = Points(nuclei).clean(0.1)  # clean makes points evenly spaced
nuclei = ncl.points()

mesh = voronoi3D(nuclei, tol=.001)
#print(len(mesh.info['cells']), mesh.info['volumes'])

pts_inside = mesh.insidePoints(nuclei)
inpts = Points(pts_inside, r=50, c='r', alpha=0.2)

show(mesh, inpts)
示例#24
0
"""
Kochanek–Bartels spline
"""
from vtkplotter import Text, Points, KSpline, show
from random import uniform as u

pts = [(u(0, 2), u(0, 2), u(0, 2) + i) for i in range(8)]

Points(pts, r=10)
Text(__doc__)

for i in range(10):
    g = (i / 10 - 0.5) * 2  # from -1 to 1
    KSpline(pts, continuity=g, tension=0, bias=0, closed=False).color(i)

# plot all object sofar created:
show(..., viewup="z", axes=1)
示例#25
0
xyz[:, 2] = top_granitoid_verticesPD.values[:, 2] - 20
tri = Delaunay(top_granitoid_verticesPD.values[:, 0:2])
top_granitoid_vertices = Mesh([xyz, tri.simplices]).c("darkcyan")
top_granitoid_vertices.name = 'Top of granite surface'
plot += top_granitoid_vertices.flag()

####################
## 3. Point objects
####################
printc("...plotting...", invert=1)

#FORGE Boundary
#Since the boundary area did not have a Z column, I assigned a Z value for where I wanted it to appear
border['zcoord'] = 1650
borderxyz = border[['xcoord', 'ycoord', 'zcoord']]
boundary = Points(borderxyz.values).c('k')
boundary.name = 'FORGE area boundary'
plot += boundary.flag()

#Microseismic
microseismicxyz = microseismic[['xloc', 'yloc', 'zloc']]
scals = microseismic[['mw']]
microseismicPts = Points(microseismicxyz.values, r=3).cellColors(scals,
                                                                 cmap="jet")
microseismicPts.name = 'Microseismic events'
plot += microseismicPts.flag()

####################
## 4. Line objects
####################
#The path of well 58_32
n = 200j
lmin, lmax = np.array(ll).min(axis=0), np.array(ll).max(axis=0)
grid = np.mgrid[lmin[0]:lmax[0]:n, lmin[1]:lmax[1]:n]
grid_x, grid_y = grid
agrid_reco_finer = griddata(ll, radii, (grid_x, grid_y), method='cubic')

pts2 = []
for i, lat in enumerate(grid_x[:,1]):
    for j, long in enumerate(grid_y[0]):
        th = np.deg2rad(90 -lat)
        ph = np.deg2rad(long)
        r = agrid_reco_finer[i][j]
        p = spher2cart(r, th, ph)
        pts2.append(p)

act1 = Points(pts1, r=8, c="b", alpha=0.5)
act2 = Points(pts2, r=2, c="r", alpha=0.5)

show(act1, act2, at=1, interactive=1)











示例#27
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 actor.info['radius'].
'''
from __future__ import division, print_function
from vtkplotter import Plotter, fitSphere, histogram, Points, Line, Text

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.add(sph)
    vp.add(Points(pts))
    vp.add(Line(sph.info['center'], p, lw=2))
    reds.append(sph.info['residue'])
    invr.append(1/sph.info['radius']**2)

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

vp.add(Text(__doc__))
vp.show(viewup='z')
示例#28
0
agrid_reco = grid_reco.to_array()

ll = []
for i, long in enumerate(np.linspace(0, 360, num=agrid_reco.shape[1], endpoint=True)):
    for j, lat in enumerate(np.linspace(90, -90, num=agrid_reco.shape[0], endpoint=True)):
        th = np.deg2rad(90 - lat)
        ph = np.deg2rad(long)
        p = spher2cart(agrid_reco[j][i], th, ph)
        ll.append((lat, long))

radii = agrid_reco.T.ravel()
n = 250j
lnmin, lnmax = np.array(ll).min(axis=0), np.array(ll).max(axis=0)
grid = np.mgrid[lnmax[0]:lnmin[0]:(n), lnmin[1]:lnmax[1]:(n + 1j)]
grid_x, grid_y = grid
agrid_reco_finer = griddata(ll, radii, (grid_x, grid_y), method='cubic')

pts2 = []
for i, long in enumerate(np.linspace(0, 360, num=agrid_reco_finer.shape[1], endpoint=False)):
    for j, lat in enumerate(np.linspace(90, -90, num=agrid_reco_finer.shape[0], endpoint=True)):
        th = np.deg2rad(90 - lat)
        ph = np.deg2rad(long)
        p = spher2cart(agrid_reco_finer[j][i], th, ph)
        pts2.append(p)

mesh2 = Points(pts2, r=2, c="r", alpha=0.5)
mesh2.clean(0.01) # impose point separation of 1% of the bounding box size

comment = Text2D('spherical harmonics\nexpansion of order '+str(lmax))
show(mesh2, comment, at=1, interactive=True)

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)
示例#30
0
plt += Opal_Mound_Fault_vertices.c("g").opacity(0.6).flag()

# Top Granite
xyz = top_granitoid_verticesPD.values
xyz[:, 2] = top_granitoid_verticesPD.values[:, 2] - 20
tri = Delaunay(top_granitoid_verticesPD.values[:, 0:2])
top_granitoid_vertices = Mesh([xyz, tri.simplices]).texture('white1')
top_granitoid_vertices.name = "Top of granite surface"
plt += top_granitoid_vertices.flag()

printc("plotting...", invert=1)

# Microseismic
microseismicxyz = microseismic[["xloc", "yloc", "zloc"]].values
scals = microseismic[["mw"]]
microseismicPts = Points(microseismicxyz, r=5).pointColors(scals, cmap="jet")
microseismicPts.name = "Microseismic events"
plt += microseismicPts.flag()

# FORGE Boundary. Since the boundary area did not have a Z column,
# I assigned a Z value for where I wanted it to appear
border["zcoord"] = 1650
borderxyz = border[["xcoord", "ycoord", "zcoord"]]
boundary = Line(borderxyz.values).extrude(zshift=120,
                                          cap=False).lw(0).texture('wood1')
boundary.name = "FORGE area boundary"
plt += boundary.flag()

# The path of well 58_32
Well1 = Line(well_5832_path[["X", "Y", "Z"]].values, lw=2, c='k')
Well1.name = "Well 58-32"