From 264721bed6a9cdd781ae8dc1e13d3c7155807923 Mon Sep 17 00:00:00 2001 From: robinroy03 Date: Thu, 21 Mar 2024 23:01:18 +0530 Subject: [PATCH] fixed docs, made it cleaner. Fixed uneven variable names for texture_on_cube. Updated _valid_examples for doc generation --- docs/examples/_valid_examples.toml | 1 + docs/examples/viz_play_cube.py | 51 +++++++++++++++++++----------- fury/actor.py | 30 +++++++++--------- 3 files changed, 49 insertions(+), 33 deletions(-) diff --git a/docs/examples/_valid_examples.toml b/docs/examples/_valid_examples.toml index e5ecfb142..5e4e4f6be 100644 --- a/docs/examples/_valid_examples.toml +++ b/docs/examples/_valid_examples.toml @@ -59,6 +59,7 @@ files = [ "viz_emwave_animation.py", "viz_helical_motion.py", "viz_play_video.py", + "viz_play_cube.py", "viz_dt_ellipsoids.py" ] diff --git a/docs/examples/viz_play_cube.py b/docs/examples/viz_play_cube.py index 3307ed004..82881c1e3 100644 --- a/docs/examples/viz_play_cube.py +++ b/docs/examples/viz_play_cube.py @@ -1,6 +1,6 @@ """ ======================================================= -Play a video in the 3D world +Play video on a Cube ======================================================= The goal of this demo is to show how to visualize a video @@ -11,9 +11,10 @@ import numpy as np import cv2 +######################################################################### # The 6 sources for the video, can be URL or directory paths on your machine. -# There'll be a significant delay if your internet connectivity is poor. -# Use local directory paths for fast rendering. +# There'll be a significant delay if your internet connectivity is poor, +# use local directory paths for fast rendering. sources = [ 'http://commondatastorage.googleapis.com/gtv-videos-bucket/' + 'sample/BigBuckBunny.mp4', @@ -29,19 +30,24 @@ + 'sample/BigBuckBunny.mp4' ] - -# We are creating OpenCV videoCapture objects to capture frames from sources +######################################################################### +# We are creating ``OpenCV videoCapture`` objects to capture frames from +# sources. video_captures = [cv2.VideoCapture(source) for source in sources] + # rgb_images will store the RGB values of the frames. rgb_images = [] for video_capture in video_captures: _, bgr_image = video_capture.read() + # OpenCV reads in BGR, we are converting it to RGB. rgb_image = cv2.cvtColor(bgr_image, cv2.COLOR_BGR2RGB) rgb_images.append(rgb_image) -# timer_callback gets called every (1/60) seconds in this particular program. +######################################################################## +# ``timer_callback`` gets called repeatedly to change texture. + def timer_callback(_caller, _timer_event): rgb_images = [] for video_capture in video_captures: @@ -60,19 +66,25 @@ def timer_callback(_caller, _timer_event): # texture_update is a function to update the texture of an actor actor.texture_update(actor_, image) - # you've to render the pipeline again to display the results + # you've to re-render the pipeline again to display the results show_manager.render() - -# texture_on_cube is the function we use, the images are assigned in +####################################################################### +# ``texture_on_cube`` is the function we use, the images are assigned in # cubemap order. -# |----| -# | +Y | -# |----|----|----|----| -# | -X | +Z | +X | -Z | -# |----|----|----|----| -# | -Y | -# |----| + + +""" + |----| + | +Y | +|----|----|----|----| +| -X | +Z | +X | -Z | +|----|----|----|----| + | -Y | + |----| +""" +###################################################################### + cube = actor.texture_on_cube(*rgb_images, centers=(0, 0, 0)) @@ -80,13 +92,16 @@ def timer_callback(_caller, _timer_event): scene = window.Scene() scene.add(*cube) -# ShowManager controls the frequency of changing textures +###################################################################### +# ``ShowManager`` controls the frequency of changing textures. # The video is rendered by changing textures very frequently. show_manager = window.ShowManager(scene, size=(1280, 720), reset_camera=False) show_manager.add_timer_callback(True, int(1/60), timer_callback) -# Flip it to True for video. +# Flip it to ``True`` for video. interactive = False if interactive: show_manager.start() + +window.record(scene, size=(1280, 720), out_path='viz_play_cube.png') diff --git a/fury/actor.py b/fury/actor.py index 8b5a50c04..7268da7c6 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -3996,7 +3996,7 @@ def texture_on_cube(negx, negy, negz, posx, posy, posz, centers=(0, 0, 0)): Check docs/examples/viz_play_cube.py """ - planes = [PlaneSource() for _ in range(6)] + plane_objects = [PlaneSource() for _ in range(6)] center_x, center_y, center_z = centers plane_centers = [ @@ -4018,7 +4018,7 @@ def texture_on_cube(negx, negy, negz, posx, posy, posz, centers=(0, 0, 0)): ] for plane, center, normal in zip( - planes, + plane_objects, plane_centers, plane_normals ): @@ -4027,33 +4027,33 @@ def texture_on_cube(negx, negy, negz, posx, posy, posz, centers=(0, 0, 0)): image_grids = [negx, negy, negz, posx, posy, posz] - image_data_objs = [ + image_data_objects = [ numpy_to_vtk_image_data(grid) for grid in image_grids ] texture_objects = [Texture() for _ in range(6)] - for image_data_obj, texture_object in zip( - image_data_objs, + for image_data, texture in zip( + image_data_objects, texture_objects ): - texture_object.SetInputDataObject(image_data_obj) + texture.SetInputDataObject(image_data) - polyDataMappers = [PolyDataMapper() for _ in range(6)] + polydatamapper_objects = [PolyDataMapper() for _ in range(6)] for mapper, plane in zip( - polyDataMappers, - planes + polydatamapper_objects, + plane_objects ): mapper.SetInputConnection(plane.GetOutputPort()) - actors = [Actor() for _ in range(6)] - for actor, mapper, texture_object in zip( - actors, - polyDataMappers, + actor_objects = [Actor() for _ in range(6)] + for actor, mapper, texture in zip( + actor_objects, + polydatamapper_objects, texture_objects ): actor.SetMapper(mapper) - actor.SetTexture(texture_object) + actor.SetTexture(texture) - return actors + return actor_objects