Skip to content

Commit

Permalink
DOCS: simplify import
Browse files Browse the repository at this point in the history
  • Loading branch information
skoudoro committed Jul 30, 2024
1 parent 08d4948 commit f975797
Show file tree
Hide file tree
Showing 42 changed files with 503 additions and 507 deletions.
29 changes: 15 additions & 14 deletions docs/examples/viz_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,41 @@
This example shows how to place different UI elements in different Layouts.
The Layouts used here is GridLayout (with different cell shapes).
First, some imports.
First, let's import fury.
"""

from fury import ui, window
from fury.layout import GridLayout
import fury

###############################################################################
# We create some panels and then we arrange them in a grid fashion
#
# First, we create some panels with different sizes/positions

panel_1 = ui.Panel2D(size=(200, 200), color=(0.4, 0.6, 0.3), position=(100, 100))
panel_1 = fury.ui.Panel2D(size=(200, 200), color=(0.4, 0.6, 0.3), position=(100, 100))

panel_2 = ui.Panel2D(size=(250, 250), color=(0.8, 0.3, 0.5), position=(150, 150))
panel_2 = fury.ui.Panel2D(size=(250, 250), color=(0.8, 0.3, 0.5), position=(150, 150))

###############################################################################
# Now we create two listboxes

listbox_1 = ui.ListBox2D(size=(150, 150), values=["First", "Second", "Third"])
listbox_1 = fury.ui.ListBox2D(size=(150, 150), values=["First", "Second", "Third"])

listbox_2 = ui.ListBox2D(size=(250, 250), values=["First", "Second", "Third"])
listbox_2 = fury.ui.ListBox2D(size=(250, 250), values=["First", "Second", "Third"])

###############################################################################
# Now we create two different UI i.e. a slider and a listbox

slider = ui.LineSlider2D(length=150)
listbox = ui.ListBox2D(size=(150, 150), values=["First", "Second", "Third"])
slider = fury.ui.LineSlider2D(length=150)
listbox = fury.ui.ListBox2D(size=(150, 150), values=["First", "Second", "Third"])

###############################################################################
# Now, we create grids with different shapes

rect_grid = GridLayout(position_offset=(0, 0, 0))
square_grid = GridLayout(cell_shape="square", position_offset=(0, 300, 0))
diagonal_grid = GridLayout(cell_shape="diagonal", position_offset=(0, 600, 0))
rect_grid = fury.layout.GridLayout(position_offset=(0, 0, 0))
square_grid = fury.layout.GridLayout(cell_shape="square", position_offset=(0, 300, 0))
diagonal_grid = fury.layout.GridLayout(
cell_shape="diagonal", position_offset=(0, 600, 0)
)


###############################################################################
Expand All @@ -50,7 +51,7 @@
diagonal_grid.apply([slider, listbox])

current_size = (1500, 1500)
show_manager = window.ShowManager(size=current_size, title="FURY UI Layout")
show_manager = fury.window.ShowManager(size=current_size, title="FURY UI Layout")

show_manager.scene.add(panel_1, panel_2, listbox_1, listbox_2, slider, listbox)

Expand All @@ -60,4 +61,4 @@
if interactive:
show_manager.start()

window.record(show_manager.scene, out_path="ui_layout.png", size=(400, 400))
fury.window.record(show_manager.scene, out_path="ui_layout.png", size=(400, 400))
12 changes: 6 additions & 6 deletions docs/examples/viz_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import numpy as np

from fury import actor, window
import fury

n = 10000

Expand All @@ -26,7 +26,7 @@
############################################################################
# You can control the edge color and edge width for each marker

nodes_actor = actor.markers(
nodes_actor = fury.actor.markers(
centers,
marker=markers,
edge_width=0.1,
Expand All @@ -38,21 +38,21 @@
############################################################################
# In addition, an 3D sphere it's also a valid type of marker

nodes_3d_actor = actor.markers(
nodes_3d_actor = fury.actor.markers(
centers + np.ones_like(centers) * 25,
marker="3d",
colors=colors,
scales=0.5,
)

scene = window.Scene()
scene = fury.window.Scene()

scene.add(nodes_actor)
scene.add(nodes_3d_actor)

interactive = False

if interactive:
window.show(scene, size=(600, 600))
fury.window.show(scene, size=(600, 600))

window.record(scene, out_path="viz_markers.png", size=(600, 600))
fury.window.record(scene, out_path="viz_markers.png", size=(600, 600))
16 changes: 7 additions & 9 deletions docs/examples/viz_morphing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@
In this tutorial, we will show how to use morphing in a glTF model in FURY.
"""

from fury import window
from fury.data import fetch_gltf, read_viz_gltf
from fury.gltf import glTF
import fury

##############################################################################
# Retrieving the model with morphing in it (look at Khronoos samples).
# We're choosing the `MorphStressTest` model here.

fetch_gltf("MorphStressTest", "glTF")
filename = read_viz_gltf("MorphStressTest")
fury.data.fetch_gltf("MorphStressTest", "glTF")
filename = fury.data.read_viz_gltf("MorphStressTest")

##############################################################################
# Initializing the glTF object, You can additionally set `apply_normals=True`.
# Note: Normals might not work as intended with morphing.

gltf_obj = glTF(filename, apply_normals=True)
gltf_obj = fury.gltf.glTF(filename, apply_normals=True)

##############################################################################
# Get the morph timeline using `morph_timeline` method, Choose the animation
Expand All @@ -40,8 +38,8 @@
# Initialize the show manager and add timeline to the scene (No need to add
# actors to the scene separately).

scene = window.Scene()
showm = window.ShowManager(
scene = fury.window.Scene()
showm = fury.window.ShowManager(
scene, size=(900, 768), reset_camera=True, order_transparent=True
)

Expand Down Expand Up @@ -71,4 +69,4 @@ def timer_callback(_obj, _event):
if interactive:
showm.start()

window.record(scene, out_path="viz_morphing.png", size=(900, 768))
fury.window.record(scene, out_path="viz_morphing.png", size=(900, 768))
12 changes: 6 additions & 6 deletions docs/examples/viz_multithread.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@

import numpy as np

from fury import actor, ui, window
import fury

# Preparing to draw some spheres
xyz = 10 * (np.random.random((100, 3)) - 0.5)
colors = np.random.random((100, 4))
radii = np.random.random(100) + 0.5

scene = window.Scene()
sphere_actor = actor.sphere(
scene = fury.window.Scene()
sphere_actor = fury.actor.sphere(
centers=xyz, colors=colors, radii=radii, use_primitive=False
)
scene.add(sphere_actor)


# Preparing the show manager as usual
showm = window.ShowManager(
showm = fury.window.ShowManager(
scene, size=(900, 768), reset_camera=False, order_transparent=True
)

# showm.initialize()

# Creating a text block to show a message and reset the camera
tb = ui.TextBlock2D(bold=True)
tb = fury.ui.TextBlock2D(bold=True)
scene.add(tb)
scene.ResetCamera()

Expand Down Expand Up @@ -77,7 +77,7 @@ def add_remove_axes():
for i in range(100):
if showm.lock_current():
if current_axes is None:
current_axes = actor.axes(scale=(0.20 * i, 0.20 * i, 0.20 * i))
current_axes = fury.actor.axes(scale=(0.20 * i, 0.20 * i, 0.20 * i))
scene.add(current_axes)
pass
else:
Expand Down
18 changes: 8 additions & 10 deletions docs/examples/viz_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@

import numpy as np

from fury import actor, colormap as cmap, window
from fury.data import fetch_viz_wiki_nw
import fury

###############################################################################
# Then let's download some available datasets.


files, folder = fetch_viz_wiki_nw()
files, folder = fury.data.fetch_viz_wiki_nw()
categories_file, edges_file, positions_file = sorted(files.keys())

###############################################################################
Expand All @@ -40,7 +38,7 @@

index2category = np.unique(categories)

categoryColors = cmap.distinguishable_colormap(nb_colors=len(index2category))
categoryColors = fury.colormap.distinguishable_colormap(nb_colors=len(index2category))

colors = np.array([categoryColors[category2index[category]] for category in categories])

Expand Down Expand Up @@ -68,15 +66,15 @@
# build 2 actors that we represent our data : sphere_actor for the nodes and
# lines_actor for the edges.

sphere_actor = actor.sphere(
sphere_actor = fury.actor.sphere(
centers=positions,
colors=colors,
radii=radii * 0.5,
theta=8,
phi=8,
)

lines_actor = actor.line(
lines_actor = fury.actor.line(
edgesPositions,
colors=edgesColors,
opacity=0.1,
Expand All @@ -86,7 +84,7 @@
# All actors need to be added in a scene, so we build one and add our
# lines_actor and sphere_actor.

scene = window.Scene()
scene = fury.window.Scene()

scene.add(lines_actor)
scene.add(sphere_actor)
Expand All @@ -98,9 +96,9 @@
interactive = False

if interactive:
window.show(scene, size=(600, 600))
fury.window.show(scene, size=(600, 600))

window.record(scene, out_path="journal_networks.png", size=(600, 600))
fury.window.record(scene, out_path="journal_networks.png", size=(600, 600))

###############################################################################
# This example can be improved by adding some interactivy with slider,
Expand Down
29 changes: 14 additions & 15 deletions docs/examples/viz_network_animated.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

import numpy as np

from fury import actor, colormap as cmap, window
from fury.utils import compute_bounds, update_actor, vertices_from_actor
import fury

###############################################################################
# This demo has two modes.
Expand Down Expand Up @@ -72,7 +71,7 @@

index2category = np.unique(categories)

category_colors = cmap.distinguishable_colormap(nb_colors=len(index2category))
category_colors = fury.colormap.distinguishable_colormap(nb_colors=len(index2category))

colors = np.array(
[category_colors[category2index[category]] for category in categories]
Expand All @@ -98,12 +97,12 @@
# build 2 actors that we represent our data : sphere_actor for the nodes and
# lines_actor for the edges.

sphere_actor = actor.sphere(
sphere_actor = fury.actor.sphere(
centers=np.zeros(positions.shape), colors=colors, radii=radii * 0.5, theta=8, phi=8
)


lines_actor = actor.line(
lines_actor = fury.actor.line(
np.zeros((len(edges), 2, 3)),
colors=edges_colors,
lod=False,
Expand All @@ -129,7 +128,7 @@ def new_layout_timer(
b = 1.0
deltaT = 1.0

sphere_geometry = np.array(vertices_from_actor(sphere_actor))
sphere_geometry = np.array(fury.utils.vertices_from_actor(sphere_actor))
geometry_length = sphere_geometry.shape[0] / vertices_count

if vertex_initial_positions is not None:
Expand Down Expand Up @@ -199,18 +198,18 @@ def _timer(_obj, _event):
iterate(1)
else:
pos[:] += (np.random.random(pos.shape) - 0.5) * 1.5
spheres_positions = vertices_from_actor(sphere_actor)
spheres_positions = fury.utils.vertices_from_actor(sphere_actor)
spheres_positions[:] = sphere_geometry + np.repeat(pos, geometry_length, axis=0)

edges_positions = vertices_from_actor(lines_actor)
edges_positions = fury.utils.vertices_from_actor(lines_actor)
edges_positions[::2] = pos[edges_list[:, 0]]
edges_positions[1::2] = pos[edges_list[:, 1]]

update_actor(lines_actor)
compute_bounds(lines_actor)
fury.utils.update_actor(lines_actor)
fury.utils.compute_bounds(lines_actor)

update_actor(sphere_actor)
compute_bounds(lines_actor)
fury.utils.update_actor(sphere_actor)
fury.utils.compute_bounds(lines_actor)
showm.scene.reset_clipping_range()
showm.render()

Expand All @@ -225,7 +224,7 @@ def _timer(_obj, _event):
# lines_actor and sphere_actor.


scene = window.Scene()
scene = fury.window.Scene()

camera = scene.camera()

Expand All @@ -238,7 +237,7 @@ def _timer(_obj, _event):
# parameter max_iteractions of the timer callback to let the animation run for
# more time.

showm = window.ShowManager(
showm = fury.window.ShowManager(
scene, reset_camera=False, size=(900, 768), order_transparent=True, multi_samples=8
)

Expand All @@ -255,4 +254,4 @@ def _timer(_obj, _event):

showm.start()

window.record(showm.scene, size=(900, 768), out_path="viz_animated_networks.png")
fury.window.record(showm.scene, size=(900, 768), out_path="viz_animated_networks.png")
Loading

0 comments on commit f975797

Please sign in to comment.