I'm having trouble using the VTK library in Python. I tried adding the data array to the VTK model, but found that the data was oriented incorrectly and was pointed randomly. Here is the basic code I use:
import vtk
from vtk.numpy_interface import dataset_adapter as dsa
import numpy as np
fileName = "E:\VS Code\Filedata.vtk"
reader = vtk.vtkUnstructuredGridReader()
reader.SetFileName(fileName)
reader.Update()
mesh = reader.GetOutput()
# Create a 3D array
array_shape = (58924, 3)
array = np.random.rand(*array_shape).astype(np.float32)
# Add data set and write VTK file
meshNew = dsa.WrapDataObject(mesh)
meshNew.PointData.append(array, "vel")
writer = vtk.vtkUnstructuredGridWriter()
writer.SetFileName("Filedata.1.vtk")
writer.SetInputData(meshNew.VTKObject)
writer.Write()
I predict that after trying the above procedure, viewing the "vel" array in the VTK file using the glyph function in paraview will have the correct orientation aligned with the model shape, i.e. the velocity direction will be correct and make physical sense as shown in Figure 2 . The current orientation is still incorrect, as shown in Figure 1.
1.

2.
