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

.. only:: html

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

        :ref:`Go to the end <sphx_glr_download_auto_examples_13_shaders_viz_sdfactor.py>`
        to download the full example code

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

.. _sphx_glr_auto_examples_13_shaders_viz_sdfactor.py:


===================
Visualize SDF Actor
===================
Here is a simple tutorial that shows how to visualize SDF primitives using
FURY.

SDFs or Signed-distance functions when passed the coordinates of a point in
space, return the shortest distance between that point and some surface.
This property of SDFs can be used to model 3D geometry at a faster rate
compared to traditional polygons based modeling.

In this example we use the raymarching algorithm to render the SDF primitives
shapes using shaders

.. GENERATED FROM PYTHON SOURCE LINES 16-21

.. code-block:: Python


    import numpy as np

    import fury








.. GENERATED FROM PYTHON SOURCE LINES 22-23

Lets define variables for the SDF Actor

.. GENERATED FROM PYTHON SOURCE LINES 23-30

.. code-block:: Python


    dirs = np.random.rand(4, 3)
    colors = np.random.rand(4, 3) * 255
    centers = np.array([[1, 0, 0], [0, 0, 0], [-1, 0, 0], [0, 1, 0]])
    scales = np.random.rand(4, 1)









.. GENERATED FROM PYTHON SOURCE LINES 31-32

Create SDF Actor

.. GENERATED FROM PYTHON SOURCE LINES 32-41

.. code-block:: Python


    sdfactor = fury.actor.sdf(
        centers=centers,
        directions=dirs,
        colors=colors,
        primitives=["sphere", "torus", "ellipsoid", "capsule"],
        scales=scales,
    )








.. GENERATED FROM PYTHON SOURCE LINES 42-43

Create a scene

.. GENERATED FROM PYTHON SOURCE LINES 43-49

.. code-block:: Python


    scene = fury.window.Scene()
    scene.background((1.0, 0.8, 0.8))
    scene.add(sdfactor)









.. GENERATED FROM PYTHON SOURCE LINES 50-54

Show Manager

Since all the elements have been initialised ,we add them to the show
manager.

.. GENERATED FROM PYTHON SOURCE LINES 54-66

.. code-block:: Python


    current_size = (1024, 720)
    showm = fury.window.ShowManager(
        scene=scene, size=current_size, title="Visualize SDF Actor"
    )

    interactive = False

    if interactive:
        showm.start()

    fury.window.record(scene=scene, out_path="viz_sdfactor.png", size=current_size)



.. image-sg:: /auto_examples/13_shaders/images/sphx_glr_viz_sdfactor_001.png
   :alt: viz sdfactor
   :srcset: /auto_examples/13_shaders/images/sphx_glr_viz_sdfactor_001.png
   :class: sphx-glr-single-img






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

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


.. _sphx_glr_download_auto_examples_13_shaders_viz_sdfactor.py:

.. only:: html

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

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

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

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

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


.. only:: html

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

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