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] UI intensity slider for the KDE rendering API #849

Draft
wants to merge 33 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
35bbb98
Post processing functions file
JoaoDell Jul 19, 2023
ef06af3
docs?
JoaoDell Jul 19, 2023
110ad6b
feat: Introduces EffectManager Class
JoaoDell Jul 20, 2023
a09e262
feat: Opacity inclusion
JoaoDell Jul 20, 2023
bec5f0e
fix: Fixed sigma scale and spelling issues
JoaoDell Jul 21, 2023
b572b4b
fix: Usage of native colormap function and cleanups
JoaoDell Jul 21, 2023
269c4de
feat: Added remove_effect feature
JoaoDell Jul 21, 2023
fae89e1
feat: Added gaussian and laplacian filters
JoaoDell Jul 22, 2023
39f43b4
feat: Added grayscale effect and changed laplacian and gaussian calcu…
JoaoDell Jul 24, 2023
13687be
fix: Fixed gaussian blur issues
JoaoDell Jul 24, 2023
6be3ddc
fix!: Experimenting with multiple effects on the same render and some…
JoaoDell Jul 25, 2023
6dedaec
fix: Fixed textured_billboard positioning issues
JoaoDell Jul 25, 2023
bf1503c
fix: Fixed bugs and cleaned EffectManager class
JoaoDell Jul 27, 2023
fb024d8
refactor!: Refactored and cleaned the whole PR
JoaoDell Jul 27, 2023
edd06e8
Merge branch 'fury-gl:master' into feat/api-kde
JoaoDell Jul 27, 2023
7ecefeb
feat: Added 5 more kernels for the KDE rendering
JoaoDell Jul 27, 2023
68e520e
fix: Added sigma restraining condition
JoaoDell Jul 27, 2023
f0a3d6d
feat: Testing renormalization approaches to KDE
JoaoDell Jul 29, 2023
f35626e
fix!: Stabilizing approaches to renormalization
JoaoDell Jul 30, 2023
9ad1501
fix: Minor refactoring on effect manager
JoaoDell Jul 31, 2023
0ffaf28
feat!: Experimenting with intensity slider (unstable)
JoaoDell Aug 1, 2023
03299b1
Merge branch 'fury-gl:master' into feat/api-kde
JoaoDell Aug 1, 2023
bd335f1
fix: Camera position update
JoaoDell Aug 1, 2023
a173dfd
feat: Updating UI
JoaoDell Aug 2, 2023
25921c3
refactor: Added tracking of original actors of applied effects
JoaoDell Aug 3, 2023
2d72b48
fix: Trying to fix the noise
JoaoDell Aug 6, 2023
90069bf
build: Changed viz_laplacian.py effect manager lib
JoaoDell Aug 7, 2023
18bda11
feat: Hardcoded fullscreen billboard
JoaoDell Aug 10, 2023
6ff0f0b
feat: testing billboard properties
JoaoDell Aug 11, 2023
ca2e1e3
refactor: Toying around with zbuffer
JoaoDell Aug 13, 2023
82fbbb2
feat: Trying median filter
JoaoDell Aug 19, 2023
071b3b5
Merge branch 'fury-gl:master' into feat/api-kde-improve
JoaoDell Aug 27, 2023
1c4c52c
feat: UI slider for bandwidth intensity
JoaoDell Aug 27, 2023
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
71 changes: 71 additions & 0 deletions docs/experimental/float_to_rgb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import numpy as np
i = 255 + 255*256 + 255*256**2 + 255*256**3
i = 0.000000001
j = 0.000000001
f = int(i*256*256*256*256 - 1)
g = int(j*256*256*256*256 - 1)
print("f:", f)

def converter(n):
f = int(n*256*256*256*256 - 1)
c = np.zeros(4, dtype = float)
c[0] = f % 256
c[1] = float((f % 256**2 - c[0]) // 256)
c[2] = float((f % 256**3 - c[1] - c[0]) // 256**2)
c[3] = float((f % 256**4 - c[2] - c[1] - c[0]) // 256**3)

return c/255

def de_converter(h):
return (255*(h[0] + h[1]*256 + h[2]*256**2 + h[3]*256**3) + 1.0)/(256*256*256*256)

c = converter(i)
d = converter(j)
# print(f, g)
# print(i)
# print(np.array(c))
de = de_converter(c + d)
# print(int(de*256*256*256*256 - 1))



def gaussian_kernel(n, sigma = 1.0):
x0 = np.arange(0.0, 1.0, 1/n)
y0 = np.arange(0.0, 1.0, 1/n)
x, y = np.meshgrid(x0, y0)
center = np.array([x0[n // 2], y0[n // 2]])
mesh = np.stack((x, y), 2)
center = np.repeat(center, x.shape[0]*y.shape[0]).reshape(x.shape[0], y.shape[0], 2)
kernel = np.exp((-1.0*np.linalg.norm(center - mesh, axis = 2)**2)/(2*sigma**2))
string = f"const float gauss_kernel[{x.shape[0]*y.shape[0]}] = "
kernel = kernel/np.sum(kernel)
flat = str(kernel.flatten()).split(" ")
copy_flat = flat.copy()
taken = 0
for i in range(len(flat)):
if flat[i] == ' ' or flat[i] == '':
copy_flat.pop(i - taken)
taken += 1
if "[" in copy_flat[0]:
copy_flat[0] = copy_flat[0][1:]
else:
copy_flat.pop(0)

if "]" in copy_flat[-1]:
copy_flat[-1] = copy_flat[-1][:-1]
else:
copy_flat.pop(-1)

if '' == copy_flat[0]:
copy_flat.pop(0)

if '' == copy_flat[-1]:
copy_flat.pop(-1)

# copy_flat.pop(-1)
print(copy_flat)

string += "{" + ", ".join(copy_flat) + "};"
return string

print(gaussian_kernel(13, 3.0))
68 changes: 68 additions & 0 deletions docs/experimental/viz_kde_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import numpy as np

from fury.actors.effect_manager import EffectManager
from fury.window import Scene, ShowManager, record

def normalize(array : np.array, min : float = 0.0, max : float = 1.0, axis : int = 0):
"""Convert an array to a given desired range.

Parameters
----------
array : np.ndarray
Array to be normalized.
min : float
Bottom value of the interval of normalization. If no value is given, it is passed as 0.0.
max : float
Upper value of the interval of normalization. If no value is given, it is passed as 1.0.

Returns
-------
array : np.array
Array converted to the given desired range.
"""
if np.max(array) != np.min(array):
return ((array - np.min(array))/(np.max(array) - np.min(array)))*(max - min) + min
else:
raise ValueError(
"Can't normalize an array which maximum and minimum value are the same.")


width, height = (1200, 1000)

scene = Scene()
scene.set_camera(position=(-24, 20, -40),
focal_point=(0.0,
0.0,
0.0),
view_up=(0.0, 0.0, 0.0))

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

manager.initialize()


n_points = 1000
points = np.random.rand(n_points, 3)
points = normalize(points, -5, 5)
sigmas = normalize(np.random.rand(n_points, 1), 0.1, 0.3)
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 = "exponential", colormap = "inferno")


manager.scene.add(kde_actor)
# effects.remove_effect(kde_actor)

interactive = True

if interactive:
manager.start()

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