GithubHelp home page GithubHelp logo

juliavtk / readvtk.jl Goto Github PK

View Code? Open in Web Editor NEW
30.0 30.0 8.0 507 KB

Julia package for reading VTK XML files

Home Page: https://juliavtk.github.io/ReadVTK.jl

License: MIT License

Julia 100.00%
julia vtk

readvtk.jl's People

Contributors

boriskaus avatar dependabot[bot] avatar eliascarv avatar github-actions[bot] avatar henry2004y avatar jorgepz avatar matthew-whisenant avatar ondrejkincl avatar ranocha avatar sloede avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

readvtk.jl's Issues

Support for PolyData?

Would you please consider adding PolyData support? It would be greatly appreciated. I use WriteVTK to save results from particle simulations and then view in paraview. Sometimes I would like to load a simulation state or do some complicated post-processing.
I have only bunch of points with point data. Actually, your package works when I add

  elseif file_type == "PolyData"
    piece = root[file_type][1]["Piece"][1]
    n_points = parse(Int, attribute(piece, "NumberOfPoints", required=true))
    n_cells = 0
  end 

after line 140. But by default it throws assertion error.

Code coverage note reported in PR

I noticed that when creating a PR (e.g., #4), there is no reporting of total or patch coverage. This makes it hard to decide if a PR has sufficient test coverage. If you have time, @ranocha it would be great if you could have a look and find out what is wrong/missing; I can then try to fix it.

Error reading VTK file

I tried installing the package with a simple ] add ReadVTK but the package manager didn't find it. Also, what are the plans to keep improving the package with time? I have a file for which VTKFile("foo.vtk") failed.

Get_data major dimension differences in scalar and vector

In both FormatBinary and FormatAppended versions of get_data, we have:

ReadVTK.jl/src/ReadVTK.jl

Lines 681 to 687 in 85db253

if N == 1
# If it is a one dimensional array, just return it as is
return v
else
# Otherwise, reshape into two-dimensional array
return reshape(v, N, :)
end

Is there a reason for the type instability here? Such as Vector type for scalar fields and Matrix type for vector fields.

My workflow includes getting data from multiple field keys at the same time, such as fluid velocity and fluid pressure. But its harder to hcat/vcat or postprocess when one get_data returns a 3xN Matrix and one is a Nx1 Vector where the major dimension is different.

Seems to me it would make more sense for it to return Nx3 Matrix and Nx1 Vector or return 3xN Matrix and 1xN Matrix. The former would preserve current typing and make the output Matrix column-major just like Julia is.

Again I'm not too concerned about the typing, moreso that to cat the arrays I have to process vectors and scalar fields differently because of the major dimension mismatch.

I can do a PR of this if you all don't forsee this breaking anything in your Trixi2Vtk.jl package. Or if its more of a unnecessary or tedious change it can just be on my local ReadVTK. Just let me know.

Read Field Data

Hello! I just started playing around with ReadVTK. Thank you very much for the effort!

Reading some cases I have, I did not find any way to read Field Data from vtk files. Passing very quickly through the documentation and the source code I found that there is already an implemented type for this (VTKBase.VTKFieldData) but there is no function to read this data from a file (in the manner of get_cells_data() or get_points_data()).

Is there any chance you will be implementing this functionality soon? Thanks in advance!

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

zlib compressor error

Hi again,

I have a vti file generated by ParaView 5.11. If I choose no compressor when saving data from ParaView, then the generated file and the corresponding point data can be read by ReadVTK.jl; however, if I choose the zlib compressor, then I get the error:

julia> vtk = VTKFile("test2.vti")
VTKFile("test2.vti", <XMLDocument>, "ImageData", "2.2.0", "LittleEndian", "vtkZLibDataCompressor", <appended_data>, 8000, 6859)

julia> point_data = get_point_data(vtk)
VTKData()

julia> B = get_data(point_data["B"])
ERROR: zlib error: incorrect header check (code: -3)
Stacktrace:
 [1] unsafe_transcode!(output::TranscodingStreams.Buffer, codec::CodecZlib.ZlibDecompressor, input::TranscodingStreams.Buffer)
   @ TranscodingStreams C:\Users\hyzho\.julia\packages\TranscodingStreams\2McN2\src\transcode.jl:183
 [2] transcode!
   @ C:\Users\hyzho\.julia\packages\TranscodingStreams\2McN2\src\transcode.jl:127 [inlined]
 [3] transcode(codec::CodecZlib.ZlibDecompressor, input::TranscodingStreams.Buffer, output::Nothing)
   @ TranscodingStreams C:\Users\hyzho\.julia\packages\TranscodingStreams\2McN2\src\transcode.jl:109
 [4] transcode
   @ C:\Users\hyzho\.julia\packages\TranscodingStreams\2McN2\src\transcode.jl:108 [inlined]
 [5] transcode
   @ C:\Users\hyzho\.julia\packages\TranscodingStreams\2McN2\src\transcode.jl:189 [inlined]
 [6] transcode(#unused#::Type{CodecZlib.ZlibDecompressor}, args::Vector{UInt8})
   @ TranscodingStreams C:\Users\hyzho\.julia\packages\TranscodingStreams\2McN2\src\transcode.jl:37
 [7] get_data(data_array::VTKDataArray{Float64, 3, ReadVTK.FormatAppended})
   @ ReadVTK D:\Computer\ReadVTK.jl\src\ReadVTK.jl:740
 [8] top-level scope
   @ REPL[5]:1

This generated compressed vti file can be read by ParaView. Does it indicate that there are different types of compression zlib format?

A link to the test file is here.

Regarding OpenFOAM VTK Files

I just wanted to comment on the types of VTK files that ReadVTK.jl can read.

My current workflow is:
run OpenFOAM -> Paraview to convert foam to vtu -> ReadVTK to load vtu

This works great for everything that is not a scalar. However, OpenFOAM's vtk writer apparently does not include the "NumberOfComponents" tag if a field is a scalar.

On line 610 of ReadVTK we have:

n_components = parse(Int, attribute(xml_element, "NumberOfComponents", required=true))

This requires that field. However, by replacing this line with:

n_components =
    try
      parse(Int, attribute(xml_element, "NumberOfComponents", required=true))
    catch
      1
    end

Then everything works fine. Scalars loaded and I don't see anything loaded incorrectly.

Perhaps this could be added (probably a better way then what I have done here) and then advertised that this can now read OpenFOAM data. I know the CFD field is increasing using Julia so this might be a boon for this repository.

adding support for Structured grid format?

Hi, thanks for your work on ReadVTK.jl, it seems a very useful tool with high potential. I am using WriteVTK.jl in some projects and at some near point I will need to read vtk files as well.

I see that your package does not support the structured grid format. Have you considered adding that? I have some matlab vtk-filereading functions and before migrating them to a simple julia version I would like to consider contributing to this...

Thanks, Jorge

ReadVTK.jl is breaking

I believe this may have occurred after the LightXML.jl update, but I can't say for sure.
MWE:

julia> import ReadVTK

julia> file = ReadVTK.get_example_file("celldata_appended_binary_compressed.vtu")
"./celldata_appended_binary_compressed.vtu"

julia> vtk = ReadVTK.VTKFile(file)
Entity: line 25: parser error : Extra content at the end of the document
</VTKFile>
          ^
ERROR: LightXML.XMLParseError{String}("Failure in parsing an XML file.")
Stacktrace:
 [1] _check_result
   @ ~/.julia/packages/LightXML/g6rbQ/src/document.jl:88 [inlined]
 [2] parse_string(s::String)
   @ LightXML ~/.julia/packages/LightXML/g6rbQ/src/document.jl:99
 [3] ReadVTK.VTKFile(filename::String)
   @ ReadVTK ~/.julia/packages/ReadVTK/XpdR0/src/ReadVTK.jl:106
 [4] top-level scope
   @ REPL[2]:1

Reading large .pvts files has extremely high memory consumption compared to Paraview

I have a large structured .pvts file, and when I read it with the following code, I was surprised to find that the memory always overflows, but Paraview runs normally. It seems that getting the coordinates is very memory expensive:

using ReadVTK

fname = "./plt-100.pvts"

vtk = PVTKFile(fname)

# point data
p_data = get_point_data(vtk)

# mesh cordinate
x,y,z = get_coordinate_data(vtk)
Nx, Ny, Nz = size(x)

# variables
p = get_data_reshaped(p_data["p"])
u = get_data_reshaped(p_data["u"])
v = get_data_reshaped(p_data["v"])
T = get_data_reshaped(p_data["T"])
ρ = get_data_reshaped(p_data["rho"])

File metadata:

<?xml version="1.0" encoding="utf-8"?>
<VTKFile type="PStructuredGrid" version="1.0" byte_order="LittleEndian">
  <PStructuredGrid GhostLevel="0" WholeExtent="0 2799 0 599 0 599">

How to read FieldData?

Hi,
I am experimenting with the WriteVTK.jl and ReadVTK.jl. I would like to store some 3D scalar field data and the velocity and acceleration of a particle. What I am using to write the vtk file is something like the following:

vtk_grid(dataset, xcoord, ycoord, zcoord) do vtk
                    vtk["Phi"] = statevector[:, :, :, 1]
                    vtk["Pi"] = statevector[:, :, :, 2]
                    vtk["Psix"] = statevector[:, :, :, 3]
                    vtk["Psiy"] = statevector[:, :, :, 4]
                    vtk["Psiz"] = statevector[:, :, :, 5]
                    vtk["Position"] = [xcoord[i], ycoord[j], zcoord[k]]
                    vtk["Velocity"] = [vx, vy, vz]
                end

I can see that the info is written in the vti file correctly. Later in VisIt or with ReadVTK.jl
I cannot retrieve the data for the Position and Velocity which are FieldData.
How could I read these data?

Constraint on the VTK version

Hi,

While testing to read one ImageData generated by ParaView 5.11, I noticed that the VTK file version was asserted to be v"1.0". The file version generated by ParaView 5.11 is 2.2, and the latest VTK version is 3.0.

I am wondering if there is a reason for only supporting version 1.0? If I remove

@assert version == v"1.0"

it seems that the reader still works in my limited attempts.

Thanks!

Connectivity mismatch between WriteVTK and ReadVTK

I am currently writing a function that can take VTU data read from ReadVTK and use that data to write a new VTU in WriteVTK.

As a test, I am doing the simple write VTU example on WriteVTK here.

Using ReadVTK's get_cells, one can obtain the connectivity list and corresponding offset vector. However, I noticed that the connectivity list is starts at index 0 while WriteVTK starts at 1, resulting in mismatch of connectivity data. Here is a minimal example:

using ReadVTK
using WriteVTK

function convert_cell_structs(cells::VTKCells)

    start_offsets = [0; cells.offsets[1:end-1]] .+ 1
    end_offsets = cells.offsets

    offset_ranges = range.(start_offsets, end_offsets)

    connectivity = getindex.([cells.connectivity], offset_ranges)
    cell_types = VTKCellType.(cells.types)

    return MeshCell.(cell_types, connectivity)

end

points = rand(3, 5)  # 5 points in three dimensions
cells = [MeshCell(VTKCellTypes.VTK_TRIANGLE, [1, 4, 2]),
    MeshCell(VTKCellTypes.VTK_QUAD, [2, 4, 3, 5])]

vtk_grid("filename", points, cells) do vtk
    # add datasets...
end


vtkcase = VTKFile("filename.vtu")
points2 = get_points(vtkcase)
cells2 = convert_cell_structs(get_cells(vtkcase))

The connectivity input can be seen as

2-element Vector{MeshCell{VTKCellType, Vector{Int64}}}:
 MeshCell{VTKCellType, Vector{Int64}}(VTKCellType("VTK_TRIANGLE", 0x05, 3), [1, 4, 2])
 MeshCell{VTKCellType, Vector{Int64}}(VTKCellType("VTK_QUAD", 0x09, 4), [2, 4, 3, 5])

and for ReadVTK:

tempcells = get_cells(vtkcase)
VTKCells{Base.ReinterpretArray{Int64, 1, UInt8, Vector{UInt8}, false}, Base.ReinterpretArray{Int64, 1, UInt8, Vector{UInt8}, false}, Vector{UInt8}}([0, 3, 1, 1, 3, 2, 4], [3, 7], UInt8[0x05, 0x09])

using my function:

2-element Vector{MeshCell{VTKCellType, Vector{Int64}}}:
 MeshCell{VTKCellType, Vector{Int64}}(VTKCellType("VTK_TRIANGLE", 0x05, 3), [0, 3, 1])
 MeshCell{VTKCellType, Vector{Int64}}(VTKCellType("VTK_QUAD", 0x09, 4), [1, 3, 2, 4])

where you can see the connectivity should be +1 for every index. This is seen in the VTKCells structure even before applying my function. Of course, I could and currently am just adding 1 to it so it comes out normal.

I say all this to say, it seems strange since this is suppose to read what WriteVTK outputs, so the connectivity should match too.
In fact, it would make sense to me to just output the MeshCell type that WriteVTK is using rather than a new VTKCells type. That way,
reading and writing would be relatively low cost as the points from get_points and the cells from get_cells are the same as in the vtk_grid function input.

This would allow for use cases of:
external software VTK -> ReadVTK ->Julia processing ->WriteVTK -> Visualize VTKs

Whereas the current use case seems to be:
Julia processing ->WriteVTK -> ReadVTK -> more Julia processing?

I do not mind contributing the function that can convert VTKCells -> Vector{MeshCell}.

Sorry for the long post, just thought it may be worth thinking about.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.