adjacency
triwarp.adjacency
Mesh face-adjacency graph: which faces share an edge, and what each adjacent pair looks like.
face_adjacency is the table every other function here reads:
one row per edge-adjacent face pair. The rest are per-adjacency-row quantities over that table, all
row-aligned with it, so a caller derives the pairs once and passes them in --
require_paired_adjacency states the one rule those
keywords carry, and is public because the functions taking the pair span three modules.
face_adjacency_unsharedgives the two opposite corners of each pair, andface_adjacency_anglesthe dihedral between the two faces.face_adjacency_convexanswers whether a pair is convex -- each face's third vertex on the inner side of the other's plane -- andface_adjacency_projectionsreturns the signed distances it thresholds, for callers that want the margin rather than the verdict.
face_connected_component_labels is the one
whole-graph answer: face-level connected components over the same adjacency.
face_adjacency
face_adjacency(
faces: array[int32],
edges_sorted: Array2dInt32 | None = None,
*,
return_edges: Literal[False] = False,
n_vertices: int | None = None,
) -> twt.Array2dInt32
face_adjacency(
faces: array[int32],
edges_sorted: Array2dInt32 | None = None,
*,
return_edges: Literal[True],
n_vertices: int | None = None,
) -> tuple[twt.Array2dInt32, twt.Array2dInt32]
face_adjacency(
faces: array[int32],
edges_sorted: Array2dInt32 | None = None,
*,
return_edges: bool = False,
n_vertices: int | None = None,
) -> (
twt.Array2dInt32
| tuple[twt.Array2dInt32, twt.Array2dInt32]
)
Face index pairs that share an undirected mesh edge.
Each output row lists two face indices whose triangles share an edge (vertex pair). On a closed manifold mesh every interior edge appears exactly twice in the edge list, so only edges with duplicate sorted rows are kept—boundary edges that appear once are omitted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
faces
|
array[int32]
|
Length- |
required |
edges_sorted
|
Array2dInt32 | None
|
Optional precomputed |
None
|
return_edges
|
bool
|
If |
False
|
n_vertices
|
int | None
|
Optional vertex count, used as the row-hashing radix. Supplying it skips the
|
None
|
Returns:
| Type | Description |
|---|---|
twt.Array2dInt32 or tuple of two such arrays
|
adjacency — shape When |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
Notes
Duplicate-edge grouping uses
group_int_rows with
length=2, equivalent to trimesh.grouping.group_rows with
require_count=2. An empty mesh yields shape (0, 2).
See Also
faces_to_edges
connected_component_labels_from_edges
face_connected_component_labels
trimesh.graph.face_adjacency
Source code in triwarp/adjacency.py
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 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 119 120 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 | |
require_paired_adjacency
require_paired_adjacency(
face_adjacency: Array2dInt32 | None,
face_adjacency_edges: Array2dInt32 | None,
) -> None
Raise unless a precomputed face-adjacency pair is either wholly given or wholly omitted.
The contract behind every face_adjacency= / face_adjacency_edges= keyword in the
package: the two tables are row-aligned halves of one answer and are useless apart, so a
function that accepts them accepts both or neither. Public because the functions that take the
pair live in three modules -- here, triwarp.curvature and
triwarp.validation -- and they must all reject the same call with the
same message; a caller that validates its own arguments before dispatching between them can
use it for that too.
Call it before an empty-mesh guard, not after. A half-supplied pair is a caller bug
whatever the mesh is, and the four wrappers that take the pair once disagreed about this, so
the same wrong call raised or returned an empty answer depending on the input. The derivation
goes the other way round -- below the guard -- because on an empty mesh
face_adjacency would build two empty tables nothing reads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
face_adjacency
|
Array2dInt32 | None
|
Candidate |
required |
face_adjacency_edges
|
Array2dInt32 | None
|
Candidate |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If exactly one of the two is given. |
RuntimeError
|
If |
See Also
face_adjacency
Produces the pair, with return_edges=True.
face_adjacency_unshared
face_adjacency_projections
face_adjacency_convex
Source code in triwarp/adjacency.py
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 | |
vertex_face_adjacency
vertex_face_adjacency(
faces: array[int32], *, n_vertices: int | None = None
) -> tuple[wp.array[wp.int32], wp.array[wp.int32]]
Incidence CSR of the faces touching each vertex, as (vertex_faces, offsets).
Row v is vertex_faces[offsets[v] : offsets[v + 1]] and lists every face that references
vertex v, once per reference. offsets has length n_vertices + 1, so its last entry
is the total 3 * n_faces and no caller needs a sentinel appended. Values first and offsets
second is the package's packed-buffer convention -- see
array.pack_1d_arrays, which states it.
Built by counting sort rather than from halfedge twins, and that is a deliberate limitation
rather than an omission: each row is a set, not a rotation. Ordering a row would require the
halfedge structure, which does not exist at a vertex-non-manifold vertex — and the decimator and
normal-flip guards that consume this must run on exactly such meshes. Use
vertex_one_rings when the rotational order is what is
wanted; it requires an edge-manifold mesh in exchange.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
faces
|
array[int32]
|
Length- |
required |
n_vertices
|
int | None
|
Number of vertices, i.e. the number of CSR rows. When |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
vertex_faces |
array[int32]
|
Length |
offsets |
array[int32]
|
Length |
See Also
face_adjacency
vertex_one_rings
igl.vertex_triangle_adjacency
Source code in triwarp/adjacency.py
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 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 | |
face_adjacency_unshared
face_adjacency_unshared(
faces: array[int32],
face_adjacency: Array2dInt32 | None = None,
face_adjacency_edges: Array2dInt32 | None = None,
*,
n_vertices: int | None = None,
) -> twt.Array2dInt32
Vertex on each adjacent face that is not on their shared edge.
For each row of face_adjacency, column 0 is the unshared vertex index on
the first face and column 1 on the second face. When a face does not have
exactly one vertex off the shared edge (degenerate case), that entry is -1.
The answer is defined by the recorded shared edge of each adjacency row, matching
trimesh.graph.face_adjacency_unshared exactly. This matters only for duplicate faces:
two coincident triangles meet along all three of their edges, so they produce three adjacency
rows and each one reports the corner off its own edge ([[2, 2], [1, 1], [0, 0]] for two
copies of (0, 1, 2)). A cheaper "vertex of one face absent from the other" rule would
return -1 for all three, and would not be trimesh.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
faces
|
array[int32]
|
Length- |
required |
face_adjacency
|
Array2dInt32 | None
|
Optional |
None
|
face_adjacency_edges
|
Array2dInt32 | None
|
Optional |
None
|
n_vertices
|
int | None
|
Optional vertex count used as the row-hashing radix, forwarded to
|
None
|
Returns:
| Type | Description |
|---|---|
Array2dInt32
|
Shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If only one of |
RuntimeError
|
If |
Source code in triwarp/adjacency.py
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 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
face_adjacency_angles
face_adjacency_angles(
vertices: array[vec3],
faces: array[int32],
face_adjacency: Array2dInt32 | None = None,
face_normals: array[vec3] | None = None,
) -> wp.array[wp.float32]
Unsigned angle in radians between each pair of adjacent faces.
For each row of face_adjacency, the angle is computed from the two
corresponding face normals (unit vectors). Pair it with
face_adjacency_convex for the sign: that function
reports which side of each shared edge the pair folds towards, which is exactly the sign this
unsigned magnitude is missing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
array[vec3]
|
|
required |
faces
|
array[int32]
|
Length- |
required |
face_adjacency
|
Array2dInt32 | None
|
Optional |
None
|
face_normals
|
array[vec3] | None
|
Optional length- |
None
|
Returns:
| Type | Description |
|---|---|
array[float32]
|
Length |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
See Also
face_adjacency
face_adjacency_convex
The sign this magnitude omits: convex or concave, per adjacency row.
vector_angle
trimesh.Trimesh.face_adjacency_angles
Source code in triwarp/adjacency.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
face_adjacency_projections
face_adjacency_projections(
vertices: array[vec3],
faces: array[int32],
face_adjacency: Array2dInt32 | None = None,
face_adjacency_edges: Array2dInt32 | None = None,
face_adjacency_unshared: Array2dInt32 | None = None,
face_normals: array[vec3] | None = None,
) -> wp.array[wp.float32]
Project each adjacent face pair's non-shared vertex onto the first face plane.
For each row of face_adjacency, the dot product is taken between the
normal of face face_adjacency[k, 0] and the vector from one endpoint of
the shared edge to the unshared vertex on face_adjacency[k, 1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
array[vec3]
|
|
required |
faces
|
array[int32]
|
Length- |
required |
face_adjacency
|
Array2dInt32 | None
|
Optional |
None
|
face_adjacency_edges
|
Array2dInt32 | None
|
Optional |
None
|
face_adjacency_unshared
|
Array2dInt32 | None
|
Optional |
None
|
face_normals
|
array[vec3] | None
|
Optional length- |
None
|
Returns:
| Type | Description |
|---|---|
array[float32]
|
Length |
Raises:
| Type | Description |
|---|---|
ValueError
|
If only one of |
RuntimeError
|
If |
Source code in triwarp/adjacency.py
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 542 543 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 630 | |
face_adjacency_convex
face_adjacency_convex(
vertices: array[vec3],
faces: array[int32],
face_adjacency: Array2dInt32 | None = None,
face_adjacency_edges: Array2dInt32 | None = None,
face_adjacency_unshared: Array2dInt32 | None = None,
face_normals: array[vec3] | None = None,
) -> wp.array[wp.bool]
Return face pairs that are adjacent and locally convex.
A pair is locally convex when the unshared vertex of the second face,
projected onto the plane of the first face, has a projection less than
TOLERANCE_MERGE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
array[vec3]
|
|
required |
faces
|
array[int32]
|
Length- |
required |
face_adjacency
|
Array2dInt32 | None
|
Optional |
None
|
face_adjacency_edges
|
Array2dInt32 | None
|
Optional |
None
|
face_adjacency_unshared
|
Array2dInt32 | None
|
Optional |
None
|
face_normals
|
array[vec3] | None
|
Optional length- |
None
|
Returns:
| Type | Description |
|---|---|
array[bool]
|
Length |
Raises:
| Type | Description |
|---|---|
ValueError
|
If only one of |
RuntimeError
|
If |
Source code in triwarp/adjacency.py
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 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 | |
face_connected_component_labels
face_connected_component_labels(
faces: array[int32],
) -> wp.array[wp.int32]
Connected-component label per face (face-adjacency graph).
The mesh entry point to the one labelling engine: this builds
face_adjacency and hands it to
connected_component_labels_from_edges
with node_count = n_faces. There is no second implementation -- graph's is
mesh-agnostic and is what every caller in the package bottoms out in, including
Trimesh.face_connected_component_labels, which calls it directly to
reuse its own cached adjacency instead of rebuilding one here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
faces
|
array[int32]
|
Length- |
required |
Returns:
| Type | Description |
|---|---|
array[int32]
|
Length |
Source code in triwarp/adjacency.py
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 | |