.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_introductory/viz_imgui.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_01_introductory_viz_imgui.py: =========================== ImGui Integration Example =========================== This example demonstrates how to integrate an ImGui user interface into a FURY scene using the :class:`fury.window.ShowManager` and ``imgui_draw_function`` callback. A small ImGui window is created with a checkbox that controls the visibility of a group of colored spheres rendered by FURY. .. GENERATED FROM PYTHON SOURCE LINES 14-22 .. code-block:: Python import numpy as np from imgui_bundle import imgui from fury.actor import sphere from fury.window import Scene, ShowManager .. GENERATED FROM PYTHON SOURCE LINES 23-28 First, we define an ImGui draw function. This function will be called every frame by the :class:`ShowManager`. Inside it, we build a simple ImGui window with a checkbox that can toggle the visibility of our actor. .. GENERATED FROM PYTHON SOURCE LINES 28-46 .. code-block:: Python def create_imgui_controls(): # Set the initial position and size of the ImGui window. The # ``first_use_ever`` condition ensures this is only applied the # first time the window appears. imgui.set_next_window_pos((10, 10), imgui.Cond_.first_use_ever) imgui.set_next_window_size((220, 120), imgui.Cond_.first_use_ever) expanded, _ = imgui.begin("Controls") if expanded: # The checkbox returns (changed, value); we only need the value. _, visible = imgui.checkbox("Show spheres", sphere_actor.visible) sphere_actor.visible = visible imgui.end() .. GENERATED FROM PYTHON SOURCE LINES 47-52 Now we create some simple data and build the FURY actor. We will render three spheres at different positions, each with a different color (red, green, blue). These are combined into a single FURY actor that we add to the scene. .. GENERATED FROM PYTHON SOURCE LINES 52-82 .. code-block:: Python points = np.asarray( [ (15.0, 0.0, 0.0), (0.0, 15.0, 0.0), (0.0, 0.0, 15.0), ], dtype=float, ) radii = 15.0 colors = np.asarray( [ (1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0), ], dtype=float, ) sphere_actor = sphere( points, radii=radii, colors=colors, phi=48, theta=48, ) .. GENERATED FROM PYTHON SOURCE LINES 83-84 Next, we create the :class:`Scene` and add our actor to it. .. GENERATED FROM PYTHON SOURCE LINES 84-89 .. code-block:: Python scene = Scene() scene.add(sphere_actor) .. GENERATED FROM PYTHON SOURCE LINES 90-95 Finally, we create a :class:`ShowManager` and enable ImGui support. Passing ``imgui=True`` turns on ImGui integration, and the ``imgui_draw_function`` argument specifies which function will be used to define the ImGui user interface each frame. .. GENERATED FROM PYTHON SOURCE LINES 95-105 .. code-block:: Python show_m = ShowManager( title="FURY ImGui Integration Example", scene=scene, size=(800, 600), window_type="default", imgui=True, imgui_draw_function=create_imgui_controls, ) show_m.start() .. _sphx_glr_download_auto_examples_01_introductory_viz_imgui.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: viz_imgui.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: viz_imgui.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: viz_imgui.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_