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

Missing XML attribute for RationalWeights and HigherOrderDegrees in Bézier cells #131

Closed
m1ka05 opened this issue Jan 29, 2024 · 2 comments · Fixed by #132
Closed

Missing XML attribute for RationalWeights and HigherOrderDegrees in Bézier cells #131

m1ka05 opened this issue Jan 29, 2024 · 2 comments · Fixed by #132

Comments

@m1ka05
Copy link
Contributor

m1ka05 commented Jan 29, 2024

Hi, I've been experimenting with Bézier cells and found that the rational weights and higher order degrees are not correctly exported. At least Paraview v5.11.2 using VTK v9.2.20220823 does not pick them up.

I attach two screenshots of the tetra quartic solid sphere octant test from bezier.jl with and without correct attribute definition. The following fixes the test:

    outfiles = vtk_grid(VTK_BASENAME, points, cells; vtkversion = v"1.0") do vtk
        vtk["RationalWeights"] = rational_weights
        
        # fix
        grid = WriteVTK.find_element(WriteVTK.root(vtk.xdoc), vtk.grid_type)
        piece = WriteVTK.find_element(grid, "Piece")
        pointdata = WriteVTK.find_element(piece, "PointData")
        WriteVTK.set_attribute(pointdata, "RationalWeights", "RationalWeights")
    end

Here is also a single cell quarter annulus PoC with anisotropic degrees:

using WriteVTK

cell_type = VTKCellTypes.VTK_BEZIER_QUADRILATERAL
points = [1.0 0.0 0.0 2.0 1.0 2.0; 0.0 1.0 2.0 0.0 1.0 2.0]
connectivity = 1:size(points, 2)
rational_weights = [1.0, 1.0, 1.0, 1.0, sqrt(0.5), sqrt(0.5)]
cells = [MeshCell(cell_type, connectivity)]

outfiles = vtk_grid("bezier_test", points, cells; vtkversion=v"1.0", compress=false, append=false, ascii=true) do vtk
    vtk["HigherOrderDegrees", VTKCellData()] = [2.0 1.0 1.0]
    vtk["RationalWeights", VTKPointData()] = rational_weights

    grid = WriteVTK.find_element(WriteVTK.root(vtk.xdoc), vtk.grid_type)
    piece = WriteVTK.find_element(grid, "Piece")
    celldata = WriteVTK.find_element(piece, "CellData")
    pointdata = WriteVTK.find_element(piece, "PointData")
    WriteVTK.set_attribute(celldata, "HigherOrderDegrees", "HigherOrderDegrees")
    WriteVTK.set_attribute(pointdata, "RationalWeights", "RationalWeights")
end

Fixed tetra quartic solid sphere octant

fixed

Broken tetra quartic solid sphere octant

broken

Quarter annulus

qa

@jipolanco
Copy link
Member

jipolanco commented Jan 29, 2024

Hi, thank you for catching this! I will fix the test, and maybe add your second example as an additional test (unless you want to do it yourself in a PR!). It may also be worth it to provide a simpler way of setting these kinds of attributes.

There's a slightly simpler way of setting an attribute to "PointData" and "CellData" elements. It is not very well documented, but it's mentioned at the very end of this section in the docs (and also here). Basically, your fix can be written as:

    outfiles = vtk_grid(VTK_BASENAME, points, cells; vtkversion = v"1.0") do vtk
        vtk["RationalWeights"] = rational_weights

        # fix
        vtk[VTKPointData()] = "RationalWeights" => "RationalWeights"
    end

@m1ka05
Copy link
Contributor Author

m1ka05 commented Jan 29, 2024

Thanks, I've missed that line in the documentation, great! I'll open a PR with the tests later today so you can link it with this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants