#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)
allarr = Arrows(apos.coordinates(), warped.coordinates())

set1 = [apos, warped, src, trs, arr, Text(__doc__, s=1.2)]
vp = show([set1, allarr], N=2, verbose=0)  # returns the Plotter class

################################################# 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
Ejemplo n.º 2
0
'''
Voronoi in 3D with Voro++ library.
'''
from vtkplotter import voronoi3D, Points, show, settings
import numpy as np

#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.coordinates()

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

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

show(actor, inpts)