Pointcloud density#

"""Density plot from a distribution of points in 3D"""
from vedo import *
settings.default_backend = "vtk"
n = 3000
p = np.random.normal(7, 0.3, (n,3))
p[:int(n*1/3) ] += [1,0,0]       # shift 1/3 of the points along x by 1
p[ int(n*2/3):] += [1.7,0.4,0.2]
pts = Points(p, alpha=0.5)
pts

vedo.pointcloud.Points
bounds
(x/y/z)
5.941 ... 9.689
5.913 ... 8.431
5.936 ... 8.214
center of mass (7.89, 7.14, 7.07)
average size 0.832
nr. points 3000
# Create a Volume from the points representing the points density
vol = pts.density(radius=0.25).cmap('Dark2').alpha([0.1,1])
vol.add_scalarbar3d(title='Density (counts in radius)', c='k')

PointDensity:   vedo.volume.Volume
bounds
(x/y/z)
5.941 ... 9.689
5.913 ... 8.431
5.936 ... 8.214
dimensions (40, 40, 40)
voxel spacing (0.0961, 0.0646, 0.0584)
in memory size 0MB
point data array ImageScalars
scalar range (0, 137.0)
show(pts, vol, __doc__, axes=1).close()