Reading a .VTK polydata file and converting it into Numpy array Reading a .VTK polydata file and converting it into Numpy array arrays arrays

Reading a .VTK polydata file and converting it into Numpy array


You can use dataset_adapter from vtk.numpy_interface:

from vtk.numpy_interface import dataset_adapter as dsapolydata = reader.GetOutput()numpy_array_of_points = dsa.WrapDataObject(polydata).Points

From Kitware blog:

It is possible to access PointData, CellData, FieldData, Points (subclasses of vtkPointSet only), Polygons (vtkPolyData only) this way.


You can get the point coordinates from a polydata object like so:

polydata = reader.GetOutput()points = polydata.GetPoints()array = points.GetData()numpy_nodes = vtk_to_numpy(array)