1
votes

I have a vtk polydata file - and I am writing a Python code that reads this polydata file as follows:

fullDirPath  = os.getcwd()
fullFileName = fullDirPath+'/'+fileName
reader = vtkPolyDataReader()
reader.SetFileName(vtkFileName)
reader.ReadAllScalarsOn()
reader.ReadAllVectorsOn()
reader.Update()

data        = reader.GetOutput()
velArray    = vtk_to_numpy(data.GetPointData().GetArray('velocity'))

where I have omitted all the relevant library import statements for vtk libraries.

I would now like to operate on this velocity data velArray, and create a new scalar field velParam, and then write a new VTK polydata file that has velParam as an additional scalar field. I unfortunately have so far not been able to come up with the correct way to manipulate the vtkPolyDataWriter object and its functions in Python - and I did not find many examples to do the same. I was wondering as to what would be a good way of writing a vtk Polydata file from a given set of point-coordinates, a vector data field, and a scalar data field.

Thanks a lot.

1

1 Answers

0
votes

Rather than manipulating the writer (it just needs filename and a polydata) , you have to create the polydata you need and then just give it to the writer. Something like:

velParam_numpy = 2*velArray
velParam_vtk = numpy_to_vtk(velParam_numpy)
velParam_vtk.SetName('VelParam') #rememebr to give an unique name
data.GetPointData().AddArray(velParam_vtk)