Skip to content

Commit

Permalink
pep8 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
robinroy03 committed Mar 10, 2024
1 parent 6fc3dcd commit a351499
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
6 changes: 4 additions & 2 deletions docs/examples/viz_play_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
=======================================================
The goal of this demo is to show how to visualize a video
on a cube by updating a texture.
on a cube by updating its textures.
"""

from fury import window, actor
import numpy as np
import cv2


def timer_callback(_caller, _timer_event):
rgb_images = []
for video_capture in video_captures:
Expand All @@ -29,6 +30,7 @@ def timer_callback(_caller, _timer_event):
*rgb_images
)


# the sources for the video, can be URL or directory links on your machine.
sources = [
'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
Expand All @@ -46,7 +48,7 @@ def timer_callback(_caller, _timer_event):
rgb_image = cv2.cvtColor(bgr_image, cv2.COLOR_BGR2RGB)
rgb_images.append(rgb_image)

# calling the TexturedCube class to create a TexturedCube with different textures on all 6 sides.
# Creating a TexturedCube with different textures on all 6 sides.
cube = actor.TexturedCube(*rgb_images)
scene = cube.get_scene()
show_manager = window.ShowManager(scene, size=(1280, 720), reset_camera=False)
Expand Down
43 changes: 29 additions & 14 deletions fury/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3956,6 +3956,7 @@ def uncertainty_cone(

return double_cone(centers, evecs, angles, colors, scales, opacity)


class TexturedCube:
"""Class to work with textured cube.
"""
Expand Down Expand Up @@ -4009,52 +4010,66 @@ def __init__(self, negx, negy, negz, posx, posy, posz):

self.image_grids = [negx, negy, negz, posx, posy, posz]
self.image_data_objs = [ImageData() for _ in range(6)]

for grid, image_data_obj in zip(self.image_grids, self.image_data_objs):
image_data_obj.SetDimensions(grid.shape[1], grid.shape[0], 1)
vtkarr = numpy_support.numpy_to_vtk(np.flip(grid.swapaxes(0,1), axis=1).reshape((-1, 3), order='F'))
vtkarr = numpy_support.numpy_to_vtk(
np.flip(grid.swapaxes(0, 1), axis=1).reshape((-1, 3), order='F')
)
vtkarr.SetName('Image')
image_data_obj.GetPointData().AddArray(vtkarr)
image_data_obj.GetPointData().SetActiveScalars('Image')

self.texture_objects = [Texture() for _ in range(6)]
for image_data_obj, texture_object in zip(self.image_data_objs, self.texture_objects):

for image_data_obj, texture_object in zip(
self.image_data_objs,
self.texture_objects
):
texture_object.SetInputDataObject(image_data_obj)

self.polyDataMappers = [PolyDataMapper() for _ in range(6)]
for mapper, plane in zip(self.polyDataMappers, self.planes):

for mapper, plane in zip(
self.polyDataMappers,
self.planes
):
mapper.SetInputConnection(plane.GetOutputPort())

self.actors = [Actor() for _ in range(6)]
for actor, mapper, texture_object in zip(self.actors, self.polyDataMappers, self.texture_objects):
for actor, mapper, texture_object in zip(
self.actors,
self.polyDataMappers,
self.texture_objects
):
actor.SetMapper(mapper)
actor.SetTexture(texture_object)

def get_scene(self):
"""Returns
-------
-------
self.scene : window.Scene"""

self.scene = window.Scene()
for actor in self.actors:
self.scene.add(actor)

return self.scene

def get_actor(self):
"""Returns
-------
-------
assembled_actor : Actor"""

assembled_actor = Assembly()
for actor_ in self.actors:
assembled_actor.AddPart(actor_)

return assembled_actor

def texture_update(self, show_manager, negx, negy, negz, posx, posy, posz):
"""Changes the texture of the cube.
Parameters
----------
show_manager : window.ShowManager
Expand All @@ -4074,7 +4089,7 @@ def texture_update(self, show_manager, negx, negy, negz, posx, posy, posz):
"""

self.image_grids = [negx, negy, negz, posx, posy, posz]

for actor_, image in zip(self.actors, self.image_grids):
texture_update(actor_, image)

Expand Down

0 comments on commit a351499

Please sign in to comment.