Reputation: 1
I want to read information from a vtu file. Thanks to a post on stack overflow, I am able to read all PointData, but not the coordinates, i.e. the Points themselves. Any ideas? Also, is there any helpful documentation on the vtk python package?
Here is the vtu file:
<?xml version="1.0"?>
<VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian">
<UnstructuredGrid>
<Piece NumberOfPoints="54621" NumberOfCells="50000">
<PointData >
<DataArray type="Float32" Name="velocity" NumberOfComponents="3" format="appended" offset="0" />
<DataArray type="Float32" Name="Fi" format="appended" offset="655456" />
<DataArray type="Float32" Name="elevation" format="appended" offset="873944" />
</PointData>
<Points>
<DataArray type="Float32" NumberOfComponents="3" format="appended" offset="1092432" />
</Points>
<Cells>
<DataArray type="Int32" Name="connectivity" format="appended" offset="1747888" />
<DataArray type="Int32" Name="offsets" format="appended" offset="3347892" />
<DataArray type="Int32" Name="types" format="appended" offset="3547896" />
</Cells>
</Piece>
</UnstructuredGrid>
<AppendedData encoding="raw">
and here the python snippet:
import vtk
import numpy
from vtk.util.numpy_support import vtk_to_numpy
# The source file
file_name = "2022-06-30_5_FNPF_Graduiertenkolleg/REEF3D_FNPF_VTU/REEF3D-FNPF-000000-00002.vtu"
# Read the source file.
reader = vtk.vtkXMLUnstructuredGridReader()
reader.SetFileName(file_name)
reader.Update() # Needed because of GetScalarRange
print('test')
output = reader.GetOutput()
elevation = output.GetPointData().GetArray("elevation")
elev = vtk_to_numpy(elevation)
The data array in Points has no name, and assigning it a name to apply GetPointData() did also not do the job.
Upvotes: 0
Views: 818
Reputation: 2498
In pure VTK (i.e. without numpy), output.GetPoints()
is what you are looking for.
Working with numpy
, you can look at the dataset_adapter
module and see some doc here .
VTK API has full c++ documentation, see vtkUnstructuredGrid class. Python has mostly same API, thanks to the automatic wrapping. You can also find examples in different languages.
Upvotes: 1