ordito.edges
Triangle edges: the directed corner edges, the deduplicated undirected set, and their lengths.
Three representations, and which one a caller wants depends on what an edge means to them:
- directed corner edges (
faces_to_edges) — three per face, in corner order, so index3 * f + kis facef's edgek. This is the halfedge indexingordito.halfedgebuilds on. - unique undirected edges (
edges_unique) — one per mesh edge, withedges_unique_inversemapping each corner back to it. - per-face length tables (
face_edge_lengths) — an(n_faces, 3)table in the opposite-corner column order the cotangent formulas want, which is the intrinsic descriptionordito.laplacianconsumes.
Referenced by 1 place
API Reference proximity › closest_point_on_edges
Functions:
| Name | Description |
|---|---|
faces_to_edges |
Directed triangle edges from a flat |
edges_face |
Face index for each directed edge produced by |
edges_unique |
Return unique undirected edges and their inverse mapping into the sorted edge list. |
unique_edge_count |
Count the unique undirected edges, without building the edge table. |
edges_unique_inverse |
Inverse mapping from sorted edges into |
edges_unique_length |
Euclidean length of each unique undirected edge. |
edges_length |
Euclidean length of every directed edge (one per face half-edge). |
face_edge_lengths |
Per-face edge lengths, in the intrinsic column order the cotangent formulas expect. |
mean_edge_length |
Mean length of the |
edge_length_sum |
Total length of the |
mean_unique_edge_length |
Mean length of the unique undirected edges. |
faces_to_edges
faces_to_edges(
faces: array[int32], sorted: bool = False
) -> odt.Array2dInt32
Directed triangle edges from a flat (i0, i1, i2) index buffer.
For each face emits three directed edges (i0, i1), (i1, i2), (i2, i0) in
row-major order, matching trimesh.geometry.faces_to_edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
faces
|
array[int32]
|
|
required |
sorted
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
Array2dInt32
|
|
See Also
Examples:
Three directed edges per face, in corner order; sorted=True puts the smaller index first:
import warp as wp
import ordito as od
faces = wp.array([0, 1, 2, 2, 1, 3], dtype=wp.int32)
directed = od.edges.faces_to_edges(faces)
print(directed.numpy().tolist()) # [[0, 1], [1, 2], [2, 0], [2, 1], [1, 3], [3, 2]]
undirected = od.edges.faces_to_edges(faces, sorted=True)
print(undirected.numpy().tolist()) # [[0, 1], [1, 2], [0, 2], [1, 2], [1, 3], [2, 3]]
Referenced by 10 places
API Reference adjacency › face_adjacency · adjacency › sorted_face_edge_keys · edges · edges › edges_face · edges › edges_unique_inverse · Trimesh › edges · Trimesh › edges_sorted · validation › edge_winding_consistent_mask · validation › is_volume
Migrating from another library Migrating from potpourri3d › Distance and vector heat
Source code in ordito/edges.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
edges_face
edges_face(faces: array[int32]) -> wp.array[wp.int32]
Face index for each directed edge produced by faces_to_edges.
Returns an array of length n_faces * 3 where entry 3*f + k equals f,
matching trimesh.Trimesh.edges_face.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
faces
|
array[int32]
|
|
required |
Returns:
| Type | Description |
|---|---|
array[int32]
|
|
See Also
Examples:
import warp as wp
import ordito as od
faces = wp.array([0, 1, 2, 2, 1, 3], dtype=wp.int32)
print(od.edges.edges_face(faces).numpy().tolist()) # [0, 0, 0, 1, 1, 1]
Referenced by 1 place
API Reference Trimesh › edges_face
Source code in ordito/edges.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
edges_unique
edges_unique(
faces: array[int32],
edges_sorted: Array2dInt32 | None = None,
n_vertices: int | None = None,
*,
validate: bool = True,
) -> tuple[odt.Array2dInt32, wp.array[wp.int32]]
Return unique undirected edges and their inverse mapping into the sorted edge list.
Equivalent to trimesh.Trimesh.edges_unique and
trimesh.Trimesh.edges_unique_inverse computed together.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
faces
|
array[int32]
|
|
required |
edges_sorted
|
Array2dInt32 | None
|
|
None
|
n_vertices
|
int | None
|
Total number of vertices (used as the hash base, and as the radix the unique rows are
unpacked with). When |
None
|
validate
|
bool
|
Whether to range-check the edge indices. With |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
unique_edges |
Array2dInt32
|
|
inverse |
array[int32]
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
RuntimeError
|
If |
Examples:
A cube has 12 triangles, 36 corner edges and 18 unique edges (12 sides and 6 face diagonals); each unique edge of a closed mesh is reached from exactly two corners:
import numpy as np
import ordito as od
vertices, faces = od.creation.box()
unique_edges, inverse = od.edges.edges_unique(faces)
print(unique_edges.shape) # (18, 2)
print(inverse.shape) # (36,)
print(np.bincount(inverse.numpy()).tolist() == [2] * 18) # True
Referenced by 30 places
API Reference API reference › Find a function by task · graph › edges_to_csr · graph › edges_to_neighbor_lists · remesh › split_edges · remesh › subdivide · remesh › subdivide_loop · remesh › subdivide_region_to_size · smoothing › relax_keep_volume · smoothing › smooth_region · smoothing › smooth_region_fixed_rim · edges · edges › edges_unique_inverse · edges › edges_unique_length · edges › mean_unique_edge_length · edges › unique_edge_count · halfedge › halfedge_twins · halfedge › key_ordered_halfedges · homology › homology_generators · homology › homology_generators_with_offsets · Trimesh › edges_unique · energies › crouzeix_raviart_cotmatrix · energies › crouzeix_raviart_massmatrix · energies › curved_hessian_energy · energies › edge_length_loss · laplacian › laplacian · laplacian › laplacian_entries · neighbors › geodesic_ball
Examples Geodesics and tangent fields › Smoothing a tangent vector field
Migrating from another library Migrating from libigl › Discrete differential geometry · Migrating from potpourri3d › Distance and vector heat
Source code in ordito/edges.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
unique_edge_count
unique_edge_count(
faces: array[int32],
n_vertices: int | None = None,
*,
validate: bool = True,
) -> int
Count the unique undirected edges, without building the edge table.
Equals edges_unique(faces, n_vertices=n_vertices)[0].shape[0]: the same sort and run scan,
stopped before the rows and the inverse map are written.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
faces
|
array[int32]
|
|
required |
n_vertices
|
int | None
|
Vertex count bounding the indices, as in |
None
|
validate
|
bool
|
As in |
True
|
Returns:
| Type | Description |
|---|---|
int
|
Unique undirected edge count. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
See Also
edges_unique
The table this counts.
Examples:
import ordito as od
vertices, faces = od.creation.box()
print(od.edges.unique_edge_count(faces)) # 18
Referenced by 1 place
API Reference measures › euler_characteristic
Source code in ordito/edges.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
edges_unique_inverse
edges_unique_inverse(
faces: array[int32],
edges_sorted: Array2dInt32 | None = None,
n_vertices: int | None = None,
) -> wp.array[wp.int32]
Inverse mapping from sorted edges into edges_unique.
Maps faces_to_edges (sorted) into edges_unique:
edges_unique(faces)[edges_unique_inverse(faces)] == faces_to_edges(faces, sorted=True)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
faces
|
array[int32]
|
|
required |
edges_sorted
|
Array2dInt32 | None
|
|
None
|
n_vertices
|
int | None
|
Total vertex count. When |
None
|
Returns:
| Type | Description |
|---|---|
array[int32]
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
RuntimeError
|
If |
See Also
Examples:
Indexing the unique edges with the inverse reproduces the sorted corner edges:
import numpy as np
import ordito as od
vertices, faces = od.creation.box()
unique_edges, _inverse = od.edges.edges_unique(faces)
inverse = od.edges.edges_unique_inverse(faces)
corner_edges = od.edges.faces_to_edges(faces, sorted=True)
print(np.array_equal(unique_edges.numpy()[inverse.numpy()], corner_edges.numpy())) # True
Referenced by 2 places
API Reference edges · Trimesh › edges_unique_inverse
Source code in ordito/edges.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | |
edges_unique_length
edges_unique_length(
vertices: array[vec3],
faces: array[int32],
unique_edges: Array2dInt32 | None = None,
n_vertices: int | None = None,
*,
validate: bool = True,
) -> wp.array[wp.float32]
Euclidean length of each unique undirected edge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
array[vec3]
|
|
required |
faces
|
array[int32]
|
|
required |
unique_edges
|
Array2dInt32 | None
|
|
None
|
n_vertices
|
int | None
|
Total vertex count passed to |
None
|
validate
|
bool
|
Forwarded to |
True
|
Returns:
| Type | Description |
|---|---|
array[float32]
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
RuntimeError
|
If |
See Also
Examples:
The unit cube's 18 unique edges are 12 sides of length 1 and 6 diagonals of length sqrt(2):
import ordito as od
vertices, faces = od.creation.box()
lengths = od.edges.edges_unique_length(vertices, faces)
print(lengths.shape) # (18,)
print(f"{lengths.numpy().min():.4f} {lengths.numpy().max():.4f}") # 1.0000 1.4142
print(int((lengths.numpy() > 1.1).sum())) # 6
Referenced by 8 places
API Reference API reference › Find a function by task · graph › edges_to_csr · smoothing › relax_approx · edges › face_edge_lengths · edges › mean_unique_edge_length · Trimesh › edges_unique_length · energies › edge_length_loss
Examples Smoothing and fairing › Relaxation: even triangle areas and a local surface fit
Source code in ordito/edges.py
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 | |
edges_length
edges_length(
vertices: array[vec3],
faces: array[int32],
edges_in: Array2dInt32 | None = None,
) -> wp.array[wp.float32]
Euclidean length of every directed edge (one per face half-edge).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
array[vec3]
|
|
required |
faces
|
array[int32]
|
|
required |
edges_in
|
Array2dInt32 | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
array[float32]
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
RuntimeError
|
If |
Examples:
One length per corner edge, so a shared edge appears once from each of its faces:
import ordito as od
vertices, faces = od.creation.box()
lengths = od.edges.edges_length(vertices, faces)
print(lengths.shape) # (36,)
print(f"{lengths.numpy().sum():.4f}") # 40.9706
Referenced by 1 place
API Reference edges › mean_edge_length
Source code in ordito/edges.py
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 | |
face_edge_lengths
face_edge_lengths(
vertices: array[vec3], faces: array[int32]
) -> odt.Array2dFloat32
Per-face edge lengths, in the intrinsic column order the cotangent formulas expect.
Column e holds the length of the edge opposite corner e, matching
cotmatrix_entries_intrinsic and
igl::cotmatrix_entries' intrinsic overload. Unlike
edges_unique_length this is a per-corner table: an
interior edge appears twice, which is what lets the entries be perturbed per face.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
array[vec3]
|
|
required |
faces
|
array[int32]
|
|
required |
Returns:
| Type | Description |
|---|---|
Array2dFloat32
|
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
See Also
Examples:
Column k is the edge opposite corner k; on a cube every face has two sides of length 1
and one diagonal:
import numpy as np
import ordito as od
vertices, faces = od.creation.box()
lengths = od.edges.face_edge_lengths(vertices, faces)
print(lengths.shape) # (12, 3)
print(np.sort(lengths.numpy()[0]).round(4)) # [1. 1. 1.4142]
Referenced by 2 places
API Reference edges · laplacian › mollify_intrinsic
Source code in ordito/edges.py
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 | |
mean_edge_length
mean_edge_length(
vertices: array[vec3], faces: array[int32]
) -> float
Mean length of the 3 * n_faces per-face edges, counting a shared edge once per face.
Every face contributes all three of its edges, so an edge shared by two faces is counted twice
and a boundary edge once -- which is what separates this from
mean_unique_edge_length, the same average over each
edge once. That weighting is deliberate, not an oversight: it is the average
libigl's CurvatureCalculator::getAverageEdge computes, which is what
igl::principal_curvature calls to set its sphere-search radius, and what
principal_curvature therefore uses here.
There are two edge averages, and they are not interchangeable
mean_unique_edge_length counts each edge once,
matching igl::avg_edge_length and MeshLab's avg_edge_length. The two agree exactly
on a closed manifold mesh -- every edge has two incident faces there, so the doubling is
uniform -- and diverge by a fraction of a percent on anything with a boundary or a
non-manifold edge.
Reach for this one when reproducing libigl's curvature; reach for the unique-edge one when reproducing anything else, including the heat method's timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
array[vec3]
|
|
required |
faces
|
array[int32]
|
|
required |
Returns:
| Type | Description |
|---|---|
float
|
Mean length over the |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
See Also
mean_unique_edge_length
The same average taken over the unique edges instead.
edges_length
The per-face lengths this averages.
Examples:
On a closed mesh this equals the unique-edge mean; on an open grid the boundary edges count once and the interior ones twice, so the two averages differ:
import ordito as od
vertices, faces = od.creation.box()
print(f"{od.edges.mean_edge_length(vertices, faces):.4f}") # 1.1381
vertices, faces = od.creation.grid(count=(2, 2))
print(f"{od.edges.mean_edge_length(vertices, faces):.4f}") # 1.1381
print(f"{od.edges.mean_unique_edge_length(vertices, faces):.4f}") # 1.0828
Referenced by 5 places
API Reference curvature › principal_curvature · edges › edge_length_sum · edges › mean_unique_edge_length · Trimesh › mean_edge_length · interpolation › interpolate_from_points
Source code in ordito/edges.py
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 | |
edge_length_sum
edge_length_sum(
vertices: array[vec3], faces: array[int32]
) -> wp.array[wp.float32]
Total length of the 3 * n_faces per-face edges, left on the device.
The sum mean_edge_length divides by 3 * n_faces, for a
caller whose kernels consume it on the device and would otherwise wait on a readback to pass
the mean in as a scalar. A shared edge counts once per face, as in the mean. Summed in
sum's order: fixed under
is_deterministic, arrival order otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
array[vec3]
|
|
required |
faces
|
array[int32]
|
|
required |
Returns:
| Type | Description |
|---|---|
array[float32]
|
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
See Also
mean_edge_length
The same total over the edge count, read back.
Examples:
import ordito as od
vertices, faces = od.creation.box()
total = od.edges.edge_length_sum(vertices, faces)
print(total.shape, f"{total.numpy()[0] / faces.size:.4f}") # (1,) 1.1381
Source code in ordito/edges.py
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 | |
mean_unique_edge_length
mean_unique_edge_length(
vertices: array[vec3],
faces: array[int32],
*,
validate: bool = True,
) -> float
Mean length of the unique undirected edges.
Each edge is counted once, however many faces share it. This is the definition
igl::avg_edge_length and MeshLab's avg_edge_length both use, and the one
igl::heat_geodesics picks its diffusion timestep from -- so it is what
heat_geodesic and
vector_heat_operators use here.
See mean_edge_length for the per-face average, how far the
two diverge on an open mesh, and why libigl carries both.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
array[vec3]
|
|
required |
faces
|
array[int32]
|
|
required |
validate
|
bool
|
Forwarded to |
True
|
Returns:
| Type | Description |
|---|---|
float
|
Mean length over the unique undirected edges. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
RuntimeError
|
If |
See Also
mean_edge_length
The same average taken over the per-face edges instead.
edges_unique_length
The per-edge lengths this averages.
Examples:
The cube's 18 unique edges average (12 + 6 * sqrt(2)) / 18:
import ordito as od
vertices, faces = od.creation.box()
print(f"{od.edges.mean_unique_edge_length(vertices, faces):.4f}") # 1.1381
Referenced by 2 places
API Reference heat › heat_geodesic · edges › mean_edge_length
Source code in ordito/edges.py
908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 | |