コード例 #1
0
def test_manifest_principled():
    # Test non-supported property
    test_actor = actor.text_3d('Test')
    npt.assert_warns(UserWarning, material.manifest_principled, test_actor)

    center = np.array([[0, 0, 0]])

    # Test expected parameters
    expected_principled_params = {
        'subsurface': 0,
        'subsurface_color': [0, 0, 0],
        'metallic': 0,
        'specular': 0,
        'specular_tint': 0,
        'roughness': 0,
        'anisotropic': 0,
        'anisotropic_direction': [0, 1, .5],
        'sheen': 0,
        'sheen_tint': 0,
        'clearcoat': 0,
        'clearcoat_gloss': 0
    }
    test_actor = actor.square(center, directions=(1, 1, 1), colors=(0, 0, 1))
    actual_principled_params = material.manifest_principled(test_actor)
    npt.assert_equal(actual_principled_params, expected_principled_params)
コード例 #2
0
def test_tangents_to_actor():
    my_actor = actor.square(np.array([[0, 0, 0]]))
    poly_point_data = my_actor.GetMapper().GetInput().GetPointData()
    npt.assert_equal(poly_point_data.HasArray('Tangents'), False)
    array = np.array([[0, 0, 0], [1, 1, 1], [2, 2, 2], [3, 3, 3]])
    tangents_to_actor(my_actor, array)
    npt.assert_equal(poly_point_data.HasArray('Tangents'), True)
    tangents = numpy_support.vtk_to_numpy(poly_point_data.GetArray('Tangents'))
    npt.assert_array_equal(tangents, array)
コード例 #3
0
def test_tangents_from_actor():
    my_actor = actor.square(np.array([[0, 0, 0]]))
    tangents = tangents_from_actor(my_actor)
    npt.assert_equal(tangents, None)
    array = np.array([[0, 0, 0], [1, 1, 1], [2, 2, 2], [3, 3, 3]])
    my_actor.GetMapper().GetInput().GetPointData().SetTangents(
        numpy_support.numpy_to_vtk(array, deep=True, array_type=VTK_FLOAT))
    tangents = tangents_from_actor(my_actor)
    npt.assert_array_equal(tangents, array)
コード例 #4
0
def test_normals_from_actor():
    my_actor = actor.square(np.array([[0, 0, 0]]))
    normals = normals_from_actor(my_actor)
    npt.assert_equal(normals, None)
    array = np.array([[0, 0, 0], [1, 1, 1], [2, 2, 2], [3, 3, 3]])
    my_actor.GetMapper().GetInput().GetPointData().SetNormals(
        numpy_support.numpy_to_vtk(array, deep=True))
    normals = normals_from_actor(my_actor)
    npt.assert_array_equal(normals, array)
コード例 #5
0
def test_manifest_pbr_vtk():
    # Test non-supported property
    test_actor = actor.text_3d('Test')
    npt.assert_warns(UserWarning, material.manifest_pbr, test_actor)

    # Test non-supported PBR interpolation
    test_actor = actor.scalar_bar()
    npt.assert_warns(UserWarning, material.manifest_pbr, test_actor)

    # Create tmp dir to save and query images
    # with TemporaryDirectory() as out_dir:
    # tmp_fname = os.path.join(out_dir, 'tmp_img.png')  # Tmp image to test

    scene = window.Scene()  # Setup scene

    test_actor = actor.square(np.array([[0, 0, 0]]), directions=(0, 0, 0),
                              colors=(0, 0, 1))

    scene.add(test_actor)

    # Test basic actor
    # window.record(scene, out_path=tmp_fname, size=(200, 200),
    #              reset_camera=True)
    ss = window.snapshot(scene, size=(200, 200))
    # npt.assert_equal(os.path.exists(tmp_fname), True)
    # ss = load_image(tmp_fname)
    actual = ss[100, 100, :] / 1000
    desired = np.array([0, 0, 255]) / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[40, 40, :] / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)

    # Test default parameters
    material.manifest_pbr(test_actor)

    ss = window.snapshot(scene, size=(200, 200))
    # window.record(scene, out_path=tmp_fname, size=(200, 200),
    #                 reset_camera=True)
    # npt.assert_equal(os.path.exists(tmp_fname), True)
    # ss = load_image(tmp_fname)
    actual = ss[100, 100, :] / 1000
    desired = np.array([66, 66, 165]) / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[40, 40, :] / 1000
    desired = np.array([40, 40, 157]) / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)

    # Test roughness
    material.manifest_pbr(test_actor, roughness=0)

    ss = window.snapshot(scene, size=(200, 200))
    # window.record(scene, out_path=tmp_fname, size=(200, 200),
    #                 reset_camera=True)
    # npt.assert_equal(os.path.exists(tmp_fname), True)
    # ss = load_image(tmp_fname)
    actual = ss[100, 100, :] / 1000
    desired = np.array([0, 0, 155]) / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[40, 40, :] / 1000
    desired = np.array([0, 0, 153]) / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)

    # Test metallicity
    material.manifest_pbr(test_actor, metallic=1)
    ss = window.snapshot(scene, size=(200, 200))
    # window.record(scene, out_path=tmp_fname, size=(200, 200),
    #                 reset_camera=True)
    # npt.assert_equal(os.path.exists(tmp_fname), True)
    # ss = load_image(tmp_fname)
    actual = ss[100, 100, :] / 1000
    desired = np.array([0, 0, 255]) / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[40, 40, :] / 1000
    desired = np.array([0, 0, 175]) / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)
コード例 #6
0
def test_manifest_standard():
    # Test non-supported property
    test_actor = actor.text_3d('Test')
    npt.assert_warns(UserWarning, material.manifest_standard, test_actor)

    center = np.array([[0, 0, 0]])

    # Test non-supported interpolation method
    test_actor = actor.square(center, directions=(1, 1, 1), colors=(0, 0, 1))
    npt.assert_warns(UserWarning, material.manifest_standard, test_actor,
                     interpolation='test')

    scene = window.Scene()  # Setup scene

    test_actor = actor.box(center, directions=(1, 1, 1), colors=(0, 0, 1),
                           scales=1)
    scene.add(test_actor)

    # scene.reset_camera()
    # window.show(scene)
    ss = window.snapshot(scene, size=(200, 200))
    actual = ss[75, 100, :] / 1000
    desired = np.array([0, 0, 170]) / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[125, 125, :] / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[125, 75, :] / 1000
    desired = np.array([0, 0, 85]) / 1000
    # TODO: check if camera affects this assert
    # npt.assert_array_almost_equal(actual, desired, decimal=2)

    # Test ambient level
    material.manifest_standard(test_actor, ambient_level=1)
    ss = window.snapshot(scene, size=(200, 200))
    actual = ss[75, 100, :] / 1000
    desired = np.array([0, 0, 255]) / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[125, 125, :] / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[125, 75, :] / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)

    # Test ambient color
    material.manifest_standard(test_actor, ambient_level=.5,
                               ambient_color=(1, 0, 0))
    ss = window.snapshot(scene, size=(200, 200))
    actual = ss[75, 100, :] / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[125, 125, :] / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[125, 75, :] / 1000
    desired = np.array([0, 0, 212]) / 1000
    # TODO: check what affects this
    # npt.assert_array_almost_equal(actual, desired, decimal=2)

    # Test diffuse level
    material.manifest_standard(test_actor, diffuse_level=.75)
    ss = window.snapshot(scene, size=(200, 200))
    actual = ss[75, 100, :] / 1000
    desired = np.array([0, 0, 127]) / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[125, 125, :] / 1000
    desired = np.array([0, 0, 128]) / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[125, 75, :] / 1000
    desired = np.array([0, 0, 64]) / 1000
    # TODO: check what affects this
    # npt.assert_array_almost_equal(actual, desired, decimal=2)

    # Test diffuse color
    material.manifest_standard(test_actor, diffuse_level=.5,
                               diffuse_color=(1, 0, 0))
    ss = window.snapshot(scene, size=(200, 200))
    actual = ss[75, 100, :] / 1000
    desired = np.array([0, 0, 85]) / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[125, 125, :] / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[125, 75, :] / 1000
    desired = np.array([0, 0, 42]) / 1000
    # TODO: check what affects the line below
    # npt.assert_array_almost_equal(actual, desired, decimal=2)

    # Test specular level
    material.manifest_standard(test_actor, specular_level=1)
    ss = window.snapshot(scene, size=(200, 200))
    actual = ss[75, 100, :] / 1000
    desired = np.array([170, 170, 255]) / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[125, 125, :] / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[125, 75, :] / 1000
    desired = np.array([85, 85, 170]) / 1000
    # TODO: check what affects the line below
    # npt.assert_array_almost_equal(actual, desired, decimal=2)

    # Test specular power
    material.manifest_standard(test_actor, specular_level=1,
                               specular_power=5)
    ss = window.snapshot(scene, size=(200, 200))
    actual = ss[75, 100, :] / 1000
    desired = np.array([34, 34, 204]) / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[125, 125, :] / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[125, 75, :] / 1000
    desired = np.array([1, 1, 86]) / 1000
    # TODO: check what affects the line below
    # npt.assert_array_almost_equal(actual, desired, decimal=2)

    # Test specular color
    material.manifest_standard(test_actor, specular_level=1,
                               specular_color=(1, 0, 0), specular_power=5)
    ss = window.snapshot(scene, size=(200, 200))
    actual = ss[75, 100, :] / 1000
    desired = np.array([34, 0, 170]) / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[125, 125, :] / 1000
    npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[125, 75, :] / 1000
    desired = np.array([1, 0, 85]) / 1000
    # TODO: check what affects the line below
    # npt.assert_array_almost_equal(actual, desired, decimal=2)

    scene.clear()  # Reset scene

    # Special case: Contour from roi
    data = np.zeros((50, 50, 50))
    data[20:30, 25, 25] = 1.
    data[25, 20:30, 25] = 1.
    test_actor = actor.contour_from_roi(data, color=np.array([1, 0, 1]))
    scene.add(test_actor)

    ss = window.snapshot(scene, size=(200, 200))
    actual = ss[90, 110, :] / 1000
    desired = np.array([253, 0, 253]) / 1000
    # TODO: check what affects the line below
    # npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[90, 60, :] / 1000
    desired = np.array([180, 0, 180]) / 1000
    # TODO: check what affects the line below
    # npt.assert_array_almost_equal(actual, desired, decimal=2)

    material.manifest_standard(test_actor)
    ss = window.snapshot(scene, size=(200, 200))
    actual = ss[90, 110, :] / 1000
    desired = np.array([253, 253, 253]) / 1000
    # TODO: check what affects the line below
    # npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[90, 60, :] / 1000
    desired = np.array([180, 180, 180]) / 1000
    # TODO: check what affects the line below
    # npt.assert_array_almost_equal(actual, desired, decimal=2)

    material.manifest_standard(test_actor, diffuse_color=(1, 0, 1))
    ss = window.snapshot(scene, size=(200, 200))
    actual = ss[90, 110, :] / 1000
    desired = np.array([253, 0, 253]) / 1000
    # TODO: check what affects the line below
    # npt.assert_array_almost_equal(actual, desired, decimal=2)
    actual = ss[90, 60, :] / 1000
    desired = np.array([180, 0, 180]) / 1000
コード例 #7
0
ファイル: test_material.py プロジェクト: SunTzunami/fury
def test_manifest_pbr_vtk_less_than_9():
    center = np.array([[0, 0, 0]])

    # Test non-supported material
    test_actor = actor.square(center, directions=(1, 1, 1), colors=(0, 0, 1))
    npt.assert_warns(UserWarning, material.manifest_pbr, test_actor)
コード例 #8
0
ファイル: test_material.py プロジェクト: SunTzunami/fury
def test_manifest_standard():
    # Test non-supported property
    test_actor = actor.text_3d('Test')
    npt.assert_warns(UserWarning, material.manifest_standard, test_actor)

    center = np.array([[0, 0, 0]])

    # Test non-supported interpolation method
    test_actor = actor.square(center, directions=(1, 1, 1), colors=(0, 0, 1))
    npt.assert_warns(UserWarning,
                     material.manifest_standard,
                     test_actor,
                     interpolation='test')

    # Create tmp dir to save and query images
    with TemporaryDirectory() as out_dir:
        tmp_fname = os.path.join(out_dir, 'tmp_img.png')  # Tmp image to test

        scene = window.Scene()  # Setup scene

        test_actor = actor.box(center,
                               directions=(1, 1, 1),
                               colors=(0, 0, 1),
                               scales=1)
        scene.add(test_actor)

        # Test basic actor
        window.record(scene,
                      out_path=tmp_fname,
                      size=(200, 200),
                      reset_camera=True)
        npt.assert_equal(os.path.exists(tmp_fname), True)
        ss = load_image(tmp_fname)
        actual = ss[75, 100, :] / 1000
        desired = np.array([0, 0, 170]) / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)
        actual = ss[125, 125, :] / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)
        actual = ss[125, 75, :] / 1000
        desired = np.array([0, 0, 85]) / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)

        # Test ambient level
        material.manifest_standard(test_actor, ambient_level=1)
        window.record(scene,
                      out_path=tmp_fname,
                      size=(200, 200),
                      reset_camera=True)
        npt.assert_equal(os.path.exists(tmp_fname), True)
        ss = load_image(tmp_fname)
        actual = ss[75, 100, :] / 1000
        desired = np.array([0, 0, 255]) / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)
        actual = ss[125, 125, :] / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)
        actual = ss[125, 75, :] / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)

        # Test ambient color
        material.manifest_standard(test_actor,
                                   ambient_level=.5,
                                   ambient_color=(1, 0, 0))
        window.record(scene,
                      out_path=tmp_fname,
                      size=(200, 200),
                      reset_camera=True)
        npt.assert_equal(os.path.exists(tmp_fname), True)
        ss = load_image(tmp_fname)
        actual = ss[75, 100, :] / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)
        actual = ss[125, 125, :] / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)
        actual = ss[125, 75, :] / 1000
        desired = np.array([0, 0, 212]) / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)

        # Test diffuse level
        material.manifest_standard(test_actor, diffuse_level=.75)
        window.record(scene,
                      out_path=tmp_fname,
                      size=(200, 200),
                      reset_camera=True)
        npt.assert_equal(os.path.exists(tmp_fname), True)
        ss = load_image(tmp_fname)
        actual = ss[75, 100, :] / 1000
        desired = np.array([0, 0, 127]) / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)
        actual = ss[125, 125, :] / 1000
        desired = np.array([0, 0, 128]) / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)
        actual = ss[125, 75, :] / 1000
        desired = np.array([0, 0, 64]) / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)

        # Test diffuse color
        material.manifest_standard(test_actor,
                                   diffuse_level=.5,
                                   diffuse_color=(1, 0, 0))
        window.record(scene,
                      out_path=tmp_fname,
                      size=(200, 200),
                      reset_camera=True)
        npt.assert_equal(os.path.exists(tmp_fname), True)
        ss = load_image(tmp_fname)
        actual = ss[75, 100, :] / 1000
        desired = np.array([0, 0, 85]) / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)
        actual = ss[125, 125, :] / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)
        actual = ss[125, 75, :] / 1000
        desired = np.array([0, 0, 42]) / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)

        # Test specular level
        material.manifest_standard(test_actor, specular_level=1)
        window.record(scene,
                      out_path=tmp_fname,
                      size=(200, 200),
                      reset_camera=True)
        npt.assert_equal(os.path.exists(tmp_fname), True)
        ss = load_image(tmp_fname)
        actual = ss[75, 100, :] / 1000
        desired = np.array([170, 170, 255]) / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)
        actual = ss[125, 125, :] / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)
        actual = ss[125, 75, :] / 1000
        desired = np.array([85, 85, 170]) / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)

        # Test specular power
        material.manifest_standard(test_actor,
                                   specular_level=1,
                                   specular_power=5)
        window.record(scene,
                      out_path=tmp_fname,
                      size=(200, 200),
                      reset_camera=True)
        npt.assert_equal(os.path.exists(tmp_fname), True)
        ss = load_image(tmp_fname)
        actual = ss[75, 100, :] / 1000
        desired = np.array([34, 34, 204]) / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)
        actual = ss[125, 125, :] / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)
        actual = ss[125, 75, :] / 1000
        desired = np.array([1, 1, 86]) / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)

        # Test specular color
        material.manifest_standard(test_actor,
                                   specular_level=1,
                                   specular_color=(1, 0, 0),
                                   specular_power=5)
        window.record(scene,
                      out_path=tmp_fname,
                      size=(200, 200),
                      reset_camera=True)
        npt.assert_equal(os.path.exists(tmp_fname), True)
        ss = load_image(tmp_fname)
        actual = ss[75, 100, :] / 1000
        desired = np.array([34, 0, 170]) / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)
        actual = ss[125, 125, :] / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)
        actual = ss[125, 75, :] / 1000
        desired = np.array([1, 0, 85]) / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)

        scene.clear()  # Reset scene

        # Special case: Contour from roi
        data = np.zeros((50, 50, 50))
        data[20:30, 25, 25] = 1.
        data[25, 20:30, 25] = 1.
        test_actor = actor.contour_from_roi(data, color=np.array([1, 0, 1]))
        scene.add(test_actor)

        window.record(scene,
                      out_path=tmp_fname,
                      size=(200, 200),
                      reset_camera=True)
        npt.assert_equal(os.path.exists(tmp_fname), True)
        ss = load_image(tmp_fname)
        actual = ss[90, 110, :] / 1000
        desired = np.array([253, 0, 253]) / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)
        actual = ss[90, 60, :] / 1000
        desired = np.array([180, 0, 180]) / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)

        material.manifest_standard(test_actor)
        window.record(scene,
                      out_path=tmp_fname,
                      size=(200, 200),
                      reset_camera=True)
        npt.assert_equal(os.path.exists(tmp_fname), True)
        ss = load_image(tmp_fname)
        actual = ss[90, 110, :] / 1000
        desired = np.array([253, 253, 253]) / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)
        actual = ss[90, 60, :] / 1000
        desired = np.array([180, 180, 180]) / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)

        material.manifest_standard(test_actor, diffuse_color=(1, 0, 1))
        window.record(scene,
                      out_path=tmp_fname,
                      size=(200, 200),
                      reset_camera=True)
        npt.assert_equal(os.path.exists(tmp_fname), True)
        ss = load_image(tmp_fname)
        actual = ss[90, 110, :] / 1000
        desired = np.array([253, 0, 253]) / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)
        actual = ss[90, 60, :] / 1000
        desired = np.array([180, 0, 180]) / 1000
        npt.assert_array_almost_equal(actual, desired, decimal=2)