"""Voronoi tessellation of a pointcloud on a grid""" from vedo import dataurl, Points, Grid, voronoi, show pts0 = Points(dataurl + 'rios.xyz').color('k') pts1 = pts0.clone().smoothLloyd2D() grid = Grid([14500, 61700], sx=22000, sy=24000, resx=30, resy=30).ps(1) allpts = pts1.points().tolist() + grid.points().tolist() msh = voronoi(allpts, method='scipy') msh.lw(0.1).wireframe(False).cmap('terrain_r', 'VoronoiID', on='cells') centers = Points(msh.cellCenters(), c='k') show(msh, pts0, __doc__, axes=dict(digits=3))
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) allarr = Arrows(apos.points(), warped.points()) set1 = [apos, warped, src, trs, arr, __doc__] plt1 = 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
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) ################################################# warp using Thin Plate Splines warped = apos.clone().warp(sources, sources + deltas) warped.alpha(0.4).color("lg").pointSize(10) allarr = Arrows(apos.points(), warped.points()) set1 = [apos, warped, src, trs, arr, __doc__] plt1 = 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