Example #1
0
def test_filter_point_cloud_to_polygon_2d_triangle_all_outside() -> None:
    """
    Test points that fall within a triangle symbol centered at
    the origin. The shape resembles:

            (0,1)
            /\
           /  \
    (-1,0)--.--(1,0)

    All of these points should fall outside. We test if we can
    break the function in such a case.
    """
    polygon = np.array([[-1, 0], [1, 0], [0, 1]])

    point_cloud_2d = np.array([
        [-1, 1],  # out
        [-0.5, 0.5],  # on boundary, so out
        [0.5, 0.5],  # on boundary, so out
        [0.0, 0.0],  # on boundary, so out
        [0.5, -0.1],  # out
        [1, -1],  # out
        [-0.5, -0.1],  # out
        [-1, -1],
    ])  # out

    interior_pts = filter_point_cloud_to_polygon(polygon,
                                                 point_cloud_2d.copy())
    assert interior_pts is None
Example #2
0
def test_filter_point_cloud_to_polygon_2d_redcross() -> None:
    """
    Test points that fall within a red cross symbol centered at
    the origin.

        -----
        |   |
    ----|   |----(2,1)
    |     .     |
    |           |
    ----|   |----(2,-1)
        |   |
        -----

    """
    polygon = np.array([
        [1, 1],
        [1, 2],
        [-1, 2],
        [-1, 1],
        [-2, 1],
        [-2, -1],
        [-1, -1],
        [-1, -2],
        [1, -2],
        [1, -2],
        [2, -1],
        [2, 1],
    ])
    point_cloud_2d = np.array([[0.9, 0.9], [1.1, 1.1], [1, 2.0], [1, 2.1],
                               [0, 1.99]])  # in  # out  # out  # out  # in
    interior_pts = filter_point_cloud_to_polygon(polygon, point_cloud_2d)

    interior_gt_bool = np.array([True, False, False, False, True])
    assert np.allclose(point_cloud_2d[interior_gt_bool], interior_pts)
Example #3
0
def test_filter_point_cloud_to_polygon_2d_triangle_and_3d_pointcloud() -> None:
    """
    Test points that fall within a triangle symbol centered at
    the origin. The shape resembles:

            (0,1)
            /\
           /  \
    (-1,0)--.--(1,0)

    By shapely convention, points on the boundary are not
    considered to be located inside of the polygon.
    """
    polygon = np.array([[-1, 0], [1, 0], [0, 1]])

    point_cloud_2d = np.array([
        [-1, 1, -3.0],  # out
        [-0.5, 0.5, -2.0],  # on boundary, so out
        [0, 0.5, -1.0],  # in
        [0.5, 0.5, 0.0],  # on boundary, so out
        [0.0, 0.0, 1.0],  # on boundary, so out
        [0.5, -0.1, 2.1],  # out
        [1, -1, 3.2],  # out
        [-0.5, -0.1, 4.3],  # out
        [-1, -1, 5.4],  # out
        [-0.5, 0.1, 0.0],  # in
        [0.49999, 0.49999, 6.0],  # in
        [-0.49999, 0.49999, 7.0],
    ])  # in

    interior_pts = filter_point_cloud_to_polygon(polygon,
                                                 point_cloud_2d.copy())

    interior_gt_bool = np.array([
        False, False, True, False, False, False, False, False, False, True,
        True, True
    ])
    assert np.allclose(point_cloud_2d[interior_gt_bool], interior_pts)