.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/07_ui/viz_ui_slider.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_auto_examples_07_ui_viz_ui_slider.py: ===================== Cube & Slider Control ===================== This example shows how to use the UI API. We will demonstrate how to create a cube and control with sliders. First, some imports. .. GENERATED FROM PYTHON SOURCE LINES 12-17 .. code-block:: Python import numpy as np from fury import actor, ui, window from fury.data import fetch_viz_icons .. GENERATED FROM PYTHON SOURCE LINES 18-19 First we need to fetch some icons that are included in FURY. .. GENERATED FROM PYTHON SOURCE LINES 19-22 .. code-block:: Python fetch_viz_icons() .. rst-class:: sphx-glr-script-out .. code-block:: none Data size is approximately 12KB Dataset is already in place. If you want to fetch it again please first remove the folder /Users/skoudoro/.fury/icons ({'icomoon.tar.gz': ('https://digital.lib.washington.edu/researchworks/bitstream/handle/1773/38478/icomoon.tar.gz', 'BC1FEEA6F58BA3601D6A0B029EB8DFC5F352E21F2A16BA41099A96AA3F5A4735')}, '/Users/skoudoro/.fury/icons') .. GENERATED FROM PYTHON SOURCE LINES 23-27 Cube and sliders ================ Add a cube to the scene . .. GENERATED FROM PYTHON SOURCE LINES 27-35 .. code-block:: Python cube = actor.cube( centers=np.array([[15, 0, 0]]), colors=np.array([[0, 0, 1]]), scales=np.array([[20, 20, 20]]), directions=np.array([[0, 0, 1]]), ) .. GENERATED FROM PYTHON SOURCE LINES 36-38 Now we'll add five sliders: 1 circular and 4 linear sliders. By default the alignments are 'bottom' for horizontal and 'top' for vertical. .. GENERATED FROM PYTHON SOURCE LINES 38-80 .. code-block:: Python ring_slider = ui.RingSlider2D( center=(630, 400), initial_value=0, text_template='{angle:5.1f}°' ) hor_line_slider_text_top = ui.LineSlider2D( center=(400, 230), initial_value=0, orientation='horizontal', min_value=-10, max_value=10, text_alignment='top', ) hor_line_slider_text_bottom = ui.LineSlider2D( center=(400, 200), initial_value=0, orientation='horizontal', min_value=-10, max_value=10, text_alignment='bottom', ) ver_line_slider_text_left = ui.LineSlider2D( center=(100, 400), initial_value=0, orientation='vertical', min_value=-10, max_value=10, text_alignment='left', ) ver_line_slider_text_right = ui.LineSlider2D( center=(150, 400), initial_value=0, orientation='vertical', min_value=-10, max_value=10, text_alignment='right', ) .. GENERATED FROM PYTHON SOURCE LINES 81-82 We can use a callback to rotate the cube with the ring slider. .. GENERATED FROM PYTHON SOURCE LINES 82-93 .. code-block:: Python def rotate_cube(slider): angle = slider.value previous_angle = slider.previous_value rotation_angle = angle - previous_angle cube.RotateX(rotation_angle) ring_slider.on_change = rotate_cube .. GENERATED FROM PYTHON SOURCE LINES 94-95 Similarly, we can translate the cube with the line slider. .. GENERATED FROM PYTHON SOURCE LINES 95-112 .. code-block:: Python def translate_cube_ver(slider): value = slider.value cube.SetPosition(0, value, 0) def translate_cube_hor(slider): value = slider.value cube.SetPosition(value, 0, 0) hor_line_slider_text_top.on_change = translate_cube_hor hor_line_slider_text_bottom.on_change = translate_cube_hor ver_line_slider_text_left.on_change = translate_cube_ver ver_line_slider_text_right.on_change = translate_cube_ver .. GENERATED FROM PYTHON SOURCE LINES 113-118 Show Manager ================================== Now that all the elements have been initialised, we add them to the show manager. .. GENERATED FROM PYTHON SOURCE LINES 118-130 .. code-block:: Python current_size = (800, 800) show_manager = window.ShowManager(size=current_size, title='FURY Cube Example') show_manager.scene.add(cube) show_manager.scene.add(ring_slider) show_manager.scene.add(hor_line_slider_text_top) show_manager.scene.add(hor_line_slider_text_bottom) show_manager.scene.add(ver_line_slider_text_left) show_manager.scene.add(ver_line_slider_text_right) .. GENERATED FROM PYTHON SOURCE LINES 131-132 Visibility by default is True .. GENERATED FROM PYTHON SOURCE LINES 132-140 .. code-block:: Python cube.SetVisibility(True) ring_slider.set_visibility(True) hor_line_slider_text_top.set_visibility(True) hor_line_slider_text_bottom.set_visibility(True) ver_line_slider_text_left.set_visibility(True) ver_line_slider_text_right.set_visibility(True) .. GENERATED FROM PYTHON SOURCE LINES 141-142 Set camera for better visualization .. GENERATED FROM PYTHON SOURCE LINES 142-153 .. code-block:: Python show_manager.scene.reset_camera() show_manager.scene.set_camera(position=(0, 0, 150)) show_manager.scene.reset_clipping_range() show_manager.scene.azimuth(30) interactive = False if interactive: show_manager.start() window.record(show_manager.scene, size=current_size, out_path='viz_slider.png') .. image-sg:: /auto_examples/07_ui/images/sphx_glr_viz_ui_slider_001.png :alt: viz ui slider :srcset: /auto_examples/07_ui/images/sphx_glr_viz_ui_slider_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.079 seconds) .. _sphx_glr_download_auto_examples_07_ui_viz_ui_slider.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: viz_ui_slider.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: viz_ui_slider.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_