.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples\04_demos\viz_ellipsoid_slicer.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_04_demos_viz_ellipsoid_slicer.py: ======================= Ellipsoid Field Slicing ======================= Visualize one Z slice of an ellipsoid field. Press Up/Down to move the slice. Across Z, the longest axes rotate from X (red) to Z (blue). .. GENERATED FROM PYTHON SOURCE LINES 9-14 .. code-block:: Python import numpy as np from fury import actor, window .. GENERATED FROM PYTHON SOURCE LINES 15-16 Define an 8x8x8 field whose first semi-axis grows along Z. .. GENERATED FROM PYTHON SOURCE LINES 16-28 .. code-block:: Python lengths = np.empty((8, 8, 8, 3), dtype=np.float32) lengths[..., 0] = np.linspace(0.15, 0.4, 8) lengths[..., 1:] = 0.15 # Each matrix's columns define the glyph axes. Rotate the longest axis from X to Z. rotations = np.empty((8, 3, 3), dtype=np.float32) for z, angle in enumerate(np.linspace(0, np.pi / 2, 8)): cosine, sine = np.cos(angle), np.sin(angle) rotations[z] = [[cosine, 0, -sine], [0, 1, 0], [sine, 0, cosine]] orientations = np.broadcast_to(rotations, (*lengths.shape[:3], 3, 3)) .. GENERATED FROM PYTHON SOURCE LINES 29-31 Show the central Z plane. Scale only the glyphs; default colors follow their longest axes, not the slice position or later world transforms. .. GENERATED FROM PYTHON SOURCE LINES 31-44 .. code-block:: Python slicer = actor.ellipsoid_slicer( lengths, orientation_matrices=orientations, scale=0.8, visibility=(False, False, True), ) scene = window.Scene() scene.add(slicer) show_manager = window.ShowManager( scene=scene, size=(800, 600), title="Ellipsoid Slicer (Up, Down - Z slice)" ) .. GENERATED FROM PYTHON SOURCE LINES 45-47 Use the same slice controls as the vector-field tutorial. Positions are clamped to the field bounds; other keys leave the slice unchanged. .. GENERATED FROM PYTHON SOURCE LINES 47-61 .. code-block:: Python def handle_key_event(event): if event.key not in ("ArrowUp", "ArrowDown"): return x, y, z = actor.get_slices(slicer) step = 1 if event.key == "ArrowUp" else -1 actor.show_slices(slicer, (x, y, z + step)) show_manager.render() show_manager.renderer.add_event_handler(handle_key_event, "key_down") show_manager.start() .. image-sg:: /auto_examples/04_demos/images/sphx_glr_viz_ellipsoid_slicer_001.png :alt: viz ellipsoid slicer :srcset: /auto_examples/04_demos/images/sphx_glr_viz_ellipsoid_slicer_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.145 seconds) .. _sphx_glr_download_auto_examples_04_demos_viz_ellipsoid_slicer.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: viz_ellipsoid_slicer.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: viz_ellipsoid_slicer.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: viz_ellipsoid_slicer.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_