Skip to content

Commit

Permalink
fix!: Stabilizing approaches to renormalization
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoDell committed Jul 30, 2023
1 parent f0a3d6d commit f35626e
Show file tree
Hide file tree
Showing 5 changed files with 971 additions and 8 deletions.
28 changes: 28 additions & 0 deletions docs/experimental/viz_billboards.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import numpy as np

from fury.actor import billboard
from fury.window import Scene, ShowManager

width, height = (1350, 800)

scene = Scene()
scene.set_camera(position=(-6, 5, -10),
focal_point=(0.0,
0.0,
0.0),
view_up=(0.0, 0.0, 0.0))

manager = ShowManager(
scene,
"demo",
(width,
height))

manager.initialize()

scale = 3.4*np.array([[width/height, 1.0, 0.0]])

bill = billboard(np.array([[0.0, 0.0, 0.0]]), scales=scale,colors = (1.0, 0.0, 0.0))
manager.scene.add(bill)

manager.start()
6 changes: 3 additions & 3 deletions docs/experimental/viz_kde_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ def normalize(array : np.array, min : float = 0.0, max : float = 1.0, axis : int

n_points = 1000
points = np.random.rand(n_points, 3)
points = normalize(points, -5.0, 5.0)
sigmas = normalize(np.random.rand(n_points, 1), 0.1, 0.5)
points = normalize(points, -5, 5)
sigmas = normalize(np.random.rand(n_points, 1), 0.2, 0.9)
offset = np.array([0.0, 0.0, 0.0])
points = points + np.tile(offset, points.shape[0]).reshape(points.shape)

effects = EffectManager(manager)

kde_actor = effects.kde(points, sigmas, kernel = "gaussian", colormap = "inferno")
kde_actor = effects.kde(points, sigmas, kernel = "linear", colormap = "inferno")


manager.scene.add(kde_actor)
Expand Down
4 changes: 3 additions & 1 deletion fury/actors/effect_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ def window_to_texture(

windowToImageFilter = WindowToImageFilter()
windowToImageFilter.SetInput(window)
type_dic = {"rgb" : windowToImageFilter.SetInputBufferTypeToRGB, "rgba" : windowToImageFilter.SetInputBufferTypeToRGBA}
type_dic = {"rgb" : windowToImageFilter.SetInputBufferTypeToRGB,

Check warning on line 77 in fury/actors/effect_manager.py

View check run for this annotation

Codecov / codecov/patch

fury/actors/effect_manager.py#L75-L77

Added lines #L75 - L77 were not covered by tests
"rgba" : windowToImageFilter.SetInputBufferTypeToRGBA,
"zbuffer" : windowToImageFilter.SetInputBufferTypeToZBuffer}
type_dic[d_type.lower()]()
windowToImageFilter.Update()

Check warning on line 81 in fury/actors/effect_manager.py

View check run for this annotation

Codecov / codecov/patch

fury/actors/effect_manager.py#L80-L81

Added lines #L80 - L81 were not covered by tests

Expand Down
32 changes: 28 additions & 4 deletions fury/actors/effect_manager_alt.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,23 @@ def kde(self,
}
"""

avg_filter = """

Check warning on line 386 in fury/actors/effect_manager_alt.py

View check run for this annotation

Codecov / codecov/patch

fury/actors/effect_manager_alt.py#L386

Added line #L386 was not covered by tests
vec4 avg_calculator(sampler2D screenTexture, vec2 tex_coords, vec2 res){
float x_median_offsets[5] = {-1.0, 0.0, 1.0,
0.0, 0.0};
const float y_median_offsets[5] = {0.0, -1.0, 0.0,
1.0, 0.0};
vec4 value = vec4(0.0);
vec4 col = vec4(0.0);
for(int i = 0; i < 5; i++){
col = texture(screenTexture, tex_coords + vec2(1/res.x, 1/res.y)*vec2(x_median_offsets[i], y_median_offsets[i]));
value += col;
}
return value/5.0;
}
"""

map_func = """

Check warning on line 403 in fury/actors/effect_manager_alt.py

View check run for this annotation

Codecov / codecov/patch

fury/actors/effect_manager_alt.py#L403

Added line #L403 was not covered by tests
float map(float value, float o_min, float o_max, float new_min, float new_max) {
return new_min + (value - o_min) * (new_max - new_min) / (o_max - o_min);
Expand All @@ -391,7 +408,7 @@ def kde(self,

tex_dec = import_fury_shader(os.path.join("effects", "color_mapping.glsl"))

Check warning on line 409 in fury/actors/effect_manager_alt.py

View check run for this annotation

Codecov / codecov/patch

fury/actors/effect_manager_alt.py#L409

Added line #L409 was not covered by tests

tex_dec = compose_shader([tex_dec, de_converter, map_func, gaussian_kernel, gauss_dec])
tex_dec = compose_shader([tex_dec, de_converter, map_func, gaussian_kernel, gauss_dec, avg_filter])

Check warning on line 411 in fury/actors/effect_manager_alt.py

View check run for this annotation

Codecov / codecov/patch

fury/actors/effect_manager_alt.py#L411

Added line #L411 was not covered by tests

tex_impl = """

Check warning on line 413 in fury/actors/effect_manager_alt.py

View check run for this annotation

Codecov / codecov/patch

fury/actors/effect_manager_alt.py#L413

Added line #L413 was not covered by tests
// Turning screen coordinates to texture coordinates
Expand Down Expand Up @@ -493,12 +510,19 @@ def kde_callback(obj, event):
d_type = "rgba")

converted_img = back_converter(img)
converted_img = converted_img[converted_img != 0.0]

Check warning on line 513 in fury/actors/effect_manager_alt.py

View check run for this annotation

Codecov / codecov/patch

fury/actors/effect_manager_alt.py#L512-L513

Added lines #L512 - L513 were not covered by tests

max_value = np.max(converted_img)
avg = np.average(converted_img)
min_value = np.min(converted_img)
print(min_value, max_value)
low_v = converted_img[converted_img <= avg].shape[0]
high_v = converted_img[converted_img > avg].shape[0]
max_value_2 = avg + (avg - min_value)*(high_v/low_v)

Check warning on line 519 in fury/actors/effect_manager_alt.py

View check run for this annotation

Codecov / codecov/patch

fury/actors/effect_manager_alt.py#L515-L519

Added lines #L515 - L519 were not covered by tests
# print(min_value, max_value)
# max_value = np.max(converted_img)
# print(min_value, max_value, max_value_2)
# print(converted_img[converted_img <= max_value_2].shape[0], converted_img[converted_img > max_value_2].shape[0])
shader_custom_uniforms(textured_billboard, "fragment").SetUniformf("min_value", min_value)
shader_custom_uniforms(textured_billboard, "fragment").SetUniformf("max_value", max_value)
shader_custom_uniforms(textured_billboard, "fragment").SetUniformf("max_value", max_value_2)

Check warning on line 525 in fury/actors/effect_manager_alt.py

View check run for this annotation

Codecov / codecov/patch

fury/actors/effect_manager_alt.py#L524-L525

Added lines #L524 - L525 were not covered by tests

# Initialization
img = window_to_texture(

Check warning on line 528 in fury/actors/effect_manager_alt.py

View check run for this annotation

Codecov / codecov/patch

fury/actors/effect_manager_alt.py#L528

Added line #L528 was not covered by tests
Expand Down
Loading

0 comments on commit f35626e

Please sign in to comment.