如何将3D点云(.ply)转换为网格(具有面和顶点)?

时间:2019-07-10 07:12:55

标签: python mesh point-clouds delaunay trimesh

我有一个100万个点的3D点云文件,需要将其转换为三边形的网格文件。这里的最终目标是获取一个点云,并确定该点云是凸的还是凹的(一旦将云转换为网格,就可以使用trimesh进行处理)。我愿意向其他图书馆开放以解决这个问题。

我已经尝试过使用scipy进行Delaunay三角剖分,但似乎无法将点云转换为正确的格式,以便三边形可以读取它。

import open3d as o3d
import numpy as np
import trimesh
from scipy.spatial import Delaunay


pointcloud = o3d.io.read_triangle_mesh("pointcloud.ply")
points = np.array(pointcloud.points)
triangle_mesh = Delaunay(points)
#  How do i include triangle_mesh from Delaunay triangulation into processing the mesh file?
mesh = trimesh.load("pointcloud.ply")
print(trimesh.convex.is_convex(mesh))

错误

geometry::TriangleMesh appears to be a geometry::PointCloud (only contains vertices, but no triangles).
geometry::TriangleMesh with 1390073 points and 0 triangles.
expected = (faces.shape[0], faces.shape[1] * 2)
AttributeError: 'NoneType' object has no attribute 'shape'

2 个答案:

答案 0 :(得分:2)

Open3d 0.8.0.0现在已实现rolling ball pivoting algorithm来从点云重建网格。

我使用以下方法解决了从点云生成三边形的问题:

import open3d as o3d
import trimesh
import numpy as np

pcd = o3d.io.read_point_cloud("pointcloud.ply")
pcd.estimate_normals()

# estimate radius for rolling ball
distances = pcd.compute_nearest_neighbor_distance()
avg_dist = np.mean(distances)
radius = 1.5 * avg_dist   

mesh = o3d.geometry.TriangleMesh.create_from_point_cloud_ball_pivoting(
           pcd,
           o3d.utility.DoubleVector([radius, radius * 2])

trimesh = trimesh.Trimesh(np.asarray(mesh.vertices), np.asarray(mesh.triangles),
                          vertex_normals=np.asarray(mesh.vertex_normals))

答案 1 :(得分:1)

只是想知道这行代码实际上做了什么?它调用带点云的函数,如pcd,但双向量部分是什么意思? - o3d.utility.DoubleVector([radius, radius * 2]))

mesh = o3d.geometry.TriangleMesh.create_from_point_cloud_ball_pivoting(
           pcd, o3d.utility.DoubleVector([radius, radius * 2]))