Skip to main content

Edge extraction for triangle meshes

Project description

fast-edges-extraction

Cython implementation of edges extraction from triangles as well as adjacency information (edge degrees and adjacent points/triangles for manifold and boundary edges).

pip install fast-edges-extraction

Example

  • Extract the edges from the triangles
from fast_edges_extraction import extract_edges

triangles = [
    [0, 1, 2],
    [1, 2, 3],
]

edges = extract_edges(triangles)
print(edges)

Out:

[[0 1]
 [0 2]
 [1 2]
 [1 3]
 [2 3]]
  • Also extract adjacency information
# Extract edges, degrees, and adjacency information (triangles and points)
edges, degrees, t_a, p_a = extract_edges(triangles, return_adjacency=True)

# Extract manifold (2 adjacent triangles) and boundary (1 adjacent triangle) edges
manifold_edges = edges[degrees == 2]
boundary_edges = edges[degrees == 1]
other = edges[degrees > 2]

# For each manifold edge, extract the adjacent triangles and points
manifold_adjacent_triangles = t_a[degrees == 2]
manifold_adjacent_points = p_a[degrees == 2]

# For each boundary edge, extract the adjacent triangle and point
boundary_adjacent_triangles = t_a[degrees == 1][:, 0]
boundary_adjacent_points = p_a[degrees == 1][:, 0]

print("Number of manifold edges:", len(manifold_edges))
print("Number of boundary edges:", len(boundary_edges))
print("Number of other edges:", len(other))
print()

print("Manifold edges:\n---------------")

for i in range(len(manifold_edges)):

    adjacent_triangles_indices = manifold_adjacent_triangles[i]
    adjacent_points_indices = manifold_adjacent_points[i]

    adjacent_triangles = [triangles[i] for i in adjacent_triangles_indices]

    print(f"Edge {manifold_edges[i]}, ", end="")
    print(f"adjacent triangles: {adjacent_triangles}, ", end="")
    print(f"adjacent points: {adjacent_points_indices}")

print("\nBoundary edges:\n---------------")

for i in range(len(boundary_edges)):

    adjacent_triangle_indice = boundary_adjacent_triangles[i]
    adjacent_point_indice = boundary_adjacent_points[i]
    adjacent_triangle = triangles[adjacent_triangle_indice]

    print(f"Edge {boundary_edges[i],}", end=" ")
    print(f"adjacent triangles: {adjacent_triangle},", end=" ")
    print(f"adjacent points: {adjacent_point_indice}")

Out:

Number of manifold edges: 1
Number of boundary edges: 4
Number of other edges: 0

Manifold edges:
---------------
Edge [1 2], adjacent triangles: [[0, 1, 2], [1, 2, 3]], adjacent points: [0 2]

Boundary edges:
---------------
Edge (array([0, 1]),) adjacent triangles: [0, 1, 2], adjacent points: 2
Edge (array([0, 2]),) adjacent triangles: [0, 1, 2], adjacent points: 1
Edge (array([1, 3]),) adjacent triangles: [1, 2, 3], adjacent points: 1
Edge (array([2, 3]),) adjacent triangles: [1, 2, 3], adjacent points: 0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fast_edges_extraction-0.1.2.tar.gz (159.1 kB view hashes)

Uploaded Source

Built Distributions

fast_edges_extraction-0.1.2-cp312-cp312-win_amd64.whl (239.4 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

fast_edges_extraction-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (680.4 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

fast_edges_extraction-0.1.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (670.0 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

fast_edges_extraction-0.1.2-cp312-cp312-macosx_10_9_x86_64.whl (251.4 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

fast_edges_extraction-0.1.2-cp311-cp311-win_amd64.whl (239.6 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

fast_edges_extraction-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (681.9 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

fast_edges_extraction-0.1.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (676.3 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

fast_edges_extraction-0.1.2-cp311-cp311-macosx_10_9_x86_64.whl (252.8 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

fast_edges_extraction-0.1.2-cp310-cp310-win_amd64.whl (239.6 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

fast_edges_extraction-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (649.1 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

fast_edges_extraction-0.1.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (642.8 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

fast_edges_extraction-0.1.2-cp310-cp310-macosx_10_9_x86_64.whl (253.0 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

fast_edges_extraction-0.1.2-cp39-cp39-win_amd64.whl (240.2 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

fast_edges_extraction-0.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (651.7 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

fast_edges_extraction-0.1.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (645.8 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

fast_edges_extraction-0.1.2-cp39-cp39-macosx_10_9_x86_64.whl (253.7 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

fast_edges_extraction-0.1.2-cp38-cp38-win_amd64.whl (240.8 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

fast_edges_extraction-0.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (656.6 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

fast_edges_extraction-0.1.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (651.5 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

fast_edges_extraction-0.1.2-cp38-cp38-macosx_10_9_x86_64.whl (252.8 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page