fix vtk array padding
@@ -578,11 +578,10 @@ 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")
+ if mesh.points.shape[1] == 2:
logging.warning(
"VTK requires 3D points, but 2D points given. "
"Appending 0 third component."
@@ -591,16 +590,17 @@ def write(filename, mesh, write_binary=True):
if mesh.point_data:
for name, values in mesh.point_data.items():
- if values.shape[1] == 2:
+ if len(values.shape) == 2 and values.shape[1] == 2:
logging.warning(
"VTK requires 3D vectors, but 2D vectors given. "
"Appending 0 third component to {}.".format(name)
)
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:
+ if len(values.shape) == 2 and values.shape[1] == 2:
logging.warning(
"VTK requires 3D vectors, but 2D vectors given. "
"Appending 0 third component to {}.".format(name)
