JuliaGeometry / JuliaGeometry/GeometryBasics.jl

GeometryBasics.Mesh incorrectly converts quads to triangles

Open
#207 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
215
Forks
64
Avg merge
3d 18h
Merged PRs (30d)
2

Description

When trying to convert quadrilateral faces F and their vertices V to a mesh using:

M=GeometryBasics.Mesh(V,F)

One correctly obtains a quadrilateral mesh description:

julia> typeof(GeometryBasics.Mesh(V,F))
GeometryBasics.Mesh{3, Float64, GeometryBasics.Ngon{3, Float64, 4, Point3{Float64}}, SimpleFaceView{3, Float64, 4, Int64, Point3{Float64}, QuadFace{Int64}}}

However an error occurs if the mesh only consists of a single quad face, i.e. length(F)==1, in this case it looks like that quad is instead interpreter as a triangle:

julia> typeof(GeometryBasics.Mesh(V,F[1]))
GeometryBasics.Mesh{3, Float64, GeometryBasics.Ngon{3, Float64, 3, Point3{Float64}}, FaceView{GeometryBasics.Ngon{3, Float64, 3, Point3{Float64}}, Point3{Float64}, TriangleFace{Int64}, Vector{Point3{Float64}}, Base.ReinterpretArray{TriangleFace{Int64}, 1, Tuple{Int64, Int64, Int64}, TupleView{Tuple{Int64, Int64, Int64}, 3, 1, QuadFace{Int64}}, false}}}

A longer example and some context is given below.

Here is an example quadrilateral mesh description, in this case for a cube.

    # Create vertices       
    V=Vector{GeometryBasics.Point{3, Float64}}(undef,8)
    s = r/sqrt(3.0)
    V[1 ] = GeometryBasics.Point{3, Float64}( -s, -s, -s)
    V[2 ] = GeometryBasics.Point{3, Float64}( -s,  s, -s)
    V[3 ] = GeometryBasics.Point{3, Float64}(  s,  s, -s)
    V[4 ] = GeometryBasics.Point{3, Float64}(  s, -s, -s)
    V[5 ] = GeometryBasics.Point{3, Float64}( -s, -s,  s)
    V[6 ] = GeometryBasics.Point{3, Float64}( -s,  s,  s)
    V[7 ] = GeometryBasics.Point{3, Float64}(  s,  s,  s)
    V[8 ] = GeometryBasics.Point{3, Float64}(  s, -s,  s)
        
    # Create faces
    F = Vector{QuadFace{Int64}}(undef,6)
    F[1 ] = QuadFace{Int64}(1,2,3,4)
    F[2 ] = QuadFace{Int64}(8,7,6,5)
    F[3 ] = QuadFace{Int64}(5,6,2,1)
    F[4 ] = QuadFace{Int64}(6,7,3,2)    
    F[5 ] = QuadFace{Int64}(7,8,4,3)    
    F[6 ] = QuadFace{Int64}(8,5,1,4)   

I am interested in visualizing such quadrilateral meshes using GLMakie and to use per face color data. Currently GLMakie requires looping over the faces to handle such "per face colors" (default is to use vertex color data instead).

using GLMakie

fig = Figure()

ax=Axis3(fig[1, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Hexahedral mesh")

for i ∈ eachindex(F)    
   poly!(ax,GeometryBasics.Mesh(V,F[i]),strokewidth=5,color=C[i], transparency=false, overdraw=false,colormap = Reverse(:Spectral), colorrange=(0,6))
end

fig

The looping causes me to have to pass single faces to Geometry.Mesh which was showing the error. Note the besides being converted to triangles, which is unwanted, the quad is also not correctly converted to triangles as one can tell from this crossed/entangled look:
image

This is related to a bug I've posted on GLMakie, but I think it starts with this bug here.

Thanks a lot for your help!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two GeometryBasics.Mesh(V,F) calls, comparing a vector of QuadFace values with F[1]. Inspect the Mesh construction and face-conversion path that produces TriangleFace for a single quad, then verify that a single QuadFace remains valid and is not crossed or entangled when passed to GLMakie poly!.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.