Skip to content

Commit

Permalink
feat: Added remove_effect feature
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoDell committed Jul 21, 2023
1 parent b572b4b commit 269c4de
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
9 changes: 7 additions & 2 deletions docs/experimental/viz_kde_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ def normalize(array : np.array, min : float = 0.0, max : float = 1.0, axis : int

manager.scene.add(kde_actor)

interactive = True
interactive = False

if interactive:
manager.start()

record(scene, out_path = "kde_points.png", size = (800, 800))
effects.remove_effect(kde_actor)

# record(scene, out_path = "kde_points.png", size = (800, 800))

if interactive:
manager.start()
24 changes: 21 additions & 3 deletions fury/actors/effect_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def __init__(self, manager : ShowManager):
size=manager.size)
self.off_manager.window.SetOffScreenRendering(True)
self.off_manager.initialize()
self._n_active_effects = 0
self._active_effects = {}



Expand Down Expand Up @@ -104,9 +106,9 @@ def kde(self, center, points : np.ndarray, sigmas, scale = 1, opacity = 1.0, col

# Blending and uniforms setup
window = self.off_manager.window

shader_apply_effects(window, bill, gl_disable_depth)
shader_apply_effects(window, bill, gl_set_additive_blending)

attribute_to_actor(bill, np.repeat(sigmas, 4), "in_sigma")
attribute_to_actor(bill, np.repeat(scales, 4), "in_scale")

Expand All @@ -129,10 +131,12 @@ def kde(self, center, points : np.ndarray, sigmas, scale = 1, opacity = 1.0, col

colormap_to_texture(cmap, "colormapTexture", textured_billboard)

def event_callback(obj, event):
def kde_callback(obj, event):
pos, focal, vu = self.on_manager.scene.get_camera()
self.off_manager.scene.set_camera(pos, focal, vu)
self.off_manager.scene.Modified()
shader_apply_effects(window, bill, gl_disable_depth)
shader_apply_effects(window, bill, gl_set_additive_blending)
self.off_manager.render()

window_to_texture(
Expand All @@ -141,13 +145,27 @@ def event_callback(obj, event):
textured_billboard,
blending_mode="Interpolate")

# Initialization
window_to_texture(
self.off_manager.window,
"screenTexture",
textured_billboard,
blending_mode="Interpolate")

self.on_manager.add_iren_callback(event_callback, "RenderEvent")
callback_id = self.on_manager.add_iren_callback(kde_callback, "RenderEvent")

self._active_effects[textured_billboard] = callback_id
self._n_active_effects += 1

return textured_billboard

def remove_effect(self, effect_actor):
if self._n_active_effects > 0:
self.on_manager.scene.RemoveObserver(self._active_effects[effect_actor])
self.on_manager.scene.RemoveActor(effect_actor)
self.off_manager.scene.RemoveActor(effect_actor)
self._active_effects.pop(effect_actor)
self._n_active_effects -= 1
else:
raise IndexError("Manager has no active effects.")

6 changes: 4 additions & 2 deletions fury/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,9 @@ def play_events_from_file(self, filename):

def add_window_callback(self, win_callback, event=Command.ModifiedEvent):
"""Add window callbacks."""
self.window.AddObserver(event, win_callback)
window_id = self.window.AddObserver(event, win_callback)
self.window.Render()
return window_id

def add_timer_callback(self, repeat, duration, timer_callback):
if not self.iren.GetInitialized():
Expand All @@ -758,7 +759,8 @@ def add_timer_callback(self, repeat, duration, timer_callback):
def add_iren_callback(self, iren_callback, event='MouseMoveEvent'):
if not self.iren.GetInitialized():
self.initialize()
self.iren.AddObserver(event, iren_callback)
iren_id = self.iren.AddObserver(event, iren_callback)
return iren_id

def destroy_timer(self, timer_id):
self.iren.DestroyTimer(timer_id)
Expand Down

0 comments on commit 269c4de

Please sign in to comment.