如何使用python将3D云数据点转换为网格?

2024-09-28 03:19:03 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

在此之后,我尝试了使用ball pivot算法使用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

我想知道如何获得这些数据点的防水网

任何线索将不胜感激

问候,

Sunag R A


Tags: 数据cloud网格nppointmeshxyzopen3d
1条回答
网友
1楼 · 发布于 2024-09-28 03:19:03

要实现防水网格,可以使用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)

使用上述代码段获得的网格: enter image description here


对于具有复杂拓扑的点云,可能不容易获得一致的法线方向,有关详细信息,请阅读my other answer

相关问题 更多 >

    热门问题