Esempio n. 1
0
def polyedge_from_to_via_vertices(mesh, from_vkey, to_vkey, via_vkeys):
	# return shortest polyedge from_vkey to_vkey via_vkeys

	adjacency = adjacency_from_to_via_vertices(mesh, from_vkey, to_vkey, via_vkeys)
	return next(breadth_first_paths(adjacency, from_vkey, to_vkey))
Esempio n. 2
0
def strip_polyedge_update(mesh, polyedge, vertex_modifications):
    """Update a polyedge in mesh that has been modified.

    Parameters
    ----------
    mesh : QuadMesh
        A quad mesh.
    polyedge : list
        A polyedge as a list of (old) vertex keys.
    vertex_modifications : dict
         A dictionary showing the vertex modifications, old vertex keys pointing to the new vertex keys.

    Returns
    -------
    shortest_polyedge: list
        The updated polyedge as a list of vertex keys.

    """

    closed = polyedge[0] == polyedge[-1]

    if closed:
        polyedge = polyedge[:-1]

    # update polyedge with candidate vertices
    polyedge_modifications = {
        vkey: (vertex_modifications[vkey]
               if vkey in vertex_modifications else [vkey])
        for vkey in polyedge
    }
    # list all candidate vertices to form new polyedge
    candidate_vertices = tuple(
        set([
            vkey for vkeys in polyedge_modifications.values() for vkey in vkeys
        ]))
    # adjacency restricted to candidate vertices
    adjacency = {
        vkey: [
            nbr for nbr in mesh.vertex_neighbors(vkey)
            if nbr in candidate_vertices
        ]
        for vkey in mesh.vertices() if vkey in candidate_vertices
    }

    # for each combination of boundary vertex extremities, get the shortest
    # valid path through the modified vertices of the polyedges
    shortest_polyedge = None
    # start vertices on boundary
    for vkey_start in polyedge_modifications[polyedge[0]]:
        if mesh.is_vertex_on_boundary(vkey_start):
            # end vertices on boundary
            for vkey_end in polyedge_modifications[polyedge[-1]]:
                if mesh.is_vertex_on_boundary(vkey_end):
                    # iterate through all paths between start and end vertices
                    # starting by the shortest
                    for candidate_polyedge in breadth_first_paths(
                            adjacency, vkey_start, vkey_end):
                        is_valid = True
                        # if was initailly closed, make sure that temporary end
                        # is adjacent to start
                        if closed:
                            if candidate_polyedge[
                                    0] not in mesh.vertex_neighbors(
                                        candidate_polyedge[-1]):
                                continue
                        # check that vertices in path come from the modified
                        # vertices of the polyedge in the same order
                        i = 0
                        for vkey in candidate_polyedge:
                            if vkey in polyedge_modifications[polyedge[i]]:
                                continue
                            elif vkey in polyedge_modifications[polyedge[i +
                                                                         1]]:
                                i += 1
                            else:
                                is_valid = False
                                break
                        # update if shorter
                        if is_valid:
                            if shortest_polyedge is None or len(
                                    shortest_polyedge) > len(
                                        candidate_polyedge):
                                shortest_polyedge = candidate_polyedge
                            break

    if closed:
        shortest_polyedge.append(shortest_polyedge[0])

    return shortest_polyedge