Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃幀 Add Create a GIF Movie with updating textures #1544

Merged
merged 2 commits into from
Jul 28, 2021

Conversation

tkoyama010
Copy link
Member

Overview

Add Create a GIF Movie with updating textures. Point is using plotter.clear() .

resolves #1528

Details

# Create a plotter object
plotter = pv.Plotter(notebook=False, off_screen=True)

# Open a gif
plotter.open_gif("texture.gif")

pts = curvsurf.points.copy()

# Update Z and write a frame for each updated position
nframe = 15
for phase in np.linspace(0, 2 * np.pi, nframe + 1)[:nframe]:

    # create an image using numpy,
    z = np.sin(r + phase)
    pts[:, -1] = z.ravel()

    # Creating a custom RGB image
    zz = A * np.exp(-0.5 * ((xx / b) ** 2.0 + (yy / b) ** 2.0))
    hue = norm(zz.ravel()) * 0.5 * (1.0 + np.sin(phase))
    colors = (cmap(hue)[:, 0:3] * 255.0).astype(np.uint8)
    image = colors.reshape((xx.shape[0], xx.shape[1], 3), order="F")

    # Convert 3D numpy array to texture
    tex = pv.numpy_to_texture(image)

    plotter.add_mesh(curvsurf, smooth_shading=True, texture=tex)
    plotter.update_coordinates(pts, render=False)

    # must update normals when smooth shading is enabled
    plotter.mesh.compute_normals(cell_normals=False, inplace=True)
    plotter.render()
    plotter.write_frame()
    plotter.clear()

# Closes and finalizes movie
plotter.close()

texture

@tkoyama010 tkoyama010 added the example There's a great example/demo in this thread! label Jul 27, 2021
@codecov
Copy link

codecov bot commented Jul 27, 2021

Codecov Report

Merging #1544 (e92d1e9) into main (c49bd31) will increase coverage by 0.41%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #1544      +/-   ##
==========================================
+ Coverage   90.13%   90.55%   +0.41%     
==========================================
  Files          68       68              
  Lines       12879    13502     +623     
==========================================
+ Hits        11609    12227     +618     
- Misses       1270     1275       +5     

@tkoyama010 tkoyama010 marked this pull request as ready for review July 27, 2021 12:55
Copy link
Member

@akaszynski akaszynski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One nitpick, but otherwise it's good to go.

Co-authored-by: Alex Kaszynski <akascap@gmail.com>
@tkoyama010 tkoyama010 merged commit 0a4175e into main Jul 28, 2021
@tkoyama010 tkoyama010 deleted the doc/examples-texture branch July 28, 2021 09:15
@tkoyama010 tkoyama010 added documentation Anything related to the documentation/website and removed example There's a great example/demo in this thread! labels Oct 8, 2021
@akaszynski akaszynski mentioned this pull request Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Anything related to the documentation/website
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants