Coverage for src/abm_shape_collection/extract_mesh_wireframe.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2024-09-25 19:34 +0000

1from __future__ import annotations 

2 

3from typing import TYPE_CHECKING 

4 

5from vtk import vtkPolyData # pylint: disable=no-name-in-module 

6 

7from abm_shape_collection.extract_mesh_projections import convert_vtk_to_trimesh 

8 

9if TYPE_CHECKING: 

10 import trimesh 

11 

12 

13def extract_mesh_wireframe( 

14 mesh: vtkPolyData | trimesh.Trimesh, offset: tuple[float, float, float] | None = None 

15) -> list[list[tuple[float, float, float]]]: 

16 """ 

17 Extract wireframe edges from mesh. 

18 

19 Parameters 

20 ---------- 

21 mesh 

22 Mesh object. 

23 offset 

24 Mesh translation applied before extracting slices and/or meshes. 

25 

26 Returns 

27 ------- 

28 : 

29 List of wireframe edges. 

30 """ 

31 

32 if isinstance(mesh, vtkPolyData): 

33 mesh = convert_vtk_to_trimesh(mesh) 

34 

35 if offset is not None: 

36 mesh.apply_translation(offset) 

37 

38 all_edges = [[tuple(mesh.vertices[a]), tuple(mesh.vertices[b])] for a, b in mesh.edges] 

39 return [ 

40 [(x1, y1, z1), (x2, y2, z2)] 

41 for (x1, y1, z1), (x2, y2, z2) in {frozenset(edge) for edge in all_edges} 

42 ]