Skip to content

PointCloud Voxelization

0. Import libraries

import os
import topogenesis as tg
import numpy as np
import pyvista as pv

1. read point cloud from csv file

pc_path = os.path.relpath('../../data/rdam_cloud.csv')
pc = tg.cloud_from_csv(pc_path)
print(type(pc))
print(pc.bounds)
print(pc)
<class 'topogenesis.datastructures.datastructures.cloud'>
[[ 9.3198970e+04  4.3618254e+05 -1.7400000e+00]
 [ 9.3361080e+04  4.3631357e+05  2.6570000e+01]]
[[9.3340350e+04 4.3631074e+05 3.1100000e+00]
 [9.3340650e+04 4.3631029e+05 3.1300000e+00]
 [9.3340950e+04 4.3630982e+05 3.1300000e+00]
 ...
 [9.3360940e+04 4.3624841e+05 3.5800000e+00]
 [9.3360720e+04 4.3624877e+05 3.4200000e+00]
 [9.3360970e+04 4.3624895e+05 3.5400000e+00]]

2. regularizing random points into a lattice

l = pc.voxelate([1, 1, 1])
print(type(l))
print(l.unit)
print(l.bounds)
<class 'topogenesis.datastructures.datastructures.lattice'>
[1 1 1]
[[ 93198 436182     -3]
 [ 93362 436315     28]]

3. plot the pointcloud

# initiating the plotter
p = pv.PlotterITK() # ITK plotter for interactivity within the python notebook (itkwidgets library is required)

# fast visualization of the point cloud
pc.fast_notebook_vis(p)

# fast visualization of the lattice
l.fast_notebook_vis(p, show_outline=True, show_centroids=True)


# Set a camera position
p.camera_position = [(0.25, 0.18, 0.5), (0, .1, 0), (0, 1, 0)]

# plotting
p.show()

point_cloud_voxelization