elrnv / vtkio

Visualization ToolKit (VTK) file parser and writer
Apache License 2.0
57 stars 13 forks source link

ParaView cannot read XML vtp files whose `connectivity` and `offsets` are `UInt64`. #25

Closed ytanimura closed 1 year ago

ytanimura commented 1 year ago

I wrote a code that creates a simple cube:

fn main() {
    use vtkio::model::*;
    #[rustfmt::skip]
    let points = IOBuffer::F32(vec![
        0.0, 0.0, 0.0,
        1.0, 0.0, 0.0,
        0.0, 1.0, 0.0,
        1.0, 1.0, 0.0,
        0.0, 0.0, 1.0,
        1.0, 0.0, 1.0,
        0.0, 1.0, 1.0,
        1.0, 1.0, 1.0,
    ]);
    let vertex_numbers = VertexNumbers::XML {
        #[rustfmt::skip]
        connectivity: vec![
            0, 2, 3, 1,
            0, 1, 5, 4,
            1, 3, 7, 5,
            3, 2, 6, 7,
            2, 0, 4, 6,
            4, 5, 7, 6,
        ],
        offsets: vec![4, 8, 12, 16, 20, 24],
    };
    let piece = PolyDataPiece {
        points,
        polys: Some(vertex_numbers),
        ..Default::default()
    };
    let vtk = Vtk {
        version: Version::new((1, 0)),
        title: "simple cube".to_string(),
        byte_order: ByteOrder::LittleEndian,
        data: DataSet::PolyData {
            meta: None,
            pieces: vec![Piece::Inline(Box::new(piece))],
        },
        file_path: None,
    };
    let mut buf = Vec::<u8>::new();
    vtk.write_xml(&mut buf).unwrap();
    std::fs::write("simple-cube.vtp", &buf).unwrap();
}

The contents of simple-cube.vtp are as follows:

<VTKFile type="PolyData" version="1.0" byte_order="LittleEndian" header_type="UInt64"><PolyData><Piece NumberOfPoints="8" NumberOfLines="0" NumberOfStrips="0" NumberOfPolys="6" NumberOfVerts="0"><PointData/><CellData/><Points><DataArray type="Float32" format="binary" NumberOfComponents="3">YAAAAAAAAAAAAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAAAAAACAPwAAAAAAAIA/AACAPwAAAAAAAAAAAAAAAAAAgD8AAIA/AAAAAAAAgD8AAAAAAACAPwAAgD8AAIA/AACAPwAAgD8=</DataArray></Points><Polys><DataArray type="UInt64" Name="connectivity" format="binary" NumberOfComponents="1">wAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAwAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAFAAAAAAAAAAQAAAAAAAAAAQAAAAAAAAADAAAAAAAAAAcAAAAAAAAABQAAAAAAAAADAAAAAAAAAAIAAAAAAAAABgAAAAAAAAAHAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAYAAAAAAAAABAAAAAAAAAAFAAAAAAAAAAcAAAAAAAAABgAAAAAAAAA=</DataArray><DataArray type="UInt64" Name="offsets" format="binary" NumberOfComponents="1">MAAAAAAAAAAEAAAAAAAAAAgAAAAAAAAADAAAAAAAAAAQAAAAAAAAABQAAAAAAAAAGAAAAAAAAAA=</DataArray></Polys></Piece></PolyData></VTKFile>

When I tried to load it in ParaView (5.8.0), I got the following error message.

Error reading cell offsets: Unsupported array type: vtkUnsignedLongLongArray

ParaView successfully displayed the cube after changing the type of connectivity and offsets to Int64, as shown below.

<VTKFile type="PolyData" version="1.0" byte_order="LittleEndian" header_type="UInt64"><PolyData><Piece NumberOfPoints="8" NumberOfLines="0" NumberOfStrips="0" NumberOfPolys="6" NumberOfVerts="0"><PointData/><CellData/><Points><DataArray type="Float32" format="binary" NumberOfComponents="3">YAAAAAAAAAAAAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAAAAAACAPwAAAAAAAIA/AACAPwAAAAAAAAAAAAAAAAAAgD8AAIA/AAAAAAAAgD8AAAAAAACAPwAAgD8AAIA/AACAPwAAgD8=</DataArray></Points><Polys><DataArray type="Int64" Name="connectivity" format="binary" NumberOfComponents="1">wAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAwAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAFAAAAAAAAAAQAAAAAAAAAAQAAAAAAAAADAAAAAAAAAAcAAAAAAAAABQAAAAAAAAADAAAAAAAAAAIAAAAAAAAABgAAAAAAAAAHAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAYAAAAAAAAABAAAAAAAAAAFAAAAAAAAAAcAAAAAAAAABgAAAAAAAAA=</DataArray><DataArray type="Int64" Name="offsets" format="binary" NumberOfComponents="1">MAAAAAAAAAAEAAAAAAAAAAgAAAAAAAAADAAAAAAAAAAQAAAAAAAAABQAAAAAAAAAGAAAAAAAAAA=</DataArray></Polys></Piece></PolyData></VTKFile>
ytanimura commented 1 year ago

It seems to be resolved in ParaView 5.11.0. My apologies. I close it.

elrnv commented 1 year ago

Thank you @ytanimura for reporting this issue. It is still good to know that paraview 5.8 doesn't have support unsigned indices.