Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Update snapshot and record #742

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/tutorials/01_introductory/viz_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@

arrow_actor2 = actor.arrow(cen2, dir2, colors=cols2, scales=1.5)

scene = window.Scene()
showm = window.ShowManager(size=(600, 600))

############################################################################
# Adding our Arrow actors to scene.

scene.add(arrow_actor)
scene.add(arrow_actor2)
showm.scene.add(arrow_actor)
showm.scene.add(arrow_actor2)

interactive = False

if interactive:
window.show(scene, size=(600, 600))
showm.start()

window.record(scene, out_path='viz_arrow.png', size=(600, 600))
showm.record(out_path='viz_arrow.png', size=(600, 600))
10 changes: 5 additions & 5 deletions docs/tutorials/01_introductory/viz_cone.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@

cone_actor2 = actor.cone(cen2, dir2, colors=cols2, heights=1.5, use_primitive=False)

scene = window.Scene()
showm = window.ShowManager(size=(600, 600))

############################################################################
# Adding our cone actors to scene.

scene.add(cone_actor1)
scene.add(cone_actor2)
showm.scene.add(cone_actor1)
showm.scene.add(cone_actor2)

interactive = False

if interactive:
window.show(scene, size=(600, 600))
showm.start()

window.record(scene, out_path='viz_cone.png', size=(600, 600))
showm.record(out_path='viz_cone.png', size=(600, 600))
2 changes: 1 addition & 1 deletion docs/tutorials/01_introductory/viz_earth_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,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')
showm.record(size=(900, 768), out_path='viz_earth_animation.png')
3 changes: 1 addition & 2 deletions docs/tutorials/01_introductory/viz_earth_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +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')
showm.record(size=(900, 768), out_path='viz_earth_coordinates.png')
6 changes: 4 additions & 2 deletions docs/tutorials/01_introductory/viz_gltf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
scene = window.Scene()
scene.SetBackground(0.1, 0.1, 0.4)

showm = window.ShowManager(scene, size=(1280, 720))

##############################################################################
# Retrieving the gltf model.
fetch_gltf('Duck', 'glTF')
Expand Down Expand Up @@ -44,6 +46,6 @@
interactive = False

if interactive:
window.show(scene, size=(1280, 720))
showm.start()

window.record(scene, out_path='viz_gltf.png', size=(1280, 720))
showm.record(out_path='viz_gltf.png', size=(1280, 720))
2 changes: 1 addition & 1 deletion docs/tutorials/01_introductory/viz_gltf_animated.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ def timer_callback(_obj, _event):
if interactive:
showm.start()

window.record(scene, out_path='viz_gltf_animated.png', size=(900, 768))
showm.record(out_path='viz_gltf_animated.png', size=(900, 768))
7 changes: 5 additions & 2 deletions docs/tutorials/01_introductory/viz_gltf_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

scene = window.Scene()

showm = window.ShowManager(scene, size=(1280, 720))
showm.initialize()

##############################################################################
# Creating actors and adding to scene.

Expand Down Expand Up @@ -62,6 +65,6 @@
interactive = False

if interactive:
window.show(scene, size=(1280, 720))
showm.start()

window.record(scene, out_path='viz_gltf_export.png', size=(1280, 720))
showm.record(out_path='viz_gltf_export.png', size=(1280, 720))
2 changes: 1 addition & 1 deletion docs/tutorials/01_introductory/viz_morphing.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ def timer_callback(_obj, _event):
if interactive:
showm.start()

window.record(scene, out_path='viz_morphing.png', size=(900, 768))
showm.record(out_path='viz_morphing.png', size=(900, 768))
2 changes: 1 addition & 1 deletion docs/tutorials/01_introductory/viz_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,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')
showm.record(size=(1024, 768), out_path='viz_picking.png')
2 changes: 1 addition & 1 deletion docs/tutorials/01_introductory/viz_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,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')
showm.record(size=(1024, 768), out_path='viz_selection.png')
2 changes: 1 addition & 1 deletion docs/tutorials/01_introductory/viz_skinning.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ def timer_callback(_obj, _event):
if interactive:
showm.start()

window.record(scene, out_path='viz_skinning.png', size=(900, 768))
showm.record(out_path='viz_skinning.png', size=(900, 768))
2 changes: 1 addition & 1 deletion docs/tutorials/01_introductory/viz_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,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)
show_m_mosaic.record(out_path='mosaic.png', size=(900, 600), reset_camera=False)
2 changes: 1 addition & 1 deletion docs/tutorials/01_introductory/viz_solar_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,4 @@ 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')
showm.record(size=(900, 768), out_path='viz_solar_system_animation.png')
2 changes: 1 addition & 1 deletion docs/tutorials/01_introductory/viz_timers.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ def timer_callback(_obj, _event):

showm.start()

window.record(showm.scene, size=(900, 768), out_path='viz_timer.png')
showm.record(size=(900, 768), out_path='viz_timer.png')
14 changes: 7 additions & 7 deletions fury/tests/test_actors.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_slicer(verbose=False):
# window.show(scene)

# copy pixels in numpy array directly
arr = window.snapshot(scene, 'test_slicer.png', offscreen=True)
arr = window.snapshot(scene, fname='test_slicer.png', offscreen=True)

if verbose:
print(arr.sum())
Expand All @@ -84,7 +84,7 @@ def test_slicer(verbose=False):
# save pixels in png file not a numpy array
with InTemporaryDirectory() as tmpdir:
fname = os.path.join(tmpdir, 'slice.png')
window.snapshot(scene, fname, offscreen=True)
window.snapshot(scene, fname=fname, offscreen=True)
report = window.analyze_snapshot(fname, find_objects=True)
npt.assert_equal(report.objects, 1)

Expand Down Expand Up @@ -191,7 +191,7 @@ def test_surface():
)
scene.add(surface_actor)
# window.show(scene, size=(600, 600), reset_camera=False)
arr = window.snapshot(scene, 'test_surface.png', offscreen=True)
arr = window.snapshot(scene, fname='test_surface.png', offscreen=True)
report = window.analyze_snapshot(arr, find_objects=True)
npt.assert_equal(report.objects, 1)

Expand Down Expand Up @@ -233,8 +233,8 @@ def test_contour_from_roi(interactive=False):
if interactive:
window.show(scene2)

arr = window.snapshot(scene, 'test_surface.png', offscreen=True)
arr2 = window.snapshot(scene2, 'test_surface2.png', offscreen=True)
arr = window.snapshot(scene, fname='test_surface.png', offscreen=True)
arr2 = window.snapshot(scene2, fname='test_surface2.png', offscreen=True)

report = window.analyze_snapshot(arr, find_objects=True)
report2 = window.analyze_snapshot(arr2, find_objects=True)
Expand Down Expand Up @@ -292,10 +292,10 @@ def test_contour_from_label(interactive=False):
window.show(scene2)

arr = window.snapshot(
scene, 'test_surface.png', offscreen=True, order_transparent=False
scene, fname='test_surface.png', offscreen=True, order_transparent=False
)
arr2 = window.snapshot(
scene2, 'test_surface2.png', offscreen=True, order_transparent=True
scene2, fname='test_surface2.png', offscreen=True, order_transparent=True
)

report = window.analyze_snapshot(
Expand Down
28 changes: 11 additions & 17 deletions fury/tests/test_thread.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@

import time
from threading import Thread
from fury.utils import rotate, update_actor, vertices_from_actor

import numpy as np
import numpy.testing as npt
import pytest

from fury import actor, window
from fury.utils import rotate, update_actor, vertices_from_actor


def test_multithreading():
Expand All @@ -14,17 +15,15 @@ def test_multithreading():
radii = np.random.random(100) + 0.5

scene = window.Scene()
sphere_actor = actor.sphere(centers = xyz,
colors = colors,
radii = radii,
use_primitive = False)
sphere_actor = actor.sphere(
centers=xyz, colors=colors, radii=radii, use_primitive=False
)
scene.add(sphere_actor)

# Preparing the show manager as usual
showm = window.ShowManager(scene,
size = (900, 768),
reset_camera = False,
order_transparent = True)
showm = window.ShowManager(
scene, size=(900, 768), reset_camera=False, order_transparent=True
)

# showm.initialize()

Expand All @@ -36,7 +35,6 @@ def callback1():
rotate(sphere_actor, rotation=(0.01 * i, 1, 0, 0))
vsa[:] = 1.01 * vsa[:]
update_actor(sphere_actor)
print(i)
showm.release_current()
time.sleep(0.01)
else:
Expand All @@ -48,12 +46,8 @@ def callback1():
# showm.exit()
# npt.assert_equal(np.sum(arr) > 1, True)


thread_a = Thread(target = callback1)
thread_a = Thread(target=callback1)
thread_a.start()

showm.start(multithreaded = True)
showm.start(multithreaded=True)
thread_a.join()


test_multithreading()
32 changes: 15 additions & 17 deletions fury/tests/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def test_parallel_projection():
def test_order_transparent():

scene = window.Scene()
show_m = window.ShowManager(scene)

red_cube = actor.cube(
centers=np.array([[0.0, 0.0, 2]]),
Expand All @@ -251,21 +252,22 @@ def test_order_transparent():

# without order_transparency the green will look stronger
# when looked from behind the red cube
arr = window.snapshot(scene, fname=None, offscreen=True, order_transparent=False)
arr = show_m.snapshot(fname=None, offscreen=True, order_transparent=False)

# check if flags are set as expected (here no order transparency)
npt.assert_equal(scene.GetLastRenderingUsedDepthPeeling(), 0)

green_stronger = arr[150, 150, 1]

arr = window.snapshot(scene, fname=None, offscreen=True, order_transparent=True)
arr = show_m.snapshot(fname=None, offscreen=True, order_transparent=True)

# # check if flags are set as expected (here with order transparency)
npt.assert_equal(scene.GetLastRenderingUsedDepthPeeling(), 1)

# when order transparency is True green should be weaker
green_weaker = arr[150, 150, 1]

print(green_stronger, green_weaker)
assert_greater(green_stronger, green_weaker)


Expand Down Expand Up @@ -447,7 +449,9 @@ def test_record():
use_primitive=True,
)
scene = window.Scene()
scene.add(sphere_actor)

show_m = window.ShowManager(scene)
show_m.scene.add(sphere_actor)

def test_content(filename='fury.png', colors_found=(True, True)):
npt.assert_equal(os.path.isfile(filename), True)
Expand All @@ -459,25 +463,25 @@ def test_content(filename='fury.png', colors_found=(True, True)):

# Basic test
with InTemporaryDirectory():
window.record(scene)
show_m.record()
test_content()

# test out_path and path_numbering, n_frame
with InTemporaryDirectory():
filename = 'tmp_snapshot.png'
window.record(scene, out_path=filename)
show_m.record(out_path=filename)
test_content(filename)
window.record(scene, out_path=filename, path_numbering=True)
show_m.record(out_path=filename, path_numbering=True)
test_content(filename + '000000.png')
window.record(scene, out_path=filename, path_numbering=True, n_frames=3)
show_m.record(out_path=filename, path_numbering=True, n_frames=3)
test_content(filename + '000000.png')
test_content(filename + '000001.png')
test_content(filename + '000002.png')
npt.assert_equal(os.path.isfile(filename + '000003.png'), False)

# test verbose
with captured_output() as (out, _):
window.record(scene, verbose=True)
show_m.record(verbose=True)

npt.assert_equal(
out.getvalue().strip(),
Expand All @@ -487,9 +491,7 @@ def test_content(filename='fury.png', colors_found=(True, True)):
)
# test camera option
with InTemporaryDirectory():
window.record(
scene, cam_pos=(310, 0, 530), cam_focal=(120, 0, 0), cam_view=(0, 0, 1)
)
show_m.record(cam_pos=(310, 0, 530), cam_focal=(120, 0, 0), cam_view=(0, 0, 1))
test_content()

# test size and clipping
Expand All @@ -498,17 +500,13 @@ def test_content(filename='fury.png', colors_found=(True, True)):
# ReadFrontBufferOff(), ShouldRerenderOn() could improved this OSX case.
if not skip_osx:
with InTemporaryDirectory():
window.record(
scene, out_path='fury_1.png', size=(1000, 1000), magnification=5
)
show_m.record(out_path='fury_1.png', size=(1000, 1000), magnification=5)
npt.assert_equal(os.path.isfile('fury_1.png'), True)
arr = io.load_image('fury_1.png')

npt.assert_equal(arr.shape, (5000, 5000, 3))

window.record(
scene, out_path='fury_2.png', size=(5000, 5000), screen_clip=True
)
show_m.record(out_path='fury_2.png', size=(5000, 5000), screen_clip=True)
npt.assert_equal(os.path.isfile('fury_2.png'), True)
arr = io.load_image('fury_2.png')

Expand Down
Loading