densifycloud.py 689 B

1234567891011121314151617
  1. """Generate a denser point cloud.
  2. The new points are created in such a way that
  3. all points in any local neighborhood are
  4. within a target distance of one another"""
  5. from vedo import Points, printc, show
  6. import numpy as np
  7. npts = 50 # nr. of points
  8. coords = np.random.rand(npts, 3) # range is [0, 1]
  9. scals = np.abs(coords[:, 1]) # let the scalar be the y of the point itself
  10. pts = Points(coords, r=9)
  11. pts.pointdata["scals"] = scals
  12. densecloud = pts.densify(0.1, nclosest=10, niter=1) # return a new pointcloud.Points
  13. printc('nr. points increased', pts.npoints, ':rightarrow:', densecloud.npoints, c='lg')
  14. show([(pts, __doc__), densecloud], N=2, axes=1).close()