Note

This page was generated from animation_3d_model.ipynb. Interactive online version: Colab badge. Some tutorial content may look better in light mode.

Animation of 3D models generated by spateo#

Import packages#

[2]:
import io
import base64
from IPython.display import HTML

import spateo as st
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
/Users/jingzehua/Documents/GitHub/spateo-release/docs/tutorials/notebooks/5_3d_reconstruction/animation_3d_model.ipynb Cell 3 in <cell line: 5>()
      <a href='vscode-notebook-cell:/Users/jingzehua/Documents/GitHub/spateo-release/docs/tutorials/notebooks/5_3d_reconstruction/animation_3d_model.ipynb#W2sZmlsZQ%3D%3D?line=1'>2</a> import base64
      <a href='vscode-notebook-cell:/Users/jingzehua/Documents/GitHub/spateo-release/docs/tutorials/notebooks/5_3d_reconstruction/animation_3d_model.ipynb#W2sZmlsZQ%3D%3D?line=2'>3</a> from IPython.display import HTML
----> <a href='vscode-notebook-cell:/Users/jingzehua/Documents/GitHub/spateo-release/docs/tutorials/notebooks/5_3d_reconstruction/animation_3d_model.ipynb#W2sZmlsZQ%3D%3D?line=4'>5</a> import spateo as st

ModuleNotFoundError: No module named 'spateo'

Load data#

[3]:
# embryo mesh,reconstructed by ``2.three dims models reconstruction``
embryo_mesh = st.tdr.read_model(f"E7-9h_embryo_aligned_mesh_model.vtk")
st.tdr.scale_model(model=embryo_mesh, scale_factor=1.05, inplace=True)

# tissue mesh, reconstructed by ``3.three dims models reconstruction of subpopulations``
tissues_name = ["amnioserosa", "CNS", "midgut", "salivary gland", "muscle", "epidermis"]
tissues_mesh = [st.tdr.read_model(f"E7-9h_aligned_mesh_model_{tissue_name}.vtk") for tissue_name in tissues_name]

# cpo
cpo = [(531.4285063139628, 1120.6071331378873, 226.6879332984771),
     (1.9670869138005287, -6.902875264241757, -2.2120172004343885),
     (-0.1349909265808914, -0.13586573883518835, 0.9814876212931068)]

Visualize tissue 3D models#

[5]:
st.pl.three_d_multi_plot(
    model=st.tdr.collect_models([st.tdr.collect_models([embryo_mesh, tm]) for tm in tissues_mesh]),
    key="tissue",
    model_style="surface",
    cpo=[cpo],
    shape=(2, 3),
    jupyter="static",
)
../../../_images/tutorials_notebooks_5_3d_reconstruction_animation_3d_model_6_0.png
[6]:
integrated_meshes = tissues_mesh.copy()
integrated_meshes.append(embryo_mesh)
st.pl.three_d_plot(
    model=st.tdr.collect_models(integrated_meshes),
    key="tissue",
    model_style="surface",
    cpo=cpo,
    jupyter="static",
)
../../../_images/tutorials_notebooks_5_3d_reconstruction_animation_3d_model_7_0.png

Animate tissue 3D models#

[7]:
st.pl.three_d_plot(
    model=st.tdr.collect_models(integrated_meshes),
    key="tissue",
    filename=f"E7-9h_completed_model_animation1.mp4",
    model_style="surface",
    show_legend=True,
    off_screen=False,
    jupyter="static",
    background="white",
    window_size=(1024, 1024),
    cpo=cpo,
    text=f"\nAxis of rotation: D-V",
    view_up=(0, 0, 1),
    framerate=6)

st.pl.three_d_plot(
    model=st.tdr.collect_models(integrated_meshes),
    key="tissue",
    filename=f"E7-9h_completed_model_animation2.mp4",
    model_style="surface",
    show_legend=True,
    off_screen=False,
    jupyter="static",
    background="white",
    window_size=(1024, 1024),
    cpo=cpo,
    text=f"\nAxis of rotation: A-P",
    view_up=(1, 0, 0),
    framerate=6)

st.pl.merge_animations(
    mp4_files=[
        f"E7-9h_completed_model_animation1.mp4",
        f"E7-9h_completed_model_animation2.mp4"
    ],
    filename=f"E7-9h_merged_completed_model_animation.mp4"
)
Moviepy - Building video visualize_sample/E7-9h_merged_completed_model_animation.mp4.
Moviepy - Writing video visualize_sample/E7-9h_merged_completed_model_animation.mp4


Moviepy - Done !
Moviepy - video ready visualize_sample/E7-9h_merged_completed_model_animation.mp4
[6]:
vedio_path = "./video/E7-9h_merged_completed_model_animation.mp4"
video = io.open(vedio_path, 'r+b').read()
encoded = base64.b64encode(video)
HTML(
    data=
    '''
    <video width="500" height="500"  controls>
    <source src="data:video/mp4;base64,{0}" type="video/mp4" />
    </video>
    '''.format(encoded.decode('ascii'))
)
[6]:
[ ]: