我想从Python中的点云生成网格

问题描述 投票:0回答:3

我有一个来自人体不同部位的点云,就像一只眼睛,我想做一个网格。我试图使用Mayavi和Delaunay,但我没有得到一个好的网格。云的点完全无序。我在.npz文件中有我的点云

enter image description here

使用难以捉摸

enter image description here

然后我想将我的模型保存在obj或stl文件中,但首先我要生成网格。你建议我使用什么,我需要一个特殊的库吗?

python-3.x numpy mesh point-clouds mayavi
3个回答
0
投票

如果你的点是“完全无序”,并且如果你想生成一个网格,那么你需要从点云到网格的某种结构网格点的插值。

在二维情况下,matplotlib的三角测量可以是一个帮助:matplotlib's triangulation 2dim

在三维情况下有2种选择。根据数据,您可能希望将它们插入到三维表面。然后matplotlib's trisurf3d可以帮助。

如果您需要一个三维体积网格,那么您可能需要寻找一个FEM(有限元)网格,例如FEnics

可以在here中找到用scipy插值三维场进行轮廓加工的示例


0
投票

你试过这个例子吗? https://docs.enthought.com/mayavi/mayavi/auto/example_surface_from_irregular_data.html

相关部分在这里

# Visualize the points
pts = mlab.points3d(x, y, z, z, scale_mode='none', scale_factor=0.2)

# Create and visualize the mesh
mesh = mlab.pipeline.delaunay2d(pts)
surf = mlab.pipeline.surface(mesh)

0
投票

enter image description here数据

让我们使用欧洲的首都。我们从带有熊猫的Excel中读取它们:

import pandas as pd
dg0 = pd.read_excel('psc_StaedteEuropa_coord.xlsx')  # ,header=None
dg0.head()

    City    Inhabit     xK          yK
0   Andorra 24574.0     42.506939   1.521247
1   Athen   664046.0    37.984149   23.727984
2   Belgrad 1373651.0   44.817813   20.456897
3   Berlin  3538652.0   52.517037   13.388860
4   Bern    122658.0    46.948271   7.451451

网格通过三角测量

我们使用Scipy。有关三维示例,请参阅HEREHEREhere(CGAL有一个Python包装器)

import numpy as np
from scipy.spatial import Delaunay
yk, xk, city = np.array(dg0['xK']), np.array(dg0['yK']), np.array(dg0['City'])
X1 = np.vstack((xk,yk)).T
tri = Delaunay(X1)

图像

import cartopy.crs as ccrs
import matplotlib.pyplot as plt
#--- grafics -------
figX = 25; figY = 18
fig1 = plt.figure(figsize=(figX, figY), facecolor='white')

myProjection = ccrs.PlateCarree()
ax = plt.axes(projection=myProjection)
ax.stock_img()
ax.set_extent([-25, 40, 35, 65], crs=myProjection)

plt.triplot(X1[:,0], X1[:,1], tri.simplices.copy(), color='r', linestyle='-',lw=2)
plt.plot(X1[:,0], X1[:,1], 's', color='w')

plt.scatter(xk,yk,s=1000,c='w')
for i, txt in enumerate(city):
    ax.annotate(txt, (X1[i,0], X1[i,1]), color='k', fontweight='bold')

plt.savefig('Europe_A.png')
plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.