首页 > 解决方案 > 如何使用 python 将 3D 云数据点转换为网格?

问题描述

我有一组看起来类似于球体的 3D 数据点。我需要将这些数据点连接为防水网格,以便将其用于模拟。

我与 Meshlab 合作并获得了合理的网格,但不是防水的。

在此之后,我尝试使用球枢轴算法来使用 Open3D python 库。由此,我无法按预期获得防水网格。我尝试使用hole_fixer 外部库(Hole_fixer),但在使用cmake 安装时发现并出错。

我已经插入了代码以及用于 open3D 的“xyz”数据点。

import numpy as np
import open3d as o3d

dataname = 'meshdata2.xyz'

point_cloud = np.loadtxt(dataname, skiprows=1)


pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(point_cloud[:,:3])
pcd.estimate_normals()



distances = pcd.compute_nearest_neighbor_distance()
avg_dist = np.mean(distances)
radius = 5*avg_dist

bpa_mesh = o3d.geometry.TriangleMesh.create_from_point_cloud_ball_pivoting(pcd, o3d.utility.DoubleVector([radius, radius*2, radius*0.5]))
print(str(bpa_mesh.is_watertight()))
o3d.visualization.draw_geometries([bpa_mesh])

“xyz 文件”的链接:xyz_file_link

从 Open3D 获得的网格:Mesh_from_open3D

我想知道如何为这些数据点获取防水网格。

任何线索将不胜感激。

问候,

苏纳格 R A.

标签: pythonstlmeshmeshlabopen3d

解决方案


要实现防水网格,您可以使用o3d.geometry.TriangleMesh.create_from_point_cloud_poisson.

然而,泊松重建需要一致的法线方向。在您的情况下,您可以将所有法线定向到点云的中心。要做到这一点:

import numpy as np
import open3d as o3d

pcd = o3d.io.read_point_cloud('./meshdata2.xyz')
pcd.estimate_normals()

# to obtain a consistent normal orientation
pcd.orient_normals_towards_camera_location(pcd.get_center())

# or you might want to flip the normals to make them point outward, not mandatory
pcd.normals = o3d.utility.Vector3dVector( - np.asarray(pcd.normals))

# surface reconstruction using Poisson reconstruction
mesh, _ = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(pcd, depth=9)

# paint uniform color to better visualize, not mandatory
mesh.paint_uniform_color(np.array([0.7, 0.7, 0.7]))

o3d.io.write_triangle_mesh('a.ply', mesh)

使用上述代码片段获得的网格: 在此处输入图像描述


对于具有复杂拓扑的点云,获得一致的法线方向可能并不容易,请阅读我的其他答案以获取更多信息。


推荐阅读