vtk: better data read
@@ -262,10 +262,7 @@ def _read_cells(f, is_ascii, num_items):
if is_ascii:
c = numpy.fromfile(f, count=num_items, sep=" ", dtype=int)
else:
- # binary
- num_bytes = 4
- total_num_bytes = num_items * num_bytes
- c = numpy.frombuffer(f.read(total_num_bytes), dtype=">i4")
+ c = numpy.fromfile(f, count=num_items, dtype=">i4")
line = f.readline().decode("utf-8")
assert line == "\n"
@@ -280,6 +277,7 @@ def _read_cell_types(f, is_ascii, num_items):
num_bytes = 4
total_num_bytes = num_items * num_bytes
ct = numpy.frombuffer(f.read(total_num_bytes), dtype=">i4")
+ # ct = numpy.fromfile(f, num_items, dtype=">i4")
line = f.readline().decode("utf-8")
# Sometimes, there's no newline at the end
assert line.strip() == ""
@@ -337,13 +335,10 @@ def _read_fields(f, num_fields, is_ascii):
if is_ascii:
dat = numpy.fromfile(f, count=shape0 * shape1, sep=" ", dtype=dtype)
else:
- # binary
- num_bytes = numpy.dtype(dtype).itemsize
- total_num_bytes = shape0 * shape1 * num_bytes
# Binary data is big endian, see
# <https://www.vtk.org/Wiki/VTK/Writing_VTK_files_using_python#.22legacy.22>.
dtype = dtype.newbyteorder(">")
- dat = numpy.frombuffer(f.read(total_num_bytes), dtype=dtype)
+ dat = numpy.fromfile(f, count=shape0 * shape1, dtype=dtype)
line = f.readline().decode("utf-8")
assert line == "\n"
