''' 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)
# 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) allarr = Arrows(apos.points(), warped.points()) set1 = [apos, warped, src, trs, arr, __doc__] vp = show([set1, allarr], N=2, bg='bb') # 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