File: plot_2d_edge_meshes.py

package info (click to toggle)
napari 0.6.6-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,036 kB
  • sloc: python: 112,264; xml: 72; makefile: 44; sh: 5
file content (40 lines) | stat: -rw-r--r-- 1,237 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Polygon

from napari.layers.shapes._accelerated_triangulate_dispatch import (
    generate_2D_edge_meshes,
)

fig, axes = plt.subplots(2, 3)
# fig.set_figwidth(15)
# fig.set_figheight(10)
colors = iter(['red', 'green', 'blue', 'yellow'])
itaxes = iter(axes.flatten())
sup = axes.flatten()[4]
for closed in [False, True]:
    for beveled in [False, True]:
        ax = next(itaxes)
        c = next(colors)
        centers, offsets, triangles = generate_2D_edge_meshes(
            np.array([[0, 3], [1, 0], [2, 3], [5, 0], [2.5, 5]]),
            closed=closed,
            limit=3,
            bevel=beveled,
        )
        points = centers + 0.3 * offsets
        for t in triangles:
            trp = points[t]
            ax.add_patch(Polygon(trp, ec='#000000', fc=c, alpha=0.2))
            sup.add_patch(Polygon(trp, ec='#000000', fc=c, alpha=0.1))
        ax.scatter(*(points).T)
        ax.scatter(*(centers).T)
        ax.set_aspect('equal')
        ax.set_title(f' {closed=}, {beveled=}')
        ax.set_xlim(-1, 6)
        ax.set_ylim(-1, 6)
        sup.set_xlim(-1, 6)
        sup.set_ylim(-1, 6)

if __name__ == '__main__':
    plt.show()