Please refresh the page if equations are not rendered correctly.
---------------------------------------------------------------
步骤:
- 将点坐标存入
ply
文件; - 将向量数据以
point_data
的形式存入; - 使用ParaView的Glyph进行可视化即可。
实现代码:
import numpy as np
import meshio
vertices = np.random.rand(10, 3)
mesh = meshio.Mesh(points=vertices,
cells = [],
# Optionally provide extra data on points, cells, etc.
point_data={"nx": vertices[:,0], "ny": vertices[:,1], "nz": vertices[:,2]},
# Each item in cell data must match the cells array
# cell_data={"a": [[0.1, 0.2], [0.4]]},
)
meshio.write("test.ply", mesh, binary=False)
vtk
# vtk DataFile Version 4.0
vtk output
ASCII
DATASET POLYDATA
POINTS 20 double
0.00000000e+00 0.00000000e+00 0.00000000e+00
3.30693964e-01 0.00000000e+00 1.62349735e-01
6.61387927e-01 0.00000000e+00 3.07106356e-01
9.92081891e-01 0.00000000e+00 4.18583239e-01
1.32277585e+00 0.00000000e+00 4.84700133e-01
1.65346982e+00 0.00000000e+00 4.98292247e-01
1.98416378e+00 0.00000000e+00 4.57886663e-01
2.31485774e+00 0.00000000e+00 3.67861955e-01
2.64555171e+00 0.00000000e+00 2.37973697e-01
2.97624567e+00 0.00000000e+00 8.22972951e-02
3.30693964e+00 0.00000000e+00 -8.22972951e-02
3.63763360e+00 0.00000000e+00 -2.37973697e-01
3.96832756e+00 0.00000000e+00 -3.67861955e-01
4.29902153e+00 0.00000000e+00 -4.57886663e-01
4.62971549e+00 0.00000000e+00 -4.98292247e-01
4.96040945e+00 0.00000000e+00 -4.84700133e-01
5.29110342e+00 0.00000000e+00 -4.18583239e-01
5.62179738e+00 0.00000000e+00 -3.07106356e-01
5.95249134e+00 0.00000000e+00 -1.62349735e-01
6.28318531e+00 0.00000000e+00 -1.22464680e-16
LINES 1 21
20 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
better than Ply
format
import numpy as np
import meshio, re
from polykriging.utility import filenames
import pyvista as pv
path = ".04_coding/Python/00_Projects" \
"/05_polyKriging/Data/processedData" \
"/Vf57/Fabric/00_pointCloud/"
file_list = filenames(path, "ply")
# get the numerics in file_list using regular expression
yarn_index = np.array([re.findall(r'\d+', file_list[i])
for i in np.arange(len(file_list))], dtype=int)
for i, index in enumerate(yarn_index):
mesh = meshio.read(path + file_list[i])
try:
vertices = np.vstack((vertices, mesh.points))
labels = np.hstack((labels, index[0] * np.ones(mesh.points.shape[0])))
print(index)
except NameError:
vertices = mesh.points
labels = index * np.ones(mesh.points.shape[0])
print(i)
labels = labels.astype(int)
# create a polydata object
point_cloud = pv.PolyData(vertices)
point_cloud.point_arrays['yarnIndex'] = labels
pv.set_plot_theme("paraview")
plotter = pv.Plotter()
plotter.add_mesh(point_cloud, point_size=3., render_points_as_spheres=True)
plotter.set_background("white")
# plotter.show_grid()
img = plotter.show(screenshot="point_cloud.png")
point_cloud.save("pc.vtk") # visualization in Paraview
Comments 1 条评论
博主 Mark
Thanks for your blog, nice to read. Do not stop.