nschloe / meshio

:spider_web: input/output for many mesh formats
MIT License
1.96k stars 402 forks source link

[BUG] Issue reading in .vtk file with STRUCTURED_POINTS data type. #1205

Open StopkaKris opened 3 years ago

StopkaKris commented 3 years ago

I saved a file in ParaView version 5.10 as a "Legacy VTK File "(*.vtk) and attempted to read this mesh using meshio. In ParaView, it is a voxelated data set. The first 12 lines of the .vtk file are shown below. Meshio (versions 4.3.6 and version 5.0.2) gives an error that the offsets variable in the vtk_cells_from_data() function in the _vtk_common.py file has type None (TypeError: object of type 'NoneType' has no len()) and fails at this line of code --> if len(offsets) != len(types):.

vtk output
ASCII
DATASET STRUCTURED_POINTS
DIMENSIONS 145 145 145
SPACING 2 2 2
ORIGIN 6 6 6
CELL_DATA 2985984
FIELD FieldData 5
GID 1 2985984 float
102 102 102 102 102 102 102 102 102 
102 102 102 102 102 102 102 102 102 

To get around this, I added this line of code right before the line above offsets = np.arange(1,len(connectivity)+1,9) I am unsure where offsets is supposed to be read/determined by the script otherwise. I suspect the current code expects some type of variable declaration or section of the .vtk file that specifies this. Maybe this is because meshio does not realize that the STRUCTURED_POINTS data set implicitly contains the necessary information provided in the offsets variable.

I realize that this 'fix' may not work for other types of DATASET or older version of .vtk.

UPDATE: Although I can read in a .vtk file with the change above, if I write the same mesh to a new file and then attempt to read that .vtk file, I get an error at the same line because the meshio-generated .vtk file does, in fact, contain a list of OFFSETS.

nschloe commented 3 years ago

The bug report form says:

To Reproduce A minimal code example that reproduces the problem would be a big help if you can provide it. Attach a small mesh file if necessary.

StopkaKris commented 3 years ago

5_10_4x4x4.txt

The attached .vtk file (uploaded as a .txt file because .vtk files cannot be uploaded) should reproduce the error in either version of meshio mentioned above.

This may be unimportant, but the .vtk files described that cause the error were created by importing an unstructured mesh into ParaView and using the filters described at this link to create a voxelated mesh. The attached screenshot shows the filter free used to generate the 4x4x4 voxel mesh .vtk file uploaded here. ss1

shimwell commented 3 years ago

Thanks for reporting, I am also seeing this issue over here.

The additional line of code provided allowed me to read the vtk mesh in using meshio.