Converting points and surfaces

Converting points and surfaces#

In this notebook we will sample points from a surface and convert the point cloud back into a surface.

import napari_process_points_and_surfaces as nppas
import vedo
import napari
viewer = napari.Viewer(ndisplay=3)

def hide_all(viewer):
    for layer in viewer.layers:
        layer.visible = False
        
def show_all(viewer):
    for layer in viewer.layers:
        layer.visible = True
mesh = vedo.load("../../data/branchoid.ply")
surface = nppas.to_napari_surface_data(mesh)

surface_layer = viewer.add_surface(surface)

napari.utils.nbscreenshot(viewer)

Creating point clouds#

We can create a point cloud from the surface. The points are located on the surface and not inside the volume.

point_cloud = nppas.sample_points_from_surface(surface, distance_fraction=0.01)
point_cloud
array([[26. , 44. , 46.5],
       [26. , 43.5, 48. ],
       [26. , 43.5, 50. ],
       ...,
       [74.5, 55. , 52. ],
       [74.5, 56. , 49. ],
       [74.5, 56. , 51. ]], dtype=float32)
hide_all(viewer)

points_layer = viewer.add_points(point_cloud, size=1)

napari.utils.nbscreenshot(viewer)

In case these are too many points, we can sample a smaller number of points from them.

hide_all(viewer)
    
subsampled_points = nppas.subsample_points(point_cloud, distance_fraction=0.05)

viewer.add_points(subsampled_points, size=1)

napari.utils.nbscreenshot(viewer)

Converting points to surfaces#

We can reconstruct surfaces from point clouds. Obviously, some information loss might have happened depending on what we did to the points.

hide_all(viewer)

reconstructed_surface = nppas.reconstruct_surface_from_pointcloud(
    subsampled_points, 
    number_of_sampling_voxels=15, 
    point_influence_radius=10)

viewer.add_surface(reconstructed_surface)

napari.utils.nbscreenshot(viewer)
hide_all(viewer)

reconstructed_surface = nppas.reconstruct_surface_from_pointcloud(
    point_cloud, 
    number_of_sampling_voxels=15, 
    point_influence_radius=10)

viewer.add_surface(reconstructed_surface)

napari.utils.nbscreenshot(viewer)