Point_Cloud_To_Mesh.dyn (57.5 KB)

Hi

I need to share with you how to convert point cloud to mesh by using use python 3 and “Open 3d” Package in dynamo

1- load Open 3d packedge in to your dynamo

2- voxel_down_sampl

downpcd=pcd.voxel_down_sample(voxel_size=0.05)

3- used dbscan to cluster point cloud and remove the noise point

labels1 = np.array(downpcd.cluster_dbscan(eps=0.05, min_points=10))

4- create mesh TriangleMesh by using point cloud ball pivoting algorithm o3d.geometry.TriangleMesh.create_from_point_cloud_ball_pivoting(rest,o3d.utility.DoubleVector([1*radius, radius*2]))

5- creat dynamo mesh and convert it to revit element

http://www.open3d.org/

```
"""
Create by Ramiz Mohareb
13-12-2021
enramiz@yahoo.com
this code use Open 3d Pack. http://www.open3d.org/
Important! This code will only work with Dynamo versions
that are able to run cPython3 and have the following ad
[Point_Cloud_To_Mesh.dyn|attachment](upload://jH5GTaDZtlEoPjKCGgGjD42Bpyj.dyn) (57.5 KB)
ditional
python packages installed.
Packages required:
Open3d
numpy
"""
import random
import numpy as np
import clr
import open3d
#libraries used
import numpy as np
import open3d as o3d
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import matplotlib.pyplot as plt
filepath=IN[0]
import numpy as np
import open3d as o3d
filepath=IN[0]
segment_models={}
segments={}
inliers={}
inlier_cloud={}
Outt=[]
Outt2=[]
Outt3=[]
dec_meshL=[]
max_plane_idx=1
point_cloud= np.loadtxt(filepath,skiprows=1)
#Format to open3d usable objects
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(point_cloud[:,:3])
pcd.colors = o3d.utility.Vector3dVector(point_cloud[:,3:6]/255)
pcd.normals = o3d.utility.Vector3dVector(point_cloud[:,6:9])
downpcd=pcd.voxel_down_sample(voxel_size=0.1)
labels1 = np.array(downpcd.cluster_dbscan(eps=0.05, min_points=10))
candidates1=[len(np.where(labels1==j)[0]) for j in np.unique(labels1)]
best_candidate1=int(np.unique(labels1)[np.where(candidates1== np.max(candidates1))[0]])
rest=downpcd.select_by_index(list(np.where(labels1== best_candidate1)[0]))
distances = rest.compute_nearest_neighbor_distance()
avg_dist = np.mean(distances)
radius = 1 * avg_dist
#computing the mehs
bpa_mesh = o3d.geometry.TriangleMesh.create_from_point_cloud_ball_pivoting(rest,o3d.utility.DoubleVector([1*radius, radius*2]))
#dec_mesh1 = bpa_mesh.filter_smooth_simple(number_of_iterations=1)
dec_mesh1 = bpa_mesh.filter_smooth_taubin(number_of_iterations=10)
dec_mesh3=dec_mesh1
dec_mesh3.remove_degenerate_triangles()
dec_mesh3.remove_duplicated_triangles()
dec_mesh3.remove_duplicated_vertices()
dec_mesh3.remove_non_manifold_edges()
# Outt.append(np.asarray(segments[i].Points).tolist())
Outt2.append(np.asarray(dec_mesh3.triangles).tolist())
Outt3.append(np.asarray(dec_mesh3.vertices).tolist())
#o3d.visualization.draw_geometries([segments[i] for i in range(max_plane_idx)]+[rest])
#
OUT = Outt2,Outt3
```