vp.actors = [] # clean up the list of actors for colony in colonies: newcells = [] for cell in colony.cells: if cell.dieAt(t): continue if cell.divideAt(t): newc = cell.split() # make daughter cell vp.add(line(cell.pos, newc.pos, c='k', lw=3, alpha=.5)) newcells.append(newc) newcells.append(cell) colony.cells = newcells pts = [c.pos for c in newcells] # draw all points at once vp.points(pts, c=colony.color, r= 5, alpha=.80) # nucleus vp.points(pts, c=colony.color, r=15, alpha=.05) # halo msg += str(len(colony.cells)) + ',' pb.print(msg+str(int(t))) vp.show(resetcam=0) # draw the oriented ellipsoid that contains 50% of the cells for colony in colonies: pts = [c.pos for c in colony.cells] a = pcaEllipsoid(pts, pvalue=0.5, c=colony.color, pcaAxes=0, alpha=.3, legend='1/rate='+str(colony.cells[0].tdiv)+'h') vp.add(a) vp.show(resetcam=0, interactive=1)
''' Draw the PCA (Principal Component Analysis) ellipsoid that contains 50% of a cloud of Points, then check if points are inside the surface. Extra info is stored in actor.info['sphericity'], 'va', 'vb', 'vc'. ''' from vtkplotter import Plotter, pcaEllipsoid, Points, Text import numpy as np vp = Plotter(verbose=0, axes=4) pts = np.random.randn(500, 3) # random gaussian point cloud act = pcaEllipsoid(pts, pvalue=0.5, pcaAxes=1) ipts = act.getActor(0).insidePoints(pts) # act is a vtkAssembly opts = act.getActor(0).insidePoints(pts, invert=True) vp.add(Points(ipts, c='g')) vp.add(Points(opts, c='r')) print('inside points #', len(ipts)) print('outside points #', len(opts)) print('sphericity :', act.info['sphericity']) vp.add([act, Text(__doc__)]) vp.show()
"""Draw the PCA (Principal Component Analysis) ellipsoid that contains 50% of a cloud of Points, then check if points are inside the surface. Extra info cab be retrieved with: mesh.asphericity() mesh.asphericity_error() """ from vtkplotter import Plotter, pcaEllipsoid, Points, Text2D import numpy as np vp = Plotter(axes=1) pts = np.random.randn(500, 3) * [3, 2, 1] # random gaussian point cloud elli = pcaEllipsoid(pts, pvalue=0.5) ipts = elli.insidePoints(pts) # elli is a vtkAssembly opts = elli.insidePoints(pts, invert=True) vp += Points(ipts, c="g") vp += Points(opts, c="r") vp += [elli, Text2D(__doc__)] print("inside points #", len(ipts)) print("outside points #", len(opts)) print("asphericity:", elli.asphericity(), '+-', elli.asphericity_error()) print("axis 1 size:", elli.va) print("axis 2 size:", elli.vb) print("axis 3 size:", elli.vc) vp.show()