.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples/00-basic/01-renderables.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__examples_00-basic_01-renderables.py: .. _ref_renderables: Renderables =========== EnSight is a simulation results postprocessing engine with an advanced rendering and display component. PyEnSight provides direct, Jupyter Notebook/Juptyer lab-aware access to the rendering component through renderables. This example explores the variety of renderables that available. .. GENERATED FROM PYTHON SOURCE LINES 15-19 Start an EnSight session ------------------------ Launch and connect to an instance of EnSight. This example uses a local EnSight installation. .. GENERATED FROM PYTHON SOURCE LINES 19-24 .. code-block:: Python from ansys.pyensight.core import LocalLauncher session = LocalLauncher().start() .. GENERATED FROM PYTHON SOURCE LINES 25-31 Load a time-varying dataset --------------------------- Load some data included in the EnSight installation, apply a displacement variable to the parts, and color them by a measure of plastic deformation. .. GENERATED FROM PYTHON SOURCE LINES 31-44 .. code-block:: Python session.load_data(f"{session.cei_home}/ensight{session.cei_suffix}/data/guard_rail/crash.case") # Apply displacements displacement = session.ensight.objs.core.VARIABLES["displacement"][0] session.ensight.objs.core.PARTS.set_attr("DISPLACEBY", displacement) # Color by the variable "plastic" plastic = session.ensight.objs.core.VARIABLES["plastic"][0] session.ensight.objs.core.PARTS.set_attr("COLORBYPALETTE", plastic) # Adjust the palette range plastic.LEGEND[0].RANGE = [0.0, 0.007] session.ensight.view_transf.rotate(-36.0, 23.0, 0.0) session.ensight.view_transf.fit(0) .. GENERATED FROM PYTHON SOURCE LINES 45-52 Show an image renderable ------------------------ Show an image renderable. This renders the image at 800x600 pixels using four antialiasing passes. If this code is being run in a Jupyter IDE, the cell displays the PNG image. .. image:: /_static/01_renderable_0.png .. GENERATED FROM PYTHON SOURCE LINES 52-56 .. code-block:: Python image = session.show("image", width=800, height=600, aa=4) .. GENERATED FROM PYTHON SOURCE LINES 57-65 Update renderable ^^^^^^^^^^^^^^^^^ The ``Renderables`` class include several useful methods. The first is the :func:`update` method, which regenerates the renderable. This code adjusts the scene rotation and updates the display of the image in the scene. .. GENERATED FROM PYTHON SOURCE LINES 65-69 .. code-block:: Python session.ensight.view_transf.rotate(10.0, 0.0, 0.0) image.update() .. GENERATED FROM PYTHON SOURCE LINES 70-77 Display renderable in a browser ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ All renderables display their results on web pages. The URL to the web page is stored in the renderable URL property. You call the :func:`browser` method to display the result of the renderable on a new browser tab. .. GENERATED FROM PYTHON SOURCE LINES 77-81 .. code-block:: Python print(image.url) image.browser() .. GENERATED FROM PYTHON SOURCE LINES 82-93 Download renderable ^^^^^^^^^^^^^^^^^^^ The physical files that make up the display of the renderable reside in the container/system running the EnSight instance. You can download these files to the local system using the :func:`download` method. .. note:: For an image renderable, this is a PNG file. But, depending on the type of the renderable, the file format could be some other type, such as TIFF, AVZ, or EVSN. .. GENERATED FROM PYTHON SOURCE LINES 93-97 .. code-block:: Python local_directory_pathname = "." image.download(local_directory_pathname) .. GENERATED FROM PYTHON SOURCE LINES 98-105 Show a deep pixel image renderable ---------------------------------- A deep pixel image is a TIFF file that has the part names and currently displayed variable values included at each pixel. For full effect, you must view a deep pixel image renderable on a web page. .. image:: /_static/01_renderable_1.png .. GENERATED FROM PYTHON SOURCE LINES 105-109 .. code-block:: Python deep_image = session.show("deep_pixel", width=800, height=600, aa=4) .. GENERATED FROM PYTHON SOURCE LINES 110-118 Show an animation renderable ---------------------------- An animation renderable is generated by rendering all the timesteps of the currently loaded dataset into an MPEG4 container. You can set the size of the animation and the playback rate in frames per second in the call to the :func:`show` method. .. image:: /_static/01_renderable_2.png .. GENERATED FROM PYTHON SOURCE LINES 118-122 .. code-block:: Python animation = session.show("animation", width=800, height=600, aa=2, fps=2.0) .. GENERATED FROM PYTHON SOURCE LINES 123-139 Show a WebGL 3D scene renderable -------------------------------- Create a 3D scene renderable and render it interactively in the web browser. The scene is generated in AVZ format, which is what the :func:`download` method would pull. By default, only the current timestep is captured, but if you set the ``temporal`` parameter, it can be over all timesteps. datasets. .. image:: /_static/01_renderable_3.png .. note:: Because the geometry is generated in the EnSight session and downloaded to the browser for display, be careful when using this method with larger datasets. .. GENERATED FROM PYTHON SOURCE LINES 139-143 .. code-block:: Python webgl = session.show("webgl") .. GENERATED FROM PYTHON SOURCE LINES 144-159 Interact directly with EnSight ------------------------------ Use remote rendering with dynamic pixel transport to interact directly with the EnSight session. The keyboard and mouse interactions are sent directly to EnSight in this mode. .. image:: /_static/01_renderable_4.png .. note:: This renderable relies on a persistent, low-latency web socket connection to the EnSight session. It is most useful when the EnSight session container has access to hardware-accelerated rendering and when datasets/geometry get larger. Multiple connections can be made to the same renderable (via HTTP). Those renderables are "shared" between all the viewers. .. GENERATED FROM PYTHON SOURCE LINES 159-163 .. code-block:: Python remote = session.show("remote") .. GENERATED FROM PYTHON SOURCE LINES 164-174 Interact directly with a remote scene ------------------------------------- A remote scene is a renderable that is basically a wrapper around an EnSight scenario file. The current scene is exported and includes all active parts/variables. The viewer is the EnVision app accessed through the same remote rendering system as the "remote" renderable. It shares many of the same benefits as the remote renderable, without the overhead of an EnSight server process. If downloaded, the saved file is an EnVision EVSN file. .. image:: /_static/01_renderable_5.png .. GENERATED FROM PYTHON SOURCE LINES 174-178 .. code-block:: Python remote_scene = session.show("remote_scene", width=800, height=600, temporal=True) .. GENERATED FROM PYTHON SOURCE LINES 179-186 Export raw content ------------------ The :func:`render` and :func:`geometry` methods are capable of returning the raw file data directly, without the use of a web browser. This example exports the raw file data for a PNG file and a GLB file. .. GENERATED FROM PYTHON SOURCE LINES 186-194 .. code-block:: Python pngdata = session.render(1920, 1080, aa=4) with open("simple_example.png", "wb") as fp: fp.write(pngdata) glbdata = session.geometry() with open("simple_example.glb", "wb") as fp: fp.write(glbdata) .. GENERATED FROM PYTHON SOURCE LINES 195-198 Close the session ----------------- Close the connection and shut down the EnSight instance. .. GENERATED FROM PYTHON SOURCE LINES 198-201 .. code-block:: Python # sphinx_gallery_thumbnail_path = '_static/01_renderable_1.png' session.close() .. _sphx_glr_download__examples_00-basic_01-renderables.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01-renderables.ipynb <01-renderables.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01-renderables.py <01-renderables.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 01-renderables.zip <01-renderables.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_