Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_field(vtk) function added to get FieldData from VTK #42

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/ReadVTK.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ function piece(vtk_file::VTKFile)
return LightXML.root(vtk_file.xml_file)[vtk_file.file_type][1]["Piece"][1]
end

# Return `FieldData` XML element that contains all VTK field data
function field_data(vtk_file::VTKFile)
return LightXML.root(vtk_file.xml_file)[vtk_file.file_type][1]["FieldData"][1]
end

"""
isstructured(xml_file)

Expand Down Expand Up @@ -406,6 +411,29 @@ function get_data_section(vtk_file::VTKFile, section)
return VTKData(names, data_arrays, vtk_file)
end

"""
get_field_data(vtk_file::VTKFile)
andresegido marked this conversation as resolved.
Show resolved Hide resolved

Retrieve a lightweight `VTKData` object with the field data of the given VTK file.

See also: [`VTKData`](@ref), [`get_point_data`](@ref), [`get_cell_data`](@ref)
"""
function get_field_data(vtk_file::VTKFile)
names = String[]
data_arrays = XMLElement[]

# Iterate over XML elemens in the section
for xml_element in child_elements(field_data(vtk_file))
# We do not know how to handle anything other than `DataArray`s
@assert LightXML.name(xml_element) == "DataArray"

# Store the name and the XML element for each found data array
push!(names, attribute(xml_element, "Name", required = true))
push!(data_arrays, xml_element)
end

return VTKData(names, data_arrays, vtk_file)
end

"""
get_cell_data(vtk_file::VTKFile)
Expand Down