예제 #1
0
def test_colormap_interpolation():
    """Test interpolation routines for colormaps."""
    import vispy.color.colormap as c
    assert_raises(AssertionError, c._glsl_step, [0., 1.],)

    for fun in (c._glsl_step, c._glsl_mix):
        assert_raises(AssertionError, fun, controls=[0.1, 1.],)
        assert_raises(AssertionError, fun, controls=[0., .9],)
        assert_raises(AssertionError, fun, controls=[0.1, .9],)

    # Interpolation tests.
    color_0 = np.array([1., 0., 0.])
    color_1 = np.array([0., 1., 0.])
    color_2 = np.array([0., 0., 1.])

    colors_00 = np.vstack((color_0, color_0))
    colors_01 = np.vstack((color_0, color_1))
    colors_11 = np.vstack((color_1, color_1))
    # colors_012 = np.vstack((color_0, color_1, color_2))
    colors_021 = np.vstack((color_0, color_2, color_1))

    controls_2 = np.array([0., 1.])
    controls_3 = np.array([0., .25, 1.])
    x = np.array([-1., 0., 0.1, 0.4, 0.5, 0.6, 1., 2.])[:, None]

    mixed_2 = c.mix(colors_01, x, controls_2)
    mixed_3 = c.mix(colors_021, x, controls_3)

    for y in mixed_2, mixed_3:
        assert_allclose(y[:2, :], colors_00)
        assert_allclose(y[-2:, :], colors_11)

    assert_allclose(mixed_2[:, -1], np.zeros(len(y)))
예제 #2
0
파일: test_color.py 프로젝트: zfule/vispy
def test_colormap_interpolation():
    """Test interpolation routines for colormaps."""
    import vispy.color.colormap as c
    assert_raises(AssertionError, c._glsl_step, [0., 1.],)

    for fun in (c._glsl_step, c._glsl_mix):
        assert_raises(AssertionError, fun, controls=[0.1, 1.],)
        assert_raises(AssertionError, fun, controls=[0., .9],)
        assert_raises(AssertionError, fun, controls=[0.1, .9],)

    # Interpolation tests.
    color_0 = np.array([1., 0., 0.])
    color_1 = np.array([0., 1., 0.])
    color_2 = np.array([0., 0., 1.])

    colors_00 = np.vstack((color_0, color_0))
    colors_01 = np.vstack((color_0, color_1))
    colors_11 = np.vstack((color_1, color_1))
    # colors_012 = np.vstack((color_0, color_1, color_2))
    colors_021 = np.vstack((color_0, color_2, color_1))

    controls_2 = np.array([0., 1.])
    controls_3 = np.array([0., .25, 1.])
    x = np.array([-1., 0., 0.1, 0.4, 0.5, 0.6, 1., 2.])[:, None]

    mixed_2 = c.mix(colors_01, x, controls_2)
    mixed_3 = c.mix(colors_021, x, controls_3)

    for y in mixed_2, mixed_3:
        assert_allclose(y[:2, :], colors_00)
        assert_allclose(y[-2:, :], colors_11)

    assert_allclose(mixed_2[:, -1], np.zeros(len(y)))