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

import numpy as np

import fury

Lets define variables for the SDF Actor

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)

Create SDF Actor

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

Create a scene

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

Show Manager

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

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

interactive = False

if interactive:
    showm.start()

fury.window.record(scene, out_path="viz_sdfactor.png", size=current_size)
viz sdfactor
/opt/homebrew/Caskroom/miniforge/base/envs/py39/lib/python3.9/site-packages/sphinx_gallery/gen_rst.py:722: UserWarning: We'll no longer accept the way you call the __init__ function in future versions of FURY.

Here's how to call the Function __init__: __init__(self_value, scene='value', title='value', size='value', png_magnify='value', reset_camera='value', order_transparent='value', interactor_style='value', stereo='value', multi_samples='value', max_peels='value', occlusion_ratio='value')

  exec(self.code, self.fake_main.__dict__)
/opt/homebrew/Caskroom/miniforge/base/envs/py39/lib/python3.9/site-packages/sphinx_gallery/gen_rst.py:722: UserWarning: We'll no longer accept the way you call the record function in future versions of FURY.

Here's how to call the Function record: record(scene='value', cam_pos='value', cam_focal='value', cam_view='value', out_path='value', path_numbering='value', n_frames='value', az_ang='value', magnification='value', size='value', reset_camera='value', screen_clip='value', stereo='value', verbose='value')

  exec(self.code, self.fake_main.__dict__)

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

Gallery generated by Sphinx-Gallery