classic vtk files written with wrong data type (single instead of double)
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
When writing double-precision data into a (legacy) VTK file, only single-precision is written out.
MWE:
import numpy
numpy.set_printoptions(precision=20)
import vtk
from vtk.util import numpy_support
mesh = vtk.vtkUnstructuredGrid()
# add points to mesh
points = numpy.array([[0.1234567890123456789, 0.0, 0.0]])
print(points)
vtk_points = vtk.vtkPoints()
vtk_array = numpy_support.numpy_to_vtk(points)
print(vtk_array)
p2 = numpy_support.vtk_to_numpy(vtk_array)
print(p2)
vtk_points.SetData(vtk_array)
mesh.SetPoints(vtk_points)
# write to VTK
writer = vtk.vtkUnstructuredGridWriter()
writer.SetFileTypeToASCII()
writer.SetFileName('test.vtk')
writer.SetInputData(mesh)
writer.Write()
This gives the file
# vtk DataFile Version 4.0
vtk output
ASCII
DATASET UNSTRUCTURED_GRID
POINTS 1 double
0.123457 0 0
CELL_TYPES 0
The points array is cut short with 0.123457
, seemingly a single precision float.