Skip to content

normal_mesh based visualisation not valid.  #34

@Kevin-Mattheus-Moerman

Description

@Kevin-Mattheus-Moerman

The example in the README contains something like:

mesh!(ax1,normal_mesh(result),color=:blue, transparency=false, overdraw=false,shading = FastShading)

Where use is made of normal_mesh. However this function does not correctly obtain the triangles.

Below is my first attempt at fixing this, i.e. to get the tetrahedra and then to create a face based mesh representation to correctly visualise the tetrahedral mesh.

function tetgen2facemesh(result)
    E = faces(result) # Called "faces" but these are tetrahedral elements really 
    V = coordinates(result)

    F = Vector{TriangleFace{Int64}}(undef,length(E)*4)
    for q = eachindex(E)
        e = E[q]
        qf = 1 + (q-1)*4
        F[qf] = TriangleFace{Int64}(e[1],e[2],e[3])
        F[qf+1] = TriangleFace{Int64}(e[1],e[2],e[4])
        F[qf+2] = TriangleFace{Int64}(e[2],e[3],e[4])
        F[qf+3] = TriangleFace{Int64}(e[3],e[1],e[4])
    end

    return GeometryBasics.Mesh(V,F)
end

M = tetgen2facemesh(result)

# N,VN=meshnormal(M)

#Visualize mesh
GLMakie.activate!(inline=false) # To avoid plotting in plotpane as per: https://github.com/MakieOrg/Makie.jl/issues/2956
fig = Figure()

ax1=Axis3(fig[1, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Using normal_mesh")
mesh!(ax1,normal_mesh(result),color=:blue, transparency=false, overdraw=false,shading = FastShading)
wireframe!(result, linewidth=5,  color=:black)

ax2=Axis3(fig[1, 2], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Proper conversion to faces")
poly!(ax2,M,strokewidth=5, color=:blue, transparency=false, overdraw=false,shading = FastShading)
# arrows!(ax2,VN,N)


fig

My guess is that normal_mesh does not create all 4 tetrahedron triangles. The below shows the issue, i.e. several "holes" exist in the mesh (sorry hard to see as shading for these is a mess too... not sure how to fix that @SimonDanisch) and the bottom corner for instance clearly misses triangles. The visualisation on the right is for my "fixed" visualisation using the above.

Screenshot from 2023-12-20 12-39-57

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions