# Use a scalar to paint colored bands on a mesh, # this can be combined with opacities values for each vertex of the mesh. # Keyword depthpeeling improves the rendering of translucent objects. # from vtkplotter import Plotter, hyperboloid, torus from numpy import linspace vp = Plotter(depthpeeling=1) hyp = hyperboloid() scalars = hyp.coordinates()[:,2] # let z-coord be the scalar hyp.pointColors(scalars, bands=5, cmap='rainbow') # make color bands tor = torus(thickness=0.3) scalars = tor.coordinates()[:,2] # let z-coord be the scalar transp = linspace(1, 0.5, len(scalars)) # set transparencies from 1 -> .5 tor.pointColors(scalars, alpha=transp, bands=3, cmap='winter') vp.addScalarBar(hyp, title='hyperboloid') vp.addScalarBar(tor, title='torus', horizontal=True) vp.show([hyp, tor], viewup='z')
# Example of boolean operations with actors or polydata # from vtkplotter import Plotter, booleanOperation, sphere # declare the instance of the class vp = Plotter(shape=(2, 2), interactive=0, axes=3) # build to sphere actors s1 = sphere(pos=[-.7, 0, 0], c='r', alpha=0.5) s2 = sphere(pos=[0.7, 0, 0], c='g', alpha=0.5) # make 3 different possible operations: b1 = booleanOperation(s1, 'intersect', s2, c='m') b2 = booleanOperation(s1, 'plus', s2, c='b', wire=True) b3 = booleanOperation(s1, 'minus', s2, c=None) # show the result in 4 different subwindows 0->3 vp.show([s1, s2], at=0, legend='2 spheres') vp.show(b1, at=1, legend='intersect') vp.show(b2, at=2, legend='plus') vp.show(b3, at=3, legend='minus') vp.addScalarBar() # adds a scalarbar to the last actor vp.show(interactive=1)
# Example on how to specify a color for each individual cell # or point of an actor's mesh. # Last example also shows the usage of addScalarBar3D(). # from vtkplotter import Plotter, arange vp = Plotter(N=3) ##################################### addPointScalars man1 = vp.load('data/shapes/man.vtk') Np = man1.N() # nr. of vertices scals = arange(0, 1, 1. / Np) # coloring by index nr of vertex man1.addPointScalars(scals, 'mypointscalars') # add a vtkArray to actor #print(man1.scalars('mypointscalars')) # info can be retrieved this way vp.show(man1, at=0, elevation=-60) vp.addScalarBar() # add a scalarbar to last drawn actor ##################################### pointColors man2 = vp.load('data/shapes/man.vtk') scals = man2.coordinates()[:, 1] + 37 # pick y coordinates of vertices man2.pointColors(scals, cmap='bone', vmin=36.2, vmax=36.7) # right dark arm vp.show(man2, at=1, axes=0, legend='pointColors') vp.addScalarBar(horizontal=True) ##################################### cellColors man3 = vp.load('data/shapes/man.vtk') scals = man3.cellCenters()[:, 2] + 37 # pick z coordinates of cells man3.cellColors(scals, cmap='afmhot') #print(man3.scalars('cellColors_afmhot')) # info can be retrieved this way
pts = s.closestPoint(p, N=12) # find the N closest points to p sph = fitSphere(pts) # find the fitting sphere if sph is None: continue value = sph.info['radius']*10 color = colorMap(value, name='jet') # map value to a RGB color n = norm(p-sph.info['center']) # unit vector from sphere center to p vals.append(value) cols.append(color) pts1.append(p) pts2.append(p+n/8) if not i%500: print(i,'/',s.N()) vp.points(pts1, c=cols) vp.addScalarBar() vp.lines(pts1, pts2, c='black 0.2') vp.histogram(vals, title='values', bins=20, vrange=[0,1]) vp.show()