Skip to content

Unable to import various VTK and VTU file types #21

@2pt0

Description

@2pt0

vtkio is unable to parse VTK and VTU files generated by pygmsh which internally uses meshio for generation of VTK and VTU files.

I have tested the following file types:

  • VTK ASCII (Legacy)
  • VTK XML Binary
  • VTU ASCII
  • VTU XML Binary - No compression
  • VTU XML Binary - LZMA compression
  • VTU XML Binary - zlib compression

Paraview is able to visualize each file without problem. The spreadsheet view for each file shows the appropriate data.

Here is the script used to generate the VTK and VTU files:

import pygmsh

with pygmsh.geo.Geometry() as geom:
    p = geom.add_polygon(
        [
            [0.0, 0.0],
            [1.0, -0.2],
            [1.1, 1.2],
            [0.1, 0.7],
        ],
        mesh_size=0.4,
    )
    geom.add_physical(p.lines[0], label="bottom")
    geom.add_physical(p.lines[1], label="right")
    geom.add_physical(p.lines[2], label="top")
    geom.add_physical(p.lines[3], label="left")

    mesh = geom.generate_mesh()

mesh.write("no-compression.vtu", compression=None)
mesh.write("lzma.vtu", compression="lzma")
mesh.write("zlib.vtu", compression="zlib")
mesh.write("ascii.vtu", binary=False)
mesh.write("binary.vtk")
mesh.write("ascii.vtk", binary=False)

Here is the file I am using to test the import of these files:

use std::path::Path;
use vtkio::model::Vtk;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let inputs = &[
        "ascii.vtk",
        "binary.vtk",
        "ascii.vtu",
        "no-compression.vtu",
        "lzma.vtu",
        "zlib.vtu",
    ];

    let vtks = inputs
        .iter()
        .map(|input| Vtk::import(input));

    for (input, vtk) in inputs.iter().zip(vtks) {
        print!("{}.. ", input);

        match vtk {
            Ok(_) => println!("parsed!"),
            Err(e) => println!("{}", e),
        };
    }

    Ok(())
}

And the output

ascii.vtk.. Parse error: Alt
binary.vtk.. Parse error: Alt
ascii.vtu.. XML error: Validation error: InvalidDataFormat
no-compression.vtu.. XML error: Validation error: DataArraySizeMismatch { name: "types", expected: 38, actual: 37 }
lzma.vtu.. XML error: Validation error: Base64Decode(InvalidByte(22, 61))
zlib.vtu.. XML error: Validation error: Base64Decode(InvalidByte(22, 61))

I'm not sure if the problem is with vtkio or mehsio. I have opened an issue here since Kitware's Paraview (which also develops VTK) reports no problems with these files.

Thanks for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions