Skip to content

Mesh Sampling

In this notebook we will complete a mesh sampling process with the topoGenesis package

0. Initialization

Importing all necessary libraries and specifying the inputs

import os
import topogenesis as tg
import pyvista as pv
vs = 0.01
unit = [vs, vs, vs]
tol = 1e-09
mesh_path = os.path.relpath('../../data/bunny_lowpoly.obj')
mesh = tg.geometry.load_mesh(mesh_path)

1. Sampling

Running the sampling algorithm and asking the function to output the ray origins as well

sample_cloud, ray_origins = tg.geometry.mesh_sampling(mesh, unit, multi_core_process=False, return_ray_origin = True, tol=tol)

2. Voxelating

Voxelating the point cloud to construct a lattice out of it

lattice = sample_cloud.voxelate(unit, closed=True)
print(type(lattice))
print(lattice.unit)
print(lattice.bounds)
<class 'topogenesis.datastructures.datastructures.lattice'>
[0.01 0.01 0.01]
[[-0.1   0.02 -0.07]
 [ 0.07  0.19  0.07]]

3. Plotting

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

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

# fast visualization of the lattice
lattice.fast_notebook_vis(p)

# adding the base mesh: light blue
mesh = pv.read(mesh_path)
p.add_mesh(mesh, color='#abd8ff')

# adding the ray origins: dark blue
p.add_points(pv.PolyData(ray_origins), color='#004887')

# plotting
p.show()

mesh_sampling