Describe the bug, what's wrong, and what you expect:
I was saving the mesh or surface created by pyvista. I was expecting to obtain the standard official vtk data format as shown here. But the vtk file I obtained doesn't.
To Reproduce
vertices = np.array([[0, 0, 0],
[1, 0, 0],
[1, 1, 0],
[0, 1, 0],
[0.5, 0.5, 1]])
faces = np.hstack([[4, 0, 1, 2, 3],
[3, 0, 1, 4],
[3, 1, 2, 4]]) # one square and two triangles
surf = pyvista.PolyData(vertices, faces)
surf.save('/home/fenqiang/test.vtk', binary=False)
```
The vtk file I obtained is:
vtk output
ASCII
DATASET POLYDATA
POINTS 5 double
0 0 0 1 0 0 1 1 0
0 1 0 0.5 0.5 1
POLYGONS 3 13
4 0 1 2 3
3 0 1 4
3 1 2 4
But according to the official format, I was expecting to obtain this:
vtk output
ASCII
DATASET POLYDATA
POINTS 5 double
0 0 0
1 0 0
1 1 0
0 1 0
0.5 0.5 1
POLYGONS 3 13
4 0 1 2 3
3 0 1 4
3 1 2 4
-----
**System Information:**
Date: Thu Nov 21 11:41:50 2019 EST
Linux : OS
12 : CPU(s)
x86_64 : Machine
64bit : Architecture
31.1 GB : RAM
Jupyter : Environment
Python 3.6.8 |Anaconda custom (64-bit)| (default, Dec 30 2018, 01:22:34)
[GCC 7.3.0]
0.22.4 : pyvista
8.2.0 : vtk
1.16.2 : numpy
2.4.1 : imageio
1.4.3 : appdirs
0.4.3 : scooby
3.1.1 : matplotlib
5.9.2 : PyQt5
7.2.0 : IPython
7.4.2 : ipywidgets
Intel(R) Math Kernel Library Version 2019.0.1 Product Build 20180928 for
```
Could you kindly take a look at this problem? Thanks a lot in advance for your help!
Hi and welcome! Thanks for posting your first issue in the PyVista project! Someone from @pyvista/developers will chime in before too long. If your question is support related, it may be automatically transfered to https://github.com/pyvista/pyvista-support
Hi @zhaofenqiang, this behavior is correct and follows the VTK file standard. Actually, PyVista controls none of the FileIO and all of the IO is done entirely by the vtkPolyDataWriter class straight from VTK. The docs you link to have nice line breaks to show where vertices and cells are separated but the format does not require that. I.e. the points in the POINTS 5 double section should be known that every three number represents a point and the number of points is know ahead of time as 5 so you can read all of those points as one long array with 3*5 elements such that you really have a single array of p0x p0y p0z p1x p1y p1z ... line breaks are arbitrary.
this is all consistent with how those data are stored when the binary option is enabled - in binary format, there wouldn't be a line break, it is just one long array
If you save a PolyData mesh in ASCII, legacy VTK format with ParaView it will produce a similar file with arbitrary line breaks
@banesullivan Hi, thank you for your reply. So it is actually the default behavior and does not affect the subsequent file reading and analysis. Thanks to your explanation. I understand the vtk format clearly now. Thanks again!