JuliaGeometry / MeshViz.jl

Makie.jl recipes for visualization of Meshes.jl

Home Page:https://github.com/JuliaGeometry/Meshes.jl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

viz(mesh, showfacets = true) crashes old laptop

mdmaas opened this issue · comments

Hi!

I am running some examples where I build a 2d triangle mesh in Meshes.jl, so I thought to give MeshViz a try for visualization. However, trying to plot the triangle mesh crashes my old laptop during precompilation.

The workaround I found is to rely directly on Makie and build a scatter for the vertices and a line plot for the connectivity.

function plotTriMesh(mesh)
    Points = [p.coords for p in mesh.points]
    Simplices = [t.indices for t in mesh.topology.connec]
    scene = Mke.Scene()                                     
    s = Mke.scatter!(scene,Points)  
    lx = Float64[]; ly = Float64[];
    for tri ∈ Simplices
        px = [Points[tri[q]][1] for q in [1:3; 1]]
        py = [Points[tri[q]][2] for q in [1:3; 1]]
        lx = vcat(lx, [px; NaN])
        ly = vcat(ly, [py; NaN])
    end
    Mke.lines!(scene,lx,ly)                              
    return scene
end

This is reasonably fast. Maybe you want to consider having a "fast" visualization for only the boundaries of a mesh, in this fashion.

I don't want to try again using viz(mesh, showfacets = true) because my laptop crashes really badly. This happened to me with Julia 1.7 and now 1.8-rc1.

Best regards,

Can you please try it without showfacets=true? I should probably change the current behavior and add a check in the code so that new users never try to use this option when the mesh does not have coherent orientation. This option only works if all your triangles or polygons in the mesh are oriented counter-clockwise or clockwise. When you mix the orientation, which is something that Makie doesn't consider, you cannot store the mesh in a half-edge structure and therefore you cannot plot the inner edges efficiently.

If you want to get the same plot that vanilla Makie gives you, you just need to omit the option showfacets=true.

Thanks Julio.

Yes, it works that way, but I need to see the triangle boundaries.

I will check my triangles orientation, as I also need the half-edges for the next step in my algorithm.

This is no longer an issue. We now fix the orientation of polygons for end-users so the option showfacets should always work. This is available in Meshes.jl v0.25.8.

Hi Julio, nice work. I think I lost the original example, tough. But my use case was that I needed to see the facets. I ended up using Makie directly, and now I'm working on something else.