Computes a helper struct with information about all edges in the mesh (i.e. number of incident triangles etc.)
(&self)
| 953 | |
| 954 | /// Computes a helper struct with information about all edges in the mesh (i.e. number of incident triangles etc.) |
| 955 | pub fn compute_edge_information(&self) -> MeshEdgeInformation { |
| 956 | let mut sorted_edges = Vec::new(); |
| 957 | let mut edge_info = Vec::new(); |
| 958 | |
| 959 | // Local indices into the triangle connectivity to obtain all edges |
| 960 | let tri_edges: [(usize, usize); 3] = [(0, 1), (1, 2), (2, 0)]; |
| 961 | |
| 962 | // For each triangle collect |
| 963 | // - each edge (with sorted vertices to use as unique key) |
| 964 | // - each edge with the index of the triangle and local index in the triangle |
| 965 | for (tri_idx, tri_conn) in self.triangles.iter().enumerate() { |
| 966 | for (local_idx, (v0, v1)) in tri_edges |
| 967 | .iter() |
| 968 | .copied() |
| 969 | .map(|(i0, i1)| (tri_conn[i0], tri_conn[i1])) |
| 970 | .enumerate() |
| 971 | { |
| 972 | // Sort the edge |
| 973 | if v0 < v1 { |
| 974 | sorted_edges.push([v0, v1]) |
| 975 | } else { |
| 976 | sorted_edges.push([v1, v0]) |
| 977 | }; |
| 978 | |
| 979 | edge_info.push(([v0, v1], tri_idx, local_idx)); |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | // Count the number of occurrences of "equivalent" edges (in the sense that they refer |
| 984 | // to the same vertex indices). |
| 985 | let mut edge_counts = new_map(); |
| 986 | for (edge_idx, edge) in sorted_edges.iter().copied().enumerate() { |
| 987 | edge_counts |
| 988 | .entry(edge) |
| 989 | .and_modify(|(_, count)| *count += 1) |
| 990 | .or_insert((edge_idx, 1)); |
| 991 | } |
| 992 | |
| 993 | MeshEdgeInformation { |
| 994 | edge_counts, |
| 995 | edge_info, |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | /// Returns all non-manifold vertices of this mesh |
| 1000 | /// |