Mackie Messer
Mackie Messer

Reputation: 1328

VTK Data does not appear in CellData or PointData (numpy interface)

I have a VTK file that correctly populates the data in ParaView:

enter image description here

However, when I open that same file with VTK's Python API, I cannot for the life of me seem to find these same labeled datasets. Here's what I've tried:

import vtk
from vtk.numpy_interface import dataset_adapter as dsa

reader = vtk.vtkUnstructuredGridReader()
reader.SetFileName('test.vtk')
reader.Update()

adapter = dsa.WrapDataObject(reader.GetOutput())
print(adapter.PointData.keys()) # ['hu', 'disp']
print(adapter.CellData.keys())  # []
print(adapter.FieldData.keys()) # []

So, it seems that ParaView is able to identify the other datasets beyond just 'hu' and 'disp', but I cannot seem to find them in the corresponding Python object.

I'm assuming it's there somewhere. Anyone know why they, e.g., 'meanstress', don't appear as keys?

Upvotes: 1

Views: 347

Answers (1)

Nico Vuaille
Nico Vuaille

Reputation: 2498

You need to ask the reader to read all the data.

reader.ReadAllScalarsOn()
reader.ReadAllVectorsOn()
...

Dependending of wich kind of data you are trying to load. (scalars, vector, tensor ... See for the whole list: https://vtk.org/doc/nightly/html/classvtkDataReader.html#a831f470c6fbfc6e7209a1243ccb546e2 )

Upvotes: 3

Related Questions