When I try to add shapes, I get an AssertionError:assert (c, b) not in self._edges_lookup. Switching to paths works as expected.
Steps to reproduce the behavior:
import numpy as np
import napari
regions = [np.array([[124.8, 669.8],
[124.6, 669.8],
[124.2, 669.8],
[123.8, 669.8],
[123.4, 669.8],
[122.8, 669.4],
[122.4, 669.2],
[122.2, 669.2],
[122. , 669. ],
[121.8, 669. ],
[121.6, 668.8],
[121.2, 668.6],
[121. , 668.4],
[120.8, 668.2],
[120.6, 668. ],
[120.4, 667.8],
[120.2, 667.6],
[120.2, 667.4],
[120.2, 667.2],
[120. , 666.8],
[119.8, 666.6],
[119.8, 666.4],
[119.8, 666.2],
[119.8, 666. ],
[119.6, 665.8],
[119.6, 665.6],
[119.6, 665.4],
[119.4, 665.2],
[119.2, 664.8],
[119. , 664.4],
[118.8, 664. ],
[118.8, 663.8],
[118.8, 663.6],
[118.8, 663.4],
[118.8, 663.2],
[118.8, 663. ],
[118.8, 662.6],
[118.8, 662.4],
[118.8, 662. ],
[118.8, 661.8],
[118.8, 661.6],
[118.8, 661.2],
[118.8, 661. ],
[118.8, 660.8],
[119. , 660.4],
[119. , 659.6],
[119. , 659.4],
[119. , 659.2],
[119.2, 659. ],
[119.4, 658.4],
[119.6, 658.2],
[119.8, 658. ],
[119.8, 657.8],
[120. , 657.6],
[120.2, 657.4],
[120.4, 657.2],
[120.6, 657. ],
[120.8, 656.8],
[121. , 656.6],
[121.2, 656.4],
[121.4, 656.2],
[121.6, 656. ],
[121.8, 655.8],
[122. , 655.6],
[122.2, 655.4],
[122.4, 655.2],
[122.6, 655. ],
[122.8, 654.8],
[123. , 654.6],
[123.2, 654.4],
[123.4, 654.2],
[123.6, 654. ],
[123.8, 653.8],
[124. , 653.8],
[124.2, 653.6],
[124.4, 653.4],
[124.6, 653.4],
[124.8, 653.2],
[125. , 653. ],
[125.2, 652.8],
[125.6, 652.6],
[125.8, 652.4],
[126. , 652.4],
[126.4, 652.2],
[126.6, 652.2],
[126.8, 652. ],
[127. , 652. ],
[127.2, 652. ],
[127.4, 651.8],
[127.6, 651.8],
[127.8, 651.8],
[128.2, 651.6],
[128.4, 651.6],
[128.6, 651.6],
[128.8, 651.6],
[129. , 651.4],
[129.2, 651.4],
[129.4, 651.4],
[129.6, 651.2],
[129.8, 651.2],
[130. , 651.2],
[130.2, 651.2],
[130.4, 651. ],
[130.6, 651. ],
[130.8, 651. ],
[131. , 651. ],
[131.2, 651. ],
[131.4, 651. ],
[131.6, 651. ],
[131.8, 651. ],
[132. , 651. ],
[132.2, 651. ],
[132.4, 651. ],
[132.6, 651. ],
[132.8, 650.8],
[133. , 650.8],
[133.2, 650.8],
[133.4, 650.8],
[133.6, 651. ],
[133.8, 651. ],
[134. , 651. ],
[134.2, 651. ],
[134.4, 651. ],
[134.6, 651. ],
[134.8, 651. ],
[135. , 651. ],
[135.2, 651. ],
[135.4, 651. ],
[135.6, 651. ],
[135.8, 651. ],
[136. , 651.2],
[136.2, 651.2],
[136.4, 651.2],
[136.6, 651.2],
[136.8, 651.2],
[137. , 651.2],
[137.4, 651.4],
[137.6, 651.4],
[137.8, 651.4],
[138. , 651.4],
[138.2, 651.4],
[138.6, 651.6],
[139. , 651.6],
[139.2, 651.6],
[139.4, 651.6],
[139.8, 651.6],
[140. , 651.6],
[140.4, 651.6],
[140.6, 651.6],
[140.8, 651.6],
[141. , 651.6],
[141.2, 651.8],
[141.4, 651.8],
[141.6, 652. ],
[141.8, 652. ],
[142.2, 652. ],
[142.4, 652. ],
[142.6, 652. ],
[143. , 652.2],
[143.4, 652.2],
[143.6, 652.2],
[144. , 652.2],
[144.2, 652.2],
[144.6, 652.2],
[145. , 652. ],
[145.2, 651.8],
[145.4, 651.8],
[145.6, 651.8],
[145.8, 651.6],
[146. , 651.6],
[146.2, 651.6],
[146.4, 651.4],
[146.6, 651.4],
[146.8, 651.4],
[147. , 651.4],
[147.2, 651.4],
[147.4, 651.4],
[147.6, 651.4],
[147.8, 651.4],
[148. , 651.4],
[148.2, 651.6],
[148.4, 651.8],
[148.6, 652. ],
[148.8, 652.2],
[149. , 652.4],
[149.2, 652.6],
[149.4, 652.8],
[149.6, 653. ],
[149.8, 653.2],
[149.8, 653.4],
[149.8, 653.6],
[149.8, 654. ],
[149.8, 654.2],
[149.8, 654.6],
[150. , 654.8],
[150. , 655. ],
[150. , 655.4],
[150. , 655.8],
[150. , 656.4],
[150.2, 656.8],
[150.2, 657. ],
[150.2, 657.2],
[150.2, 657.8],
[150.2, 658.2],
[150.2, 658.6],
[150.2, 658.8],
[150.2, 659.2],
[150.2, 659.4],
[150. , 659.8],
[150. , 660. ],
[150. , 660.4],
[150. , 660.6],
[150. , 661. ],
[150. , 661.2],
[150. , 661.4],
[150. , 661.8],
[150. , 662. ],
[150. , 662.2],
[149.8, 662.6],
[149.6, 662.8],
[149.4, 663. ],
[149.2, 663.2],
[149. , 663.4],
[149. , 663.6],
[148.6, 664.2],
[148.4, 664.4],
[148. , 664.6],
[147.8, 664.8],
[147.6, 665. ],
[147.4, 665.2],
[147.2, 665.4],
[147. , 665.6],
[146.8, 665.8],
[146.6, 666. ],
[146.6, 666.2],
[146.4, 666.6],
[146.2, 666.8],
[146. , 667. ],
[145.8, 667.2],
[145.6, 667.6],
[145.4, 668. ],
[145.2, 668.2],
[145. , 668.4],
[144.8, 668.6],
[144.6, 668.8],
[144.4, 669. ],
[144. , 669.2],
[143.8, 669.4],
[143.6, 669.4],
[143.4, 669.6],
[143.2, 669.6],
[142.8, 669.8],
[142.4, 670.2],
[142.2, 670.2],
[142. , 670.2],
[141.8, 670.2],
[141.4, 670.4],
[141.2, 670.6],
[141. , 670.6],
[140.8, 670.8],
[140.2, 671. ],
[140. , 671.2],
[139.8, 671.2],
[139.6, 671.2],
[139.4, 671.4],
[139. , 671.6],
[138.8, 671.6],
[138.6, 671.6],
[138.4, 671.6],
[138.2, 671.8],
[138. , 671.8],
[137.8, 671.8],
[137.6, 671.8],
[137.4, 671.8],
[137.2, 671.8],
[137. , 671.8],
[136.8, 671.8],
[136.4, 671.6],
[136.2, 671.6],
[136. , 671.6],
[135.8, 671.6],
[135.6, 671.6],
[135.4, 671.6],
[135.2, 671.6],
[135. , 671.6],
[134.8, 671.4],
[134.6, 671.4],
[134.4, 671.4],
[134.2, 671.4],
[134. , 671.4],
[133.8, 671.2],
[133.6, 671.2],
[133.4, 671.2],
[133.2, 671.2],
[133. , 671.2],
[132.8, 671.2],
[132.6, 671.2],
[132.4, 671. ],
[132.2, 671. ],
[132. , 671. ],
[131.8, 671. ],
[131.6, 671. ],
[131.4, 671. ],
[131.2, 671. ],
[131. , 670.8],
[130.4, 670.6],
[130.2, 670.4],
[130. , 670.2],
[129.8, 670.2],
[129.6, 670.2],
[129.4, 670.2],
[129.2, 670. ],
[129. , 670. ],
[128.8, 669.8],
[128.6, 669.8],
[128.4, 669.8],
[128.2, 669.8],
[128. , 669.8],
[127.8, 669.6],
[127.6, 669.6],
[127.4, 669.6],
[127.2, 669.6],
[127. , 669.6],
[126.8, 669.6],
[126.6, 669.6],
[126.4, 669.6],
[126.2, 669.6],
[126. , 669.6],
[125.8, 669.6],
[125.6, 669.8],
[125.4, 669.8],
[125.2, 669.8],
[125. , 669.8],
[124.8, 669.8],
[124.6, 669.6],
[124.4, 669.6],
[124.2, 669.4]])]
with napari.gui_qt():
viewer = napari.Viewer()
_ = viewer.add_shapes(regions, shape_type='polygon')
# this works:
# _ = viewer.add_shapes(regions, shape_type='path')
Results in the following error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/suman/Library/Caches/pypoetry/virtualenvs/viewmask-FY58-nbg-py3.6/lib/python3.6/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/Users/suman/Library/Caches/pypoetry/virtualenvs/viewmask-FY58-nbg-py3.6/lib/python3.6/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/Users/suman/Library/Caches/pypoetry/virtualenvs/viewmask-FY58-nbg-py3.6/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/suman/Library/Caches/pypoetry/virtualenvs/viewmask-FY58-nbg-py3.6/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/suman/Library/Caches/pypoetry/virtualenvs/viewmask-FY58-nbg-py3.6/lib/python3.6/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Users/suman/quantum/viewmask/bin/cli.py", line 79, in view_overlay
regions, shape_type='polygon', edge_color=f"#{line_color}")
File "/Users/suman/Library/Caches/pypoetry/virtualenvs/viewmask-FY58-nbg-py3.6/lib/python3.6/site-packages/napari/components/add_layers_mixin.py", line 547, in add_shapes
visible=visible,
File "/Users/suman/Library/Caches/pypoetry/virtualenvs/viewmask-FY58-nbg-py3.6/lib/python3.6/site-packages/napari/layers/shapes/shapes.py", line 309, in __init__
z_index=z_index,
File "/Users/suman/Library/Caches/pypoetry/virtualenvs/viewmask-FY58-nbg-py3.6/lib/python3.6/site-packages/napari/layers/shapes/shapes.py", line 698, in add
ndisplay=self.dims.ndisplay,
File "/Users/suman/Library/Caches/pypoetry/virtualenvs/viewmask-FY58-nbg-py3.6/lib/python3.6/site-packages/napari/layers/shapes/shape_models/polygon.py", line 56, in __init__
self.data = data
File "/Users/suman/Library/Caches/pypoetry/virtualenvs/viewmask-FY58-nbg-py3.6/lib/python3.6/site-packages/napari/layers/shapes/shape_models/polygon.py", line 80, in data
self._update_displayed_data()
File "/Users/suman/Library/Caches/pypoetry/virtualenvs/viewmask-FY58-nbg-py3.6/lib/python3.6/site-packages/napari/layers/shapes/shape_models/polygon.py", line 84, in _update_displayed_data
self._set_meshes(self.data_displayed)
File "/Users/suman/Library/Caches/pypoetry/virtualenvs/viewmask-FY58-nbg-py3.6/lib/python3.6/site-packages/napari/layers/shapes/shape_models/shape.py", line 322, in _set_meshes
vertices, triangles = triangulate_face(clean_data)
File "/Users/suman/Library/Caches/pypoetry/virtualenvs/viewmask-FY58-nbg-py3.6/lib/python3.6/site-packages/napari/layers/shapes/shape_utils.py", line 555, in triangulate_face
vertices, triangles = PolygonData(vertices=data).triangulate()
File "/Users/suman/Library/Caches/pypoetry/virtualenvs/viewmask-FY58-nbg-py3.6/lib/python3.6/site-packages/vispy/geometry/polygon.py", line 130, in triangulate
tri.triangulate()
File "/Users/suman/Library/Caches/pypoetry/virtualenvs/viewmask-FY58-nbg-py3.6/lib/python3.6/site-packages/vispy/geometry/triangulation.py", line 187, in triangulate
self._edge_event(i, j)
File "/Users/suman/Library/Caches/pypoetry/virtualenvs/viewmask-FY58-nbg-py3.6/lib/python3.6/site-packages/vispy/geometry/triangulation.py", line 407, in _edge_event
polygon[ind+1])
File "/Users/suman/Library/Caches/pypoetry/virtualenvs/viewmask-FY58-nbg-py3.6/lib/python3.6/site-packages/vispy/geometry/triangulation.py", line 775, in _add_tri
assert (c, b) not in self._edges_lookup
AssertionError
The shapes should render just as they did with shape_type='path', but the shapes should be filled in.
napari: 0.2.12
Platform: Darwin-19.4.0-x86_64-i386-64bit
Python: 3.6.8 (v3.6.8:3c6b436a57, Dec 24 2018, 02:04:31) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]
Qt: 5.13.2
PySide2: 5.13.2
VisPy: 0.6.4
NumPy: 1.18.1
SciPy: 1.4.1
scikit-image: 0.16.2
Dask: 2.12.0
GL version: 2.1 INTEL-14.5.21
MAX_TEXTURE_SIZE: 16384
opencv-python is also installed (I do see the Qt warnings)Thanks for reporting this @sumanthratna. This looks like a corner case in vispy's triangulation code. I will dig in and take a look. Ultimately this might require a PR to vispy to fix.
Note that this error can be reproduced with the following minimal example shape
regions = [np.array([[1248, 6698],
[1246, 6698],
[1242, 6698],
[1248, 6698],
[1242, 6694]])]
and that the following
regions = [np.array([[1248, 6698],
[1246, 6697],
[1242, 6698],
[1248, 6698],
[1242, 6694]])]
leads to an incorrect triangulation.
The issue seems to arise with collinear / overlapping points
