|
30 | 30 | cuda = None |
31 | 31 |
|
32 | 32 |
|
33 | | -# Marching squares lookup table. |
34 | | -# For each of the 16 cases (4-bit index from corner classification), |
35 | | -# stores pairs of edge indices that form line segments. |
36 | | -# Edge numbering: 0=top, 1=right, 2=bottom, 3=left. |
37 | | -# Empty tuple means no contour passes through the quad. |
38 | | -_MS_TABLE = ( |
39 | | - (), # 0000 - all below |
40 | | - ((3, 2),), # 0001 - bl above: left-bottom |
41 | | - ((2, 1),), # 0010 - br above: bottom-right |
42 | | - ((3, 1),), # 0011 - bl+br above: left-right |
43 | | - ((0, 1),), # 0100 - tr above: top-right |
44 | | - ((2, 3), (0, 1)), # 0101 - saddle: bl+tr above (default: separated) |
45 | | - ((0, 2),), # 0110 - tr+br above: top-bottom |
46 | | - ((0, 3),), # 0111 - only tl below: top-left |
47 | | - ((0, 3),), # 1000 - tl above: top-left |
48 | | - ((0, 2),), # 1001 - tl+bl above: top-bottom |
49 | | - ((0, 3), (1, 2)), # 1010 - saddle: tl+br above (default: separated) |
50 | | - ((0, 1),), # 1011 - only tr below: top-right |
51 | | - ((1, 3),), # 1100 - tl+tr above: right-left |
52 | | - ((1, 2),), # 1101 - only br below: right-bottom |
53 | | - ((2, 3),), # 1110 - only bl below: bottom-left |
54 | | - (), # 1111 - all above |
55 | | -) |
56 | | - |
57 | | - |
58 | | -def _interp_edge(edge, r, c, tl, tr, bl, br, level): |
59 | | - """Return interpolated (row, col) for a contour crossing on the given edge. |
60 | | -
|
61 | | - Corners of the quad: |
62 | | - tl = (r, c) tr = (r, c+1) |
63 | | - bl = (r+1, c) br = (r+1, c+1) |
64 | | -
|
65 | | - Edge numbering: 0=top (tl-tr), 1=right (tr-br), 2=bottom (bl-br), 3=left (tl-bl) |
66 | | - """ |
67 | | - if edge == 0: # top: tl -> tr |
68 | | - t = (level - tl) / (tr - tl) if tr != tl else 0.5 |
69 | | - return r, c + t |
70 | | - elif edge == 1: # right: tr -> br |
71 | | - t = (level - tr) / (br - tr) if br != tr else 0.5 |
72 | | - return r + t, c + 1 |
73 | | - elif edge == 2: # bottom: bl -> br |
74 | | - t = (level - bl) / (br - bl) if br != bl else 0.5 |
75 | | - return r + 1, c + t |
76 | | - else: # edge == 3, left: tl -> bl |
77 | | - t = (level - tl) / (bl - tl) if bl != tl else 0.5 |
78 | | - return r + t, c |
79 | | - |
80 | | - |
81 | 33 | @ngjit |
82 | 34 | def _marching_squares_kernel(data, level, seg_rows, seg_cols, seg_count): |
83 | 35 | """Process all 2x2 quads for a single contour level. |
|
0 commit comments