Skip to content

Fix MetaIO ElementSpacing precision mismatch

David Gobbi requested to merge dgobbi/vtk:fix-meta-spacing into master

Between the VTK 8 release and the VTK 9 release, the MetaIO library changed the ElementSpacing type from float to double. However, the vtkMetaImageWriter was not changed to match. Instead, it rounded the vtkImageData Spacing from double to float, and then the MetaIO API converted it back to double before printing the .mhd file header. Also note that the MetaIO file header changed from using 6 decimal digits of precision for spacing in VTK 8, to 17 decimal digits of precision for VTK 9.

In VTK 9 before this change, SetSpacing(0.15, 0.15, 0.15) would give a .mhd spacing of '0.15000000596046448', which is the float representation of 0.15 when printed with 17 digits of precision. In VTK 8, due to the use of 6 digits of precision, the .mhd spacing would be '0.15'.

For full backwards compatibility with VTK 8, we would want to force MetaIO to use just 6 digits of precision. However, it is probably better to have the extra precision than to be strict about compatibility. ITK opted to bump the precision from 6 digits to 17 digits for ElementSpacing many years ago, for ITK 4.13.

Backport: paraview/release
Backport: release

Merge request reports