Reading data from a raw VTK (.vtu) file

后端 未结 2 1026
小蘑菇
小蘑菇 2021-01-24 23:10

I want to extract data arrays from a .vtu file using the Python VTK module. The file looks like this (the raw data at the end of the file is ommitted):



        
相关标签:
2条回答
  • 2021-01-24 23:31

    A more lightweight solution would be to use meshio (which I authored). It has no required dependencies except numpy. Install with

    pip install meshio
    

    and read the file with

    import meshio
    
    mesh = meshio.read("foo.vtu")
    # mesh.points, mesh.cells, mesh.point_data, ...
    
    0 讨论(0)
  • 2021-01-24 23:32

    You are not using the right reader, this is a .vtu file, you have to use the vtkXMLUnstructuredGridReader.

    import vtk.vtk
    
    # The source file
    file_name = "path/to/your/file.vtu"
    
    # Read the source file.
    reader = vtk.vtkXMLUnstructuredGridReader()
    reader.SetFileName(file_name)
    reader.Update()  # Needed because of GetScalarRange
    output = reader.GetOutput()
    potential = output.GetPointData().GetArray("potential")
    
    0 讨论(0)
提交回复
热议问题