[util] add merge_polyhedra
This commit is contained in:
parent
d71cb6a535
commit
0bed641d08
1 changed files with 31 additions and 0 deletions
31
adze/util.py
31
adze/util.py
|
|
@ -29,6 +29,37 @@ def build_empty() -> poly_t:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def merge_polyhedra(polys: Sequence[poly_t]) -> poly_t:
|
||||||
|
"""
|
||||||
|
Merge multiple polyhedra into a single representation.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
polys: Sequence of polyhedra to merge.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A single polyhedron containing all input polyhedra as separate components.
|
||||||
|
"""
|
||||||
|
if not polys:
|
||||||
|
return build_empty()
|
||||||
|
|
||||||
|
valid_polys = [p for p in polys if p['vertices'].shape[0] > 0]
|
||||||
|
if not valid_polys:
|
||||||
|
return build_empty()
|
||||||
|
|
||||||
|
all_vertices = numpy.vstack([p['vertices'] for p in valid_polys])
|
||||||
|
|
||||||
|
all_neighbors = []
|
||||||
|
offset = 0
|
||||||
|
for p in valid_polys:
|
||||||
|
all_neighbors.append(p['neighbors'] + offset)
|
||||||
|
offset += p['vertices'].shape[0]
|
||||||
|
|
||||||
|
return {
|
||||||
|
'vertices': all_vertices,
|
||||||
|
'neighbors': numpy.vstack(all_neighbors),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def find_components(neighbors: NDArray[numpy.integer]) -> NDArray[numpy.integer]:
|
def find_components(neighbors: NDArray[numpy.integer]) -> NDArray[numpy.integer]:
|
||||||
"""
|
"""
|
||||||
Given an adjacency list, flood-fill to find and label connected components.
|
Given an adjacency list, flood-fill to find and label connected components.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue