Skip to content

Commit

Permalink
➕ ADD: integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiadMansourM committed Jun 9, 2023
1 parent 6212a61 commit 26d384c
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,54 @@
"o3d.io.write_triangle_mesh(mesh_file, combined_mesh)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Meshing"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Inliner Meshing\n",
"import open3d as o3d\n",
"import numpy as np\n",
"\n",
"# 1. Transforming core points cloud (numpy array) to open3d point cloud\n",
"pcd = o3d.geometry.PointCloud()\n",
"pcd.points = o3d.utility.Vector3dVector(core_points[:, :3])\n",
"\n",
"# 1.1 Estimate normals for the point cloud\n",
"pcd.estimate_normals()\n",
"\n",
"# 1.2 Apply statistical outlier removal to the point cloud\n",
"_, inlier_indices = pcd.remove_statistical_outlier(nb_neighbors=20, std_ratio=2.0)\n",
"inlier_pcd = pcd.select_by_index(inlier_indices)\n",
"\n",
"# 2. Applying Ball-Pivoting Algorithm on the inlier point cloud\n",
"distances = inlier_pcd.compute_nearest_neighbor_distance()\n",
"avg_dist = np.mean(distances)\n",
"radius = 3 * avg_dist\n",
"bpa_mesh = o3d.geometry.TriangleMesh.create_from_point_cloud_ball_pivoting(inlier_pcd, o3d.utility.DoubleVector([radius, radius * 2]))\n",
"\n",
"# 3. Downsampling the mesh to an acceptable number of triangles (100,000)\n",
"dec_mesh = bpa_mesh.simplify_quadric_decimation(100_000)\n",
"\n",
"# 4. Smoothing the mesh by removing any weird artifacts\n",
"dec_mesh.remove_degenerate_triangles()\n",
"dec_mesh.remove_duplicated_triangles()\n",
"dec_mesh.remove_duplicated_vertices()\n",
"dec_mesh.remove_non_manifold_edges()\n",
"\n",
"# 5. Exporting the mesh to a .stl file and visualizing it\n",
"o3d.io.write_triangle_mesh(f\"data/{image_set_name}/output/triangulate/mesh.stl\", dec_mesh)"
]
},
{
"attachments": {},
"cell_type": "markdown",
Expand Down Expand Up @@ -1424,6 +1472,23 @@
"\n",
"o3d.visualization.draw_geometries([point_cloud, mesh])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# load mesh from f\"data/{image_set_name}/output/triangulate/mesh.stl\" and visualize it\n",
"import open3d as o3d\n",
"\n",
"mesh_file_path = (\n",
" f\"data/{image_set_name}/output/triangulate/mesh.stl\"\n",
")\n",
"\n",
"mesh = o3d.io.read_triangle_mesh(mesh_file_path)\n",
"o3d.visualization.draw_geometries([mesh])"
]
}
],
"metadata": {
Expand Down

0 comments on commit 26d384c

Please sign in to comment.