Resolve all-intersections of the input mesh and extract cell partitions induced by the mesh. A cell-partition is subset of the ambient space where any pair of points belonging the partition can be connected by a curve without ever going through any mesh faces. Args: mesh (
(mesh)
| 4 | from .meshutils import remove_isolated_vertices |
| 5 | |
| 6 | def partition_into_cells(mesh): |
| 7 | """ Resolve all-intersections of the input mesh and extract cell partitions |
| 8 | induced by the mesh. A cell-partition is subset of the ambient space where |
| 9 | any pair of points belonging the partition can be connected by a curve |
| 10 | without ever going through any mesh faces. |
| 11 | |
| 12 | Args: |
| 13 | mesh (:class:`Mesh`): The input mesh. |
| 14 | |
| 15 | Returns: The output mesh with all intersections resolved and a list of |
| 16 | meshes representing individual cells. |
| 17 | |
| 18 | The following attributes are defined in the output mesh: |
| 19 | |
| 20 | * ``source_face``: the original face index. |
| 21 | * ``patches``: the scalar field marking manifold patches (A set of |
| 22 | connected faces connected by manifold edges). |
| 23 | * ``cells``: a per-face scalar field indicating the cell id on the |
| 24 | positive side of each face. |
| 25 | * ``winding_number``: the scalar field indicating the piece-wise |
| 26 | constant winding number of the cell on the positive side of each face. |
| 27 | """ |
| 28 | partition = PyMesh.CellPartition.create_raw(mesh.vertices, mesh.faces) |
| 29 | partition.run() |
| 30 | |
| 31 | vertices = partition.get_vertices() |
| 32 | resolved_mesh = form_mesh(vertices, partition.get_faces()) |
| 33 | |
| 34 | patch_ids = partition.get_patches().ravel() |
| 35 | per_patch_cells = partition.get_cells() |
| 36 | cell_ids = per_patch_cells[patch_ids] |
| 37 | |
| 38 | resolved_mesh.add_attribute("source_face") |
| 39 | resolved_mesh.set_attribute("source_face", partition.get_source_faces()) |
| 40 | resolved_mesh.add_attribute("patches") |
| 41 | resolved_mesh.set_attribute("patches", patch_ids) |
| 42 | resolved_mesh.add_attribute("cells") |
| 43 | resolved_mesh.set_attribute("cells", cell_ids[:,0].ravel()) |
| 44 | resolved_mesh.add_attribute("winding_number") |
| 45 | resolved_mesh.set_attribute("winding_number", |
| 46 | partition.get_winding_number()[:,0].ravel()) |
| 47 | |
| 48 | num_cells = partition.get_num_cells() |
| 49 | cell_faces = [partition.get_cell_faces(i) for i in range(num_cells)] |
| 50 | cells = [form_mesh(vertices, f) for f in cell_faces] |
| 51 | cells = [remove_isolated_vertices(m)[0] for m in cells] |
| 52 | |
| 53 | return resolved_mesh, cells |
| 54 |
nothing calls this directly
no test coverage detected