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

Plot mesh with a ill-oriented triangle crashes the Julia session

stla opened this issue · comments

commented

Hello,
Here is a mesh with a ill-oriented triangle:

v1 = [1, 0, 0]
v2 = [0, 1, 0]
v3 = [0, 0, 1]
m12 = [0.5, 0.5, 0]
m13 = [0.5, 0, 0.5]
m23 = [0, 0.5, 0.5]
mesh = SimpleMesh(
  Meshes.Point.([v1, v2, v3, m12, m13, m23]), 
  Meshes.connect.([(4,1,5), (2,6,4), (3,5,6), (4,5,6)], Meshes.Triangle)
)
viz(mesh)

First, the plot is strange: we see a shadowed triangle with two vertices that do not belong to the vertices of the mesh:
Capture du 2022-12-24 22-11-37
Now, viz(mesh; showfacets=true) crashes the Julia session. I'm using the latest versions of Meshes.jl and MeshViz.jl.

commented

Did you find any way to get an error message?

I think we have two issues in this case:

  1. A residual issue of #30. I remember changing the algorithm in the HalfEdgeTopology to reorient the triangles whenever they had inconsistent orientation. However, I just realized that the new algorithm still has a bug when triangles are fed in arbitrary order. I will try to fix it in Meshes.jl over the week.

  2. The other issue seems to exist in Makie.jl itself. Feeding triangles with incosistent orientation leads to a visualization that is not expected even if we disregard the normals pointing to different sides of the parent triangle.

This is the part of the algorithm that needs to be adjusted:

https://github.com/JuliaGeometry/Meshes.jl/blob/82fa2c1dc7920f8cdf34be8ef92d1801114d27fc/src/topologies/halfedge.jl#L142-L170

It fails if the triangles (i.e. elems) are traversed in arbitrary order. All examples we have in our test suite traverse the mesh in geometric order (i.e. top left to bottom right)

I fixed the issue with the reorientation algorithm in Meshes.jl. Now the showfacets option works as expected, and you can see the edges correctly displayed:

image

The visualization is still buggy, but that is an issue in Makie.jl.

commented

And I forgot to say there's also a crash if there's a face like (1, 2, 1).

And I forgot to say there's also a crash if there's a face like (1, 2, 1).

Yes, we don't want to support such degenerate faces, at least for now.

Issue fixed downstream. You can be sure that the remaining issue lives in Makie.jl by trying to visualize the original mesh with incosistent orientation and the mesh with reoriented triangles obtained by the HalfEdgeTopology:

mesh |> viz

image

topoconvert(HalfEdgeTopology, mesh) |> viz

image