Esempio n. 1
0
def test_slice_cube_corner():
    common_kwargs = dict(
        vertices=cube_vertices,
        faces=cube_faces,
        point_on_plane=cube_extent - 0.05,
        plane_normal=np.array([1, 1, 1]),
    )

    sliced_vertices, sliced_faces = slice_triangles_by_plane(**common_kwargs, )

    np.testing.assert_array_almost_equal(np.min(sliced_vertices, axis=0),
                                         cube_extent - 0.15)
    np.testing.assert_array_almost_equal(np.max(sliced_vertices, axis=0),
                                         cube_extent)
    assert len(sliced_faces) == 4

    sliced_vertices, sliced_faces, face_mapping = slice_triangles_by_plane(
        **common_kwargs,
        ret_face_mapping=True,
    )

    # Check that the `face_mapping` is correct by seeing that the new faces
    # correspond to the expected `cube_faces`. See mapping above.

    # Confidence check.
    np.testing.assert_array_equal(
        surface_normals(sliced_vertices[sliced_faces]),
        np.array([vg.basis.y, vg.basis.x, vg.basis.z, vg.basis.z]),
    )

    # Assert.
    np.testing.assert_array_equal(
        face_mapping,
        np.array([2, 6, 8, 9]),
    )
Esempio n. 2
0
def test_slice_cube_top():
    """
    Tests new quads and entirely contained triangles.
    """
    common_kwargs = dict(
        vertices=cube_vertices,
        faces=cube_faces,
        point_on_plane=cube_extent - 0.05,
        plane_normal=vg.basis.z,
    )

    sliced_vertices, sliced_faces = slice_triangles_by_plane(**common_kwargs)

    np.testing.assert_array_almost_equal(np.min(sliced_vertices, axis=0),
                                         cube_origin + np.array([0, 0, 0.95]))
    np.testing.assert_array_almost_equal(np.max(sliced_vertices, axis=0),
                                         cube_extent)
    assert len(sliced_faces) == 14

    sliced_vertices, sliced_faces, face_mapping = slice_triangles_by_plane(
        **common_kwargs, ret_face_mapping=True)

    # Check that the `face_mapping` is correct by seeing that the new faces
    # correspond to the expected `cube_faces`. See mapping above.

    # Confidence check.
    np.testing.assert_array_equal(
        surface_normals(sliced_vertices[sliced_faces]),
        np.array([
            vg.basis.z,
            vg.basis.z,
            vg.basis.neg_y,
            vg.basis.neg_y,
            vg.basis.y,
            vg.basis.y,
            vg.basis.x,
            vg.basis.x,
            vg.basis.neg_x,
            vg.basis.neg_x,
            vg.basis.neg_y,
            vg.basis.y,
            vg.basis.x,
            vg.basis.neg_x,
        ]),
    )

    # Assert.
    np.testing.assert_array_equal(
        face_mapping, np.array([8, 9, 1, 1, 2, 2, 6, 6, 10, 10, 0, 3, 7, 11]))
Esempio n. 3
0
def test_slice_cube_edge_multiple_planes():
    sliced_vertices, sliced_faces = slice_triangles_by_plane(
        *slice_triangles_by_plane(
            vertices=cube_vertices,
            faces=cube_faces,
            point_on_plane=cube_extent - 0.05,
            plane_normal=vg.basis.z,
        ),
        point_on_plane=cube_extent - 0.05,
        plane_normal=vg.basis.y,
    )

    np.testing.assert_array_almost_equal(
        np.min(sliced_vertices, axis=0),
        cube_origin + np.array([0, 0.95, 0.95]))
    np.testing.assert_array_almost_equal(np.max(sliced_vertices, axis=0),
                                         cube_extent)
    assert len(sliced_faces) == 12
Esempio n. 4
0
def test_slice_cube_all_in_back():
    common_kwargs = dict(
        vertices=cube_vertices,
        faces=cube_faces,
        point_on_plane=cube_origin + 5,
        plane_normal=vg.basis.x,
    )

    sliced_vertices, sliced_faces = slice_triangles_by_plane(**common_kwargs)

    assert len(sliced_vertices) == 0
    assert len(sliced_faces) == 0

    sliced_vertices, sliced_faces, face_mapping = slice_triangles_by_plane(
        **common_kwargs, ret_face_mapping=True)

    assert len(sliced_vertices) == 0
    assert len(sliced_faces) == 0
    assert len(face_mapping) == 0
Esempio n. 5
0
def test_slice_empty():
    common_kwargs = dict(
        vertices=np.zeros((0, 3), dtype=np.float64),
        faces=np.zeros((0, 3), dtype=FACE_DTYPE),
        point_on_plane=np.zeros(3),
        plane_normal=vg.basis.x,
    )

    sliced_vertices, sliced_faces = slice_triangles_by_plane(**common_kwargs)

    assert len(sliced_vertices) == 0
    assert len(sliced_faces) == 0

    sliced_vertices, sliced_faces, face_mapping = slice_triangles_by_plane(
        **common_kwargs,
        ret_face_mapping=True,
    )

    assert len(sliced_vertices) == 0
    assert len(sliced_faces) == 0
    assert len(face_mapping) == 0
Esempio n. 6
0
def test_slice_cube_all_in_front():
    common_kwargs = dict(
        vertices=cube_vertices,
        faces=cube_faces,
        point_on_plane=cube_origin,
        plane_normal=vg.basis.x,
    )

    sliced_vertices, sliced_faces = slice_triangles_by_plane(**common_kwargs)

    np.testing.assert_array_equal(sliced_vertices, cube_vertices)
    np.testing.assert_array_equal(sliced_faces, cube_faces)

    sliced_vertices, sliced_faces, face_mapping = slice_triangles_by_plane(
        **common_kwargs,
        ret_face_mapping=True,
    )

    np.testing.assert_array_equal(sliced_vertices, cube_vertices)
    np.testing.assert_array_equal(sliced_faces, cube_faces)
    np.testing.assert_array_equal(face_mapping, np.arange(len(cube_faces)))
Esempio n. 7
0
def test_slice_cube_submesh():
    # Only act on the top of the cube.
    mask = np.zeros(len(cube_faces), dtype=np.bool)
    mask[[2, 3]] = True

    _, sliced_faces = slice_triangles_by_plane(
        vertices=cube_vertices,
        faces=cube_faces,
        point_on_plane=cube_extent - 0.05,
        plane_normal=np.array([1, 1, 1]),
        faces_to_slice=mask,
    )
    # Only the corner of the top is kept, along with the rest of the cube.
    # TODO: Improve this assertion. For now, verify visually.
    assert len(sliced_faces) == 11