
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "tutorial/09_trame/b_trame_vtk.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_tutorial_09_trame_b_trame_vtk.py>`
        to download the full example code. or to run this example in your browser via Binder

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_tutorial_09_trame_b_trame_vtk.py:


Using VTK/PyVista and Trame
~~~~~~~~~~~~~~~~~~~~~~~~~~~

In this application, we will connect a VTK filter with PyVista.

It will use Trame to visualize the results and interactively control
parameters of the VTK filter.

.. GENERATED FROM PYTHON SOURCE LINES 11-70

.. code-block:: Python


    import pyvista as pv
    from pyvista import examples
    from trame.app import get_server
    from trame.ui.vuetify3 import VAppLayout
    from trame.widgets import vtk as vtk_widgets
    from trame.widgets import vuetify3 as v3
    from vtkmodules.vtkFiltersGeneral import vtkWarpScalar

    mesh = examples.load_random_hills()
    warp_by_scalar = vtkWarpScalar()
    warp_by_scalar.SetInputData(mesh)
    warp_by_scalar.SetScaleFactor(0.3)

    plotter = pv.Plotter()
    actor = plotter.add_mesh(warp_by_scalar)
    plotter.reset_camera()

    # Trame server setup
    server = get_server("trame_vtk_example")
    state, ctrl = server.state, server.controller


    @state.change("scale")
    def update_scale(scale, **kwargs) -> None:
        warp_by_scalar.SetScaleFactor(scale)
        ctrl.view_update()


    with VAppLayout(server, full_height=True) as layout:  # noqa: SIM117
        with v3.VContainer(fluid=True, classes="fill-height"):
            with vtk_widgets.VtkRemoteView(plotter.render_window, interactive_ratio=1) as view:
                ctrl.view_update = view.update
                ctrl.view_reset_camera = view.reset_camera

            # Event binding
            v3.VBtn(
                icon="mdi-crop-free",
                click=ctrl.view_reset_camera,
                classes="position-absolute",
                style="left: 1rem; top: 1rem; z-index: 1",
                density="compact",
            )

            # State binding
            v3.VSlider(
                v_model=("scale", 0.3),
                min=0,
                max=0.5,
                step=0.01,
                density="compact",
                classes="position-absolute",
                style="right: 1rem; top: 1rem; width: 400px; z-index: 1",
            )

    # Make sure the app is running and ready
    await layout.ready
    # Show UI in result
    layout


.. _sphx_glr_download_tutorial_09_trame_b_trame_vtk.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: binder-badge

      .. image:: images/binder_badge_logo.svg
        :target: https://mybinder.org/v2/gh/pyvista/pyvista-tutorial/gh-pages?urlpath=lab/tree/notebooks/tutorial/09_trame/b_trame_vtk.ipynb
        :alt: Launch binder
        :width: 150 px

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: b_trame_vtk.ipynb <b_trame_vtk.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: b_trame_vtk.py <b_trame_vtk.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: b_trame_vtk.zip <b_trame_vtk.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
