def canvas_from_map(environment_map):

    canvas = np.zeros(
        [environment_map.data.shape[0], environment_map.data.shape[1], 3],
        dtype=np.uint8,
    )

    obstacle_space_mask = environment_map.data == MapConstants.OBSTACLE

    # Paint the entire canvas as empty space first.
    paint_canvas(canvas, MAP_CONSTANTS_TO_CANVAS_COLORS[MapConstants.EMPTY])

    # Paint obstacles.
    # TODO: Modify this accordingly when Map has obstacle passes.
    paint_canvas(
        canvas,
        MAP_CONSTANTS_TO_CANVAS_COLORS[MapConstants.OBSTACLE],
        obstacle_space_mask,
    )

    return canvas
def test_paint_canvas(empty_canvas):

    # Test painting the entire canvas.
    paint_canvas(empty_canvas, (1, 2, 3))

    assert np.allclose(empty_canvas[..., 0], np.ones(empty_canvas.shape[:2]))
    assert np.allclose(empty_canvas[..., 1], 2 * np.ones(empty_canvas.shape[:2]))
    assert np.allclose(empty_canvas[..., 2], 3 * np.ones(empty_canvas.shape[:2]))

    # Test painting a mask.
    mask = np.zeros(empty_canvas.shape[:2], dtype=np.bool)
    mask[:, :250] = True

    paint_canvas(empty_canvas, (0, 0, 0), mask)

    # The left half of the image must be colored with (0, 0, 0)
    assert np.allclose(empty_canvas[:, :250, 0], np.zeros([500, 250]))
    assert np.allclose(empty_canvas[:, :250, 1], np.zeros([500, 250]))
    assert np.allclose(empty_canvas[:, :250, 2], np.zeros([500, 250]))

    # The right half must be unchanged.
    assert np.allclose(empty_canvas[:, 250:, 0], np.ones([500, 250]))
    assert np.allclose(empty_canvas[:, 250:, 1], 2 * np.ones([500, 250]))
    assert np.allclose(empty_canvas[:, 250:, 2], 3 * np.ones([500, 250]))
Exemple #3
0
 def _invalid_drawing_kernel(canvas, robot):
     paint_canvas(canvas, (0, 0, 0))
Exemple #4
0
 def _drawing_kernel(canvas, robot, resolution):
     paint_canvas(canvas, (1, 1, 1))