Skip to content

Commit

Permalink
feat: Added grayscale effect and changed laplacian and gaussian calcu…
Browse files Browse the repository at this point in the history
…lations
  • Loading branch information
JoaoDell committed Jul 24, 2023
1 parent fae89e1 commit 39f43b4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 13 deletions.
5 changes: 3 additions & 2 deletions docs/experimental/viz_kde_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,19 @@ def normalize(array : np.array, min : float = 0.0, max : float = 1.0, axis : int

effects = EffectManager(manager)

kde_actor = effects.kde(np.array([[0.0, 0.0, 0.0]]), points, sigmas, scale = 20.0, colormap = "viridis")
kde_actor = effects.kde(np.array([[0.0, 0.0, 0.0]]), points, sigmas, scale = 20.0, colormap = "inferno")

manager.scene.add(kde_actor)

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()
74 changes: 63 additions & 11 deletions fury/actors/effect_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,62 @@ def kde_callback(obj, event):
self._n_active_effects += 1

return textured_billboard

def grayscale(self, center, actor, scale, opacity):


tex_impl = """
// Turning screen coordinates to texture coordinates
vec2 res_factor = vec2(res.y/res.x, 1.0);
vec2 renorm_tex = res_factor*normalizedVertexMCVSOutput.xy*0.5 + 0.5;
vec3 col = texture(screenTexture, renorm_tex).rgb;
float bw = 0.2126*col.r + 0.7152*col.g + 0.0722*col.b;
color = vec3(bw);
fragOutput0 = vec4(color, opacity);
"""

self.off_manager.scene.add(actor)

self.off_manager.render()

# Render to second billboard for color map post-processing.
textured_billboard = billboard(center, scales=scale, fs_impl=tex_impl)
shader_custom_uniforms(textured_billboard, "fragment").SetUniform2f("res", self.off_manager.size)
shader_custom_uniforms(textured_billboard, "fragment").SetUniformf("opacity", opacity)

# Disables the texture warnings
textured_billboard.GetProperty().GlobalWarningDisplayOff()

def gray_callback(obj, event):
actor.SetVisibility(True)
pos, focal, vu = self.on_manager.scene.get_camera()
self.off_manager.scene.set_camera(pos, focal, vu)
self.off_manager.render()

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

actor.SetVisibility(False)
actor.Modified()


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

callback_id = self.on_manager.add_iren_callback(gray_callback, "RenderEvent")

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

return textured_billboard

def laplacian(self, center, actor, scale, opacity):

Expand All @@ -177,12 +233,11 @@ def laplacian(self, center, actor, scale, opacity):
"""

lapl_dec = """
float laplacian_calculator(sampler2D screenTexture, vec2 tex_coords, vec2 res){
float value = 0.0;
vec3 laplacian_calculator(sampler2D screenTexture, vec2 tex_coords, vec2 res){
vec3 value = vec3(0.0);
for(int i = 0; i < 9; i++){
vec3 col = texture(screenTexture, tex_coords + vec2(1/res.x, 1/res.y)*vec2(x_offsets[i], y_offsets[i])).rgb;
float bw = 0.2126*col.r + 0.7152*col.g + 0.0722*col.b;
value += laplacian_mat[i]*bw;
value += vec3(laplacian_mat[i])*col;
}
return value;
}
Expand All @@ -192,7 +247,7 @@ def laplacian(self, center, actor, scale, opacity):
// Turning screen coordinates to texture coordinates
vec2 res_factor = vec2(res.y/res.x, 1.0);
vec2 renorm_tex = res_factor*normalizedVertexMCVSOutput.xy*0.5 + 0.5;
color = vec3(laplacian_calculator(screenTexture, renorm_tex, res));
color = laplacian_calculator(screenTexture, renorm_tex, res);
//color = vec3(1.0, 0.0, 0.0);
fragOutput0 = vec4(color, opacity);
Expand All @@ -215,7 +270,6 @@ def laplacian_callback(obj, event):
actor.SetVisibility(True)
pos, focal, vu = self.on_manager.scene.get_camera()
self.off_manager.scene.set_camera(pos, focal, vu)
self.off_manager.scene.Modified()
self.off_manager.render()

window_to_texture(
Expand Down Expand Up @@ -260,11 +314,10 @@ def gaussian_blur(self, center, actor, scale, opacity):
"""

gauss_dec = """
float kernel_calculator(sampler2D screenTexture, vec2 tex_coords, vec2 res){
float value = 0.0;
vec3 kernel_calculator(sampler2D screenTexture, vec2 tex_coords, vec2 res){
vec3 value = vec3(0.0);
for(int i = 0; i < 9; i++){
vec3 col = texture(screenTexture, tex_coords + vec2(1/res.x, 1/res.y)*vec2(x_offsets[i], y_offsets[i])).rgb;
float bw = 0.2126*col.r + 0.7152*col.g + 0.0722*col.b;
value += gauss_kernel[i]*bw;
}
return value;
Expand All @@ -275,7 +328,7 @@ def gaussian_blur(self, center, actor, scale, opacity):
// Turning screen coordinates to texture coordinates
vec2 res_factor = vec2(res.y/res.x, 1.0);
vec2 renorm_tex = res_factor*normalizedVertexMCVSOutput.xy*0.5 + 0.5;
color = vec3(kernel_calculator(screenTexture, renorm_tex, res));
color = kernel_calculator(screenTexture, renorm_tex, res);
//color = vec3(1.0, 0.0, 0.0);
fragOutput0 = vec4(color, opacity);
Expand All @@ -298,7 +351,6 @@ def kernel_callback(obj, event):
actor.SetVisibility(True)
pos, focal, vu = self.on_manager.scene.get_camera()
self.off_manager.scene.set_camera(pos, focal, vu)
self.off_manager.scene.Modified()
self.off_manager.render()

window_to_texture(
Expand Down

0 comments on commit 39f43b4

Please sign in to comment.