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

.. only:: html

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

        Click :ref:`here <sphx_glr_download_gallery_scene_flipped_axis.py>`
        to download the full example code

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

.. _sphx_glr_gallery_scene_flipped_axis.py:


Aspect Ratios
=============

Example demonstrating the use of aspect ratio, and also the flipping
of axis using negative aspect ratios.

Keys:
* 1: flip x dimension
* 2: flip y dimension
* 3: flip z dimension
* 4: cycle through up-vectors
* 5: cycle through cameras

.. GENERATED FROM PYTHON SOURCE LINES 22-92



.. image-sg:: /gallery/scene/images/sphx_glr_flipped_axis_001.png
   :alt: flipped axis
   :srcset: /gallery/scene/images/sphx_glr_flipped_axis_001.png
   :class: sphx-glr-single-img





.. code-block:: default


    from itertools import cycle

    import numpy as np

    from vispy import app, scene, io

    # Read volume
    vol1 = np.load(io.load_data_file('volume/stent.npz'))['arr_0']

    # Prepare canvas
    canvas = scene.SceneCanvas(keys='interactive', size=(800, 600), show=True)
    canvas.measure_fps()

    # Set up a viewbox to display the image with interactive pan/zoom
    view = canvas.central_widget.add_view()

    # Create the volume visuals, only one is visible
    volume1 = scene.visuals.Volume(vol1, parent=view.scene, threshold=0.5)
    # volume1.method = 'iso'
    volume1.threshold = 0.1

    # Plot a line that shows where positive x is, with at the end a small
    # line pointing at positive y
    arr = np.array([(100, -1, -1), (-1, -1, -1), (-1, 10, -1)])
    line1 = scene.visuals.Line(arr, color='red', parent=view.scene)

    # Create cameras
    cam1 = scene.cameras.PanZoomCamera(parent=view.scene, aspect=1, name='PanZoom')
    cam2 = scene.cameras.FlyCamera(parent=view.scene, name='Fly')
    cam3 = scene.cameras.TurntableCamera(fov=60, parent=view.scene,
                                         name='Turntable')
    cam4 = scene.cameras.ArcballCamera(fov=60, parent=view.scene, name='Arcball')
    cams = (cam1, cam2, cam3, cam4)
    view.camera = cam3  # Select turntable at first

    ups = cycle(('+z', '-z', '+y', '-y', '+x', '-x'))


    # Implement key presses
    @canvas.events.key_press.connect
    def on_key_press(event):
        if event.text == '1':
            for cam in cams:
                flip = cam.flip
                cam.flip = not flip[0], flip[1], flip[2]
        elif event.text == '2':
            for cam in cams:
                flip = cam.flip
                cam.flip = flip[0], not flip[1], flip[2]
        elif event.text == '3':
            for cam in cams:
                flip = cam.flip
                cam.flip = flip[0], flip[1], not flip[2]
        elif event.text == '4':
            up = next(ups)
            print('up: ' + up)
            for cam in cams:
                cam.up = up
        if event.text == '5':
            cam_toggle = {cam1: cam2, cam2: cam3, cam3: cam4, cam4: cam1}
            view.camera = cam_toggle.get(view.camera, cam2)
            print(view.camera.name + ' camera')
        elif event.text == '0':
            for cam in cams:
                cam.set_range()

    if __name__ == '__main__':
        print(__doc__)
        app.run()


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** ( 0 minutes  1.538 seconds)


.. _sphx_glr_download_gallery_scene_flipped_axis.py:


.. only :: html

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



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

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



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

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


.. only:: html

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

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