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
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 83 84 85 86 87 88 89 90 91 | |
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
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 119 120 121 122 123 124 125 126 127 | |
edges_unique
edges_unique(
faces: array[int32],
edges_sorted: Array2dInt32 | None = None,
n_vertices: int | None = None,
*,
validate: bool = True,
return_counts: Literal[False] = False,
) -> tuple[odt.Array2dInt32, wp.array[wp.int32]]
edges_unique(
faces: array[int32],
edges_sorted: Array2dInt32 | None = None,
n_vertices: int | None = None,
*,
validate: bool = True,
return_counts: Literal[True],
) -> tuple[
odt.Array2dInt32, wp.array[wp.int32], wp.array[wp.int32]
]
edges_unique(
faces: array[int32],
edges_sorted: Array2dInt32 | None = None,
n_vertices: int | None = None,
*,
validate: bool = True,
return_counts: bool = False,
) -> (
tuple[odt.Array2dInt32, wp.array[wp.int32]]
| tuple[
odt.Array2dInt32,
wp.array[wp.int32],
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
|
return_counts
|
bool
|
Also return how many rows of |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
unique_edges |
Array2dInt32
|
|
inverse |
array[int32]
|
|
counts |
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
unique_edges, inverse, counts = od.edges.edges_unique(faces, return_counts=True)
print(counts.numpy().tolist() == [2] * 18) # True
Referenced by 29 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 · 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
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 243 244 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 | |
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], counted in one pass over
the faces with neither the rows nor the inverse map written.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
faces
|
array[int32]
|
|
required |
n_vertices
|
int | None
|
Vertex count bounding the indices, as in |
None
|
validate
|
bool
|
Check the index range, in the count's own readback: against |
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
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
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
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 630 631 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 | |
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
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 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 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 | |
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
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 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 | |
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
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 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 | |
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 6 places
API Reference curvature › principal_curvature · edges › edge_length_sum · edges › mean_unique_edge_length · Trimesh › mean_edge_length · interpolation › interpolate_from_points · parametrization › low_distortion_parametrization
Source code in ordito/edges.py
899 900 901 902 903 904 905 906 907 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 | |
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
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 | |
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
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 | |