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) #################################### draw errors vp2 = Plotter(pos=(200, 400), shape=(1, 2), axes=4, bg="w")
4. a triangular mesh is extracted from this set of sparse Points, 'bins' is the number of voxels of the subdivision ''' from __future__ import division, print_function from vtkplotter import Plotter, recoSurface, smoothMLS2D, Points, Text import numpy as np vp = Plotter(shape=(1, 5), axes=0) vp.show(Text(__doc__), at=4) act = vp.load('data/shapes/pumpkin.vtk') vp.show(act, at=0) noise = np.random.randn(act.N(), 3) * 0.05 act_pts0 = Points(act.coordinates() + noise, r=3) # add noise act_pts1 = act_pts0.clone() # make a copy to modify vp.show(act_pts0, at=1, legend='noisy cloud') smoothMLS2D(act_pts1, f=0.4) # smooth cloud, input actor is modified print('Nr of points before cleaning polydata:', act_pts1.N()) act_pts1.clean(tol=0.01) # impose a min distance among mesh points print(' after cleaning polydata:', act_pts1.N()) vp.show(act_pts1, at=2, legend='smooth cloud') act_reco = recoSurface(act_pts1, bins=128) # reconstructed from points vp.show(act_reco, at=3, axes=7, interactive=1, legend='surf reco')
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__] 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
''' Using 1D Moving Least Squares to skeletonize a surface. ''' print(__doc__) from vtkplotter import Plotter, smoothMLS1D, Points N=10 # nr of iterations f=0.1 # fraction of neighbours vp = Plotter(N=N, axes=0) pts = vp.load('data/shapes/man.vtk').decimate(0.1).coordinates() #pts = vp.load('data/shapes/spider.ply').coordinates() #pts = vp.load('data/shapes/magnolia.vtk').subdivide().coordinates() #pts = vp.load('data/shapes/pumpkin.vtk').coordinates() #pts = vp.load('data/shapes/teapot.vtk').coordinates() a = Points(pts) for i in range(N): vp.show(a, at=i, elevation=-5) a = a.clone().color(i) smoothMLS1D(a, f) vp.show(interactive=1)