While using the dataset_adapter enabling numpy-like access to vtk dataset I have come across an unfortunate behavior. Here is the sequence :
u_grid_vtk = vtk.vtkUnstructuredGrid() u_grid = dsa.WrapDataObject(u_grid_vtk) test_arr = np.zeros((2,9) dtype=np.int32) print(load_arr.shape) # print (2, 9) as expected u_grid.FieldData.append(test_arr 'TEST') print(u_grid.FieldData['TEST'].shape) # print (2,3,3) not expected
I found that this behavior comes from the method “vtkDataArrayToVTKArray” in dataset_adapter.py. In fact, if the vtk data array second dimension is of size 9, then the array is understood as a matrix and rearranged such that its shape is (2,3,3) (+ transposing for handling Fortran to C order). In my case it complety messed my array.
I understand that it can make sense to reshape it as a matrix, however I think that the transposition is unsafe. While appending the array with
u_grid.FieldData.append(test_arr 'TEST'), could we treat the array such as it is understood as a matrix of shape (x, 3, 3), and handle the transposition (as it is already done if the array is of shape (x,3,3))?
This way we make sure when getting the array that the data order is the same as the input data order.
Thanks in advance,