diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 07b9b3c95..9ed6db979 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/docs/examples/viz_domino.py b/docs/examples/viz_domino.py index 9bb54afa4..104ec4db9 100644 --- a/docs/examples/viz_domino.py +++ b/docs/examples/viz_domino.py @@ -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. @@ -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, @@ -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, @@ -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 ) @@ -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) @@ -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) @@ -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() @@ -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)) diff --git a/docs/examples/viz_drawpanel.py b/docs/examples/viz_drawpanel.py index 6b5295ebe..3a0fe1d76 100644 --- a/docs/examples/viz_drawpanel.py +++ b/docs/examples/viz_drawpanel.py @@ -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 @@ -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) @@ -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") diff --git a/docs/examples/viz_dt_ellipsoids.py b/docs/examples/viz_dt_ellipsoids.py index f9e7ec5ab..4b2d37e02 100644 --- a/docs/examples/viz_dt_ellipsoids.py +++ b/docs/examples/viz_dt_ellipsoids.py @@ -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 @@ -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) ############################################################################### @@ -70,7 +67,7 @@ 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 ) @@ -78,12 +75,12 @@ def __init__(self, vertices, faces): # 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 @@ -91,7 +88,7 @@ def __init__(self, vertices, faces): 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 @@ -99,14 +96,14 @@ def __init__(self, vertices, faces): 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), @@ -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 @@ -166,7 +163,7 @@ 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) @@ -174,7 +171,7 @@ def get_params(evecs, evals): 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 @@ -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), @@ -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 ) @@ -244,13 +247,13 @@ 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, @@ -258,17 +261,17 @@ def get_params(evecs, evals): 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", @@ -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 ) @@ -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() @@ -312,7 +315,7 @@ 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) @@ -320,7 +323,7 @@ def get_params(evecs, evals): 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() @@ -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, diff --git a/docs/examples/viz_earth_animation.py b/docs/examples/viz_earth_animation.py index ff430a31b..38675c595 100644 --- a/docs/examples/viz_earth_animation.py +++ b/docs/examples/viz_earth_animation.py @@ -9,18 +9,12 @@ import numpy as np -from fury import actor, io, utils, window -from fury.data import ( - fetch_viz_models, - fetch_viz_textures, - read_viz_models, - read_viz_textures, -) +import fury ############################################################################## # Create a scene to start. -scene = window.Scene() +scene = fury.window.Scene() ############################################################################## # Next, load in a texture for each of the actors. For this tutorial, we will @@ -29,23 +23,23 @@ # and ``read_viz_textures``, then use ``io.load_image`` to load in the # image. -fetch_viz_textures() -earth_filename = read_viz_textures("1_earth_8k.jpg") -earth_image = io.load_image(earth_filename) +fury.data.fetch_viz_textures() +earth_filename = fury.data.read_viz_textures("1_earth_8k.jpg") +earth_image = fury.io.load_image(earth_filename) ############################################################################## # Using ``actor.texture_on_sphere()``, create an earth_actor with your newly # loaded texture. -earth_actor = actor.texture_on_sphere(earth_image) +earth_actor = fury.actor.texture_on_sphere(earth_image) ############################################################################## # Then, do the same for the moon. -moon_filename = read_viz_textures("moon-8k.jpg") -moon_image = io.load_image(moon_filename) +moon_filename = fury.data.read_viz_textures("moon-8k.jpg") +moon_image = fury.io.load_image(moon_filename) -moon_actor = actor.texture_on_sphere(moon_image) +moon_actor = fury.actor.texture_on_sphere(moon_image) ############################################################################## # Add both actors to the already existing scene. @@ -61,13 +55,13 @@ moon_actor.SetPosition(1, 0.1, 0.5) moon_actor.SetScale(0.25, 0.25, 0.25) -utils.rotate(earth_actor, (-90, 1, 0, 0)) +fury.utils.rotate(earth_actor, (-90, 1, 0, 0)) ############################################################################## # The ShowManager class is the interface between the scene, the window and the # interactor. -showm = window.ShowManager( +showm = fury.window.ShowManager( scene, size=(900, 768), reset_camera=False, order_transparent=True ) @@ -94,23 +88,23 @@ center = np.array([[-0.39, 0.3175, 0.025]]) radius = 0.002 -sphere_actor = actor.sphere(center, window.colors.blue_medium, radius) +sphere_actor = fury.actor.sphere(center, fury.window.colors.blue_medium, radius) ############################################################################## # Also creating a text actor to add below the sphere. -text_actor = actor.text_3d( - "Bloomington, Indiana", (-0.42, 0.31, 0.03), window.colors.white, 0.004 +text_actor = fury.actor.text_3d( + "Bloomington, Indiana", (-0.42, 0.31, 0.03), fury.window.colors.white, 0.004 ) -utils.rotate(text_actor, (-90, 0, 1, 0)) +fury.utils.rotate(text_actor, (-90, 0, 1, 0)) ############################################################################## # Let's also import a model of a satellite to visualize circling the moon. -fetch_viz_models() -satellite_filename = read_viz_models("satellite_obj.obj") -satellite = io.load_polydata(satellite_filename) -satellite_actor = utils.get_actor_from_polydata(satellite) +fury.data.fetch_viz_models() +satellite_filename = fury.data.read_viz_models("satellite_obj.obj") +satellite = fury.io.load_polydata(satellite_filename) +satellite_actor = fury.utils.get_actor_from_polydata(satellite) satellite_actor.SetPosition(-0.75, 0.1, 0.4) satellite_actor.SetScale(0.005, 0.005, 0.005) @@ -127,7 +121,7 @@ def timer_callback(_obj, _event): cnt = next(counter) showm.render() if cnt < 450: - utils.rotate(earth_actor, (1, 0, 1, 0)) + fury.utils.rotate(earth_actor, (1, 0, 1, 0)) if cnt % 5 == 0 and cnt < 450: showm.scene.azimuth(-1) if cnt == 300: @@ -152,15 +146,15 @@ def timer_callback(_obj, _event): ) scene.zoom(0.03) scene.add(satellite_actor) - utils.rotate(satellite_actor, (180, 0, 1, 0)) + fury.utils.rotate(satellite_actor, (180, 0, 1, 0)) scene.rm(earth_actor) if cnt > 575 and cnt < 750: showm.scene.azimuth(-2) - utils.rotate(moon_actor, (-2, 0, 1, 0)) + fury.utils.rotate(moon_actor, (-2, 0, 1, 0)) satellite_actor.SetPosition(-0.8, 0.1 - cnt / 10000, 0.4) if cnt >= 750 and cnt < 1100: showm.scene.azimuth(-2) - utils.rotate(moon_actor, (-2, 0, 1, 0)) + fury.utils.rotate(moon_actor, (-2, 0, 1, 0)) satellite_actor.SetPosition(-0.8, -0.07 + cnt / 10000, 0.4) if cnt == 1100: showm.exit() @@ -172,4 +166,4 @@ def timer_callback(_obj, _event): showm.add_timer_callback(True, 35, timer_callback) showm.start() -window.record(showm.scene, size=(900, 768), out_path="viz_earth_animation.png") +fury.window.record(showm.scene, size=(900, 768), out_path="viz_earth_animation.png") diff --git a/docs/examples/viz_earth_coordinates.py b/docs/examples/viz_earth_coordinates.py index 3c3c10eec..6b5abd564 100644 --- a/docs/examples/viz_earth_coordinates.py +++ b/docs/examples/viz_earth_coordinates.py @@ -12,28 +12,27 @@ import numpy as np -from fury import actor, io, utils, window -from fury.data import fetch_viz_textures, read_viz_textures +import fury ############################################################################### # Create a new scene, and load in the image of the Earth using # ``fetch_viz_textures`` and ``read_viz_textures``. We will use a 16k # resolution texture for maximum detail. -scene = window.Scene() +scene = fury.window.Scene() -fetch_viz_textures() -earth_file = read_viz_textures("1_earth_16k.jpg") -earth_image = io.load_image(earth_file) -earth_actor = actor.texture_on_sphere(earth_image) +fury.data.fetch_viz_textures() +earth_file = fury.data.read_viz_textures("1_earth_16k.jpg") +earth_image = fury.io.load_image(earth_file) +earth_actor = fury.actor.texture_on_sphere(earth_image) scene.add(earth_actor) ############################################################################### # Rotate the Earth to make sure the texture is correctly oriented. Change it's # scale using ``actor.SetScale()``. -utils.rotate(earth_actor, (-90, 1, 0, 0)) -utils.rotate(earth_actor, (180, 0, 1, 0)) +fury.utils.rotate(earth_actor, (-90, 1, 0, 0)) +fury.utils.rotate(earth_actor, (180, 0, 1, 0)) earth_actor.SetScale(2, 2, 2) ############################################################################### @@ -73,40 +72,40 @@ def latlong_coordinates(lat, lon): centers = np.array([[*locationone], [*locationtwo], [*locationthree]]) colors = np.random.rand(3, 3) radii = np.array([0.005, 0.005, 0.005]) -sphere_actor = actor.sphere(centers, colors, radii) +sphere_actor = fury.actor.sphere(centers, colors, radii) scene.add(sphere_actor) ############################################################################### # Create some text actors to add to the scene indicating each location and its # geographical coordinates. -nyc_actor = actor.text_3d( +nyc_actor = fury.actor.text_3d( "New York City, New York\n40.7128° N, 74.0060° W", (locationone[0] - 0.04, locationone[1], locationone[2] + 0.07), - window.colors.white, + fury.window.colors.white, 0.01, ) -paris_actor = actor.text_3d( +paris_actor = fury.actor.text_3d( "Paris, France\n48.8566° N, 2.3522° E", (locationthree[0] - 0.04, locationthree[1], locationthree[2] - 0.07), - window.colors.white, + fury.window.colors.white, 0.01, ) -beijing_actor = actor.text_3d( +beijing_actor = fury.actor.text_3d( "Beijing, China\n39.9042° N, 116.4074° E", (locationtwo[0] - 0.06, locationtwo[1], locationtwo[2] - 0.07), - window.colors.white, + fury.window.colors.white, 0.01, ) -utils.rotate(paris_actor, (85, 0, 1, 0)) -utils.rotate(beijing_actor, (180, 0, 1, 0)) -utils.rotate(nyc_actor, (5, 1, 0, 0)) +fury.utils.rotate(paris_actor, (85, 0, 1, 0)) +fury.utils.rotate(beijing_actor, (180, 0, 1, 0)) +fury.utils.rotate(nyc_actor, (5, 1, 0, 0)) ############################################################################## # Create a ShowManager object, which acts as the interface between the scene, # the window and the interactor. -showm = window.ShowManager( +showm = fury.window.ShowManager( scene, size=(900, 768), reset_camera=False, order_transparent=True ) @@ -157,4 +156,4 @@ def timer_callback(_obj, _event): showm.add_timer_callback(True, 25, timer_callback) showm.start() -window.record(showm.scene, size=(900, 768), out_path="viz_earth_coordinates.png") +fury.window.record(showm.scene, size=(900, 768), out_path="viz_earth_coordinates.png") diff --git a/docs/examples/viz_emwave_animation.py b/docs/examples/viz_emwave_animation.py index 163e0d8d2..8584a5014 100644 --- a/docs/examples/viz_emwave_animation.py +++ b/docs/examples/viz_emwave_animation.py @@ -19,7 +19,7 @@ import numpy as np -from fury import actor, ui, utils, window +import fury ############################################################################### # function that updates and returns the coordinates of the waves which are @@ -58,11 +58,11 @@ def update_coordinates(wavenumber, ang_frq, time, phase_angle): ############################################################################### # Creating a scene object and configuring the camera's position -scene = window.Scene() +scene = fury.window.Scene() scene.set_camera( position=(-6, 5, -10), focal_point=(0.0, 0.0, 0.0), view_up=(0.0, 0.0, 0.0) ) -showm = window.ShowManager( +showm = fury.window.ShowManager( scene, size=(800, 600), reset_camera=True, order_transparent=True ) @@ -74,10 +74,10 @@ def update_coordinates(wavenumber, ang_frq, time, phase_angle): centers = np.array([[3, 0, 0]]) directions = np.array([[-1, 0, 0]]) heights = np.array([6.4]) -arrow_actor = actor.arrow( +arrow_actor = fury.actor.arrow( centers, directions, - window.colors.yellow, + fury.window.colors.yellow, heights, resolution=20, tip_length=0.06, @@ -96,12 +96,12 @@ def update_coordinates(wavenumber, ang_frq, time, phase_angle): pts = np.array(list(zip(x, y, z))) pts = [pts] -colors = window.colors.red -wave_actor1 = actor.line(pts, colors, linewidth=3) +colors = fury.window.colors.red +wave_actor1 = fury.actor.line(pts, colors, linewidth=3) scene.add(wave_actor1) -vertices = utils.vertices_from_actor(wave_actor1) -vcolors = utils.colors_from_actor(wave_actor1, "colors") +vertices = fury.utils.vertices_from_actor(wave_actor1) +vcolors = fury.utils.colors_from_actor(wave_actor1, "colors") no_vertices_per_point = len(vertices) / npoints initial_vertices = vertices.copy() - np.repeat(pts, no_vertices_per_point, axis=0) @@ -115,12 +115,12 @@ def update_coordinates(wavenumber, ang_frq, time, phase_angle): pts2 = np.array(list(zip(xx, yy, zz))) pts2 = [pts2] -colors2 = window.colors.blue -wave_actor2 = actor.line(pts2, colors2, linewidth=3) +colors2 = fury.window.colors.blue +wave_actor2 = fury.actor.line(pts2, colors2, linewidth=3) scene.add(wave_actor2) -vertices2 = utils.vertices_from_actor(wave_actor2) -vcolors2 = utils.colors_from_actor(wave_actor2, "colors") +vertices2 = fury.utils.vertices_from_actor(wave_actor2) +vcolors2 = fury.utils.colors_from_actor(wave_actor2, "colors") no_vertices_per_point2 = len(vertices2) / npoints initial_vertices2 = vertices2.copy() - np.repeat(pts2, no_vertices_per_point2, axis=0) @@ -128,7 +128,7 @@ def update_coordinates(wavenumber, ang_frq, time, phase_angle): ############################################################################### # Initializing text box to display the title of the animation -tb = ui.TextBlock2D(bold=True, position=(160, 90)) +tb = fury.ui.TextBlock2D(bold=True, position=(160, 90)) tb.message = "Electromagnetic Wave" scene.add(tb) @@ -156,12 +156,12 @@ def timer_callback(_obj, _event): x, y, z = update_coordinates(wavenumber, angular_frq, phase_angle, time) pts = np.array(list(zip(x, y, z))) vertices[:] = initial_vertices + np.repeat(pts, no_vertices_per_point, axis=0) - utils.update_actor(wave_actor1) + fury.utils.update_actor(wave_actor1) xx, zz, yy = update_coordinates(wavenumber, angular_frq, phase_angle, time) pts2 = np.array(list(zip(xx, yy, zz))) vertices2[:] = initial_vertices2 + np.repeat(pts2, no_vertices_per_point2, axis=0) - utils.update_actor(wave_actor2) + fury.utils.update_actor(wave_actor2) showm.render() @@ -178,4 +178,4 @@ def timer_callback(_obj, _event): interactive = False if interactive: showm.start() -window.record(showm.scene, size=(800, 600), out_path="viz_emwave.png") +fury.window.record(showm.scene, size=(800, 600), out_path="viz_emwave.png") diff --git a/docs/examples/viz_fiber_odf.py b/docs/examples/viz_fiber_odf.py index ac327aa7f..dcc078762 100644 --- a/docs/examples/viz_fiber_odf.py +++ b/docs/examples/viz_fiber_odf.py @@ -14,17 +14,15 @@ # First, we import some useful modules and methods. import numpy as np -from fury import actor, ui, window -from fury.data import fetch_viz_dmri, fetch_viz_icons, read_viz_dmri -from fury.utils import fix_winding_order +import fury ############################################################################### # Here, we fetch and load the fiber ODF volume to display. The ODF are # expressed as spherical harmonics (SH) coefficients in a 3D grid. -fetch_viz_dmri() -fetch_viz_icons() +fury.data.fetch_viz_dmri() +fury.data.fetch_viz_icons() -fodf_img = nib.load(read_viz_dmri("fodf.nii.gz")) +fodf_img = nib.load(fury.data.read_viz_dmri("fodf.nii.gz")) sh = fodf_img.get_fdata() affine = fodf_img.affine grid_shape = sh.shape[:-1] @@ -49,7 +47,7 @@ global_cm = False # ODF slicer for axial slice -odf_actor_z = actor.odf_slicer( +odf_actor_z = fury.actor.odf_slicer( sh, affine=affine, sphere=sphere_low, @@ -63,7 +61,7 @@ ) # ODF slicer for coronal slice -odf_actor_y = actor.odf_slicer( +odf_actor_y = fury.actor.odf_slicer( sh, affine=affine, sphere=sphere_low, @@ -80,7 +78,7 @@ ) # ODF slicer for sagittal slice -odf_actor_x = actor.odf_slicer( +odf_actor_x = fury.actor.odf_slicer( sh, affine=affine, sphere=sphere_low, @@ -96,18 +94,18 @@ grid_shape[0] // 2, grid_shape[0] // 2, 0, grid_shape[1] - 1, 0, grid_shape[2] - 1 ) -scene = window.Scene() +scene = fury.window.Scene() scene.add(odf_actor_z) scene.add(odf_actor_y) scene.add(odf_actor_x) -show_m = window.ShowManager(scene, reset_camera=True, size=(1200, 900)) +show_m = fury.window.ShowManager(scene, reset_camera=True, size=(1200, 900)) ############################################################################### # Now that we have a `ShowManager` containing our slicer, we can go on and # configure our UI for changing the slices to visualize. -line_slider_z = ui.LineSlider2D( +line_slider_z = fury.ui.LineSlider2D( min_value=0, max_value=grid_shape[2] - 1, initial_value=grid_shape[2] / 2, @@ -115,7 +113,7 @@ length=140, ) -line_slider_y = ui.LineSlider2D( +line_slider_y = fury.ui.LineSlider2D( min_value=0, max_value=grid_shape[1] - 1, initial_value=grid_shape[1] / 2, @@ -123,7 +121,7 @@ length=140, ) -line_slider_x = ui.LineSlider2D( +line_slider_x = fury.ui.LineSlider2D( min_value=0, max_value=grid_shape[0] - 1, initial_value=grid_shape[0] / 2, @@ -138,7 +136,9 @@ # We fix the order of the faces' three vertices to a clockwise winding. This # ensures all faces have a normal going away from the center of the sphere. -sphere_high.faces = fix_winding_order(sphere_high.vertices, sphere_high.faces, True) +sphere_high.faces = fury.utils.fix_winding_order( + sphere_high.vertices, sphere_high.faces, True +) B_high = sh_to_sf_matrix(sphere_high, 8, return_inv=False) ############################################################################### @@ -147,7 +147,7 @@ "Low resolution": (sphere_low, B_low), "High resolution": (sphere_high, B_high), } -combobox = ui.ComboBox2D(items=list(sphere_dict)) +combobox = fury.ui.ComboBox2D(items=list(sphere_dict)) scene.add(combobox) ############################################################################### @@ -186,7 +186,7 @@ def change_sphere(combobox): def build_label(text): - label = ui.TextBlock2D() + label = fury.ui.TextBlock2D() label.message = text label.font_size = 18 label.font_family = "Arial" @@ -204,7 +204,7 @@ def build_label(text): line_slider_label_y = build_label(text="Y Slice") line_slider_label_x = build_label(text="X Slice") -panel = ui.Panel2D(size=(300, 200), color=(1, 1, 1), opacity=0.1, align="right") +panel = fury.ui.Panel2D(size=(300, 200), color=(1, 1, 1), opacity=0.1, align="right") panel.center = (1030, 120) panel.add_element(line_slider_label_x, (0.1, 0.75)) @@ -245,7 +245,7 @@ def win_callback(obj, _event): show_m.render() show_m.start() else: - window.record( + fury.window.record( scene, out_path="odf_slicer_3D.png", size=(1200, 900), reset_camera=False ) diff --git a/docs/examples/viz_fine_tuning_gl_context.py b/docs/examples/viz_fine_tuning_gl_context.py index 2f11ee588..a347bf691 100644 --- a/docs/examples/viz_fine_tuning_gl_context.py +++ b/docs/examples/viz_fine_tuning_gl_context.py @@ -16,9 +16,7 @@ import numpy as np -from fury import actor, window -from fury.shaders import shader_apply_effects -from fury.utils import remove_observer_from_actor +import fury ############################################################################### # We just proceed as usual: creating the actors and initializing a scene in @@ -27,21 +25,21 @@ centers = np.array([[0, 0, 0], [-0.1, 0, 0], [0.1, 0, 0]]) colors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) -actor_no_depth_test = actor.markers( +actor_no_depth_test = fury.actor.markers( centers, marker="s", colors=colors, marker_opacity=0.5, scales=0.2, ) -actor_normal_blending = actor.markers( +actor_normal_blending = fury.actor.markers( centers - np.array([[0, -0.5, 0]]), marker="s", colors=colors, marker_opacity=0.5, scales=0.2, ) -actor_add_blending = actor.markers( +actor_add_blending = fury.actor.markers( centers - np.array([[0, -1, 0]]), marker="s", colors=colors, @@ -49,14 +47,14 @@ scales=0.2, ) -actor_sub_blending = actor.markers( +actor_sub_blending = fury.actor.markers( centers - np.array([[0, -1.5, 0]]), marker="s", colors=colors, marker_opacity=0.5, scales=0.2, ) -actor_mul_blending = actor.markers( +actor_mul_blending = fury.actor.markers( centers - np.array([[0, -2, 0]]), marker="s", colors=colors, @@ -65,11 +63,11 @@ ) -scene = window.Scene() +scene = fury.window.Scene() scene.background((0.5, 0.5, 0.5)) -showm = window.ShowManager( +showm = fury.window.ShowManager( scene, size=(900, 768), reset_camera=False, order_transparent=False ) @@ -89,36 +87,40 @@ # Here we're using the pre-build FURY window functions which has already a # set of specific behaviors to be applied in the OpenGL context -shader_apply_effects( - showm.window, actor_normal_blending, effects=window.gl_set_normal_blending +fury.shaders.shader_apply_effects( + showm.window, actor_normal_blending, effects=fury.window.gl_set_normal_blending ) # ############################################################################### # It's also possible use a list of effects. The final opengl state it'll # be the composition of each effect that each function has in the opengl state -id_observer = shader_apply_effects( +id_observer = fury.shaders.shader_apply_effects( showm.window, actor_no_depth_test, - effects=[window.gl_reset_blend, window.gl_disable_blend, window.gl_disable_depth], + effects=[ + fury.window.gl_reset_blend, + fury.window.gl_disable_blend, + fury.window.gl_disable_depth, + ], ) -shader_apply_effects( +fury.shaders.shader_apply_effects( showm.window, actor_add_blending, effects=[ - window.gl_reset_blend, - window.gl_enable_depth, - window.gl_set_additive_blending, + fury.window.gl_reset_blend, + fury.window.gl_enable_depth, + fury.window.gl_set_additive_blending, ], ) -shader_apply_effects( - showm.window, actor_sub_blending, effects=window.gl_set_subtractive_blending +fury.shaders.shader_apply_effects( + showm.window, actor_sub_blending, effects=fury.window.gl_set_subtractive_blending ) -shader_apply_effects( - showm.window, actor_mul_blending, effects=window.gl_set_multiplicative_blending +fury.shaders.shader_apply_effects( + showm.window, actor_mul_blending, effects=fury.window.gl_set_multiplicative_blending ) ############################################################################### @@ -137,9 +139,11 @@ def timer_callback(obj, event): # the results of each specific opengl-state showm.scene.azimuth(1) if cnt == 400: - remove_observer_from_actor(actor_no_depth_test, id_observer) - shader_apply_effects( - showm.window, actor_no_depth_test, effects=window.gl_set_additive_blending + fury.utils.remove_observer_from_actor(actor_no_depth_test, id_observer) + fury.shaders.shader_apply_effects( + showm.window, + actor_no_depth_test, + effects=fury.window.gl_set_additive_blending, ) if cnt == 1000: showm.exit() @@ -150,4 +154,4 @@ def timer_callback(obj, event): if interactive: showm.start() -window.record(scene, out_path="viz_fine_tuning_gl_context.png", size=(600, 600)) +fury.window.record(scene, out_path="viz_fine_tuning_gl_context.png", size=(600, 600)) diff --git a/docs/examples/viz_fractals.py b/docs/examples/viz_fractals.py index acbd3061e..a1573c194 100644 --- a/docs/examples/viz_fractals.py +++ b/docs/examples/viz_fractals.py @@ -21,7 +21,7 @@ import numpy as np -from fury import primitive, ui, utils, window +import fury ############################################################################### # Before we create our first fractal, let's set some ground rules for us to @@ -64,7 +64,7 @@ def tetrix(N): offset = (4**N - 1) // 3 + 1 # just need the vertices - U, _ = primitive.prim_tetrahedron() + U, _ = fury.primitive.prim_tetrahedron() def gen_centers(depth, pos, center, dist): if depth == N: @@ -78,7 +78,7 @@ def gen_centers(depth, pos, center, dist): # the division by sqrt(6) is to ensure correct scale gen_centers(0, 1, np.zeros(3), 2 / (6**0.5)) - vertices, faces = primitive.prim_tetrahedron() + vertices, faces = fury.primitive.prim_tetrahedron() # primitive is scaled down depending on level vertices /= 2 ** (N - 1) @@ -87,10 +87,10 @@ def gen_centers(depth, pos, center, dist): bounds_min, bounds_max = np.min(centers, axis=0), np.max(centers, axis=0) colors = (centers - bounds_min) / (bounds_max - bounds_min) - vertices, triangles, colors, _ = primitive.repeat_primitive( + vertices, triangles, colors, _ = fury.primitive.repeat_primitive( centers=centers, colors=colors, vertices=vertices, faces=faces ) - return utils.get_actor_from_primitive(vertices, triangles, colors) + return fury.utils.get_actor_from_primitive(vertices, triangles, colors) ############################################################################### @@ -149,16 +149,16 @@ def gen_centers(depth, pos, center, dist): gen_centers(0, 1, np.zeros(3), 1 / 3) - vertices, faces = primitive.prim_box() + vertices, faces = fury.primitive.prim_box() vertices /= 3**N bounds_min, bounds_max = np.min(centers, axis=0), np.max(centers, axis=0) colors = (centers - bounds_min) / (bounds_max - bounds_min) - vertices, triangles, colors, _ = primitive.repeat_primitive( + vertices, triangles, colors, _ = fury.primitive.repeat_primitive( centers=centers, colors=colors, vertices=vertices, faces=faces ) - return utils.get_actor_from_primitive(vertices, triangles, colors) + return fury.utils.get_actor_from_primitive(vertices, triangles, colors) ############################################################################### @@ -204,24 +204,24 @@ def gen_centers(depth, pos, center, side): gen_centers(0, 1, np.zeros(3), 1 / 3) - vertices, faces = primitive.prim_box() + vertices, faces = fury.primitive.prim_box() vertices /= 3**N bounds_min, bounds_max = np.min(centers, axis=0), np.max(centers, axis=0) colors = (centers - bounds_min) / (bounds_max - bounds_min) - vertices, triangles, colors, _ = primitive.repeat_primitive( + vertices, triangles, colors, _ = fury.primitive.repeat_primitive( centers=centers, colors=colors, vertices=vertices, faces=faces ) - return utils.get_actor_from_primitive(vertices, triangles, colors) + return fury.utils.get_actor_from_primitive(vertices, triangles, colors) ############################################################################### # Now that we have the functions to generate fractals, we can start setting up # the Scene and ShowManager. -scene = window.Scene() -showmgr = window.ShowManager(scene, "Fractals", (800, 800), reset_camera=True) +scene = fury.window.Scene() +showmgr = fury.window.ShowManager(scene, "Fractals", (800, 800), reset_camera=True) ############################################################################### # These values are what work nicely on my machine without lagging. If you have @@ -240,7 +240,7 @@ def gen_centers(depth, pos, center, side): "Snowflake": 2, } -shape_chooser = ui.RadioButton( +shape_chooser = fury.ui.RadioButton( options.keys(), padding=10, font_size=16, @@ -289,4 +289,4 @@ def timer_callback(_obj, _event): if interactive: showmgr.start() else: - window.record(showmgr.scene, out_path="fractals.png", size=(800, 800)) + fury.window.record(showmgr.scene, out_path="fractals.png", size=(800, 800)) diff --git a/docs/examples/viz_gltf.py b/docs/examples/viz_gltf.py index 8d1c50ca4..dbf668e82 100644 --- a/docs/examples/viz_gltf.py +++ b/docs/examples/viz_gltf.py @@ -5,20 +5,18 @@ In this tutorial, we will show how to display a glTF file in a scene. """ -from fury import window -from fury.data import fetch_gltf, read_viz_gltf -from fury.gltf import glTF +import fury ############################################################################## # Create a scene. -scene = window.Scene() +scene = fury.window.Scene() scene.SetBackground(0.1, 0.1, 0.4) ############################################################################## # Retrieving the gltf model. -fetch_gltf("Duck", "glTF") -filename = read_viz_gltf("Duck") +fury.data.fetch_gltf("Duck", "glTF") +filename = fury.data.read_viz_gltf("Duck") ############################################################################## # Initialize the glTF object and get actors using `actors` method. @@ -26,7 +24,7 @@ # or materials manually afterwards. # Experimental: For smooth mesh/actor you can set `apply_normals=True`. -gltf_obj = glTF(filename, apply_normals=False) +gltf_obj = fury.gltf.glTF(filename, apply_normals=False) actors = gltf_obj.actors() ############################################################################## @@ -44,6 +42,6 @@ interactive = False if interactive: - window.show(scene, size=(1280, 720)) + fury.window.show(scene, size=(1280, 720)) -window.record(scene, out_path="viz_gltf.png", size=(1280, 720)) +fury.window.record(scene, out_path="viz_gltf.png", size=(1280, 720)) diff --git a/docs/examples/viz_gltf_animated.py b/docs/examples/viz_gltf_animated.py index a7bf84ced..a664883c0 100644 --- a/docs/examples/viz_gltf_animated.py +++ b/docs/examples/viz_gltf_animated.py @@ -6,16 +6,14 @@ scene. """ -from fury import window -from fury.data import fetch_gltf, read_viz_gltf -from fury.gltf import glTF +import fury ############################################################################## # Create a scene. -scene = window.Scene() +scene = fury.window.Scene() -showm = window.ShowManager( +showm = fury.window.ShowManager( scene, size=(900, 768), reset_camera=False, order_transparent=True ) showm.initialize() @@ -23,14 +21,14 @@ ############################################################################## # Retrieving the gltf model. -fetch_gltf("InterpolationTest", "glTF") -filename = read_viz_gltf("InterpolationTest") +fury.data.fetch_gltf("InterpolationTest", "glTF") +filename = fury.data.read_viz_gltf("InterpolationTest") ############################################################################## # Initialize the glTF object and get actors using `actors` method. # Get the main_timeline (which contains multiple Timeline objects). -gltf_obj = glTF(filename) +gltf_obj = fury.gltf.glTF(filename) timeline = gltf_obj.main_animation() ############################################################################## @@ -54,4 +52,4 @@ def timer_callback(_obj, _event): if interactive: showm.start() -window.record(scene, out_path="viz_gltf_animated.png", size=(900, 768)) +fury.window.record(scene, out_path="viz_gltf_animated.png", size=(900, 768)) diff --git a/docs/examples/viz_gltf_export.py b/docs/examples/viz_gltf_export.py index 9d54a2f8a..bc74bd2a1 100644 --- a/docs/examples/viz_gltf_export.py +++ b/docs/examples/viz_gltf_export.py @@ -7,8 +7,7 @@ import numpy as np -from fury import actor, gltf, window -from fury.data import fetch_gltf, read_viz_gltf +import fury ############################################################################ # Specifying centers and colors for actors. We will use these parameters @@ -20,20 +19,20 @@ ############################################################################## # Create a scene. -scene = window.Scene() +scene = fury.window.Scene() ############################################################################## # Creating actors and adding to scene. -cube = actor.cube(np.add(centers, np.array([2, 0, 0])), colors=colors / 2) +cube = fury.actor.cube(np.add(centers, np.array([2, 0, 0])), colors=colors / 2) scene.add(cube) -sphere = actor.sphere(np.add(centers, np.array([0, 2, 0])), colors=colors) +sphere = fury.actor.sphere(np.add(centers, np.array([0, 2, 0])), colors=colors) scene.add(sphere) -fetch_gltf("BoxTextured", "glTF") -filename = read_viz_gltf("BoxTextured") -gltf_obj = gltf.glTF(filename) +fury.data.fetch_gltf("BoxTextured", "glTF") +filename = fury.data.read_viz_gltf("BoxTextured") +gltf_obj = fury.gltf.glTF(filename) box_actor = gltf_obj.actors() scene.add(box_actor[0]) @@ -47,12 +46,12 @@ ############################################################################## # Exporting scene as a glTF file -gltf.export_scene(scene, filename="viz_gltf_export.gltf") +fury.gltf.export_scene(scene, filename="viz_gltf_export.gltf") ############################################################################## # Reading the newly created glTF file and get actors. -gltf_obj = gltf.glTF("viz_gltf_export.gltf") +gltf_obj = fury.gltf.glTF("viz_gltf_export.gltf") actors = gltf_obj.actors() ############################################################################## @@ -63,6 +62,6 @@ interactive = False if interactive: - window.show(scene, size=(1280, 720)) + fury.window.show(scene, size=(1280, 720)) -window.record(scene, out_path="viz_gltf_export.png", size=(1280, 720)) +fury.window.record(scene, out_path="viz_gltf_export.png", size=(1280, 720)) diff --git a/docs/examples/viz_helical_motion.py b/docs/examples/viz_helical_motion.py index b17f319ff..b3cad3132 100644 --- a/docs/examples/viz_helical_motion.py +++ b/docs/examples/viz_helical_motion.py @@ -20,7 +20,7 @@ import numpy as np -from fury import actor, ui, utils, window +import fury ############################################################################### # Let's define some variable and their description: @@ -50,12 +50,12 @@ ############################################################################### # Creating a scene object and configuring the camera's position -scene = window.Scene() +scene = fury.window.Scene() scene.zoom(1.2) scene.set_camera( position=(10, 12.5, 19), focal_point=(3.0, 0.0, 0.0), view_up=(0.0, 0.0, 0.0) ) -showm = window.ShowManager( +showm = fury.window.ShowManager( scene, size=(800, 600), reset_camera=True, order_transparent=True ) @@ -64,11 +64,11 @@ # Creating a blue colored arrow which shows the direction of magnetic field and # electric field. -color_arrow = window.colors.blue # color of the arrow can be manipulated +color_arrow = fury.window.colors.blue # color of the arrow can be manipulated centers = np.array([[0, 0, 0]]) directions = np.array([[1, 0, 0]]) heights = np.array([8]) -arrow_actor = actor.arrow( +arrow_actor = fury.actor.arrow( centers, directions, color_arrow, @@ -90,13 +90,13 @@ ############################################################################### # Initializing point actor which will represent the charged particle -color_particle = window.colors.red # color of particle can be manipulated +color_particle = fury.window.colors.red # color of particle can be manipulated pts = np.array([[x, y, z]]) -charge_actor = actor.point(pts, color_particle, point_radius=radius_particle) +charge_actor = fury.actor.point(pts, color_particle, point_radius=radius_particle) scene.add(charge_actor) -vertices = utils.vertices_from_actor(charge_actor) -vcolors = utils.colors_from_actor(charge_actor, "colors") +vertices = fury.utils.vertices_from_actor(charge_actor) +vcolors = fury.utils.colors_from_actor(charge_actor, "colors") no_vertices_per_point = len(vertices) initial_vertices = vertices.copy() - np.repeat(pts, no_vertices_per_point, axis=0) @@ -104,7 +104,7 @@ ############################################################################### # Initializing text box to display the name of the animation -tb = ui.TextBlock2D(bold=True, position=(100, 90)) +tb = fury.ui.TextBlock2D(bold=True, position=(100, 90)) m1 = "Motion of a charged particle in a " m2 = "combined electric and magnetic field" tb.message = m1 + m2 @@ -143,13 +143,13 @@ def timer_callback(_obj, _event): vertices[:] = initial_vertices + np.repeat(pts, no_vertices_per_point, axis=0) - utils.update_actor(charge_actor) + fury.utils.update_actor(charge_actor) # Plotting the path followed by the particle coor_2 = np.array([x, y, z]) coors = np.array([coor_1, coor_2]) coors = [coors] - line_actor = actor.line(coors, window.colors.cyan, linewidth=3) + line_actor = fury.actor.line(coors, fury.window.colors.cyan, linewidth=3) scene.add(line_actor) coor_1 = coor_2 @@ -166,4 +166,4 @@ def timer_callback(_obj, _event): showm.add_timer_callback(True, 15, timer_callback) showm.start() -window.record(showm.scene, size=(800, 600), out_path="viz_helical_motion.png") +fury.window.record(showm.scene, size=(800, 600), out_path="viz_helical_motion.png") diff --git a/docs/examples/viz_hierarchical_animation.py b/docs/examples/viz_hierarchical_animation.py index 8b727e708..5e0772493 100644 --- a/docs/examples/viz_hierarchical_animation.py +++ b/docs/examples/viz_hierarchical_animation.py @@ -8,26 +8,25 @@ import numpy as np -from fury import actor, window -from fury.animation import Animation +import fury -scene = window.Scene() +scene = fury.window.Scene() -showm = window.ShowManager( +showm = fury.window.ShowManager( scene, size=(900, 768), reset_camera=False, order_transparent=True ) showm.initialize() ############################################################################### # Creating the road -road = actor.box( +road = fury.actor.box( np.array([[0, 0, 0]]), colors=np.array([[1, 1, 1]]), scales=np.array([[22, 0.1, 5]]) ) ############################################################################### # Constructing the car geometry -body_actor = actor.box( +body_actor = fury.actor.box( np.array([[0, 0.5, 0], [-0.2, 1, 0]]), scales=((4, 1, 2), (2.5, 1.5, 1.8)), colors=(0.6, 0.3, 0.1), @@ -35,7 +34,7 @@ ############################################################################### # Adding the the car's body to an Animation to be able to animate it later. -car_anim = Animation(body_actor) +car_anim = fury.animation.Animation(body_actor) ############################################################################### # Creating the wheels of the car @@ -50,7 +49,7 @@ ] wheels = [ - actor.cylinder( + fury.actor.cylinder( wheel_center, wheel_direction, (0.1, 0.7, 0.3), @@ -66,7 +65,7 @@ # Animating each wheel and setting its position to the right position using a # single keyframe that will not change. -wheels_animations = [Animation(wheel) for wheel in wheels] +wheels_animations = [fury.animation.Animation(wheel) for wheel in wheels] for wheel_anim in wheels_animations: wheel_anim.set_position(0.0, wheel_positions.pop()) @@ -78,13 +77,13 @@ ############################################################################### # First we create the shaft holding and rotating the radar -radar_shaft = actor.cylinder( +radar_shaft = fury.actor.cylinder( np.array([[0, 0, 0]]), np.array([[0, 1, 0]]), (0, 1, 0), heights=1 ) ############################################################################### # In order to animate the shaft actor we have to add it to an Animation -radar_shaft_anim = Animation(radar_shaft) +radar_shaft_anim = fury.animation.Animation(radar_shaft) ############################################################################### # Setting a single position keyframe will make sure the actor will be placed at @@ -99,11 +98,13 @@ ############################################################################### # Now we create the radar itself -radar = actor.cone(np.array([[0, 0, 0]]), directions=(0, 0, 0), colors=(0.2, 0.2, 0.9)) +radar = fury.actor.cone( + np.array([[0, 0, 0]]), directions=(0, 0, 0), colors=(0.2, 0.2, 0.9) +) ############################################################################### # Then add it to an animation in order to rotate it -radar_animation = Animation(radar) +radar_animation = fury.animation.Animation(radar) ############################################################################### # Set position and rotation as done above with the shaft. @@ -140,6 +141,6 @@ if interactive: showm.start() -window.record( +fury.window.record( scene, out_path="viz_keyframe_hierarchical_animation.png", size=(900, 768) ) diff --git a/docs/examples/viz_interaction.py b/docs/examples/viz_interaction.py index 7becb5964..73eb145dc 100644 --- a/docs/examples/viz_interaction.py +++ b/docs/examples/viz_interaction.py @@ -36,13 +36,11 @@ import numpy as np -from fury import actor, window -from fury.stream.client import FuryStreamClient, FuryStreamInteraction +import fury # if this example it's not working for you and you're using MacOs # uncomment the following line # multiprocessing.set_start_method('spawn') -from fury.stream.server.main import WEBRTC_AVAILABLE, web_server, web_server_raw_array if __name__ == "__main__": interactive = False @@ -77,23 +75,23 @@ centers = np.array([[0, 0, 0], [-1, 0, 0], [1, 0, 0]]) colors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) - actors = actor.sphere(centers, opacity=0.5, radii=0.4, colors=colors) - scene = window.Scene() + actors = fury.actor.sphere(centers, opacity=0.5, radii=0.4, colors=colors) + scene = fury.window.Scene() scene.add(actors) - showm = window.ShowManager(scene, size=(window_size[0], window_size[1])) + showm = fury.window.ShowManager(scene, size=(window_size[0], window_size[1])) - stream = FuryStreamClient( + stream = fury.stream.FuryStreamClient( showm, max_window_size=max_window_size, use_raw_array=use_raw_array ) - stream_interaction = FuryStreamInteraction( + stream_interaction = fury.stream.client.FuryStreamInteraction( showm, max_queue_size=max_queue_size, use_raw_array=use_raw_array ) if use_raw_array: p = multiprocessing.Process( - target=web_server_raw_array, + target=fury.stream.server.web_server_raw_array, args=( stream.img_manager.image_buffers, stream.img_manager.info_buffer, @@ -102,13 +100,13 @@ 8000, "localhost", True, - WEBRTC_AVAILABLE, + fury.stream.server.main.WEBRTC_AVAILABLE, ), ) else: p = multiprocessing.Process( - target=web_server, + target=fury.stream.server.web_server, args=( stream.img_manager.image_buffer_names, stream.img_manager.info_buffer_name, @@ -117,7 +115,7 @@ 8000, "localhost", True, - WEBRTC_AVAILABLE, + fury.stream.server.main.WEBRTC_AVAILABLE, ), ) p.start() @@ -143,4 +141,4 @@ stream.cleanup() stream_interaction.cleanup() - window.record(showm.scene, size=window_size, out_path="viz_interaction.png") + fury.window.record(showm.scene, size=window_size, out_path="viz_interaction.png") diff --git a/docs/examples/viz_interpolators.py b/docs/examples/viz_interpolators.py index d6793bb18..104bd40e1 100644 --- a/docs/examples/viz_interpolators.py +++ b/docs/examples/viz_interpolators.py @@ -15,9 +15,7 @@ import numpy as np -from fury import actor, window -from fury.animation import Animation -from fury.animation.interpolator import cubic_spline_interpolator +import fury keyframes = { 1.0: {"value": np.array([0, 0, 0])}, @@ -43,7 +41,7 @@ # Below there is an example on how to use interpolators manually to interpolate # the above defined ``keyframes``. -interpolation_function = cubic_spline_interpolator(keyframes) +interpolation_function = fury.animation.cubic_spline_interpolator(keyframes) ############################################################################### # Now, if we feed any time to this function it would return the cubic @@ -61,21 +59,21 @@ # In order to make any animations in FURY, a `ShowManager` is needed to handle # updating the animation and rendering the scene. -scene = window.Scene() +scene = fury.window.Scene() -showm = window.ShowManager( +showm = fury.window.ShowManager( scene, size=(900, 768), reset_camera=False, order_transparent=True ) showm.initialize() -arrow = actor.arrow(np.array([[0, 0, 0]]), (0, 0, 0), (1, 0, 1), scales=6) +arrow = fury.actor.arrow(np.array([[0, 0, 0]]), (0, 0, 0), (1, 0, 1), scales=6) ############################################################################### # Creating an ``Animation`` # ========================= # # First step is creating the Animation. -animation = Animation() +animation = fury.animation.Animation() ############################################################################### # Adding the sphere actor to the timeline @@ -104,7 +102,7 @@ # # Below we set the interpolator for position keyframes to be # **cubic spline interpolator**. -animation.set_position_interpolator(cubic_spline_interpolator) +animation.set_position_interpolator(fury.animation.cubic_spline_interpolator) ############################################################################### # Adding some rotation keyframes. @@ -133,4 +131,4 @@ if interactive: showm.start() -window.record(scene, out_path="viz_keyframe_interpolator.png", size=(900, 768)) +fury.window.record(scene, out_path="viz_keyframe_interpolator.png", size=(900, 768)) diff --git a/docs/examples/viz_introduction.py b/docs/examples/viz_introduction.py index f3b2673bf..55c6a124e 100644 --- a/docs/examples/viz_introduction.py +++ b/docs/examples/viz_introduction.py @@ -57,12 +57,11 @@ import numpy as np -from fury import actor, window -from fury.animation import Animation +import fury -scene = window.Scene() +scene = fury.window.Scene() -showm = window.ShowManager(scene, size=(900, 768)) +showm = fury.window.ShowManager(scene, size=(900, 768)) showm.initialize() @@ -73,11 +72,11 @@ # This is a quick demo showing how to translate a sphere from (0, 0, 0) to # (1, 1, 1). # First, we create an ``Animation``. See ``viz_interpolators.py`` tutorial -animation = Animation() +animation = fury.animation.Animation() ############################################################################### # We also create the FURY sphere actor that will be animated. -sphere = actor.sphere(np.zeros([1, 3]), np.ones([1, 3])) +sphere = fury.actor.sphere(np.zeros([1, 3]), np.ones([1, 3])) ############################################################################### # Then lets add the sphere actor to the ``Animation`` @@ -112,6 +111,6 @@ if interactive: showm.start() -window.record( +fury.window.record( scene, out_path="viz_keyframe_animation_introduction.png", size=(900, 768) ) diff --git a/docs/examples/viz_layout.py b/docs/examples/viz_layout.py index c7fd19e92..1859caf96 100644 --- a/docs/examples/viz_layout.py +++ b/docs/examples/viz_layout.py @@ -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) +) ############################################################################### @@ -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) @@ -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)) diff --git a/docs/examples/viz_markers.py b/docs/examples/viz_markers.py index 600296c2d..5a532598d 100644 --- a/docs/examples/viz_markers.py +++ b/docs/examples/viz_markers.py @@ -8,7 +8,7 @@ import numpy as np -from fury import actor, window +import fury n = 10000 @@ -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, @@ -38,14 +38,14 @@ ############################################################################ # 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) @@ -53,6 +53,6 @@ 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)) diff --git a/docs/examples/viz_morphing.py b/docs/examples/viz_morphing.py index 9bf996759..ecd229e6a 100644 --- a/docs/examples/viz_morphing.py +++ b/docs/examples/viz_morphing.py @@ -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 @@ -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 ) @@ -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)) diff --git a/docs/examples/viz_multithread.py b/docs/examples/viz_multithread.py index 33060f75f..2d491eefe 100644 --- a/docs/examples/viz_multithread.py +++ b/docs/examples/viz_multithread.py @@ -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() @@ -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: diff --git a/docs/examples/viz_network.py b/docs/examples/viz_network.py index 13140a96f..c6189fb67 100644 --- a/docs/examples/viz_network.py +++ b/docs/examples/viz_network.py @@ -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()) ############################################################################### @@ -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]) @@ -68,7 +66,7 @@ # 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, @@ -76,7 +74,7 @@ phi=8, ) -lines_actor = actor.line( +lines_actor = fury.actor.line( edgesPositions, colors=edgesColors, opacity=0.1, @@ -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) @@ -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, diff --git a/docs/examples/viz_network_animated.py b/docs/examples/viz_network_animated.py index d68a19e4c..2f144a411 100644 --- a/docs/examples/viz_network_animated.py +++ b/docs/examples/viz_network_animated.py @@ -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. @@ -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] @@ -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, @@ -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: @@ -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() @@ -225,7 +224,7 @@ def _timer(_obj, _event): # lines_actor and sphere_actor. -scene = window.Scene() +scene = fury.window.Scene() camera = scene.camera() @@ -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 ) @@ -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") diff --git a/docs/examples/viz_no_interaction.py b/docs/examples/viz_no_interaction.py index d68b70076..1a968a5ef 100644 --- a/docs/examples/viz_no_interaction.py +++ b/docs/examples/viz_no_interaction.py @@ -12,10 +12,7 @@ # multiprocessing.set_start_method('spawn') import numpy as np -from fury import actor, colormap as cmap, window -from fury.data.fetcher import fetch_viz_wiki_nw -from fury.stream.client import FuryStreamClient -from fury.stream.server.main import web_server_raw_array +import fury if __name__ == "__main__": interactive = False @@ -24,7 +21,7 @@ window_size = (400, 400) - files, folder = fetch_viz_wiki_nw() + files, folder = fury.data.fetch_viz_wiki_nw() categories_file, edges_file, positions_file = sorted(files.keys()) positions = np.loadtxt(pjoin(folder, positions_file)) categories = np.loadtxt(pjoin(folder, categories_file), dtype=str) @@ -33,7 +30,9 @@ 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] @@ -49,19 +48,19 @@ edgesPositions = np.array(edgesPositions) edgesColors = np.average(np.array(edgesColors), axis=1) - sphere_actor = actor.sdf( + sphere_actor = fury.actor.sdf( centers=positions, colors=colors, primitives="sphere", scales=radii * 0.5, ) - lines_actor = actor.line( + lines_actor = fury.actor.line( edgesPositions, colors=edgesColors, opacity=0.1, ) - scene = window.Scene() + scene = fury.window.Scene() scene.add(lines_actor) scene.add(sphere_actor) @@ -70,7 +69,7 @@ position=(0, 0, 1000), focal_point=(0.0, 0.0, 0.0), view_up=(0.0, 0.0, 0.0) ) - showm = window.ShowManager( + showm = fury.window.ShowManager( scene, reset_camera=False, size=(window_size[0], window_size[1]), @@ -82,9 +81,9 @@ ms = 0 - stream = FuryStreamClient(showm, use_raw_array=True) + stream = fury.stream.FuryStreamClient(showm, use_raw_array=True) p = multiprocessing.Process( - target=web_server_raw_array, + target=fury.stream.server.web_server_raw_array, args=( stream.img_manager.image_buffers, stream.img_manager.info_buffer, @@ -100,4 +99,4 @@ stream.stop() stream.cleanup() - window.record(showm.scene, size=window_size, out_path="viz_no_interaction.png") + fury.window.record(showm.scene, size=window_size, out_path="viz_no_interaction.png") diff --git a/docs/examples/viz_pbr_interactive.py b/docs/examples/viz_pbr_interactive.py index 3238e8ac5..768363919 100644 --- a/docs/examples/viz_pbr_interactive.py +++ b/docs/examples/viz_pbr_interactive.py @@ -9,14 +9,7 @@ Let's start by importing the necessary modules: """ -from fury import actor, material, ui, window -from fury.data import fetch_viz_cubemaps, read_viz_cubemap -from fury.io import load_cubemap_texture -from fury.utils import ( - normals_from_actor, - tangents_from_direction_of_anisotropy, - tangents_to_actor, -) +import fury ############################################################################### # The following functions will help us to manage the sliders events. @@ -40,22 +33,22 @@ def change_slice_anisotropy(slider): def change_slice_anisotropy_direction_x(slider): global doa, normals, sphere doa[0] = slider.value - tangents = tangents_from_direction_of_anisotropy(normals, doa) - tangents_to_actor(sphere, tangents) + tangents = fury.utils.tangents_from_direction_of_anisotropy(normals, doa) + fury.utils.tangents_to_actor(sphere, tangents) def change_slice_anisotropy_direction_y(slider): global doa, normals, sphere doa[1] = slider.value - tangents = tangents_from_direction_of_anisotropy(normals, doa) - tangents_to_actor(sphere, tangents) + tangents = fury.utils.tangents_from_direction_of_anisotropy(normals, doa) + fury.utils.tangents_to_actor(sphere, tangents) def change_slice_anisotropy_direction_z(slider): global doa, normals, sphere doa[2] = slider.value - tangents = tangents_from_direction_of_anisotropy(normals, doa) - tangents_to_actor(sphere, tangents) + tangents = fury.utils.tangents_from_direction_of_anisotropy(normals, doa) + fury.utils.tangents_to_actor(sphere, tangents) def change_slice_anisotropy_rotation(slider): @@ -100,19 +93,19 @@ def win_callback(obj, event): ############################################################################### # Let's fetch a skybox texture from the FURY data repository. -fetch_viz_cubemaps() +fury.data.fetch_viz_cubemaps() ############################################################################### # The following function returns the full path of the 6 images composing the # skybox. -textures = read_viz_cubemap("skybox") +textures = fury.data.read_viz_cubemap("skybox") ############################################################################### # Now that we have the location of the textures, let's load them and create a # Cube Map Texture object. -cubemap = load_cubemap_texture(textures) +cubemap = fury.io.load_cubemap_texture(textures) ############################################################################### # The Scene object in FURY can handle cube map textures and extract light @@ -120,13 +113,13 @@ def win_callback(obj, event): # interactions. The ``skybox`` parameter takes as input a cube map texture and # performs the previously described process. -scene = window.Scene(skybox=cubemap) +scene = fury.window.Scene(skybox=cubemap) ############################################################################### # With the scene created, we can then populate it. In this demo we will only # add a sphere actor. -sphere = actor.sphere([[0, 0, 0]], (0.7, 0.7, 0.7), radii=2, theta=64, phi=64) +sphere = fury.actor.sphere([[0, 0, 0]], (0.7, 0.7, 0.7), radii=2, theta=64, phi=64) ############################################################################### # The direction of anisotropy (DoA) defines the direction at which all the @@ -137,17 +130,17 @@ def win_callback(obj, event): ############################################################################### # The following process gets the normals of the actor and computes the tangents # that are aligned to the provided DoA. Then it registers those tangents to the -# actor. +# fury.actor. -normals = normals_from_actor(sphere) -tangents = tangents_from_direction_of_anisotropy(normals, doa) -tangents_to_actor(sphere, tangents) +normals = fury.utils.normals_from_actor(sphere) +tangents = fury.utils.tangents_from_direction_of_anisotropy(normals, doa) +fury.utils.tangents_to_actor(sphere, tangents) ############################################################################### # With the tangents computed and in place, we have all the elements needed to # add some material properties to the actor. -pbr_params = material.manifest_pbr(sphere) +pbr_params = fury.material.manifest_pbr(sphere) ############################################################################### # Our actor is now ready to be added to the scene. @@ -157,7 +150,7 @@ def win_callback(obj, event): ############################################################################### # Let's setup now the window and the UI. -show_m = window.ShowManager( +show_m = fury.window.ShowManager( scene=scene, size=(1920, 1080), reset_camera=False, order_transparent=True ) @@ -165,7 +158,7 @@ def win_callback(obj, event): ############################################################################### # We will create one single panel with all of our labels and sliders. -control_panel = ui.Panel2D( +control_panel = fury.ui.Panel2D( (400, 500), position=(5, 5), color=(0.25, 0.25, 0.25), opacity=0.75, align="right" ) @@ -173,25 +166,25 @@ def win_callback(obj, event): # By using our previously defined function, we can easily create all the labels # we need for this demo. And then add them to the panel. -slider_label_metallic = ui.TextBlock2D(text="Metallic", font_size=16) -slider_label_roughness = ui.TextBlock2D(text="Roughness", font_size=16) -slider_label_anisotropy = ui.TextBlock2D(text="Anisotropy", font_size=16) -slider_label_anisotropy_rotation = ui.TextBlock2D( +slider_label_metallic = fury.ui.TextBlock2D(text="Metallic", font_size=16) +slider_label_roughness = fury.ui.TextBlock2D(text="Roughness", font_size=16) +slider_label_anisotropy = fury.ui.TextBlock2D(text="Anisotropy", font_size=16) +slider_label_anisotropy_rotation = fury.ui.TextBlock2D( text="Anisotropy Rotation", font_size=16 ) -slider_label_anisotropy_direction_x = ui.TextBlock2D( +slider_label_anisotropy_direction_x = fury.ui.TextBlock2D( text="Anisotropy Direction X", font_size=16 ) -slider_label_anisotropy_direction_y = ui.TextBlock2D( +slider_label_anisotropy_direction_y = fury.ui.TextBlock2D( text="Anisotropy Direction Y", font_size=16 ) -slider_label_anisotropy_direction_z = ui.TextBlock2D( +slider_label_anisotropy_direction_z = fury.ui.TextBlock2D( text="Anisotropy Direction Z", font_size=16 ) -slider_label_coat_strength = ui.TextBlock2D(text="Coat Strength", font_size=16) -slider_label_coat_roughness = ui.TextBlock2D(text="Coat Roughness", font_size=16) -slider_label_base_ior = ui.TextBlock2D(text="Base IoR", font_size=16) -slider_label_coat_ior = ui.TextBlock2D(text="Coat IoR", font_size=16) +slider_label_coat_strength = fury.ui.TextBlock2D(text="Coat Strength", font_size=16) +slider_label_coat_roughness = fury.ui.TextBlock2D(text="Coat Roughness", font_size=16) +slider_label_base_ior = fury.ui.TextBlock2D(text="Base IoR", font_size=16) +slider_label_coat_ior = fury.ui.TextBlock2D(text="Coat IoR", font_size=16) control_panel.add_element(slider_label_metallic, (0.01, 0.95)) control_panel.add_element(slider_label_roughness, (0.01, 0.86)) @@ -208,37 +201,37 @@ def win_callback(obj, event): ############################################################################### # Our sliders are created and added to the panel in the following way. -slider_slice_metallic = ui.LineSlider2D( +slider_slice_metallic = fury.ui.LineSlider2D( initial_value=pbr_params.metallic, max_value=1, length=195, text_template="{value:.1f}", ) -slider_slice_roughness = ui.LineSlider2D( +slider_slice_roughness = fury.ui.LineSlider2D( initial_value=pbr_params.roughness, max_value=1, length=195, text_template="{value:.1f}", ) -slider_slice_anisotropy = ui.LineSlider2D( +slider_slice_anisotropy = fury.ui.LineSlider2D( initial_value=pbr_params.anisotropy, max_value=1, length=195, text_template="{value:.1f}", ) -slider_slice_anisotropy_rotation = ui.LineSlider2D( +slider_slice_anisotropy_rotation = fury.ui.LineSlider2D( initial_value=pbr_params.anisotropy_rotation, max_value=1, length=195, text_template="{value:.1f}", ) -slider_slice_coat_strength = ui.LineSlider2D( +slider_slice_coat_strength = fury.ui.LineSlider2D( initial_value=pbr_params.coat_strength, max_value=1, length=195, text_template="{value:.1f}", ) -slider_slice_coat_roughness = ui.LineSlider2D( +slider_slice_coat_roughness = fury.ui.LineSlider2D( initial_value=pbr_params.coat_roughness, max_value=1, length=195, @@ -250,21 +243,21 @@ def win_callback(obj, event): # within that range we cover all the possible 3D directions needed to align the # tangents. -slider_slice_anisotropy_direction_x = ui.LineSlider2D( +slider_slice_anisotropy_direction_x = fury.ui.LineSlider2D( initial_value=doa[0], min_value=-1, max_value=1, length=195, text_template="{value:.1f}", ) -slider_slice_anisotropy_direction_y = ui.LineSlider2D( +slider_slice_anisotropy_direction_y = fury.ui.LineSlider2D( initial_value=doa[1], min_value=-1, max_value=1, length=195, text_template="{value:.1f}", ) -slider_slice_anisotropy_direction_z = ui.LineSlider2D( +slider_slice_anisotropy_direction_z = fury.ui.LineSlider2D( initial_value=doa[2], min_value=-1, max_value=1, @@ -277,14 +270,14 @@ def win_callback(obj, event): # cases, the values are defined in the range [1, 2.3] according to the # documentation of the material. -slider_slice_base_ior = ui.LineSlider2D( +slider_slice_base_ior = fury.ui.LineSlider2D( initial_value=pbr_params.base_ior, min_value=1, max_value=2.3, length=195, text_template="{value:.02f}", ) -slider_slice_coat_ior = ui.LineSlider2D( +slider_slice_coat_ior = fury.ui.LineSlider2D( initial_value=pbr_params.coat_ior, min_value=1, max_value=2.3, @@ -343,4 +336,4 @@ def win_callback(obj, event): if interactive: show_m.start() -window.record(scene, size=(1920, 1080), out_path="viz_pbr_interactive.png") +fury.window.record(scene, size=(1920, 1080), out_path="viz_pbr_interactive.png") diff --git a/docs/examples/viz_pbr_spheres.py b/docs/examples/viz_pbr_spheres.py index 318fcc51e..e0cfa6f59 100644 --- a/docs/examples/viz_pbr_spheres.py +++ b/docs/examples/viz_pbr_spheres.py @@ -17,17 +17,12 @@ import numpy as np -from fury import actor, material, window -from fury.utils import ( - normals_from_actor, - tangents_from_direction_of_anisotropy, - tangents_to_actor, -) +import fury ############################################################################### # Now set up a new scene. -scene = window.Scene() +scene = fury.window.Scene() scene.background((0.9, 0.9, 0.9)) ############################################################################### @@ -59,13 +54,15 @@ center = [[0, -5 * i, 0]] for j in range(num_values): center[0][0] = -25 + 5 * j - sphere = actor.sphere(center, color, radii=2, theta=32, phi=32) - normals = normals_from_actor(sphere) - tangents = tangents_from_direction_of_anisotropy(normals, (0, 1, 0.5)) - tangents_to_actor(sphere, tangents) + sphere = fury.actor.sphere(center, color, radii=2, theta=32, phi=32) + normals = fury.utils.normals_from_actor(sphere) + tangents = fury.utils.tangents_from_direction_of_anisotropy( + normals, (0, 1, 0.5) + ) + fury.utils.tangents_to_actor(sphere, tangents) keys = list(params) params[keys[0]] = np.round(0.1 * j, decimals=1) - material.manifest_pbr(sphere, **params) + fury.material.manifest_pbr(sphere, **params) scene.add(sphere) ############################################################################### @@ -83,12 +80,14 @@ for i, name in enumerate(labels): pos = [-40, -5 * i, 0] - label = actor.vector_text(name, pos=pos, scale=(0.8, 0.8, 0.8), color=(0, 0, 0)) + label = fury.actor.vector_text( + name, pos=pos, scale=(0.8, 0.8, 0.8), color=(0, 0, 0) + ) scene.add(label) for j in range(num_values): pos = [-26 + 5 * j, 3, 0] - label = actor.vector_text( + label = fury.actor.vector_text( str(np.round(j * 0.1, decimals=1)), pos=pos, scale=(0.8, 0.8, 0.8), @@ -123,10 +122,10 @@ center = [[0, -35 - (5 * i), 0]] for j in range(num_values): center[0][0] = -25 + 5 * j - sphere = actor.sphere(center, color, radii=2, theta=32, phi=32) + sphere = fury.actor.sphere(center, color, radii=2, theta=32, phi=32) keys = list(params) params[keys[0]] = iors[j] - material.manifest_pbr(sphere, **params) + fury.material.manifest_pbr(sphere, **params) scene.add(sphere) ############################################################################### @@ -136,12 +135,14 @@ for i, name in enumerate(labels): pos = [-40, -35 - (5 * i), 0] - label = actor.vector_text(name, pos=pos, scale=(0.8, 0.8, 0.8), color=(0, 0, 0)) + label = fury.actor.vector_text( + name, pos=pos, scale=(0.8, 0.8, 0.8), color=(0, 0, 0) + ) scene.add(label) for j in range(num_values): pos = [-26 + 5 * j, -32, 0] - label = actor.vector_text( + label = fury.actor.vector_text( "{:.02f}".format(iors[j]), pos=pos, scale=(0.8, 0.8, 0.8), color=(0, 0, 0) ) scene.add(label) @@ -151,6 +152,6 @@ interactive = False if interactive: - window.show(scene) + fury.window.show(scene) -window.record(scene, size=(600, 600), out_path="viz_pbr_spheres.png") +fury.window.record(scene, size=(600, 600), out_path="viz_pbr_spheres.png") diff --git a/docs/examples/viz_picking.py b/docs/examples/viz_picking.py index 772ca79d5..954cc9d5a 100644 --- a/docs/examples/viz_picking.py +++ b/docs/examples/viz_picking.py @@ -13,7 +13,7 @@ import numpy as np -from fury import actor, pick, ui, utils, window +import fury centers = 0.5 * np.array([[0, 0, 0], [100, 0, 0], [200, 0, 0.0]]) colors = np.array([[0.8, 0, 0], [0, 0.8, 0], [0, 0, 0.8]]) @@ -24,18 +24,18 @@ ############################################################################### # Let's create a panel to show what is picked -panel = ui.Panel2D(size=(400, 200), color=(1, 0.5, 0.0), align="right") +panel = fury.ui.Panel2D(size=(400, 200), color=(1, 0.5, 0.0), align="right") panel.center = (150, 200) -text_block = ui.TextBlock2D(text="Left click on object \n") +text_block = fury.ui.TextBlock2D(text="Left click on object \n") panel.add_element(text_block, (0.3, 0.3)) ############################################################################### # Build scene and add an actor with many objects. -scene = window.Scene() +scene = fury.window.Scene() -label_actor = actor.vector_text(text="Test") +label_actor = fury.actor.vector_text(text="Test") ############################################################################### # This actor is made with 3 cubes of different orientation @@ -47,23 +47,23 @@ [0, np.sqrt(2) / 2, np.sqrt(2) / 2], ] ) -fury_actor = actor.cube(centers, directions, colors, scales=radii) +fury_actor = fury.actor.cube(centers, directions, colors, scales=radii) ############################################################################### # Access the memory of the vertices of all the cubes -vertices = utils.vertices_from_actor(fury_actor) +vertices = fury.utils.vertices_from_actor(fury_actor) num_vertices = vertices.shape[0] num_objects = centers.shape[0] ############################################################################### # Access the memory of the colors of all the cubes -vcolors = utils.colors_from_actor(fury_actor, "colors") +vcolors = fury.utils.colors_from_actor(fury_actor, "colors") ############################################################################### # Adding an actor showing the axes of the world coordinates -ax = actor.axes(scale=(10, 10, 10)) +ax = fury.actor.axes(scale=(10, 10, 10)) scene.add(fury_actor) scene.add(label_actor) @@ -73,7 +73,7 @@ ############################################################################### # Create the Picking manager -pickm = pick.PickingManager() +pickm = fury.pick.PickingManager() ############################################################################### # Time to make the callback which will be called when we pick an object @@ -117,7 +117,7 @@ def left_click_callback(obj, event): vcolors[object_index * sec : object_index * sec + sec] += color_add # Tell actor that memory is modified - utils.update_actor(fury_actor) + fury.utils.update_actor(fury_actor) face_index = picked_info["face"] @@ -139,7 +139,7 @@ def left_click_callback(obj, event): ############################################################################### # Make the window appear -showm = window.ShowManager(scene, size=(1024, 768), order_transparent=True) +showm = fury.window.ShowManager(scene, size=(1024, 768), order_transparent=True) scene.add(panel) @@ -155,4 +155,4 @@ def left_click_callback(obj, event): ############################################################################### # Save the current framebuffer in a PNG file -window.record(showm.scene, size=(1024, 768), out_path="viz_picking.png") +fury.window.record(showm.scene, size=(1024, 768), out_path="viz_picking.png") diff --git a/docs/examples/viz_play_video.py b/docs/examples/viz_play_video.py index 920d2b1a7..dde63d78d 100644 --- a/docs/examples/viz_play_video.py +++ b/docs/examples/viz_play_video.py @@ -12,7 +12,7 @@ import cv2 import numpy as np -from fury import actor, window +import fury # The VideoCapturer Class @@ -48,16 +48,16 @@ def __init__(self, video, time=10): # Initialize Scene self.initialize_scene() # Create a Show Manager and Initialize it - self.show_manager = window.ShowManager( + self.show_manager = fury.window.ShowManager( self.scene, size=(900, 768), reset_camera=False, order_transparent=True ) # Initialize the Scene with actors def initialize_scene(self): - self.scene = window.Scene() + self.scene = fury.window.Scene() # Initialize a Plane actor with the 1st video frame along with # the actor grid which is to be updated in each iteration - self.plane_actor = actor.texture(self.current_video_frame) + self.plane_actor = fury.actor.texture(self.current_video_frame) self.scene.add(self.plane_actor) # The timer_callback function getting called by the show manager @@ -66,7 +66,7 @@ def timer_callback(self, _obj, _event): if isinstance(self.current_video_frame, np.ndarray): # update texture of the actor with the current frame image # by updating the actor grid - actor.texture_update(self.plane_actor, self.current_video_frame) + fury.actor.texture_update(self.plane_actor, self.current_video_frame) self.show_manager.scene.azimuth(1.5) # to rotate the camera else: self.show_manager.exit() @@ -90,4 +90,6 @@ def run(self): ) vp = VideoPlayer(video_url) vp.run() -window.record(vp.show_manager.scene, out_path="viz_play_video.png", size=(600, 600)) +fury.window.record( + vp.show_manager.scene, out_path="viz_play_video.png", size=(600, 600) +) diff --git a/docs/examples/viz_principled_spheres.py b/docs/examples/viz_principled_spheres.py index 018672433..82ded4337 100644 --- a/docs/examples/viz_principled_spheres.py +++ b/docs/examples/viz_principled_spheres.py @@ -21,12 +21,12 @@ import numpy as np -from fury import actor, material, window +import fury ############################################################################### # Now set up a new scene. -scene = window.Scene() +scene = fury.window.Scene() scene.background((0.9, 0.9, 0.9)) ############################################################################### @@ -56,12 +56,12 @@ center = np.array([[0, -5 * i, 0]]) for j in range(11): center[0][0] = -25 + 5 * j - sphere = actor.sphere( + sphere = fury.actor.sphere( center, colors=material_params[i][0], radii=2, theta=32, phi=32 ) keys = list(material_params[i][1]) material_params[i][1][keys[0]] = np.round(0.1 * j, decimals=1) - material.manifest_principled(sphere, **material_params[i][1]) + fury.material.manifest_principled(sphere, **material_params[i][1]) scene.add(sphere) ############################################################################### @@ -82,14 +82,14 @@ for i in range(10): pos = [-40, -5 * i, 0] - label = actor.vector_text( + label = fury.actor.vector_text( labels[i], pos=pos, scale=(0.8, 0.8, 0.8), color=(0, 0, 0) ) scene.add(label) for j in range(11): pos = [-26 + 5 * j, 5, 0] - label = actor.vector_text( + label = fury.actor.vector_text( str(np.round(j * 0.1, decimals=1)), pos=pos, scale=(0.8, 0.8, 0.8), @@ -102,6 +102,6 @@ interactive = False if interactive: - window.show(scene) + fury.window.show(scene) -window.record(scene, size=(600, 600), out_path="viz_principled_spheres.png") +fury.window.record(scene, size=(600, 600), out_path="viz_principled_spheres.png") diff --git a/docs/examples/viz_radio_buttons.py b/docs/examples/viz_radio_buttons.py index 71dd1c6fe..e10e5f376 100644 --- a/docs/examples/viz_radio_buttons.py +++ b/docs/examples/viz_radio_buttons.py @@ -11,13 +11,12 @@ import numpy as np -from fury import actor, ui, utils, window -from fury.data import fetch_viz_icons +import fury ############################################################################## # First we need to fetch some icons that are included in FURY. -fetch_viz_icons() +fury.data.fetch_viz_icons() ######################################################################## # Sphere and Radio Buttons @@ -25,7 +24,7 @@ # # Add a Sphere to the scene. -sphere = actor.sphere( +sphere = fury.actor.sphere( centers=np.array([[50, 0, 0]]), colors=np.array([[0, 0, 1]]), radii=11.0, @@ -36,7 +35,7 @@ # Creating a dict of possible options and mapping it with their values. options = {"Blue": (0, 0, 255), "Red": (255, 0, 0), "Green": (0, 255, 0)} -color_toggler = ui.RadioButton( +color_toggler = fury.ui.RadioButton( list(options), checked_labels=["Blue"], padding=1, @@ -48,10 +47,10 @@ # A callback which will set the values for the box def toggle_color(radio): - vcolors = utils.colors_from_actor(sphere) + vcolors = fury.utils.colors_from_actor(sphere) color = options[radio.checked_labels[0]] vcolors[:] = np.array(color) - utils.update_actor(sphere) + fury.utils.update_actor(sphere) color_toggler.on_change = toggle_color @@ -65,7 +64,7 @@ def toggle_color(radio): # manager. current_size = (800, 800) -show_manager = window.ShowManager(size=current_size, title="FURY Sphere Example") +show_manager = fury.window.ShowManager(size=current_size, title="FURY Sphere Example") show_manager.scene.add(sphere) show_manager.scene.add(color_toggler) @@ -82,4 +81,6 @@ def toggle_color(radio): if interactive: show_manager.start() -window.record(show_manager.scene, size=current_size, out_path="viz_radio_buttons.png") +fury.window.record( + show_manager.scene, size=current_size, out_path="viz_radio_buttons.png" +) diff --git a/docs/examples/viz_robot_arm_animation.py b/docs/examples/viz_robot_arm_animation.py index 1e9485d02..b35fd105c 100644 --- a/docs/examples/viz_robot_arm_animation.py +++ b/docs/examples/viz_robot_arm_animation.py @@ -8,13 +8,11 @@ import numpy as np -from fury import actor, window -from fury.animation import Animation, Timeline -from fury.utils import set_actor_origin +import fury -scene = window.Scene() +scene = fury.window.Scene() -showm = window.ShowManager( +showm = fury.window.ShowManager( scene, size=(900, 768), reset_camera=False, order_transparent=True ) showm.initialize() @@ -23,16 +21,20 @@ ############################################################################### # Creating robot arm components -base = actor.cylinder( +base = fury.actor.cylinder( np.array([[0, 0, 0]]), np.array([[0, 1, 0]]), colors=(0, 1, 0), radius=1 ) -main_arm = actor.box(np.array([[0, 0, 0]]), colors=(1, 0.5, 0), scales=(12, 1, 1)) +main_arm = fury.actor.box(np.array([[0, 0, 0]]), colors=(1, 0.5, 0), scales=(12, 1, 1)) -sub_arm = actor.box(np.array([[0, 0, 0]]), colors=(0, 0.5, 0.8), scales=(8, 0.7, 0.7)) -joint_1 = actor.sphere(np.array([[0, 0, 0]]), colors=np.array([1, 0, 1]), radii=1.2) -joint_2 = actor.sphere(np.array([[0, 0, 0]]), colors=np.array([1, 0, 1])) +sub_arm = fury.actor.box( + np.array([[0, 0, 0]]), colors=(0, 0.5, 0.8), scales=(8, 0.7, 0.7) +) +joint_1 = fury.actor.sphere( + np.array([[0, 0, 0]]), colors=np.array([1, 0, 1]), radii=1.2 +) +joint_2 = fury.actor.sphere(np.array([[0, 0, 0]]), colors=np.array([1, 0, 1])) -end = actor.cone( +end = fury.actor.cone( np.array([[0, 0, 0]]), np.array([[1, 0, 0]]), np.array([[1, 0, 0]]), @@ -42,18 +44,18 @@ ############################################################################### # Setting the center of both shafts to the beginning. -set_actor_origin(main_arm, np.array([-6, 0, 0])) -set_actor_origin(sub_arm, np.array([-4, 0, 0])) +fury.utils.set_actor_origin(main_arm, np.array([-6, 0, 0])) +fury.utils.set_actor_origin(sub_arm, np.array([-4, 0, 0])) ############################################################################### # Creating a timeline -timeline = Timeline(playback_panel=True) +timeline = fury.animation.Timeline(playback_panel=True) ############################################################################### # Creating animations -main_arm_animation = Animation([main_arm, joint_1], length=2 * np.pi) -child_arm_animation = Animation([sub_arm, joint_2]) -drill_animation = Animation(end) +main_arm_animation = fury.animation.Animation([main_arm, joint_1], length=2 * np.pi) +child_arm_animation = fury.animation.Animation([sub_arm, joint_2]) +drill_animation = fury.animation.Animation(end) ############################################################################### @@ -119,4 +121,4 @@ def rot_drill(t): if interactive: showm.start() -window.record(scene, out_path="viz_robot_arm.png", size=(900, 768)) +fury.window.record(scene, out_path="viz_robot_arm.png", size=(900, 768)) diff --git a/docs/examples/viz_roi_contour.py b/docs/examples/viz_roi_contour.py index 17590a3df..1a8b07806 100644 --- a/docs/examples/viz_roi_contour.py +++ b/docs/examples/viz_roi_contour.py @@ -24,8 +24,7 @@ from dipy.tracking import utils from dipy.tracking.streamline import Streamlines -from fury import actor, window -from fury.colormap import line_colors +import fury ############################################################################### # First, we need to generate some streamlines. For a more complete @@ -39,7 +38,7 @@ white_matter = (labels == 1) | (labels == 2) -csa_model = CsaOdfModel(gtab, sh_order=6) +csa_model = CsaOdfModel(gtab, sh_order_max=6) csa_peaks = peaks_from_model( csa_model, data, @@ -63,7 +62,7 @@ ############################################################################### # We will create a streamline actor from the streamlines. -streamlines_actor = actor.line(streamlines, line_colors(streamlines)) +streamlines_actor = fury.actor.line(streamlines, fury.colormap.line_colors(streamlines)) ############################################################################### # Next, we create a surface actor from the corpus callosum seed ROI. We @@ -74,7 +73,7 @@ surface_opacity = 0.5 surface_color = [0, 1, 1] -seedroi_actor = actor.contour_from_roi( +seedroi_actor = fury.actor.contour_from_roi( seed_mask, affine, surface_color, surface_opacity ) @@ -82,7 +81,7 @@ # Next, we initialize a ''Scene'' object and add both actors # to the rendering. -scene = window.Scene() +scene = fury.window.Scene() scene.add(streamlines_actor) scene.add(seedroi_actor) @@ -92,9 +91,9 @@ interactive = False if interactive: - window.show(scene) + fury.window.show(scene) # scene.zoom(1.5) # scene.reset_clipping_range() -window.record(scene, out_path="contour_from_roi_tutorial.png", size=(600, 600)) +fury.window.record(scene, out_path="contour_from_roi_tutorial.png", size=(600, 600)) diff --git a/docs/examples/viz_sdf_cylinder.py b/docs/examples/viz_sdf_cylinder.py index bebeb4f30..30cfa00db 100644 --- a/docs/examples/viz_sdf_cylinder.py +++ b/docs/examples/viz_sdf_cylinder.py @@ -19,13 +19,7 @@ import numpy as np -from fury import actor, window -from fury.shaders import ( - attribute_to_actor, - compose_shader, - import_fury_shader, - shader_to_actor, -) +import fury ############################################################################### # Cylinder using polygons @@ -87,7 +81,7 @@ # of sides used to define the bases of the cylinder) to see how it changes the # surface of the primitive. -cylinders_8 = actor.cylinder( +cylinders_8 = fury.actor.cylinder( centers[:3], dirs[:3], colors[:3], @@ -96,7 +90,7 @@ capped=True, resolution=8, ) -cylinders_16 = actor.cylinder( +cylinders_16 = fury.actor.cylinder( centers[3:6], dirs[3:6], colors[3:6], @@ -105,7 +99,7 @@ capped=True, resolution=16, ) -cylinders_32 = actor.cylinder( +cylinders_32 = fury.actor.cylinder( centers[6:9], dirs[6:9], colors[6:9], @@ -118,7 +112,7 @@ ############################################################################### # Next, we set up a new scene to add and visualize the actors created. -scene = window.Scene() +scene = fury.window.Scene() scene.add(cylinders_8) scene.add(cylinders_16) @@ -127,9 +121,9 @@ interactive = False if interactive: - window.show(scene) + fury.window.show(scene) -window.record(scene, size=(600, 600), out_path="viz_poly_cylinder.png") +fury.window.record(scene, size=(600, 600), out_path="viz_poly_cylinder.png") ############################################################################### # Visualize the surface geometry representation for the object. @@ -139,9 +133,9 @@ cylinders_32.GetProperty().SetRepresentationToWireframe() if interactive: - window.show(scene) + fury.window.show(scene) -window.record(scene, size=(600, 600), out_path="viz_poly_cylinder_geom.png") +fury.window.record(scene, size=(600, 600), out_path="viz_poly_cylinder_geom.png") ############################################################################### # Then we clean the scene to render the boxes we will use to render our @@ -167,7 +161,7 @@ # Now we create cylinders using box actor and SDF implementation on shaders. # For this, we first create a box actor. -box_actor = actor.box( +box_actor = fury.actor.box( centers=centers, directions=dirs, colors=colors, @@ -187,10 +181,10 @@ rep_radii = np.repeat(np.repeat(radius, 9), 8, axis=0) rep_heights = np.repeat(np.repeat(height, 9), 8, axis=0) -attribute_to_actor(box_actor, rep_centers, "center") -attribute_to_actor(box_actor, rep_directions, "direction") -attribute_to_actor(box_actor, rep_radii, "radius") -attribute_to_actor(box_actor, rep_heights, "height") +fury.shaders.attribute_to_actor(box_actor, rep_centers, "center") +fury.shaders.attribute_to_actor(box_actor, rep_directions, "direction") +fury.shaders.attribute_to_actor(box_actor, rep_radii, "radius") +fury.shaders.attribute_to_actor(box_actor, rep_heights, "height") ############################################################################### # Then we have the shader code implementation corresponding to vertex and @@ -225,7 +219,7 @@ # to apply our implementation to the shader creation process, this function # joins our code to the shader template that FURY has by default. -shader_to_actor(box_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) +fury.shaders.shader_to_actor(box_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) ############################################################################### # Fragment shaders are used to define the colors of each pixel being processed, @@ -252,14 +246,14 @@ # to transform our position vectors in order to align the direction of # cylinder with respect to the box. -vec_to_vec_rot_mat = import_fury_shader( +vec_to_vec_rot_mat = fury.shaders.import_fury_shader( os.path.join("utils", "vec_to_vec_rot_mat.glsl") ) ############################################################################### # We calculate the distance using the SDF function for the cylinder. -sd_cylinder = import_fury_shader(os.path.join("sdf", "sd_cylinder.frag")) +sd_cylinder = fury.shaders.import_fury_shader(os.path.join("sdf", "sd_cylinder.frag")) ############################################################################### # This is used on calculations for surface normals of the cylinder. @@ -283,24 +277,28 @@ ############################################################################### # We use central differences technique for computing surface normals. -central_diffs_normal = import_fury_shader(os.path.join("sdf", "central_diffs.frag")) +central_diffs_normal = fury.shaders.import_fury_shader( + os.path.join("sdf", "central_diffs.frag") +) ############################################################################### # We use cast_ray for the implementation of Ray Marching. -cast_ray = import_fury_shader(os.path.join("ray_marching", "cast_ray.frag")) +cast_ray = fury.shaders.import_fury_shader( + os.path.join("ray_marching", "cast_ray.frag") +) ############################################################################### # For the illumination of the scene we use the Blinn-Phong model. -blinn_phong_model = import_fury_shader( +blinn_phong_model = fury.shaders.import_fury_shader( os.path.join("lighting", "blinn_phong_model.frag") ) ############################################################################### # Now we use compose_shader to join our pieces of GLSL shader code. -fs_dec = compose_shader( +fs_dec = fury.shaders.compose_shader( [ fs_vars_dec, vec_to_vec_rot_mat, @@ -312,7 +310,7 @@ ] ) -shader_to_actor(box_actor, "fragment", decl_code=fs_dec) +fury.shaders.shader_to_actor(box_actor, "fragment", decl_code=fs_dec) ############################################################################### # Here we have the implementation of all the previous code with all the @@ -350,7 +348,9 @@ } """ -shader_to_actor(box_actor, "fragment", impl_code=sdf_cylinder_frag_impl, block="light") +fury.shaders.shader_to_actor( + box_actor, "fragment", impl_code=sdf_cylinder_frag_impl, block="light" +) ############################################################################### # Finally, we visualize the cylinders made using ray marching and SDFs. @@ -358,9 +358,9 @@ scene.add(box_actor) if interactive: - window.show(scene) + fury.window.show(scene) -window.record(scene, size=(600, 600), out_path="viz_sdf_cylinder.png") +fury.window.record(scene, size=(600, 600), out_path="viz_sdf_cylinder.png") ############################################################################### # References diff --git a/docs/examples/viz_sdfactor.py b/docs/examples/viz_sdfactor.py index 1223d38aa..7d99356dc 100644 --- a/docs/examples/viz_sdfactor.py +++ b/docs/examples/viz_sdfactor.py @@ -16,7 +16,7 @@ import numpy as np -from fury import actor, window +import fury ############################################################################### # Lets define variables for the SDF Actor @@ -30,7 +30,7 @@ ############################################################################### # Create SDF Actor -sdfactor = actor.sdf( +sdfactor = fury.actor.sdf( centers=centers, directions=dirs, colors=colors, @@ -41,7 +41,7 @@ ############################################################################## # Create a scene -scene = window.Scene() +scene = fury.window.Scene() scene.background((1.0, 0.8, 0.8)) scene.add(sdfactor) @@ -53,11 +53,11 @@ # manager. current_size = (1024, 720) -showm = window.ShowManager(scene, size=current_size, title="Visualize SDF Actor") +showm = fury.window.ShowManager(scene, size=current_size, title="Visualize SDF Actor") interactive = False if interactive: showm.start() -window.record(scene, out_path="viz_sdfactor.png", size=current_size) +fury.window.record(scene, out_path="viz_sdfactor.png", size=current_size) diff --git a/docs/examples/viz_selection.py b/docs/examples/viz_selection.py index 6c0a4c485..58b71ebca 100644 --- a/docs/examples/viz_selection.py +++ b/docs/examples/viz_selection.py @@ -22,7 +22,7 @@ import numpy as np -from fury import actor, pick, utils, window +import fury ############################################################################### # Adding many cubes of different sizes and colors @@ -44,31 +44,31 @@ ############################################################################### # Build scene and add an actor with many objects. -scene = window.Scene() +scene = fury.window.Scene() ############################################################################### # Build the actor containing all the cubes -cube_actor = actor.cube(centers, directions=(1, 0, 0), colors=colors, scales=radii) +cube_actor = fury.actor.cube(centers, directions=(1, 0, 0), colors=colors, scales=radii) ############################################################################### # Access the memory of the vertices of all the cubes -vertices = utils.vertices_from_actor(cube_actor) +vertices = fury.utils.vertices_from_actor(cube_actor) num_vertices = vertices.shape[0] num_objects = centers.shape[0] ############################################################################### # Access the memory of the colors of all the cubes -vcolors = utils.colors_from_actor(cube_actor, "colors") +vcolors = fury.utils.colors_from_actor(cube_actor, "colors") ############################################################################### # Create a rectangular 2d box as a texture rgba = 255 * np.ones((100, 200, 4)) rgba[1:-1, 1:-1] = np.zeros((98, 198, 4)) + 100 -texa = actor.texture_2d(rgba.astype(np.uint8)) +texa = fury.actor.texture_2d(rgba.astype(np.uint8)) scene.add(cube_actor) scene.add(texa) @@ -78,7 +78,7 @@ ############################################################################### # Create the Selection Manager -selm = pick.SelectionManager(select="faces") +selm = fury.pick.SelectionManager(select="faces") ############################################################################### # Tell Selection Manager to avoid selecting specific actors @@ -109,14 +109,14 @@ def hover_callback(_obj, _event): vcolors[object_index * sec : object_index * sec + sec] = ( color_change ) - utils.update_actor(cube_actor) + fury.utils.update_actor(cube_actor) showm.render() ############################################################################### # Make the window appear -showm = window.ShowManager( +showm = fury.window.ShowManager( scene, size=(1024, 768), order_transparent=True, reset_camera=False ) @@ -138,4 +138,4 @@ def hover_callback(_obj, _event): ############################################################################### # Save the current framebuffer in a PNG file -window.record(showm.scene, size=(1024, 768), out_path="viz_selection.png") +fury.window.record(showm.scene, size=(1024, 768), out_path="viz_selection.png") diff --git a/docs/examples/viz_shader.py b/docs/examples/viz_shader.py index 19b1a36ba..479b42289 100644 --- a/docs/examples/viz_shader.py +++ b/docs/examples/viz_shader.py @@ -7,19 +7,17 @@ This example shows how to use shaders to generate a shaded output. We will demonstrate how to load polydata then use a custom shader calls to render a custom shaded model. -First, a bunch of imports. +First, let's import FURY """ -from fury import io, ui, utils, window -from fury.data.fetcher import fetch_viz_models, read_viz_models -from fury.shaders import add_shader_callback, shader_to_actor +import fury ############################################################################### # Let's download and load the model -fetch_viz_models() -model = read_viz_models("utah.obj") +fury.data.fetch_viz_models() +model = fury.data.read_viz_models("utah.obj") ############################################################################### @@ -28,9 +26,9 @@ # For this example we use the standard utah teapot model. # currently supported formats include OBJ, VTK, FIB, PLY, STL and XML -utah = io.load_polydata(model) -utah = utils.get_polymapper_from_polydata(utah) -utah = utils.get_actor_from_polymapper(utah) +utah = fury.io.load_polydata(model) +utah = fury.utils.get_polymapper_from_polydata(utah) +utah = fury.utils.get_actor_from_polymapper(utah) mapper = utah.GetMapper() @@ -58,16 +56,18 @@ fragOutput0 = vec4(col, fragOutput0.a); """ -shader_to_actor( +fury.shaders.shader_to_actor( utah, "vertex", impl_code=vertex_shader_code_impl, decl_code=vertex_shader_code_decl ) -shader_to_actor(utah, "fragment", decl_code=fragment_shader_code_decl) -shader_to_actor(utah, "fragment", impl_code=fragment_shader_code_impl, block="light") +fury.shaders.shader_to_actor(utah, "fragment", decl_code=fragment_shader_code_decl) +fury.shaders.shader_to_actor( + utah, "fragment", impl_code=fragment_shader_code_impl, block="light" +) ############################################################################### # Let's create a scene. -scene = window.Scene() +scene = fury.window.Scene() global timer timer = 0 @@ -98,11 +98,11 @@ def shader_callback(_caller, _event, calldata=None): pass -add_shader_callback(utah, shader_callback) +fury.shaders.add_shader_callback(utah, shader_callback) ############################################################################### # Let's add a textblock to the scene with a custom message -tb = ui.TextBlock2D() +tb = fury.ui.TextBlock2D() tb.message = "Hello Shaders" ############################################################################### @@ -112,7 +112,7 @@ def shader_callback(_caller, _event, calldata=None): # manager. current_size = (1024, 720) -showm = window.ShowManager(scene, size=current_size, reset_camera=False) +showm = fury.window.ShowManager(scene, size=current_size, reset_camera=False) showm.add_timer_callback(True, 30, timer_callback) @@ -124,4 +124,4 @@ def shader_callback(_caller, _event, calldata=None): if interactive: showm.start() -window.record(showm.scene, size=current_size, out_path="viz_shader.png") +fury.window.record(showm.scene, size=current_size, out_path="viz_shader.png") diff --git a/docs/examples/viz_shapes.py b/docs/examples/viz_shapes.py index e7e64361c..33a88ec80 100644 --- a/docs/examples/viz_shapes.py +++ b/docs/examples/viz_shapes.py @@ -10,28 +10,29 @@ First, a bunch of imports. """ -from fury import ui, window -from fury.data import fetch_viz_icons +import fury ############################################################################## # First we need to fetch some icons that are included in FURY. -fetch_viz_icons() +fury.data.fetch_viz_icons() ############################################################################### # Let's draw some simple shapes. First, a rectangle. -rect = ui.Rectangle2D(size=(100, 100), position=(400, 400), color=(1, 0, 1)) +rect = fury.ui.Rectangle2D(size=(100, 100), position=(400, 400), color=(1, 0, 1)) ############################################################################### # Then we can draw a solid circle, or disk. -disk = ui.Disk2D(outer_radius=50, center=(400, 200), color=(1, 1, 0)) +disk = fury.ui.Disk2D(outer_radius=50, center=(400, 200), color=(1, 1, 0)) ############################################################################### # Add an inner radius to make a ring. -ring = ui.Disk2D(outer_radius=50, inner_radius=45, center=(500, 600), color=(0, 1, 1)) +ring = fury.ui.Disk2D( + outer_radius=50, inner_radius=45, center=(500, 600), color=(0, 1, 1) +) ############################################################################### @@ -39,7 +40,7 @@ # manager. current_size = (800, 800) -show_manager = window.ShowManager(size=current_size, title="FURY Shapes Example") +show_manager = fury.window.ShowManager(size=current_size, title="FURY Shapes Example") show_manager.scene.add(rect) show_manager.scene.add(disk) @@ -50,4 +51,4 @@ if interactive: show_manager.start() -window.record(show_manager.scene, size=current_size, out_path="viz_shapes.png") +fury.window.record(show_manager.scene, size=current_size, out_path="viz_shapes.png") diff --git a/docs/examples/viz_skinning.py b/docs/examples/viz_skinning.py index 0657e0b1d..010fbbf1b 100644 --- a/docs/examples/viz_skinning.py +++ b/docs/examples/viz_skinning.py @@ -6,22 +6,20 @@ 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 skeletal animations. # We're choosing the `RiggedFigure` model here. -fetch_gltf("RiggedFigure", "glTF") -filename = read_viz_gltf("RiggedFigure") +fury.data.fetch_gltf("RiggedFigure", "glTF") +filename = fury.data.read_viz_gltf("RiggedFigure") ############################################################################## # Initializing the glTF object, You can additionally set `apply_normals=True`. # Note: Normals might not work well as intended with skinning animations. -gltf_obj = glTF(filename, apply_normals=False) +gltf_obj = fury.gltf.glTF(filename, apply_normals=False) ############################################################################## # Get the skinning timeline using `skin_timeline` method, Choose the animation @@ -43,8 +41,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 ) showm.initialize() @@ -73,4 +71,4 @@ def timer_callback(_obj, _event): if interactive: showm.start() -window.record(scene, out_path="viz_skinning.png", size=(900, 768)) +fury.window.record(scene, out_path="viz_skinning.png", size=(900, 768)) diff --git a/docs/examples/viz_slice.py b/docs/examples/viz_slice.py index 0a8c01303..e198b5aca 100644 --- a/docs/examples/viz_slice.py +++ b/docs/examples/viz_slice.py @@ -11,7 +11,7 @@ from dipy.data import fetch_bundles_2_subjects import nibabel as nib -from fury import actor, ui, window +import fury ############################################################################### # Let's download and load a T1. @@ -35,7 +35,7 @@ ############################################################################### # Create a Scene object which holds all the actors which we want to visualize. -scene = window.Scene() +scene = fury.window.Scene() scene.background((0.5, 0.5, 0.5)) ############################################################################### @@ -53,7 +53,7 @@ # transformation matrix. The default behavior of this function is to show the # middle slice of the last dimension of the resampled data. -slice_actor = actor.slicer(data, affine, value_range) +slice_actor = fury.actor.slicer(data, affine, value_range) ############################################################################### # The ``slice_actor`` contains an axial slice. @@ -81,12 +81,12 @@ ############################################################################### # In order to interact with the data you will need to uncomment the line below. -# window.show(scene, size=(600, 600), reset_camera=False) +# fury.window.show(scene, size=(600, 600), reset_camera=False) ############################################################################### # Otherwise, you can save a screenshot using the following command. -window.record(scene, out_path="slices.png", size=(600, 600), reset_camera=False) +fury.window.record(scene, out_path="slices.png", size=(600, 600), reset_camera=False) ############################################################################### # Render slices from FA with your colormap @@ -111,7 +111,7 @@ ############################################################################### # Notice here how the scale range is. We use FA min and max values to set it up -lut = actor.colormap_lookup_table( +lut = fury.actor.colormap_lookup_table( scale_range=(fa.min(), fa.max()), hue_range=(0.4, 1.0), saturation_range=(1, 1.0), @@ -122,7 +122,7 @@ # This is because the lookup table is applied in the slice after interpolating # to (0, 255). -fa_actor = actor.slicer(fa, affine, lookup_colormap=lut) +fa_actor = fury.actor.slicer(fa, affine, lookup_colormap=lut) scene.clear() scene.add(fa_actor) @@ -130,9 +130,11 @@ scene.reset_camera() scene.zoom(1.4) -# window.show(scene, size=(600, 600), reset_camera=False) +# fury.window.show(scene, size=(600, 600), reset_camera=False) -window.record(scene, out_path="slices_lut.png", size=(600, 600), reset_camera=False) +fury.window.record( + scene, out_path="slices_lut.png", size=(600, 600), reset_camera=False +) ############################################################################### # Now we would like to add the ability to click on a voxel and show its value @@ -142,19 +144,19 @@ # the ``ShowManager`` object, which allows accessing the pipeline in different # areas. -show_m = window.ShowManager(scene, size=(1200, 900)) +show_m = fury.window.ShowManager(scene, size=(1200, 900)) ############################################################################### # We'll start by creating the panel and adding it to the ``ShowManager`` -label_position = ui.TextBlock2D(text="Position:") -label_value = ui.TextBlock2D(text="Value:") +label_position = fury.ui.TextBlock2D(text="Position:") +label_value = fury.ui.TextBlock2D(text="Value:") -result_position = ui.TextBlock2D(text="") -result_value = ui.TextBlock2D(text="") +result_position = fury.ui.TextBlock2D(text="") +result_value = fury.ui.TextBlock2D(text="") -panel_picking = ui.Panel2D( +panel_picking = fury.ui.Panel2D( size=(250, 125), position=(20, 20), color=(0, 0, 0), opacity=0.75, align="left" ) @@ -203,7 +205,7 @@ def left_click_callback(obj, _ev): result_position.message = "" result_value.message = "" -show_m_mosaic = window.ShowManager(scene, size=(1200, 900)) +show_m_mosaic = fury.window.ShowManager(scene, size=(1200, 900)) def left_click_callback_mosaic(obj, _ev): @@ -260,4 +262,4 @@ def left_click_callback_mosaic(obj, _ev): # zoom in/out using the scroll wheel, and pick voxels with left click. -window.record(scene, out_path="mosaic.png", size=(900, 600), reset_camera=False) +fury.window.record(scene, out_path="mosaic.png", size=(900, 600), reset_camera=False) diff --git a/docs/examples/viz_solar_system.py b/docs/examples/viz_solar_system.py index 2e60bb351..ffd495d0d 100644 --- a/docs/examples/viz_solar_system.py +++ b/docs/examples/viz_solar_system.py @@ -13,21 +13,24 @@ import numpy as np -from fury import actor, io, ui, utils, window -from fury.data import fetch_viz_textures, read_viz_icons, read_viz_textures +import fury ############################################################################## # Create a scene to start. -scene = window.Scene() +scene = fury.window.Scene() # Create a panel and the start/pause buttons -panel = ui.Panel2D(size=(300, 100), color=(1, 1, 1), align="right") +panel = fury.ui.Panel2D(size=(300, 100), color=(1, 1, 1), align="right") panel.center = (400, 50) -pause_button = ui.Button2D(icon_fnames=[("square", read_viz_icons(fname="pause2.png"))]) -start_button = ui.Button2D(icon_fnames=[("square", read_viz_icons(fname="play3.png"))]) +pause_button = fury.ui.Button2D( + icon_fnames=[("square", fury.data.read_viz_icons(fname="pause2.png"))] +) +start_button = fury.ui.Button2D( + icon_fnames=[("square", fury.data.read_viz_icons(fname="play3.png"))] +) # Add the buttons on the panel @@ -91,7 +94,7 @@ }, {"filename": "8k_sun.jpg", "position": 0, "earth_days": 27, "scale": (5, 5, 5)}, ] -fetch_viz_textures() +fury.data.fetch_viz_textures() ############################################################################## # To take advantage of the previously defined data structure we are going to @@ -114,12 +117,12 @@ def init_planet(planet_data): planet_actor: actor The corresponding sphere actor with texture applied. """ - planet_file = read_viz_textures(planet_data["filename"]) - planet_image = io.load_image(planet_file) - planet_actor = actor.texture_on_sphere(planet_image) + planet_file = fury.data.read_viz_textures(planet_data["filename"]) + planet_image = fury.io.load_image(planet_file) + planet_actor = fury.actor.texture_on_sphere(planet_image) planet_actor.SetPosition(planet_data["position"], 0, 0) if planet_data["filename"] != "8k_saturn_ring_alpha.png": - utils.rotate(planet_actor, (90, 1, 0, 0)) + fury.utils.rotate(planet_actor, (90, 1, 0, 0)) planet_actor.SetScale(planet_data["scale"]) scene.add(planet_actor) return planet_actor @@ -185,7 +188,7 @@ def get_orbital_position(radius, time): def rotate_axial(actor, time, radius): axis = (0, radius, 0) angle = 50 / time - utils.rotate(actor, (angle, axis[0], axis[1], axis[2])) + fury.utils.rotate(actor, (angle, axis[0], axis[1], axis[2])) return angle @@ -198,7 +201,7 @@ def rotate_axial(actor, time, radius): # Next, create a ShowManager object. The ShowManager class is the interface # between the scene, the window and the interactor. -showm = window.ShowManager( +showm = fury.window.ShowManager( scene, size=(900, 768), reset_camera=False, order_transparent=True ) scene.add(panel) @@ -277,7 +280,7 @@ def calculate_path(r_planet, c): # This is for orbit visualization. We are using line actor for orbits. # After creating an actor we add it to the scene. -orbit_actor = actor.line(planet_tracks, colors=(1, 1, 1), linewidth=0.1) +orbit_actor = fury.actor.line(planet_tracks, colors=(1, 1, 1), linewidth=0.1) scene.add(orbit_actor) ############################################################################## @@ -331,4 +334,6 @@ def pause_animation(i_ren, _obj, _button): showm.add_timer_callback(True, 10, timer_callback) showm.start() -window.record(showm.scene, size=(900, 768), out_path="viz_solar_system_animation.png") +fury.window.record( + showm.scene, size=(900, 768), out_path="viz_solar_system_animation.png" +) diff --git a/docs/examples/viz_sphere.py b/docs/examples/viz_sphere.py index 92df3c73c..f81aae96f 100644 --- a/docs/examples/viz_sphere.py +++ b/docs/examples/viz_sphere.py @@ -7,7 +7,7 @@ import numpy as np -from fury import actor, window +import fury ############################################################################ # First thing, you have to specify centers and colors of the sphere @@ -18,7 +18,7 @@ ############################################################################ # The below sphere actor is generated by repeating the sphere primitive. -prim_sphere_actor = actor.sphere(centers, colors=colors, radii=5) +prim_sphere_actor = fury.actor.sphere(centers, colors=colors, radii=5) ############################################################################ # This time, we're using vtkSphereSource to generate the sphere actor @@ -26,9 +26,9 @@ cen2 = np.add(centers, np.array([12, 0, 0])) cols2 = np.array([1, 0, 0]) -vtk_sphere_actor = actor.sphere(cen2, colors=cols2, radii=5, use_primitive=False) +vtk_sphere_actor = fury.actor.sphere(cen2, colors=cols2, radii=5, use_primitive=False) -scene = window.Scene() +scene = fury.window.Scene() ############################################################################ # Adding our sphere actors to scene. @@ -39,6 +39,6 @@ interactive = False if interactive: - window.show(scene, size=(600, 600)) + fury.window.show(scene, size=(600, 600)) -window.record(scene, out_path="viz_sphere.png", size=(600, 600)) +fury.window.record(scene, out_path="viz_sphere.png", size=(600, 600)) diff --git a/docs/examples/viz_spiky.py b/docs/examples/viz_spiky.py index 3ab10c87c..a8de7e3ca 100644 --- a/docs/examples/viz_spiky.py +++ b/docs/examples/viz_spiky.py @@ -9,7 +9,7 @@ import numpy as np -from fury import actor, primitive, utils, window +import fury ############################################################################## # Create a sphere actor. Define the center, radius and color of a sphere. @@ -17,27 +17,27 @@ # sphere. # Let's create a scene. -scene = window.Scene() +scene = fury.window.Scene() ############################################################################## # The vertices are connected with triangles in order to specify the direction # of the surface normal. # ``prim_sphere`` provides a sphere with evenly distributed points -vertices, triangles = primitive.prim_sphere(name="symmetric362", gen_faces=False) +vertices, triangles = fury.primitive.prim_sphere(name="symmetric362", gen_faces=False) ############################################################################## # To be able to visualize the vertices, let's define a point actor with # green color. -point_actor = actor.point(vertices, point_radius=0.01, colors=(0, 1, 0)) +point_actor = fury.actor.point(vertices, point_radius=0.01, colors=(0, 1, 0)) ############################################################################## # Normals are the vectors that are perpendicular to the surface at each # vertex. We specify the normals at the vertices to tell the system # whether triangles represent curved surfaces. -normals = utils.normals_from_v_f(vertices, triangles) +normals = fury.utils.normals_from_v_f(vertices, triangles) ############################################################################## # The normals are usually used to calculate how the light will bounce on @@ -45,7 +45,7 @@ # spikes (represented with arrows). # So, let's create an arrow actor at the center of each vertex. -arrow_actor = actor.arrow( +arrow_actor = fury.actor.arrow( centers=vertices, directions=normals, colors=(1, 0, 0), @@ -61,7 +61,7 @@ primitive_colors = np.zeros(vertices.shape) primitive_colors[:, 2] = 180 -primitive_actor = utils.get_actor_from_primitive( +primitive_actor = fury.utils.get_actor_from_primitive( vertices=vertices, triangles=triangles, colors=primitive_colors, @@ -75,13 +75,13 @@ scene.add(point_actor) scene.add(arrow_actor) scene.add(primitive_actor) -scene.add(actor.axes()) +scene.add(fury.actor.axes()) ############################################################################## # The ShowManager class is the interface between the scene, the window and the # interactor. -showm = window.ShowManager( +showm = fury.window.ShowManager( scene, size=(900, 768), reset_camera=False, order_transparent=True ) @@ -108,7 +108,7 @@ def timer_callback(_obj, _event): showm.add_timer_callback(True, 200, timer_callback) showm.start() -window.record(showm.scene, size=(900, 768), out_path="viz_spiky.png") +fury.window.record(showm.scene, size=(900, 768), out_path="viz_spiky.png") ############################################################################## # Instead of arrows, you can choose other geometrical objects diff --git a/docs/examples/viz_spinbox.py b/docs/examples/viz_spinbox.py index 1fbe02f97..d7b9fdfae 100644 --- a/docs/examples/viz_spinbox.py +++ b/docs/examples/viz_spinbox.py @@ -12,18 +12,17 @@ import numpy as np -from fury import actor, ui, utils, window -from fury.data import fetch_viz_icons +import fury ############################################################################## # First we need to fetch some icons that are included in FURY. -fetch_viz_icons() +fury.data.fetch_viz_icons() ############################################################################### # Let's create a Cone. -cone = actor.cone( +cone = fury.actor.cone( centers=np.random.rand(1, 3), directions=np.random.rand(1, 3), colors=(1, 1, 1), @@ -33,7 +32,7 @@ ############################################################################### # Creating the SpinBox UI. -spinbox = ui.SpinBox( +spinbox = fury.ui.SpinBox( position=(200, 100), size=(300, 100), min_val=0, @@ -47,7 +46,7 @@ # manager. current_size = (800, 800) -show_manager = window.ShowManager(size=current_size, title="FURY SpinBox Example") +show_manager = fury.window.ShowManager(size=current_size, title="FURY SpinBox Example") show_manager.scene.add(cone) show_manager.scene.add(spinbox) @@ -62,7 +61,7 @@ def rotate_cone(spinbox): global previous_value change_in_value = spinbox.value - previous_value - utils.rotate(cone, (change_in_value, 1, 0, 0)) + fury.utils.rotate(cone, (change_in_value, 1, 0, 0)) previous_value = spinbox.value @@ -76,4 +75,4 @@ def rotate_cone(spinbox): if interactive: show_manager.start() -window.record(show_manager.scene, size=current_size, out_path="viz_spinbox.png") +fury.window.record(show_manager.scene, size=current_size, out_path="viz_spinbox.png") diff --git a/docs/examples/viz_spline_interpolator.py b/docs/examples/viz_spline_interpolator.py index c5ca86344..eff208200 100644 --- a/docs/examples/viz_spline_interpolator.py +++ b/docs/examples/viz_spline_interpolator.py @@ -8,13 +8,11 @@ import numpy as np -from fury import actor, window -from fury.animation import Animation, Timeline -from fury.animation.interpolator import spline_interpolator +import fury -scene = window.Scene() +scene = fury.window.Scene() -showm = window.ShowManager( +showm = fury.window.ShowManager( scene, size=(900, 768), reset_camera=False, order_transparent=True ) @@ -33,15 +31,15 @@ ############################################################################### # creating FURY dots to visualize the position values. -pos_dots = actor.dot(np.array(list(position_keyframes.values()))) +pos_dots = fury.actor.dot(np.array(list(position_keyframes.values()))) ############################################################################### # creating two timelines (one uses linear and the other uses' spline # interpolator), each timeline controls a sphere actor -sphere_linear = actor.sphere(np.array([[0, 0, 0]]), (1, 0.5, 0.2), 0.5) +sphere_linear = fury.actor.sphere(np.array([[0, 0, 0]]), (1, 0.5, 0.2), 0.5) -linear_anim = Animation() +linear_anim = fury.animation.Animation() linear_anim.add_actor(sphere_linear) linear_anim.set_position_keyframes(position_keyframes) @@ -53,13 +51,13 @@ ############################################################################### # creating a second timeline that translates another larger sphere actor using # spline interpolator. -sphere_spline = actor.sphere(np.array([[0, 0, 0]]), (0.3, 0.9, 0.6), 1) -spline_anim = Animation(sphere_spline) +sphere_spline = fury.actor.sphere(np.array([[0, 0, 0]]), (0.3, 0.9, 0.6), 1) +spline_anim = fury.animation.Animation(sphere_spline) spline_anim.set_position_keyframes(position_keyframes) ############################################################################### # Setting 5th degree spline interpolator for position keyframes. -spline_anim.set_position_interpolator(spline_interpolator, degree=5) +spline_anim.set_position_interpolator(fury.animation.spline_interpolator, degree=5) ############################################################################### # Wrapping animations up! @@ -69,7 +67,7 @@ ############################################################################### # First we create a timeline with a playback panel: -timeline = Timeline(playback_panel=True) +timeline = fury.animation.Timeline(playback_panel=True) ############################################################################### # Add visualization dots actor to the scene. @@ -94,4 +92,4 @@ if interactive: showm.start() -window.record(scene, out_path="viz_keyframe_animation_spline.png", size=(900, 768)) +fury.window.record(scene, out_path="viz_keyframe_animation_spline.png", size=(900, 768)) diff --git a/docs/examples/viz_surfaces.py b/docs/examples/viz_surfaces.py index 6cc62c551..fe19ecb91 100644 --- a/docs/examples/viz_surfaces.py +++ b/docs/examples/viz_surfaces.py @@ -14,9 +14,7 @@ import numpy as np -from fury import utils, window -from fury.io import load_polydata, save_polydata -from fury.lib import PolyData +import fury ############################################################################### # Import useful functions @@ -25,7 +23,7 @@ ############################################################################### # Create an empty ``PolyData`` -my_polydata = PolyData() +my_polydata = fury.lib.PolyData() ############################################################################### # Create a cube with vertices and triangles as numpy arrays @@ -65,43 +63,43 @@ ############################################################################### # Set vertices and triangles in the ``PolyData`` -utils.set_polydata_vertices(my_polydata, my_vertices) -utils.set_polydata_triangles(my_polydata, my_triangles) +fury.utils.set_polydata_vertices(my_polydata, my_vertices) +fury.utils.set_polydata_triangles(my_polydata, my_triangles) ############################################################################### # Save the ``PolyData`` file_name = "my_cube.vtk" -save_polydata(my_polydata, file_name) +fury.io.save_polydata(my_polydata, file_name) print("Surface saved in " + file_name) ############################################################################### # Load the ``PolyData`` -cube_polydata = load_polydata(file_name) +cube_polydata = fury.io.load_polydata(file_name) ############################################################################### # add color based on vertices position -cube_vertices = utils.get_polydata_vertices(cube_polydata) +cube_vertices = fury.utils.get_polydata_vertices(cube_polydata) colors = cube_vertices * 255 -utils.set_polydata_colors(cube_polydata, colors) +fury.utils.set_polydata_colors(cube_polydata, colors) print("new surface colors") -print(utils.get_polydata_colors(cube_polydata)) +print(fury.utils.get_polydata_colors(cube_polydata)) ############################################################################### # Visualize surfaces # get Actor -cube_actor = utils.get_actor_from_polydata(cube_polydata) +cube_actor = fury.utils.get_actor_from_polydata(cube_polydata) # Create a scene -scene = window.Scene() +scene = fury.window.Scene() scene.add(cube_actor) scene.set_camera(position=(10, 5, 7), focal_point=(0.5, 0.5, 0.5)) scene.zoom(3) # display -# window.show(scene, size=(600, 600), reset_camera=False) -window.record(scene, out_path="cube.png", size=(600, 600)) +# fury.window.show(scene, size=(600, 600), reset_camera=False) +fury.window.record(scene, out_path="cube.png", size=(600, 600)) diff --git a/docs/examples/viz_tab.py b/docs/examples/viz_tab.py index da6f542c1..a4814c71e 100644 --- a/docs/examples/viz_tab.py +++ b/docs/examples/viz_tab.py @@ -15,18 +15,17 @@ import numpy as np -from fury import actor, ui, window -from fury.data import fetch_viz_icons +import fury ############################################################################## # First we need to fetch some icons that are included in FURY. -fetch_viz_icons() +fury.data.fetch_viz_icons() ############################################################################### # First, we create the Tab UI. -tab_ui = ui.TabUI(position=(49, 94), size=(300, 300), nb_tabs=3, draggable=True) +tab_ui = fury.ui.TabUI(position=(49, 94), size=(300, 300), nb_tabs=3, draggable=True) ############################################################################### # We can also define the position of the Tab Bar. @@ -40,9 +39,9 @@ # # Now we prepare content for the first tab. -ring_slider = ui.RingSlider2D(initial_value=0, text_template="{angle:5.1f}°") +ring_slider = fury.ui.RingSlider2D(initial_value=0, text_template="{angle:5.1f}°") -line_slider_x = ui.LineSlider2D( +line_slider_x = fury.ui.LineSlider2D( initial_value=0, min_value=-10, max_value=10, @@ -50,7 +49,7 @@ text_alignment="Top", ) -line_slider_y = ui.LineSlider2D( +line_slider_y = fury.ui.LineSlider2D( initial_value=0, min_value=-10, max_value=10, @@ -58,7 +57,7 @@ text_alignment="Right", ) -cube = actor.box( +cube = fury.actor.box( centers=np.array([[10, 0, 0]]), directions=np.array([[0, 1, 0]]), colors=np.array([[0, 0, 1]]), @@ -105,17 +104,17 @@ def translate_cube_y(slider): # # Now we prepare content for second tab. -cylinder = actor.cylinder( +cylinder = fury.actor.cylinder( centers=np.array([[0, 0, 0]]), directions=np.array([[1, 1, 0]]), colors=np.array([[0, 1, 1]]), radius=1.0, ) -sphere = actor.sphere(centers=np.array([[5, 0, 0]]), colors=(1, 1, 0)) +sphere = fury.actor.sphere(centers=np.array([[5, 0, 0]]), colors=(1, 1, 0)) figure_dict = {"cylinder": cylinder, "sphere": sphere} -checkbox = ui.Checkbox(labels=["cylinder", "sphere"]) +checkbox = fury.ui.Checkbox(labels=["cylinder", "sphere"]) # Get difference between two lists. @@ -149,7 +148,7 @@ def set_figure_visiblity(checkboxes): # # Now we prepare content for third tab. -label = ui.TextBlock2D( +label = fury.ui.TextBlock2D( position=(600, 300), font_size=40, color=(1, 0.5, 0), @@ -168,7 +167,7 @@ def set_figure_visiblity(checkboxes): "Red": (1, 0, 0), } -color_combobox = ui.ComboBox2D( +color_combobox = fury.ui.ComboBox2D( items=list(colors.keys()), placeholder="Choose Text Color", size=(250, 150), @@ -228,7 +227,7 @@ def collapse(tab_ui): ############################################################################### # Next we prepare the scene and render it with the help of show manager. -sm = window.ShowManager(size=(800, 500), title="Viz Tab") +sm = fury.window.ShowManager(size=(800, 500), title="Viz Tab") sm.scene.add(tab_ui, cube, cylinder, sphere, label) # To interact with the ui set interactive = True @@ -237,4 +236,4 @@ def collapse(tab_ui): if interactive: sm.start() -window.record(sm.scene, size=(500, 500), out_path="viz_tab.png") +fury.window.record(sm.scene, size=(500, 500), out_path="viz_tab.png") diff --git a/docs/examples/viz_tesseract.py b/docs/examples/viz_tesseract.py index f037c9026..a66312ea4 100644 --- a/docs/examples/viz_tesseract.py +++ b/docs/examples/viz_tesseract.py @@ -14,8 +14,7 @@ import numpy as np -from fury import actor, utils, window -from fury.ui import TextBlock2D +import fury ############################################################################### # Let's define some variables and their descriptions: @@ -118,11 +117,11 @@ def connect_points(verts3D): ############################################################################### # Creating a scene object and configuring the camera's position -scene = window.Scene() +scene = fury.window.Scene() scene.set_camera( position=(0, 10, -1), focal_point=(0.0, 0.0, 0.0), view_up=(0.0, 0.0, 0.0) ) -showm = window.ShowManager(scene, size=(1920, 1080), order_transparent=True) +showm = fury.window.ShowManager(scene, size=(1920, 1080), order_transparent=True) ############################################################################### @@ -130,8 +129,8 @@ def connect_points(verts3D): verts3D = rotate4D(verts4D) if not wireframe: - points = actor.point(verts3D, colors=p_color) - point_verts = utils.vertices_from_actor(points) + points = fury.actor.point(verts3D, colors=p_color) + point_verts = fury.utils.vertices_from_actor(points) no_vertices = len(point_verts) / 16 initial_verts = point_verts.copy() - np.repeat(verts3D, no_vertices, axis=0) @@ -141,8 +140,10 @@ def connect_points(verts3D): # Connecting points with lines actor lines = connect_points(verts3D) -edges = actor.line(lines=lines, colors=e_color, lod=False, fake_tube=True, linewidth=4) -lines_verts = utils.vertices_from_actor(edges) +edges = fury.actor.line( + lines=lines, colors=e_color, lod=False, fake_tube=True, linewidth=4 +) +lines_verts = fury.utils.vertices_from_actor(edges) initial_lines = lines_verts.copy() - np.reshape(lines, (-1, 3)) scene.add(edges) @@ -150,7 +151,7 @@ def connect_points(verts3D): ############################################################################### # Initializing text box to display the name -tb = TextBlock2D(text="Tesseract", position=(900, 950), font_size=20) +tb = fury.ui.TextBlock2D(text="Tesseract", position=(900, 950), font_size=20) showm.scene.add(tb) ############################################################################### @@ -167,11 +168,11 @@ def timer_callback(_obj, _event): verts3D = rotate4D(verts4D) if not wireframe: point_verts[:] = initial_verts + np.repeat(verts3D, no_vertices, axis=0) - utils.update_actor(points) + fury.utils.update_actor(points) lines = connect_points(verts3D) lines_verts[:] = initial_lines + np.reshape(lines, (-1, 3)) - utils.update_actor(edges) + fury.utils.update_actor(edges) showm.render() angle += dtheta @@ -186,4 +187,4 @@ def timer_callback(_obj, _event): showm.add_timer_callback(True, 20, timer_callback) showm.start() -window.record(showm.scene, size=(600, 600), out_path="viz_tesseract.png") +fury.window.record(showm.scene, size=(600, 600), out_path="viz_tesseract.png") diff --git a/docs/examples/viz_texture.py b/docs/examples/viz_texture.py index 31043b706..fe46def4c 100644 --- a/docs/examples/viz_texture.py +++ b/docs/examples/viz_texture.py @@ -5,13 +5,12 @@ In this tutorial, we will show how to create a sphere with a texture. """ -from fury import actor, io, window -from fury.data import fetch_viz_textures, read_viz_textures +import fury ############################################################################## # Create a scene to start. -scene = window.Scene() +scene = fury.window.Scene() ############################################################################## # Load an image (png, bmp, jpeg or jpg) using ``io.load_image``. In this @@ -19,17 +18,17 @@ # Earth's surface from the fury Github after using ''fetch_viz_textures()'' # to download the available textures. -fetch_viz_textures() -filename = read_viz_textures("1_earth_8k.jpg") -image = io.load_image(filename) +fury.data.fetch_viz_textures() +filename = fury.data.read_viz_textures("1_earth_8k.jpg") +image = fury.io.load_image(filename) ############################################################################## -# Next, use ``actor.texture_on_sphere`` to add a sphere with the texture from +# Next, use ``fury.actor.texture_on_sphere`` to add a sphere with the texture from # your loaded image to the already existing scene. # To add a texture to your scene as visualized on a plane, use -# ``actor.texture`` instead. +# ``fury.actor.texture`` instead. -scene.add(actor.texture_on_sphere(image)) +scene.add(fury.actor.texture_on_sphere(image)) ############################################################################## # Lastly, record the scene, or set interactive to True if you would like to @@ -37,5 +36,5 @@ interactive = False if interactive: - window.show(scene, size=(600, 600), reset_camera=False) -window.record(scene, size=(900, 768), out_path="viz_texture.png") + fury.window.show(scene, size=(600, 600), reset_camera=False) +fury.window.record(scene, size=(900, 768), out_path="viz_texture.png") diff --git a/docs/examples/viz_timeline.py b/docs/examples/viz_timeline.py index 45218aacc..4e579e57f 100644 --- a/docs/examples/viz_timeline.py +++ b/docs/examples/viz_timeline.py @@ -18,14 +18,13 @@ import numpy as np -from fury import actor, window -from fury.animation import Animation, Timeline +import fury ############################################################################### # We create our ``Scene`` and ``ShowManager`` as usual. -scene = window.Scene() +scene = fury.window.Scene() -showm = window.ShowManager(scene, size=(900, 768)) +showm = fury.window.ShowManager(scene, size=(900, 768)) showm.initialize() ############################################################################### @@ -37,12 +36,12 @@ ############################################################################### # Creating a ``Timeline`` with a PlaybackPanel. -timeline = Timeline(playback_panel=True) +timeline = fury.animation.Timeline(playback_panel=True) ############################################################################### # Creating a Fury Animation as usual -anim = Animation() -sphere = actor.sphere(np.zeros([1, 3]), np.ones([1, 3])) +anim = fury.animation.Animation() +sphere = fury.actor.sphere(np.zeros([1, 3]), np.ones([1, 3])) anim.add_actor(sphere) # Now that the actor is add to the ``Animation``, setting keyframes to the # Animation will animate the actor accordingly. @@ -88,4 +87,6 @@ if interactive: showm.start() -window.record(scene, out_path="viz_keyframe_animation_timeline.png", size=(900, 768)) +fury.window.record( + scene, out_path="viz_keyframe_animation_timeline.png", size=(900, 768) +) diff --git a/docs/examples/viz_timers.py b/docs/examples/viz_timers.py index 4618cee44..e0217a7a5 100644 --- a/docs/examples/viz_timers.py +++ b/docs/examples/viz_timers.py @@ -17,24 +17,24 @@ import numpy as np -from fury import actor, ui, window +import fury xyz = 10 * np.random.rand(100, 3) colors = np.random.rand(100, 4) radii = np.random.rand(100) + 0.5 -scene = window.Scene() +scene = fury.window.Scene() -sphere_actor = actor.sphere(centers=xyz, colors=colors, radii=radii) +sphere_actor = fury.actor.sphere(centers=xyz, colors=colors, radii=radii) scene.add(sphere_actor) -showm = window.ShowManager( +showm = fury.window.ShowManager( scene, size=(900, 768), reset_camera=False, order_transparent=True ) -tb = ui.TextBlock2D(bold=True) +tb = fury.ui.TextBlock2D(bold=True) # use itertools to avoid global variables counter = itertools.count() @@ -66,4 +66,4 @@ def timer_callback(_obj, _event): showm.start() -window.record(showm.scene, size=(900, 768), out_path="viz_timer.png") +fury.window.record(showm.scene, size=(900, 768), out_path="viz_timer.png") diff --git a/docs/examples/viz_ui.py b/docs/examples/viz_ui.py index 31eecdc0b..8d50712e2 100644 --- a/docs/examples/viz_ui.py +++ b/docs/examples/viz_ui.py @@ -12,8 +12,7 @@ import numpy as np -from fury import actor, ui, window -from fury.data import fetch_viz_icons, read_viz_icons +import fury ############################################################################### # Shapes @@ -21,17 +20,19 @@ # # Let's start by drawing some simple shapes. First, a rectangle. -rect = ui.Rectangle2D(size=(200, 200), position=(400, 300), color=(1, 0, 1)) +rect = fury.ui.Rectangle2D(size=(200, 200), position=(400, 300), color=(1, 0, 1)) ############################################################################### # Then we can draw a solid circle, or disk. -disk = ui.Disk2D(outer_radius=50, center=(500, 500), color=(1, 1, 0)) +disk = fury.ui.Disk2D(outer_radius=50, center=(500, 500), color=(1, 1, 0)) ############################################################################### # Add an inner radius to make a ring. -ring = ui.Disk2D(outer_radius=50, inner_radius=45, center=(500, 300), color=(0, 1, 1)) +ring = fury.ui.Disk2D( + outer_radius=50, inner_radius=45, center=(500, 300), color=(0, 1, 1) +) ############################################################################### # Image @@ -40,13 +41,13 @@ # Now let's display an image. First we need to fetch some icons that are # included in FURY. -fetch_viz_icons() +fury.data.fetch_viz_icons() ############################################################################### # Now we can create an image container. -img = ui.ImageContainer2D( - img_path=read_viz_icons(fname="home3.png"), position=(450, 350) +img = fury.ui.ImageContainer2D( + img_path=fury.data.read_viz_icons(fname="home3.png"), position=(450, 350) ) ############################################################################### @@ -56,15 +57,15 @@ # Let's create some buttons and text and put them in a panel. First we'll # make the panel. -panel = ui.Panel2D(size=(300, 150), color=(1, 1, 1), align="right") +panel = fury.ui.Panel2D(size=(300, 150), color=(1, 1, 1), align="right") panel.center = (500, 400) ############################################################################### # Then we'll make two text labels and place them on the panel. # Note that we specify the position with integer numbers of pixels. -text = ui.TextBlock2D(text="Click me") -text2 = ui.TextBlock2D(text="Me too") +text = fury.ui.TextBlock2D(text="Click me") +text2 = fury.ui.TextBlock2D(text="Me too") panel.add_element(text, (50, 100)) panel.add_element(text2, (180, 100)) @@ -75,17 +76,17 @@ # percentages of the panel size. -button_example = ui.Button2D( - icon_fnames=[("square", read_viz_icons(fname="stop2.png"))] +button_example = fury.ui.Button2D( + icon_fnames=[("square", fury.data.read_viz_icons(fname="stop2.png"))] ) icon_files = [] -icon_files.append(("down", read_viz_icons(fname="circle-down.png"))) -icon_files.append(("left", read_viz_icons(fname="circle-left.png"))) -icon_files.append(("up", read_viz_icons(fname="circle-up.png"))) -icon_files.append(("right", read_viz_icons(fname="circle-right.png"))) +icon_files.append(("down", fury.data.read_viz_icons(fname="circle-down.png"))) +icon_files.append(("left", fury.data.read_viz_icons(fname="circle-left.png"))) +icon_files.append(("up", fury.data.read_viz_icons(fname="circle-up.png"))) +icon_files.append(("right", fury.data.read_viz_icons(fname="circle-right.png"))) -second_button_example = ui.Button2D(icon_fnames=icon_files) +second_button_example = fury.ui.Button2D(icon_fnames=icon_files) panel.add_element(button_example, (0.25, 0.33)) panel.add_element(second_button_example, (0.66, 0.33)) @@ -114,7 +115,7 @@ def change_icon_callback(i_ren, _obj, _button): # Let's add a cube to the scene and control it with sliders. -cube = actor.cube( +cube = fury.actor.cube( centers=np.array([[15, 0, 0]]), colors=np.array([[0, 0, 1]]), scales=np.array([[20, 20, 20]]), @@ -124,11 +125,11 @@ def change_icon_callback(i_ren, _obj, _button): ############################################################################### # Now we'll add three sliders: one circular and two linear. -ring_slider = ui.RingSlider2D( +ring_slider = fury.ui.RingSlider2D( center=(740, 400), initial_value=0, text_template="{angle:5.1f}°" ) -line_slider_x = ui.LineSlider2D( +line_slider_x = fury.ui.LineSlider2D( center=(500, 250), initial_value=0, min_value=-10, @@ -136,7 +137,7 @@ def change_icon_callback(i_ren, _obj, _button): orientation="horizontal", ) -line_slider_y = ui.LineSlider2D( +line_slider_y = fury.ui.LineSlider2D( center=(650, 350), initial_value=0, min_value=-10, @@ -187,7 +188,7 @@ def translate_cube_y(slider): # Finally, we can add a range slider. This element is composed of two sliders. # The first slider has two handles which let you set the range of the second. -range_slider_x = ui.RangeSlider( +range_slider_x = fury.ui.RangeSlider( line_width=8, handle_side=25, range_slider_center=(450, 450), @@ -201,7 +202,7 @@ def translate_cube_y(slider): shape="square", ) -range_slider_y = ui.RangeSlider( +range_slider_y = fury.ui.RangeSlider( line_width=8, handle_side=25, range_slider_center=(750, 400), @@ -263,7 +264,7 @@ def hide_all_examples(): ############################################################################### # Now we can create the menu. -listbox = ui.ListBox2D( +listbox = fury.ui.ListBox2D( values=values, position=(10, 300), size=(300, 200), multiselection=False ) @@ -291,7 +292,7 @@ def display_element(): # manager. current_size = (800, 800) -show_manager = window.ShowManager(size=current_size, title="FURY UI Example") +show_manager = fury.window.ShowManager(size=current_size, title="FURY UI Example") show_manager.scene.add(listbox) for example in examples: @@ -309,4 +310,4 @@ def display_element(): if interactive: show_manager.start() -window.record(show_manager.scene, size=current_size, out_path="viz_ui.png") +fury.window.record(show_manager.scene, size=current_size, out_path="viz_fury.ui.png") diff --git a/docs/examples/viz_ui_listbox.py b/docs/examples/viz_ui_listbox.py index c89335662..146d147b6 100644 --- a/docs/examples/viz_ui_listbox.py +++ b/docs/examples/viz_ui_listbox.py @@ -10,21 +10,20 @@ First, a bunch of imports. """ -from fury import ui, window -from fury.data import fetch_viz_icons +import fury ############################################################################## # First we need to fetch some icons that are included in FURY. -fetch_viz_icons() +fury.data.fetch_viz_icons() ############################################################################### # Create some text blocks that will be shown when # list elements will be selected -welcome_text = ui.TextBlock2D(text="Welcome", font_size=30, position=(500, 400)) -bye_text = ui.TextBlock2D(text="Bye", font_size=30, position=(500, 400)) -fury_text = ui.TextBlock2D(text="Fury", font_size=30, position=(500, 400)) +welcome_text = fury.ui.TextBlock2D(text="Welcome", font_size=30, position=(500, 400)) +bye_text = fury.ui.TextBlock2D(text="Bye", font_size=30, position=(500, 400)) +fury_text = fury.ui.TextBlock2D(text="Fury", font_size=30, position=(500, 400)) example = [welcome_text, bye_text, fury_text] @@ -43,7 +42,7 @@ def hide_all_examples(): # Create ListBox with the values as parameter. values = ["Welcome", "Bye", "Fury"] -listbox = ui.ListBox2D( +listbox = fury.ui.ListBox2D( values=values, position=(10, 300), size=(200, 200), multiselection=False ) @@ -64,7 +63,9 @@ def display_element(): # manager. current_size = (800, 800) -show_manager = window.ShowManager(size=current_size, title="FURY UI ListBox_Example") +show_manager = fury.window.ShowManager( + size=current_size, title="FURY UI ListBox_Example" +) show_manager.scene.add(listbox) show_manager.scene.add(welcome_text) @@ -75,4 +76,4 @@ def display_element(): if interactive: show_manager.start() -window.record(show_manager.scene, size=current_size, out_path="viz_listbox.png") +fury.window.record(show_manager.scene, size=current_size, out_path="viz_listbox.png") diff --git a/docs/examples/viz_ui_slider.py b/docs/examples/viz_ui_slider.py index 034761fc3..31e47f0c4 100644 --- a/docs/examples/viz_ui_slider.py +++ b/docs/examples/viz_ui_slider.py @@ -12,13 +12,12 @@ import numpy as np -from fury import actor, ui, window -from fury.data import fetch_viz_icons +import fury ############################################################################## # First we need to fetch some icons that are included in FURY. -fetch_viz_icons() +fury.data.fetch_viz_icons() ############################################################################### # Cube and sliders @@ -26,7 +25,7 @@ # # Add a cube to the scene . -cube = actor.cube( +cube = fury.actor.cube( centers=np.array([[15, 0, 0]]), colors=np.array([[0, 0, 1]]), scales=np.array([[20, 20, 20]]), @@ -37,11 +36,11 @@ # Now we'll add five sliders: 1 circular and 4 linear sliders. # By default the alignments are 'bottom' for horizontal and 'top' for vertical. -ring_slider = ui.RingSlider2D( +ring_slider = fury.ui.RingSlider2D( center=(630, 400), initial_value=0, text_template="{angle:5.1f}°" ) -hor_line_slider_text_top = ui.LineSlider2D( +hor_line_slider_text_top = fury.ui.LineSlider2D( center=(400, 230), initial_value=0, orientation="horizontal", @@ -50,7 +49,7 @@ text_alignment="top", ) -hor_line_slider_text_bottom = ui.LineSlider2D( +hor_line_slider_text_bottom = fury.ui.LineSlider2D( center=(400, 200), initial_value=0, orientation="horizontal", @@ -59,7 +58,7 @@ text_alignment="bottom", ) -ver_line_slider_text_left = ui.LineSlider2D( +ver_line_slider_text_left = fury.ui.LineSlider2D( center=(100, 400), initial_value=0, orientation="vertical", @@ -68,7 +67,7 @@ text_alignment="left", ) -ver_line_slider_text_right = ui.LineSlider2D( +ver_line_slider_text_right = fury.ui.LineSlider2D( center=(150, 400), initial_value=0, orientation="vertical", @@ -118,7 +117,7 @@ def translate_cube_hor(slider): # manager. current_size = (800, 800) -show_manager = window.ShowManager(size=current_size, title="FURY Cube Example") +show_manager = fury.window.ShowManager(size=current_size, title="FURY Cube Example") show_manager.scene.add(cube) show_manager.scene.add(ring_slider) @@ -150,4 +149,4 @@ def translate_cube_hor(slider): if interactive: show_manager.start() -window.record(show_manager.scene, size=current_size, out_path="viz_slider.png") +fury.window.record(show_manager.scene, size=current_size, out_path="viz_slider.png") diff --git a/docs/examples/viz_using_time_equations.py b/docs/examples/viz_using_time_equations.py index baf680b2c..a4ae678fd 100644 --- a/docs/examples/viz_using_time_equations.py +++ b/docs/examples/viz_using_time_equations.py @@ -8,21 +8,20 @@ import numpy as np -from fury import actor, window -from fury.animation import Animation +import fury -scene = window.Scene() +scene = fury.window.Scene() -showm = window.ShowManager( +showm = fury.window.ShowManager( scene, size=(900, 768), reset_camera=False, order_transparent=True ) -cube = actor.cube(np.array([[0, 0, 0]]), (0, 0, 0), (1, 0, 1), scales=6) +cube = fury.actor.cube(np.array([[0, 0, 0]]), (0, 0, 0), (1, 0, 1), scales=6) ############################################################################### # Creating an ``Animation`` to animate the actor and show its motion path. -anim = Animation(length=2 * np.pi, loop=True, motion_path_res=200) +anim = fury.animation.Animation(length=2 * np.pi, loop=True, motion_path_res=200) ############################################################################### # Adding the sphere actor to the timeline @@ -77,4 +76,6 @@ def scale_eval(t): if interactive: showm.start() -window.record(scene, out_path="viz_keyframe_animation_evaluators.png", size=(900, 768)) +fury.window.record( + scene, out_path="viz_keyframe_animation_evaluators.png", size=(900, 768) +) diff --git a/docs/examples/viz_widget.py b/docs/examples/viz_widget.py index 6768a843e..ee7b99da8 100644 --- a/docs/examples/viz_widget.py +++ b/docs/examples/viz_widget.py @@ -42,23 +42,22 @@ import numpy as np -from fury import actor, window -from fury.stream.widget import Widget +import fury interactive = False window_size = (720, 500) N = 4 centers = np.random.normal(size=(N, 3)) colors = np.random.uniform(0.1, 1.0, size=(N, 3)) -actors = actor.sphere(centers, opacity=0.5, radii=0.4, colors=colors) -scene = window.Scene() +actors = fury.actor.sphere(centers, opacity=0.5, radii=0.4, colors=colors) +scene = fury.window.Scene() scene.add(actors) -showm = window.ShowManager(scene, size=(window_size[0], window_size[1])) +showm = fury.window.ShowManager(scene, size=(window_size[0], window_size[1])) ########################################################################## # Create a stream widget -widget = Widget(showm, port=8000) +widget = fury.stream.Widget(showm, port=8000) # if you want to use webRTC, you can pass the argument to choose this encoding # which is a more robust option. @@ -86,4 +85,4 @@ async def main(): time.sleep(time_sleep) widget.stop() -window.record(showm.scene, size=window_size, out_path="viz_widget.png") +fury.window.record(showm.scene, size=window_size, out_path="viz_widget.png") diff --git a/docs/examples/viz_wrecking_ball.py b/docs/examples/viz_wrecking_ball.py index 1e574ccc3..31e9587a3 100644 --- a/docs/examples/viz_wrecking_ball.py +++ b/docs/examples/viz_wrecking_ball.py @@ -15,7 +15,7 @@ import numpy as np import pybullet as p -from fury import actor, ui, utils, window +import fury ############################################################################### # Initiate pybullet and enable gravity. @@ -52,7 +52,7 @@ # Creating the base plane actor. # Base -base_actor = actor.box( +base_actor = fury.actor.box( centers=np.array([[0, 0, 0]]), directions=[0, 0, 0], scales=(5, 5, 0.2), @@ -108,7 +108,7 @@ p.changeDynamics(bricks[idx], -1, lateralFriction=0.1, restitution=0.1) idx += 1 -brick_actor = actor.box( +brick_actor = fury.actor.box( centers=brick_centers, directions=brick_directions, scales=brick_sizes, @@ -160,7 +160,7 @@ link_heights = np.zeros(n_links) link_heights[:] = dx_link -rope_actor = actor.cylinder( +rope_actor = fury.actor.cylinder( centers=linkPositions, directions=linkDirections, colors=np.random.rand(n_links, 3), @@ -213,14 +213,14 @@ rope, -1, -1, -1, p.JOINT_FIXED, [0, 0, 0], [0, 0, 0], [0, 0, 2] ) -box_actor = actor.box( +box_actor = fury.actor.box( centers=np.array([[0, 0, 0]]), directions=np.array([[0, 0, 0]]), scales=(0.02, 0.02, 0.02), colors=np.array([[1, 0, 0]]), ) -ball_actor = actor.sphere( +ball_actor = fury.actor.sphere( centers=np.array([[0, 0, 0]]), radii=ball_radius, colors=np.array([1, 0, 1]) ) @@ -228,12 +228,12 @@ # Now we add the necessary actors to the scene and set the camera for better # visualization. -scene = window.Scene() +scene = fury.window.Scene() scene.set_camera((10.28, -7.10, 6.39), (0.0, 0.0, 0.4), (-0.35, 0.26, 1.0)) -scene.add(actor.axes(scale=(0.5, 0.5, 0.5)), base_actor, brick_actor) +scene.add(fury.actor.axes(scale=(0.5, 0.5, 0.5)), base_actor, brick_actor) scene.add(rope_actor, box_actor, ball_actor) -showm = window.ShowManager( +showm = fury.window.ShowManager( scene, size=(900, 768), reset_camera=False, order_transparent=True ) @@ -247,7 +247,7 @@ ############################################################################### # Calculate the vertices of the bricks. -brick_vertices = utils.vertices_from_actor(brick_actor) +brick_vertices = fury.utils.vertices_from_actor(brick_actor) num_vertices = brick_vertices.shape[0] num_objects = brick_centers.shape[0] brick_sec = int(num_vertices / num_objects) @@ -255,7 +255,7 @@ ############################################################################### # Calculate the vertices of the wrecking ball. -chain_vertices = utils.vertices_from_actor(rope_actor) +chain_vertices = fury.utils.vertices_from_actor(rope_actor) num_vertices = chain_vertices.shape[0] num_objects = brick_centers.shape[0] chain_sec = int(num_vertices / num_objects) @@ -316,7 +316,7 @@ def sync_chain(actor_list, multibody): counter = itertools.count() fpss = np.array([]) -tb = ui.TextBlock2D( +tb = fury.ui.TextBlock2D( position=(0, 680), font_size=30, color=(1, 0.5, 0), text="Avg. FPS: \nSim Steps: " ) scene.add(tb) @@ -355,8 +355,8 @@ def timer_callback(_obj, _event): pos = p.getLinkState(rope, p.getNumJoints(rope) - 1)[4] ball_actor.SetPosition(*pos) sync_chain(rope_actor, rope) - utils.update_actor(brick_actor) - utils.update_actor(rope_actor) + fury.utils.update_actor(brick_actor) + fury.utils.update_actor(rope_actor) # Simulate a step. p.stepSimulation() @@ -375,4 +375,4 @@ def timer_callback(_obj, _event): if interactive: showm.start() -window.record(scene, size=(900, 768), out_path="viz_wrecking_ball.png") +fury.window.record(scene, size=(900, 768), out_path="viz_wrecking_ball.png") diff --git a/docs/experimental/viz_molecular_demo.py b/docs/experimental/viz_molecular_demo.py index d72338a55..6f94154df 100644 --- a/docs/experimental/viz_molecular_demo.py +++ b/docs/experimental/viz_molecular_demo.py @@ -129,10 +129,10 @@ # 3. Creating and adding axes actor to the scene. # 4. Computing the bonding information for the molecule. # 5. Generating and adding various molecular representations to the scene. -scene = window.Scene() +scene = fury.window.Scene() scene.set_camera(position=(20, 10, 0), focal_point=(0, 0, 0), view_up=(0, 1, 0)) scene.zoom(0.8) -axes_actor = actor.axes() +axes_actor = fury.actor.axes() scene.add(axes_actor) molecule = mol.Molecule( @@ -172,9 +172,9 @@ ############################################################################### # creating a ShowManager object -showm = window.ShowManager(scene, size=dims, reset_camera=True, order_transparent=True) +showm = fury.window.ShowManager(scene, size=dims, reset_camera=True, order_transparent=True) -tb = ui.TextBlock2D( +tb = fury.ui.TextBlock2D( text=pdb_code.upper(), position=(screen_x_dim / 2 - 40, screen_y_dim / 12), font_size=30, @@ -189,5 +189,5 @@ interactive = False if interactive: - window.show(scene, size=dims, title=pdb_code.upper()) -window.record(scene, size=dims, out_path=pdb_code.upper() + '.png') + fury.window.show(scene, size=dims, title=pdb_code.upper()) +fury.window.record(scene, size=dims, out_path=pdb_code.upper() + '.png') diff --git a/docs/experimental/viz_multisdf.py b/docs/experimental/viz_multisdf.py index 37a78c5b4..fee954482 100644 --- a/docs/experimental/viz_multisdf.py +++ b/docs/experimental/viz_multisdf.py @@ -46,7 +46,7 @@ vtk.vtkShader.Fragment, '//VTK::Light::Impl', True, fs_impl_code, False ) -scene = window.Scene() +scene = fury.window.Scene() scene.background((1.0, 0.8, 0.8)) centers = np.array([[0, 0, 0]]) @@ -61,7 +61,7 @@ def timer_callback(obj, event): showm.render() -@window.vtk.calldata_type(window.vtk.VTK_OBJECT) +@fury.window.vtk.calldata_type(fury.window.vtk.VTK_OBJECT) def vtk_shader_callback(caller, event, calldata=None): program = calldata global timer @@ -72,15 +72,15 @@ def vtk_shader_callback(caller, event, calldata=None): pass -mapper.AddObserver(window.vtk.vtkCommand.UpdateShaderEvent, vtk_shader_callback) +mapper.AddObserver(fury.window.vtk.vtkCommand.UpdateShaderEvent, vtk_shader_callback) -showm = window.ShowManager(scene, reset_camera=False) +showm = fury.window.ShowManager(scene, reset_camera=False) showm.add_timer_callback(True, 10, timer_callback) scene.add(sdfactor) -scene.add(actor.axes()) +scene.add(fury.actor.axes()) showm.start() diff --git a/fury/__init__.pyi b/fury/__init__.pyi index ec5cb5563..9a961b136 100644 --- a/fury/__init__.pyi +++ b/fury/__init__.pyi @@ -59,6 +59,7 @@ from . import ( stream, testing, transform, + ui, utils, window, ) diff --git a/fury/shaders/base.py b/fury/shaders/base.py index c2ea7f015..cf1769759 100644 --- a/fury/shaders/base.py +++ b/fury/shaders/base.py @@ -1,7 +1,7 @@ from functools import partial import os -from fury import enable_warnings +import fury from fury.decorators import warn_on_args_to_kwargs from fury.deprecator import deprecate_with_version from fury.io import load_text @@ -239,7 +239,7 @@ def shader_to_actor( impl_code = block_impl + "\n" + impl_code if debug: - enable_warnings() + fury.enable_warnings() error_msg = "\n\n--- DEBUG: THIS LINE GENERATES AN ERROR ---\n\n" impl_code += error_msg