pad cell_data to 3D as well as point_data
@@ -384,13 +384,16 @@ def translate_cells(data, types, cell_data_raw):
def write(filename, mesh, write_binary=True):
if mesh.points.shape[1] == 2:
+
+ def pad(array):
+ return numpy.pad(array, ((0, 0), (0, 1)), "constant")
+
logging.warning(
"VTK requires 3D points, but 2D points given. "
"Appending 0 third component."
)
- mesh.points = numpy.column_stack(
- [mesh.points[:, 0], mesh.points[:, 1], numpy.zeros(mesh.points.shape[0])]
- )
+ mesh.points = pad(mesh.points)
+
if mesh.point_data:
for name, values in mesh.point_data.items():
if values.shape[1] == 2:
@@ -398,8 +401,16 @@ def write(filename, mesh, write_binary=True):
"VTK requires 3D vectors, but 2D vectors given. "
"Appending 0 third component to {}.".format(name)
)
- mesh.point_data[name] = numpy.column_stack(
- [values[:, 0], values[:, 1], numpy.zeros(mesh.points.shape[0])])
+ mesh.point_data[name] = pad(values)
+ if mesh.cell_data:
+ for t, data in mesh.cell_data.items():
+ for name, values in data.items():
+ if values.shape[1] == 2:
+ logging.warning(
+ "VTK requires 3D vectors, but 2D vectors given. "
+ "Appending 0 third component to {}.".format(name)
+ )
+ mesh.cell_data[t][name] = pad(mesh.cell_data[t][name])
if not write_binary:
logging.warning("VTK ASCII files are only meant for debugging.")
