python vtk_使用python读取和绘制VTK文件数据结构

博客讨论了如何使用Python的meshio库读取VTK文件,并探讨了尝试用matplotlib绘制VTK数据结构的困难。作者建议使用专门的VTK库,如vtk、mayavi或pyvista,因为matplotlib不适合此类3D复杂数据的可视化。文章提供了一个简化版的VTK数据示例,并展示了如何使用vtk和mayavi进行可视化。

1586010002-jmsa.png

I have a VTK file (unstructured grid) with points and cells.

I can import the file and read it into using the meshio python package.

If I type the command mesh.cells I see a dictionary called 'hexahedron' with an array made up of lists inside like this:

{'hexahedron': array([[ 0, 162, 185, ..., 163, 186, 23],

[162, 329, 351, ..., 330, 352, 186],

[329, 491, 514, ..., 492, 515, 352],

...,

[483, 583, 600, ..., 584, 601, 490],

[583, 650, 656, ..., 651, 657, 601],

[650, 746, 762, ..., 747, 763, 657]])}

I would like to plot this in matplotlib (I know ParaView is an alternative, which I've been using, but I would also like to use matplotlib for this at the moment). Anyways, I'm having trouble wrapping my head around the structure.

There are 8 data points in each list.

If I run the command mesh.points I get an array of lists of x, y, z coordinates, which makes sense. However, with the hexahedron, are there also x, y, z coordinates in the list? It would make more sense if there were lists of x, y, z coordinates, as that would make up polygons.

I've seen this thread, but I'm still stuck on understanding this.

Attached is the VTK file, as well as what it looks like in ParaView. Thanks!

MSMu8.png

解决方案

tl;dr: I don't think you should try to use matplotlib for this, and it would be difficult and not work very well. I suggest using a dedicated vtk library, either bare vtk, the higher-level mayavi.mlab or my recently acquired favourite, pyvista. I'll elaborate on all this in detail.

The data

First, here is a small, self-contained version of your input data (since the data you linked in the question is both too large and likely to become a broken link sooner or later). I've reduced your data to three rectangular cuboids of varying sizes to approximate your figure.

# vtk DataFile Version 3.1

MCVE VTK file

ASCII

DATASET UNSTRUCTURED_GRID

POINTS 16 float

0. 0. 0.

0. 0. 3.

0. 2. 0.

0. 2. 3.

4. 0. 0.

4. 0. 3.

4. 2. 0.

4. 2. 3.

5. 0. 0.

<
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值