Loading VTK legacy files
The motivation behind VTKLegacy is the ability to extract the contents of a VTK file written in legacy format and load the data to an object deppending of the geometry/topology of the datasets. The data must be written in binary and, currently, only "STRUCTURED_POINTS" and "UNSTRUCTURED_GRID" with "POINT_DATA" and "CELL_DATA" are supported.
To load the content of a VTK file, use the function LoadVTK:
julia> vtk = LoadVTK("path/to/file.vtk");This will load the VTK file in a custom object deppending if the VTK file has "STRUCTURED_POINTS" or "UNSTRUCTURED_GRID". When working with files with "STRUCTURED_POINTS", the load function will create a StructuredPoints object that contains all the information in the file in it's fields and print to stdout a summary of the data. Since this type of topology only has point data, the vtk.data field will contain all of the datasets in the file. Accesing m.data will return an array with shape (ndata,nx,ny,nz) where ndata = SCALARS+3*VECTORS (the number of SCALARS datasets plus 3 times the number of VECTORS datasets, one for each component of the vector) and nx, ny and nz the number of points in each axis. Using the example file StructuredPointsExample.vtk we get:
julia> vtk = LoadVTK("/home/luis/.julia/dev/VTKLegacy/VTK_examples/StructuredPointsExample.vtk");
Title: output from Diable
Dimensions: Int32[50, 50, 50]
Spacing: [0.04, 0.04, 0.04]
Origin: [-1.0, -1.0, -1.0]
Name of the data: ["Density", "Pressure", "Velocity"]
Data type: ["SCALARS", "SCALARS", "VECTORS"]
julia> vtk.data.size
(5, 50, 50, 50)
julia> vtk.dataAttributes
3-element Vector{String}:
"SCALARS"
"SCALARS"
"VECTORS"
julia> vtk.dimensions
3-element Vector{Int32}:
50
50
50To retrieve a dataset from m.data you can index like with any array or with the dataset name directly from the StructuredPoints object:
julia> vtk.data[1,:,:,:] == vtk["Density"]
trueAnd to print the general info showed when loading the file:
julia> show(vtk)
Title: output from Diable
Dimensions: Int32[50, 50, 50]
Spacing: [0.04, 0.04, 0.04]
Origin: [-1.0, -1.0, -1.0]
Name of the data: ["Density", "Pressure", "Velocity"]
Data type: ["SCALARS", "SCALARS", "VECTORS"]If the file(s) topology is "UNSTRUCTURED_GRID", the load function will create an UnstructuredGrid object. Since this type of file can contain any type of dataset attribute format without any type of regular structure data will be stored in a field for each dataset attribute format (currently only supporting "POINT_DATA" and "CELL_DATA"). For example loading the file UnstructuredGridExample.vtk we get:
julia> vtk = LoadVTK("VTK_examples/UnstructuredGridExample.vtk");
Title: Output from Walicxe3D
Number of Cells: 36864
Name of cell datasets: ["rho", "velx", "vely", "velz", "P"]
Cell data types: ["SCALARS", "VECTORS", "SCALARS"]
Number of Points: 294912
Name of point datasets: ["Nothing"]
Point data types: ["Nothing"]Since this file only contains "CELL_DATA" vtk.pointData will return nothing but vtk.cellData will return the array with the datasets:
julia> vtk.pointData == nothing
true
julia> vtk.cellData
5×36864 Matrix{AbstractFloat}:
98.009 155.998 … 50001.6 50002.7
⋮ ⋱ ⋮
1.60406f6 1.47006f6 … 9623.2 9651.74