Ejemplo n.º 1
0
def add_wall(floor_plan: FloorPlan, node_a: Node,
             node_b: Node) -> Tuple[FloorPlan, Tuple[Node, Node]]:
    edge = Edge(edge_type=EdgeType.wall, node_a=node_a, node_b=node_b)
    node_a.add_edge(edge)
    node_b.add_edge(edge)
    floor_plan.add_node(node_a)
    floor_plan.add_node(node_b)
    floor_plan.add_edge(edge)
    return floor_plan, (node_a, node_b)
Ejemplo n.º 2
0
 def run(self, ) -> None:
     for floor_plan in self.floor_plans:
         frame = cv2.imread(str(floor_plan))
         frame_copy = frame.copy()
         self.current_floor_plan = FloorPlan(str(floor_plan),
                                             status=FloorPlanStatus.start)
         while True:
             cv2.destroyAllWindows()
             cv2.namedWindow("image")
             cv2.moveWindow("image", 20, 20)
             cv2.imshow("image", frame_copy)
             print('What would you like to draw?\n' +
                   '[c] corner | [w] window | [d] door | [e] edge' +
                   '| [p] disregard image\n' + 'Press [q] to quit fully\n' +
                   'Press [n] to move on')
             key = cv2.waitKey(0)
             key = key & 0xFF
             if key == ord('c') or key == ord('w') \
                     or key == ord('d') or key == ord('e'):
                 frame, results = self.annotate(frame_copy, key)
             elif key & 0xFF == ord('q'):
                 print("Are you sure you want to quit [y]/[n]")
                 while True:
                     q = cv2.waitKey(0)
                     if q & 0xFF == ord('y'):
                         sys.exit(0)
                     elif q & 0xFF == ord('n'):
                         break
             elif key & 0xFF == ord('n'):
                 print("Are you sure you want to move on")
                 _continue = False
                 while True:
                     q = cv2.waitKey(0)
                     if q & 0xFF == ord('y'):
                         _continue = True
                         break
                     elif q & 0xFF == ord('n'):
                         break
                 if _continue:
                     break
Ejemplo n.º 3
0
def add_adj_room(
    floor_plan: FloorPlan, corners: List[Node], room_type: RoomType, name,
    midpoint: Tuple[float, float]
) -> Tuple[FloorPlan, Tuple[Node, Node, Node, Node]]:
    node_a = corners[0]
    node_b = corners[1]
    node_c = corners[2]
    node_d = corners[3]
    room_node = RoomNode(Vector(midpoint[0], midpoint[1]),
                         room_type=RoomType.staircase)
    edge_a = Edge(edge_type=EdgeType.wall, node_a=node_a, node_b=node_b)
    edge_b = Edge(edge_type=EdgeType.wall, node_a=node_b, node_b=node_c)
    edge_c = Edge(edge_type=EdgeType.wall, node_a=node_c, node_b=node_d)
    edge_d = Edge(edge_type=EdgeType.wall, node_a=node_d, node_b=node_a)
    edge_la = Edge(edge_type=EdgeType.wall, node_a=node_a, node_b=room_node)
    edge_lb = Edge(edge_type=EdgeType.wall, node_a=node_b, node_b=room_node)
    edge_lc = Edge(edge_type=EdgeType.wall, node_a=node_c, node_b=room_node)
    edge_ld = Edge(edge_type=EdgeType.wall, node_a=node_d, node_b=room_node)
    node_a.add_edge(edge_a)
    node_a.add_edge(edge_d)
    node_a.add_edge(edge_la)
    node_b.add_edge(edge_a)
    node_b.add_edge(edge_b)
    node_b.add_edge(edge_lb)
    node_c.add_edge(edge_b)
    node_c.add_edge(edge_c)
    node_c.add_edge(edge_lc)
    node_d.add_edge(edge_c)
    node_d.add_edge(edge_d)
    node_d.add_edge(edge_ld)
    room = Room(corners=[node_a, node_b, node_c, node_d],
                name=name,
                room_node=room_node)
    floor_plan.add_node(node_a)
    floor_plan.add_node(node_b)
    floor_plan.add_node(node_c)
    floor_plan.add_node(node_d)
    floor_plan.add_node(room_node)
    floor_plan.add_edge(edge_a)
    floor_plan.add_edge(edge_b)
    floor_plan.add_edge(edge_c)
    floor_plan.add_edge(edge_d)
    floor_plan.add_edge(edge_la)
    floor_plan.add_edge(edge_lb)
    floor_plan.add_edge(edge_lc)
    floor_plan.add_edge(edge_ld)
    floor_plan.add_room(room)
    return floor_plan, (node_a, node_b, node_c, node_d)
Ejemplo n.º 4
0
def house_32_floor_0():
    floor_plan = FloorPlan('house_32_floor_0', status=FloorPlanStatus.start)
    # origin = (6, 7)
    # footprint
    floor_plan, (node_a, node_b) = add_wall(floor_plan,
                                            node_a=Node(Vector(0, 0)),
                                            node_b=Node(Vector(58, 0)))
    floor_plan, (node_a, node_b) = add_wall(floor_plan,
                                            node_a=node_b,
                                            node_b=Node(Vector(386, 0)))
    floor_plan, (node_a, node_b) = add_wall(floor_plan,
                                            node_a=node_b,
                                            node_b=Node(Vector(386, -183)))
    floor_plan, (node_a, node_b) = add_wall(floor_plan,
                                            node_a=node_b,
                                            node_b=Node(Vector(184, -183)))
    floor_plan, (node_a, node_b) = add_wall(floor_plan,
                                            node_a=node_b,
                                            node_b=Node(Vector(184, -165)))
    floor_plan, (node_a, node_b) = add_wall(floor_plan,
                                            node_a=node_b,
                                            node_b=Node(Vector(127, -165)))
    floor_plan, (node_a, node_b) = add_wall(floor_plan,
                                            node_a=node_b,
                                            node_b=Node(Vector(127, -183)))
    floor_plan, (node_a, node_b) = add_wall(floor_plan,
                                            node_a=node_b,
                                            node_b=Node(Vector(14, -183)))
    floor_plan, (node_a, node_b) = add_wall(floor_plan,
                                            node_a=node_b,
                                            node_b=Node(Vector(14, -77)))
    floor_plan, (node_a, node_b) = add_wall(floor_plan,
                                            node_a=node_b,
                                            node_b=Node(Vector(56, -77)))
    floor_plan, (node_a, node_b) = add_wall(floor_plan,
                                            node_a=node_b,
                                            node_b=Node(Vector(58, 0)))

    floor_plan, (node_a, node_b, node_c,
                 node_d) = add_room(floor_plan,
                                    corners=[
                                        Node(Vector(134, 0)),
                                        Node(Vector(201, 0)),
                                        Node(Vector(201, -77)),
                                        Node(Vector(134, -77))
                                    ],
                                    room_type=RoomType.staircase,
                                    name='stairs',
                                    midpoint=(167.5, -38.5))
    floor_plan, (node_a, node_b, node_c, node_d) = add_room(
        floor_plan,
        corners=[node_b,
                 Node(Vector(254, 0)),
                 Node(Vector(254, -77)), node_c],
        room_type=RoomType.bath,
        name='stairs',
        midpoint=(227.5, -38.5))
    floor_plan, (node_a, node_b, node_c, node_d) = add_room(
        floor_plan,
        corners=[node_b,
                 Node(Vector(341, 0)),
                 Node(Vector(341, -77)), node_c],
        room_type=RoomType.bed,
        name='stairs',
        midpoint=(297.5, -38.5))
Ejemplo n.º 5
0
def test_floor_plan_nodes():
    name = 'test'
    status = FloorPlanStatus.start
    fp = FloorPlan(name, status)

    vector_orig = Vector(0, 0)
    node = Node(vector_orig)
    fp.add_node(node)
    vector2 = Vector(0, 1)
    try:
        fp.add_node(vector2)
        pytest.fail()
    except ValueError:
        pass
    fail_if(fp.nodes[str(vector_orig)] != node)

    # can't add a duplicate node/vector location
    fail_if(fp.add_node(node))

    try:
        fp.remove_node(Vector(0, 0))
        pytest.fail()
    except ValueError:
        pass
    fail_if(not fp.remove_node(node))
    # doesn't exist
    fail_if(fp.remove_node(Node(Vector(0, 100))))

    fp.add_node(node)
    fail_if(fp.get_node(vector_orig) is None)
    fail_if(fp.get_node(Vector(0, 100)) is not None)
    try:
        fp.get_node((0, 0))
        pytest.fail()
    except ValueError:
        pass

    fail_if(not fp.node_exists(node))
    fail_if(not fp.node_exists(vector_orig))
    try:
        fp.node_exists((0, 0))
        pytest.fail()
    except ValueError:
        pass
    _, exists = fp.nodes_exist([node])
    fail_if(not exists)
    _, exists = fp.nodes_exist([node, vector_orig])
    fail_if(not exists)
    _, exists = fp.nodes_exist([node, Vector(0, 100)])
    fail_if(exists)
    try:
        fp.nodes_exist([node, (0, 0)])
        pytest.fail()
    except ValueError:
        pass
    try:
        fp.nodes_exist((0, 0))
        pytest.fail()
    except ValueError:
        pass
    try:
        fp.nodes_exist(node)
        pytest.fail()
    except ValueError:
        pass

    # test update
    node, ret = fp.update_node_vector(node, vector2)
    fail_if(not ret)
    fail_if(node.vector == vector_orig)
    fail_if(node.vector != vector2)
    fail_if(str(vector_orig) in fp.nodes)
    fail_if(not str(vector2) in fp.nodes)
    fail_if(fp.get_node(vector2) != node)
    fail_if(fp.nodes[str(vector2)].vector != vector2)
    fail_if(len(fp.nodes) != 1)
    try:
        fp.update_node_vector(node, (0, 0))
        pytest.fail()
    except ValueError:
        pass
    fail_if(fp.update_node_vector(Node(Vector(0, 100)), Vector(0, 300)))
Ejemplo n.º 6
0
def test_floor_plan_edges():
    name = 'test'
    status = FloorPlanStatus.start
    fp = FloorPlan(name, status)

    node = Node(Vector(0, 1))
    node_b = Node(Vector(0, 2))
    fp.add_node(node)
    fp.add_node(node_b)
    edge = Edge(edge_type=EdgeType.wall, node_a=node, node_b=node_b)
    node.add_edge(edge)
    node_b.add_edge(edge)

    fail_if(fp.get_node(Vector(0, 1)).neighbour_edges[0] != edge)
    fail_if(fp.get_node(Vector(0, 1)).neighbour_edges[0].upper_node != node_b)
    fail_if(fp.get_node(Vector(0, 1)).neighbour_edges[0].bottom_node != node)

    fp.add_edge(edge)
    fail_if(fp.edges[f'{node}_{node.get_direction_to(node_b)}'] != edge)
    fail_if(fp.edges[f'{node_b}_{node_b.get_direction_to(node)}'] != edge)
    fail_if(fp.edges[str(edge)] != edge)

    try:
        fp.add_edge(0)
        pytest.fail()
    except ValueError:
        pass

    try:
        fp.remove_edge(0)
        pytest.fail()
    except ValueError:
        pass

    fail_if(not fp.remove_edge(edge))
    fp.add_edge(edge)
    node_3 = Node(Vector(0, 10))
    node_4 = Node(Vector(0, 30))
    edge2 = Edge(EdgeType.wall, node_a=node_3, node_b=node_4)
    fail_if(fp.remove_edge(edge2))
    fp.add_edge(edge2)
    fail_if(len(fp.edges) != 2)
    fail_if(fp.edges[f'{node}_{node.get_direction_to(node_b)}'] != edge)
    fail_if(fp.edges[f'{node_b}_{node_b.get_direction_to(node)}'] != edge)
    fail_if(fp.edges[str(edge)] != edge)
    fail_if(fp.edges[f'{node_3}_{node_3.get_direction_to(node_4)}'] == edge)
    fail_if(fp.edges[f'{node_3}_{node_3.get_direction_to(node_4)}'] != edge2)
    fail_if(fp.edges[f'{node_4}_{node_4.get_direction_to(node_3)}'] != edge2)
    fail_if(fp.edges[str(edge2)] != edge2)

    fail_if(not fp.edge_exists(edge))
    fail_if(not fp.edge_exists(edge2))
    edge3 = Edge(EdgeType.wall, node_a=node, node_b=node_4)
    fail_if(fp.edge_exists(edge3))
    try:
        fp.edge_exists(0)
        pytest.fail()
    except ValueError:
        pass
    _, ret = fp.edges_exist([edge, edge2])
    fail_if(not ret)
    edge_ret, ret = fp.edges_exist([edge, edge2, edge3])
    fail_if(ret)
    fail_if(edge_ret != edge3)
    try:
        _, ret = fp.edges_exist([edge, edge2, 0])
        pytest.fail()
    except ValueError:
        pass
    try:
        _, ret = fp.edges_exist(edge)
        pytest.fail()
    except ValueError:
        pass

    node_4 = Node(Vector(0, -10))
    edge = Edge(EdgeType.wall, node_a=node, node_b=node_4)
    fail_if(node.neighbour_edges[node.get_direction_to(node_4).integer_value]
            is not None)
    fp.add_edge(edge)
    node.add_edge(edge)
    node_4.add_edge(edge)
    fail_if(node.neighbour_edges[node.get_direction_to(
        node_4).integer_value] is None)
    print(fp.nodes)
    fail_if(fp.nodes[str(node.vector)].neighbour_edges[
        node.get_direction_to(node_4).integer_value] != edge)
Ejemplo n.º 7
0
def test_floor_plan_rooms():
    name = 'test'
    status = FloorPlanStatus.start
    fp = FloorPlan(name, status)
    fail_if(fp.name != name)
    fail_if(fp.status != status)

    str(fp)

    bl = CornerNode(Vector(0, 0))
    tl = CornerNode(Vector(0, 1))
    tr = CornerNode(Vector(1, 1))
    br = CornerNode(Vector(1, 0))
    room_node = RoomNode(Vector(0.5, 0.5), RoomType.kitchen)
    room = Room(name='name', corners=[bl, tl, tr, br], room_node=room_node)
    try:
        fp.add_room(0)
        pytest.fail()
    except ValueError:
        pass
    fp.add_room(room)
    fail_if(fp.rooms != {room.name: room})

    fail_if(not fp.remove_room('name'))
    fp.add_room(room)
    fail_if(not fp.remove_room(room))
    try:
        fail_if(fp.remove_room(0))
        pytest.fail()
    except ValueError:
        pass

    fp.add_room(room)
    fail_if(fp.rooms['name'] != room)
    fail_if(not fp.room_exists(room))
    fail_if(not fp.room_exists('name'))
    try:
        fail_if(fp.room_exists(0))
        pytest.fail()
    except ValueError:
        pass

    room_, ret = fp.rooms_exist(['name', room])
    fail_if(not ret)
    fail_if(fp.remove_room('test'))
    room_, ret = fp.rooms_exist(['ame', room])
    fail_if(ret)
    fail_if(room_ != 'ame')
    try:
        fp.rooms_exist('name')
        pytest.fail()
    except ValueError:
        pass
    try:
        fp.rooms_exist([0])
        pytest.fail()
    except ValueError:
        pass