elrnv / vtkio

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

Support `VtkIdType` datatype in legacy VTK files #34

Closed w1th0utnam3 closed 1 year ago

w1th0utnam3 commented 1 year ago

When exporting meshes from Paraview that were extracted using the "Extract Selection" filter from a larger mesh, Paraview also exports vtkOriginalCellIds and vtkOriginalPointIds attribute fields. They have the datatype vtkIdType, e.g.:

CELLS 2 3
OFFSETS vtktypeint64
...
CONNECTIVITY vtktypeint64
...
CELL_TYPES 1
...
CELL_DATA 1
FIELD FieldData 1
vtkOriginalCellIds 1 1 vtkIdType
...
POINT_DATA 3
FIELD FieldData 1
vtkOriginalPointIds 1 3 vtkIdType
...

Without any additional support parsing these files leads to an error.

According to the VTK documention, the actual datatype (long or long long) depends on whether VTK was built in 32-bit or 64-bit mode:

VTK_USE_64BIT_IDS (default OFF for 32-bit builds; ON for 64-bit builds): Whether vtkIdType should be 32-bit or 64-bit.

(https://docs.vtk.org/en/latest/build_instructions/build_settings.html#build-settings)

Apparently Paraview uses a 32-bit build. However, this is not explicitly indicated in the VTK files... Of course it would be nice to support such files but I don't see a way to nicely handle both possible underlying types. At the moment I hard-coded it to 32-bit to support Paraview, but I'm not sure if this is a good solution.

Alternatively one could also try to skip attributes if this data-type is encountered.

elrnv commented 1 year ago

Thank you @w1th0utnam3, I think assuming 32-bit here is fine, and seems like it may only cause problems for extremely obscure use cases.