newton.utils.MeshAdjacency#

class newton.utils.MeshAdjacency(indices)[source]#

Bases: object

Builds and stores edge adjacency information for a triangle mesh.

This class processes triangle indices to create a mapping from edges to their adjacent triangles. Each edge stores references to both adjacent triangles (if they exist) along with the opposite vertices.

edges#

Dictionary mapping edge keys (min_vertex, max_vertex) to MeshAdjacency.Edge objects.

indices#

The original triangle indices used to build the adjacency.

class Edge(v0, v1, o0, o1, f0, f1)#

Bases: object

Represents an edge in a triangle mesh with adjacency information.

Stores the two vertices of the edge, the opposite vertices from each adjacent triangle, and the indices of those triangles. The winding order is consistent: the first triangle is reconstructed as {v0, v1, o0}, and the second triangle as {v1, v0, o1}.

For boundary edges (edges with only one adjacent triangle), o1 and f1 are set to -1.

__init__(v0, v1, o0, o1, f0, f1)#
f0: int#

Index of the first adjacent triangle.

f1: int#

Index of the second adjacent triangle, or -1 if boundary edge.

o0: int#

Index of the vertex opposite to the edge in the first adjacent triangle.

o1: int#

Index of the vertex opposite to the edge in the second adjacent triangle, or -1 if boundary.

v0: int#

Index of the first vertex of the edge.

v1: int#

Index of the second vertex of the edge.

__init__(indices)#

Build edge adjacency from triangle indices.

Parameters:

indices (Sequence[Sequence[int]] | ndarray) – Array-like of triangle indices, where each element is a sequence of 3 vertex indices defining a triangle.

add_edge(i0, i1, o, f)#

Add or update an edge in the adjacency structure.

If the edge already exists, updates it with the second adjacent triangle. If the edge would have more than two adjacent triangles, prints a warning (non-manifold edge).

Parameters:
  • i0 (int) – Index of the first vertex of the edge.

  • i1 (int) – Index of the second vertex of the edge.

  • o (int) – Index of the opposite vertex in the triangle.

  • f (int) – Index of the triangle containing this edge.