vtk: separate out point and cell data writes
@@ -391,7 +391,27 @@ def write(filename,
f.write(('BINARY\n' if write_binary else 'ASCII\n').encode('utf-8'))
f.write('DATASET UNSTRUCTURED_GRID\n'.encode('utf-8'))
- # write points
+ # write points and cells
+ _write_points(f, points, write_binary)
+ _write_cells(f, cells, write_binary)
+
+ # write point data
+ if point_data:
+ num_points = len(points)
+ f.write('POINT_DATA {}\n'.format(num_points).encode('utf-8'))
+ _write_field_data(f, point_data, write_binary)
+
+ # write cell data
+ if cell_data:
+ total_num_cells = sum([len(c) for c in cells.values()])
+ cell_data_raw = raw_from_cell_data(cell_data)
+ f.write('CELL_DATA {}\n'.format(total_num_cells).encode('utf-8'))
+ _write_field_data(f, cell_data_raw, write_binary)
+
+ return
+
+
+def _write_points(f, points, write_binary):
f.write(
'POINTS {} {}\n'.format(
len(points), numpy_to_vtk_dtype[points.dtype]
@@ -405,8 +425,10 @@ def write(filename,
# ascii
points.tofile(f, sep=' ')
f.write('\n'.encode('utf-8'))
+ return
- # write cells
+
+def _write_cells(f, cells, write_binary):
total_num_cells = sum([len(c) for c in cells.values()])
total_num_idx = sum([numpy.prod(c.shape) for c in cells.values()])
# For each cell, the number of nodes is stored
@@ -449,19 +471,6 @@ def write(filename,
f.write(
'{}\n'.format(meshio_to_vtk_type[key]).encode('utf-8')
)
-
- # write point data
- if point_data:
- num_points = len(points)
- f.write('POINT_DATA {}\n'.format(num_points).encode('utf-8'))
- _write_field_data(f, point_data, write_binary)
-
- # write cell data
- if cell_data:
- cell_data_raw = raw_from_cell_data(cell_data)
- f.write('CELL_DATA {}\n'.format(total_num_cells).encode('utf-8'))
- _write_field_data(f, cell_data_raw, write_binary)
-
return
@@ -475,7 +484,7 @@ def _write_field_data(f, data, write_binary):
num_components = 1
else:
assert len(values.shape) == 2, \
- 'Only one and two-dimensional point data supported.'
+ 'Only one and two-dimensional field data supported.'
num_tuples = values.shape[0]
num_components = values.shape[1]
f.write(('{} {} {} {}\n'.format(
