napari / napari

napari: a fast, interactive, multi-dimensional image viewer for python
https://napari.org
BSD 3-Clause "New" or "Revised" License
2.07k stars 410 forks source link

Polygon faces in Shapes layer are not shown in 3D if not contained in an *axis-orthogonal* plane #6860

Open jni opened 3 weeks ago

jni commented 3 weeks ago

πŸ› Bug Report

If I make polygons that are planar but not on a single z (or whatever) plane, the faces of the polygon are not rendered, only the edges.

πŸ’‘ Steps to Reproduce

import napari

viewer = napari.Viewer()
poly0 = [[0, 0, 0], [0, 1, 1], [1, 1, 1], [1, 0, 0]]
poly1 = [[2, 2, 2], [3, 3, 3], [3, 2, 2]]
viewer.add_shapes(
        [poly0, poly1],
        shape_type='polygon',
        edge_width=0.1,
        face_color='white',
        )

viewer.dims.ndisplay = 3
viewer.camera.angles = (-35, 50, 35)
viewer.camera.zoom = 150

napari.run()

Result:

Screenshot 2024-04-22 at 10 11 49β€―AM

πŸ’‘ Expected Behavior

The face color of the polygons should be white as specified.

🌎 Environment

napari: 0.5.0a2.dev640+gbdf6d644b Platform: macOS-14.4-arm64-arm-64bit System: MacOS 14.4 Python: 3.11.9 | packaged by conda-forge | (main, Apr 19 2024, 18:34:54) [Clang 16.0.6 ] Qt: 5.15.8 PyQt5: 5.15.9 NumPy: 1.26.4 SciPy: 1.13.0 Dask: 2024.4.2 VisPy: 0.14.2 magicgui: 0.8.2 superqt: 0.6.3 in-n-out: 0.2.0 app-model: 0.2.6 npe2: 0.7.5

OpenGL:

Screens:

Optional:

Settings path:

πŸ’‘ Additional Context

I expect that this is a case of "we did the easy thing and left the hard thing till later" β€” only display polygons that are "easy" ie orthogonal planes, since the triangulation libraries are 2D-only. But polygons with co-planar vertices should be displayed correctly also. We could project them onto a 2D plane, do the 2D triangulation, then back-project the triangulations to 3D.

imagesc-bot commented 3 weeks ago

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/high-quantities-of-extruded-polygons/95174/6