예제 #1
0
def test_texture():
    """Test adding texture coordinates"""
    # create a rectangle vertices
    vertices = np.array([
        [0, 0, 0],
        [1, 0, 0],
        [1, 0.5, 0],
        [0, 0.5, 0],
    ])

    # mesh faces
    faces = np.hstack([[3, 0, 1, 2], [3, 0, 3, 2]]).astype(np.int8)

    # Create simple texture coordinates
    t_coords = np.array([[0, 0], [1, 0], [1, 1], [0, 1]])
    # Create the poly data
    mesh = pyvista.PolyData(vertices, faces)
    # Attempt setting the texture coordinates
    mesh.t_coords = t_coords
    # now grab the texture coordinates
    foo = mesh.t_coords
    assert np.allclose(foo, t_coords)
    texture = Texture(examples.mapfile)
    mesh.textures['map'] = texture
    assert mesh.textures['map'] is not None
    mesh.clear_textures()
    assert len(mesh.textures) == 0
예제 #2
0
def test_texture_airplane():
    mesh = examples.load_airplane()
    mesh.texture_map_to_plane(inplace=True, name="tex_a", use_bounds=False)
    mesh.texture_map_to_plane(inplace=True, name="tex_b", use_bounds=True)
    assert not np.allclose(mesh["tex_a"], mesh["tex_b"])
    texture = Texture(examples.mapfile)
    mesh.textures["tex_a"] = texture.copy()
    mesh.textures["tex_b"] = texture.copy()
    mesh._activate_texture("tex_a")
    assert np.allclose(mesh.t_coords, mesh["tex_a"])
    mesh._activate_texture("tex_b")
    assert np.allclose(mesh.t_coords, mesh["tex_b"])

    # Now test copying
    cmesh = mesh.copy()
    assert len(cmesh.textures) == 2
    assert "tex_a" in cmesh.textures
    assert "tex_b" in cmesh.textures
예제 #3
0
파일: raster.py 프로젝트: bjlittle/geovista
def wrap_texture(texture: pv.Texture,
                 central_meridian: Optional[float] = None) -> pv.Texture:
    """
    Re-center the texture about the specified central meridian, wrapping
    the image appropriately.

    Assumes that the source of the texture has global coverage, is on the Geographic
    projection and uses the WGS84 datum, with square pixels and no rotation.

    Parameters
    ----------
    texture : Texture
        The global texture to be re-centered.
    central_meridian : float, default=0.0
        The meridian (degrees) that specifies the new center of the texture image.

    Returns
    -------
    Texture
        The re-centered PyVista texture.

    Notes
    -----
    .. versionadded:: 0.1.0

    """
    if central_meridian is None:
        central_meridian = 0.0

    meridian = wrap(central_meridian)[0]

    if not np.isclose(meridian, 0):
        # get the texture as a pyvista.UniformGrid
        grid = texture.to_image()
        shape = (grid.dimensions[1], grid.dimensions[0], texture.n_components)
        # convert grid to an rgb image (un-do pyvista.Texture._from_array mangling)
        image = np.flip(grid.active_scalars.reshape(shape), axis=0)

        width, height = image.shape[1], image.shape[0]
        logger.debug("texture image width=%dpx, height=%dpx)", width, height)

        # calculate the rendering window over the tiled image centered around the meridian
        offset = int(np.round(
            ((meridian + 180) / 360) * width, decimals=0)) + width
        start = offset - (width // 2)
        end = start + width
        logger.debug("start=%dpx, meridian=%dpx, end=%dpx", start, offset, end)
        # horizontally tile the image (along the x-axis)
        tiled = np.concatenate([image, image, image], axis=1)
        # now extract the image based on the central meridian
        image = tiled[:, start:end]
        texture = pv.Texture(image)

    return texture