slightly simplify vtk reads
@@ -134,11 +134,11 @@ def read_buffer(f):
c = None
ct = None
- # One of the problem in reading VTK files are POINT_DATA and CELL_DATA
- # fields. They can contain a number of SCALARS+LOOKUP_TABLE tables, without
- # giving and indication of how many there are. Hence, SCALARS must be
- # treated like a first-class section. To associate it with POINT/CELL_DATA,
- # we store the `active` section in this variable.
+ # One of the problem in reading VTK files are POINT_DATA and CELL_DATA fields. They
+ # can contain a number of SCALARS+LOOKUP_TABLE tables, without giving and indication
+ # of how many there are. Hence, SCALARS must be treated like a first-class section.
+ # To associate it with POINT/CELL_DATA, we store the `active` section in this
+ # variable.
active = None
while True:
@@ -189,29 +189,7 @@ def read_buffer(f):
data = numpy.fromfile(f, count=num_items * 4, sep=" ", dtype=float)
rgba = data.reshape((num_items, 4)) # noqa F841
- elif section == "SCALARS":
- if active == "POINT_DATA":
- d = point_data
else:
- assert active == "CELL_DATA", "Illegal SCALARS in section '{}'.".format(
- active
- )
- d = cell_data_raw
-
- d.update(_read_scalar_field(f, num_items, split))
-
- elif section == "VECTORS":
- if active == "POINT_DATA":
- d = point_data
- else:
- assert active == "CELL_DATA", "Illegal SCALARS in section '{}'.".format(
- active
- )
- d = cell_data_raw
-
- d.update(_read_vector_field(f, num_items, split))
-
- elif section == "TENSORS":
if active == "POINT_DATA":
d = point_data
elif active == "CELL_DATA":
@@ -219,18 +197,14 @@ def read_buffer(f):
else:
d = field_data
+ if section == "SCALARS":
+ d.update(_read_scalar_field(f, num_items, split))
+ elif section == "VECTORS":
+ d.update(_read_vector_field(f, num_items, split))
+ elif section == "TENSORS":
d.update(_read_tensor_field(f, num_items, split))
-
else:
assert section == "FIELD", "Unknown section '{}'.".format(section)
-
- if active == "POINT_DATA":
- d = point_data
- elif active == "CELL_DATA":
- d = cell_data_raw
- else:
- d = field_data
-
d.update(_read_fields(f, int(split[2]), is_ascii))
assert c is not None, "Required section CELLS not found."
@@ -303,7 +277,7 @@ def _read_scalar_field(f, num_data, split):
def _read_vector_field(f, num_data, split):
data_name = split[1]
- data_type = split[2]
+ data_type = split[2].lower()
dtype = numpy.dtype(vtk_to_numpy_dtype_name[data_type])
data = numpy.fromfile(f, count=3 * num_data, sep=" ", dtype=dtype).reshape(-1, 3)
