def quadrangulate_polygonal_faces(self): # WIP: problem not all faces should have the same source for propagation supermesh = self.mesh delaunay_vertex_map = tuple(geometric_key(self.vertex_coordinates(vkey)) for vkey in self.vertices()) #newly added vertices in mesh that were not in the Delaunay are missing... edges_to_unweld = [edge for edge in supermesh.edges() if sum([geometric_key(supermesh.vertex_coordinates(i)) in delaunay_vertex_map for i in edge]) == 2] mesh_unweld_edges(supermesh, edges_to_unweld) meshes = mesh_explode(supermesh) for mesh in meshes: candidate_map = {geometric_key(mesh.vertex_coordinates(vkey)): [] for vkey in mesh.vertices()} for vkey in mesh.vertices_on_boundary(): candidate_map[geometric_key(mesh.vertex_coordinates(vkey))].append(mesh.vertex_degree(vkey)) source_map = tuple([geom_key for geom_key, valencies in candidate_map.items() if len(list(set(valencies))) > 1]) self.mesh = mesh_weld(mesh) mesh = self.mesh sources = [vkey for vkey in mesh.vertices() if geometric_key(mesh.vertex_coordinates(vkey)) in source_map] quadrangulate_mesh(mesh, sources)
def boundary_triangulation(outer_boundary, inner_boundaries, polyline_features = [], point_features = [], src='numpy_rpc'): """Generate Delaunay triangulation between a planar outer boundary and planar inner boundaries. All vertices lie the boundaries. Parameters ---------- outer_boundary : list Planar outer boundary as list of vertex coordinates. inner_boundaries : list List of planar inner boundaries as lists of vertex coordinates. polyline_features : list List of planar polyline_features as lists of vertex coordinates. point_features : list List of planar point_features as lists of vertex coordinates. src : str Source of Delaunay triangulation. Default is NumPy via RPC. Returns ------- delaunay_mesh : Mesh The Delaunay mesh. """ # generate planar Delaunay triangulation vertices = [pt for boundary in [outer_boundary] + inner_boundaries + polyline_features for pt in boundary] + point_features if src == 'numpy_rpc': faces = delaunay_numpy_rpc(vertices) elif src == 'numpy': faces = delaunay_numpy(vertices) else: delaunay_compas(vertices) delaunay_mesh = Mesh.from_vertices_and_faces(vertices, faces) # delete false faces with aligned vertices for fkey in list(delaunay_mesh.faces()): a, b, c = [delaunay_mesh.vertex_coordinates(vkey) for vkey in delaunay_mesh.face_vertices(fkey)] ab = subtract_vectors(b, a) ac = subtract_vectors(c, a) if length_vector(cross_vectors(ab, ac)) == 0: delaunay_mesh.delete_face(fkey) # delete faces outisde the borders for fkey in list(delaunay_mesh.faces()): centre = trimesh_face_circle(delaunay_mesh, fkey)[0] if not is_point_in_polygon_xy(centre, outer_boundary) or any([is_point_in_polygon_xy(centre, inner_boundary) for inner_boundary in inner_boundaries]): delaunay_mesh.delete_face(fkey) # topological cut along the feature polylines through unwelding vertex_map = {geometric_key(delaunay_mesh.vertex_coordinates(vkey)): vkey for vkey in delaunay_mesh.vertices()} edges = [edge for polyline in polyline_features for edge in pairwise([vertex_map[geometric_key(point)] for point in polyline])] mesh_unweld_edges(delaunay_mesh, edges) return delaunay_mesh