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 c98659c
Show file tree
Hide file tree
Showing 61 changed files with 773 additions and 785 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ jobs:
USE_PRE: ${{ matrix.use-pre }}
COVERAGE: ${{ matrix.coverage }}
PRE_WHEELS: "https://pypi.anaconda.org/scipy-wheels-nightly/simple"
# EAGER_IMPORT: 1 # to explore what is the issue.


steps:
- uses: actions/checkout@v4
Expand Down
20 changes: 10 additions & 10 deletions docs/examples/viz_domino.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import numpy as np
import pybullet as p

from fury import actor, ui, utils, window
import fury

# Next, we initialize a pybullet client to render the physics.
# We use `DIRECT` mode to initialize pybullet without a GUI.
Expand All @@ -35,7 +35,7 @@
base_orientation = np.array([0, 0, 0, 1])

# Render a BASE plane to support the Dominoes.
base_actor = actor.box(
base_actor = fury.actor.box(
centers=np.array([[0, 0, 0]]),
directions=[0, 0, 0],
scales=base_size,
Expand Down Expand Up @@ -94,7 +94,7 @@
p.changeDynamics(dominos[i], -1, lateralFriction=0.2, restitution=0.1)


domino_actor = actor.box(
domino_actor = fury.actor.box(
centers=domino_centers,
directions=domino_directions,
scales=domino_sizes,
Expand All @@ -103,13 +103,13 @@

###############################################################################
# Now, we define a scene and add actors to it.
scene = window.Scene()
scene.add(actor.axes())
scene = fury.window.Scene()
scene.add(fury.actor.axes())
scene.add(base_actor)
scene.add(domino_actor)

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

Expand All @@ -128,7 +128,7 @@


# Calculate the vertices of the dominos.
vertices = utils.vertices_from_actor(domino_actor)
vertices = fury.utils.vertices_from_actor(domino_actor)
num_vertices = vertices.shape[0]
num_objects = domino_centers.shape[0]
sec = int(num_vertices / num_objects)
Expand Down Expand Up @@ -173,7 +173,7 @@ def sync_domino(object_index, multibody):
# Here, we define a textblock to display the Avg. FPS and simulation steps.

fpss = np.array([])
tb = ui.TextBlock2D(
tb = fury.ui.TextBlock2D(
text="Avg. FPS: \nSim Steps: ", position=(0, 680), font_size=30, color=(1, 0.5, 0)
)
scene.add(tb)
Expand Down Expand Up @@ -224,7 +224,7 @@ def timer_callback(_obj, _event):
# Updating the position and orientation of individual dominos.
for idx, domino in enumerate(dominos):
sync_domino(idx, domino)
utils.update_actor(domino_actor)
fury.utils.update_actor(domino_actor)

# Simulate a step.
p.stepSimulation()
Expand All @@ -244,4 +244,4 @@ def timer_callback(_obj, _event):
if interactive:
showm.start()

window.record(scene, out_path="viz_domino.png", size=(900, 768))
fury.window.record(scene, out_path="viz_domino.png", size=(900, 768))
11 changes: 5 additions & 6 deletions docs/examples/viz_drawpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
First, some imports.
"""

from fury import ui, window
from fury.data import fetch_viz_new_icons
import fury

##############################################################################
# First we need to fetch some icons that are needed for DrawPanel.

fetch_viz_new_icons()
fury.data.fetch_viz_new_icons()

#########################################################################
# We then create a DrawPanel Object.

drawing_canvas = ui.DrawPanel(size=(560, 560), position=(40, 10))
drawing_canvas = fury.ui.DrawPanel(size=(560, 560), position=(40, 10))

###############################################################################
# Show Manager
Expand All @@ -29,7 +28,7 @@
# Now we add DrawPanel to the scene.

current_size = (650, 650)
showm = window.ShowManager(size=current_size, title="DrawPanel UI Example")
showm = fury.window.ShowManager(size=current_size, title="DrawPanel UI Example")

showm.scene.add(drawing_canvas)

Expand All @@ -43,4 +42,4 @@
drawing_canvas.draw_shape(shape_type="circle", current_position=(275, 275))
drawing_canvas.shape_list[-1].resize((50, 50))

window.record(showm.scene, size=current_size, out_path="viz_drawpanel.png")
fury.window.record(showm.scene, size=current_size, out_path="viz_drawpanel.png")
93 changes: 48 additions & 45 deletions docs/examples/viz_dt_ellipsoids.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,25 @@
from dipy.io.image import load_nifti
import numpy as np

from fury import actor, ui, window
from fury.actor import _color_fa, _fa
from fury.data import fetch_viz_dmri, read_viz_dmri
from fury.primitive import prim_sphere
import fury

###############################################################################
# Now, we fetch and load the data needed to display the Diffusion Tensor
# Images.

fetch_viz_dmri()
fury.data.fetch_viz_dmri()

###############################################################################
# The tensor ellipsoids are expressed as eigenvalues and eigenvectors which are
# the decomposition of the diffusion tensor that describes the water diffusion
# within a voxel.

slice_evecs, _ = load_nifti(read_viz_dmri("slice_evecs.nii.gz"))
slice_evals, _ = load_nifti(read_viz_dmri("slice_evals.nii.gz"))
roi_evecs, _ = load_nifti(read_viz_dmri("roi_evecs.nii.gz"))
roi_evals, _ = load_nifti(read_viz_dmri("roi_evals.nii.gz"))
whole_brain_evecs, _ = load_nifti(read_viz_dmri("whole_brain_evecs.nii.gz"))
whole_brain_evals, _ = load_nifti(read_viz_dmri("whole_brain_evals.nii.gz"))
slice_evecs, _ = load_nifti(fury.data.read_viz_dmri("slice_evecs.nii.gz"))
slice_evals, _ = load_nifti(fury.data.read_viz_dmri("slice_evals.nii.gz"))
roi_evecs, _ = load_nifti(fury.data.read_viz_dmri("roi_evecs.nii.gz"))
roi_evals, _ = load_nifti(fury.data.read_viz_dmri("roi_evals.nii.gz"))
whole_brain_evecs, _ = load_nifti(fury.data.read_viz_dmri("whole_brain_evecs.nii.gz"))
whole_brain_evals, _ = load_nifti(fury.data.read_viz_dmri("whole_brain_evals.nii.gz"))

###############################################################################
# Using tensor_slicer actor
Expand All @@ -49,7 +46,7 @@
# vertices that made up the sphere, which have a standard number of 100, 200,
# and 724 vertices.

vertices, faces = prim_sphere("repulsion100", True)
vertices, faces = fury.prim_sphere("repulsion100", True)


###############################################################################
Expand All @@ -70,43 +67,43 @@ def __init__(self, vertices, faces):
# brain slice. We also define the scale so that the tensors are not so large
# and overlap each other.

tensor_slice = actor.tensor_slicer(
tensor_slice = fury.actor.tensor_slicer(
evals=slice_evals, evecs=slice_evecs, sphere=sphere100, scale=0.3
)

###############################################################################
# Next, we set up a new scene to add and visualize the tensor ellipsoids
# created.

scene = window.Scene()
scene = fury.window.Scene()
scene.background([255, 255, 255])
scene.add(tensor_slice)

# Create show manager
showm = window.ShowManager(scene, size=(600, 600))
showm = fury.window.ShowManager(scene, size=(600, 600))

# Enables/disables interactive visualization
interactive = False

if interactive:
showm.start()

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

###############################################################################
# If we zoom in at the scene to see with detail the tensor ellipsoids displayed
# with the different spheres, we get the following results.

scene.roll(10)
scene.pitch(90)
showm = window.ShowManager(scene, size=(600, 600), order_transparent=True)
showm = fury.window.ShowManager(scene, size=(600, 600), order_transparent=True)
showm.scene.zoom(50)

if interactive:
showm.render()
showm.start()

window.record(
fury.window.record(
showm.scene,
out_path="tensor_slice_100_zoom.png",
size=(600, 300),
Expand Down Expand Up @@ -151,7 +148,7 @@ def get_params(evecs, evals):
# coloring in tensor_slicer that is uses _color_fa that is a way to map
# colors to each tensor based on the fractional anisotropy (FA) of each
# diffusion tensor.
colors = _color_fa(_fa(fevals), fevecs)
colors = fury.actor._color_fa(fury.actor._fa(fevals), fevecs)

return centers, fevecs, fevals, colors

Expand All @@ -166,15 +163,15 @@ def get_params(evecs, evals):
# Now, we can use the ``ellipsoid`` actor to create the tensor ellipsoids as
# follows.

tensors = actor.ellipsoid(
tensors = fury.actor.ellipsoid(
centers=centers, colors=colors, axes=evecs, lengths=evals, scales=0.6
)
showm.scene.add(tensors)

if interactive:
showm.start()

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

###############################################################################
# Thus, one can see that the same result is obtained, however there is a
Expand All @@ -185,14 +182,14 @@ def get_params(evecs, evals):

scene.roll(10)
scene.pitch(90)
showm = window.ShowManager(scene, size=(600, 600), order_transparent=True)
showm = fury.window.ShowManager(scene, size=(600, 600), order_transparent=True)
showm.scene.zoom(50)

if interactive:
showm.render()
showm.start()

window.record(
fury.window.record(
showm.scene,
out_path="tensor_slice_sdf_zoom.png",
size=(600, 300),
Expand Down Expand Up @@ -224,17 +221,23 @@ def get_params(evecs, evals):
evals[..., :] = mevals
evecs[..., :, :] = mevecs

vertices, faces = prim_sphere("repulsion200", True)
vertices, faces = fury.prim_sphere("repulsion200", True)
sphere200 = Sphere(vertices, faces)
vertices, faces = prim_sphere("repulsion724", True)
vertices, faces = fury.prim_sphere("repulsion724", True)
sphere724 = Sphere(vertices, faces)

tensor_100 = actor.tensor_slicer(evals=evals, evecs=evecs, sphere=sphere100, scale=1.0)
tensor_200 = actor.tensor_slicer(evals=evals, evecs=evecs, sphere=sphere200, scale=1.0)
tensor_724 = actor.tensor_slicer(evals=evals, evecs=evecs, sphere=sphere724, scale=1.0)
tensor_100 = fury.actor.tensor_slicer(
evals=evals, evecs=evecs, sphere=sphere100, scale=1.0
)
tensor_200 = fury.actor.tensor_slicer(
evals=evals, evecs=evecs, sphere=sphere200, scale=1.0
)
tensor_724 = fury.actor.tensor_slicer(
evals=evals, evecs=evecs, sphere=sphere724, scale=1.0
)

centers, evecs, evals, colors = get_params(evecs=evecs, evals=evals)
tensor_sdf = actor.ellipsoid(
tensor_sdf = fury.actor.ellipsoid(
centers=centers, axes=evecs, lengths=evals, colors=colors, scales=2.0
)

Expand All @@ -244,31 +247,31 @@ def get_params(evecs, evals):

objects = [tensor_100, tensor_200, tensor_724, tensor_sdf]
text = [
actor.vector_text("Tensor 100"),
actor.vector_text("Tensor 200"),
actor.vector_text("Tensor 724"),
actor.vector_text("Tensor SDF"),
fury.actor.vector_text("Tensor 100"),
fury.actor.vector_text("Tensor 200"),
fury.actor.vector_text("Tensor 724"),
fury.actor.vector_text("Tensor SDF"),
]

grid_ui = ui.GridUI(
grid_ui = fury.ui.GridUI(
actors=objects,
captions=text,
cell_padding=0.1,
caption_offset=(-0.7, -2.5, 0),
dim=(1, 4),
)

scene = window.Scene()
scene = fury.window.Scene()
scene.background([255, 255, 255])
scene.zoom(3.5)
scene.set_camera(position=(3.2, -20, 12), focal_point=(3.2, 0.0, 0.0))
showm = window.ShowManager(scene, size=(560, 200))
showm = fury.window.ShowManager(scene, size=(560, 200))
showm.scene.add(grid_ui)

if interactive:
showm.start()

window.record(
fury.window.record(
showm.scene,
size=(560, 200),
out_path="tensor_comparison.png",
Expand All @@ -285,7 +288,7 @@ def get_params(evecs, evals):
# ``display_extent()``. Here we can see an example of a region of interest
# (ROI) using a sphere of 100 vertices.

tensor_roi = actor.tensor_slicer(
tensor_roi = fury.actor.tensor_slicer(
evals=roi_evals, evecs=roi_evecs, sphere=sphere100, scale=0.3
)

Expand All @@ -300,7 +303,7 @@ def get_params(evecs, evals):
if interactive:
showm.start()

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

showm.scene.clear()

Expand All @@ -312,15 +315,15 @@ def get_params(evecs, evals):

centers, evecs, evals, colors = get_params(roi_evecs, roi_evals)

tensors = actor.ellipsoid(
tensors = fury.actor.ellipsoid(
centers=centers, colors=colors, axes=evecs, lengths=evals, scales=0.6
)
showm.scene.add(tensors)

if interactive:
showm.start()

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

showm.scene.clear()

Expand All @@ -338,19 +341,19 @@ def get_params(evecs, evals):
evecs = np.array(list(itertools.compress(evecs, fil)))
evals = np.array(list(itertools.compress(evals, fil)))

tensors = actor.ellipsoid(
tensors = fury.actor.ellipsoid(
centers=centers, colors=colors, axes=evecs, lengths=evals, scales=0.6
)

scene = window.Scene()
scene = fury.window.Scene()
scene.add(tensors)
scene.pitch(180)
showm = window.ShowManager(scene, size=(600, 600))
showm = fury.window.ShowManager(scene, size=(600, 600))

if interactive:
showm.start()

window.record(
fury.window.record(
showm.scene,
size=(600, 600),
reset_camera=False,
Expand Down
Loading

0 comments on commit c98659c

Please sign in to comment.