Skip to content

Commit

Permalink
fixed docs, made it cleaner. Fixed uneven variable names for texture_…
Browse files Browse the repository at this point in the history
…on_cube. Updated _valid_examples for doc generation
  • Loading branch information
robinroy03 committed Mar 21, 2024
1 parent dc74532 commit 264721b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 33 deletions.
1 change: 1 addition & 0 deletions docs/examples/_valid_examples.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]

Expand Down
51 changes: 33 additions & 18 deletions docs/examples/viz_play_cube.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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',
Expand All @@ -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:
Expand All @@ -60,33 +66,42 @@ 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))

# adding the returned Actors to scene
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')
30 changes: 15 additions & 15 deletions fury/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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
):
Expand All @@ -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

0 comments on commit 264721b

Please sign in to comment.