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

First Stage of the KDE Rendering API #826

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
43 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
2c1685a
fix: Deleted effects testing file
JoaoDell Aug 1, 2023
73dfc3f
fix: Deleted experimental files
JoaoDell Aug 1, 2023
bacae2e
fix: Improved ui and cleaned the code (deleted other effects)
JoaoDell Aug 1, 2023
80acf71
fix: Added ui tracking inside class
JoaoDell Aug 1, 2023
4490950
fix: Fixed formatting issues and removed UI
JoaoDell Aug 2, 2023
51ae7a6
feat: Initial draft of testing script
JoaoDell Aug 3, 2023
e153297
test: Completed testing scripts
JoaoDell Aug 3, 2023
10bcb90
refactor: Written and relocated file to examples
JoaoDell Aug 3, 2023
e4612b5
style: Formatted some codes to pep8 and improved example text
JoaoDell Aug 4, 2023
0e475f6
fix: Fixing view up vector
JoaoDell Aug 7, 2023
70d911b
fix: Adressing style issues
JoaoDell Aug 10, 2023
734e8e7
fix: Fixed major scaling issue, sigmas bug, and adressed style issues
JoaoDell Aug 14, 2023
1722b2e
doc: minor doc fix
JoaoDell Aug 15, 2023
c54c97f
refactor: use callable approach
devmessias Aug 15, 2023
3f7d335
refactor: effects module
devmessias Aug 15, 2023
f996852
refactor: Cleaning refactored API
JoaoDell Aug 16, 2023
daa810b
test: Added tests for effects module and tweaked multiple effects han…
JoaoDell Aug 17, 2023
f0d855c
test: Implemented the features from last commit
JoaoDell Aug 17, 2023
700e010
fix: Fixed KDE description and set interactive to False
JoaoDell Aug 20, 2023
f03bd6a
style: Fixing upper case in shaders.base
JoaoDell Aug 21, 2023
ac2ce0d
style: Added Union of float and np.ndarray in bandwidth
JoaoDell Aug 21, 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
3 changes: 2 additions & 1 deletion docs/examples/_valid_examples.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ files = [
"viz_pbr_interactive.py",
"viz_emwave_animation.py",
"viz_helical_motion.py",
"viz_play_video.py"
"viz_play_video.py",
"viz_kde_render.py"
]

[ui]
Expand Down
112 changes: 112 additions & 0 deletions docs/examples/viz_kde_render.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
"""
======================================================================
Fury Kernel Density Estimation rendering Actor
======================================================================
This example shows how to use the KDE actor. This is a special actor in Fury that works
with post-processing effects to render kernel density estimations of a given set of points
in real-time to the screen. For better understanding on KDEs, check this
`Wikipedia page <https://en.wikipedia.org/wiki/Kernel_density_estimation>`_ about it.

For this example, you will only need the modules below:
"""
import numpy as np

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

#####################################################################################
# This function below will help us to relocate the points for a better visualization,
# but it is not required.

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.")

##################################################################
# First, we need to setup the screen we will render the points to.

width, height = (1200, 1000)
JoaoDell marked this conversation as resolved.
Show resolved Hide resolved

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

manager = ShowManager(
scene,
"demo",
JoaoDell marked this conversation as resolved.
Show resolved Hide resolved
(width,
height))

manager.initialize()

####################################################################
# ``numpy.random.rand`` will be used to generate random points, which
# will be then relocated with the function we declared below to the
# range of ``[-5.0, 5.0]``, so they get more space between them. In case
# offsetted points are wanted, it can be done just as below.

n_points = 1000
points = np.random.rand(n_points, 3)
points = normalize(points, -5, 5)
offset = np.array([0.0, 0.0, 0.0])
points = points + np.tile(offset, points.shape[0]).reshape(points.shape)

###################################################################
# For this KDE render, we will use a set of random sigmas as well,
# generated with ``numpy.random.rand`` as well, which are also
JoaoDell marked this conversation as resolved.
Show resolved Hide resolved
# remapped to the range of ``[0.05, 0.2]``.

sigmas = normalize(np.random.rand(n_points, 1), 0.05, 0.2)


###################################################################
# Now, for the KDE render, a special class is needed, the
# ``EffectManager``. This class is needed to manage the post-processing
# aspect of this kind of render, as it will need to first be
# rendered to an offscreen buffer, retrieved and then processed
# by the final actor that will render it to the screen, but don't
# worry, none of this will need to be setup by you! Just call the
# ``EffectManager`` like below, passing the manager to it:

effects = EffectManager(manager)

###################################################################
# After having the ``effects`` setup, just call the kde actor method
# from it, passing the points, sigma, and other optional options
# if wished, like the kernel to be used or the colormap desired.
# The colormaps are by default taken from *matplotlib*, but a
# custom one can be passed. After calling it, just pass the actor
# to the scene, and start it as usual.

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

manager.scene.add(kde_actor)

interactive = True
JoaoDell marked this conversation as resolved.
Show resolved Hide resolved

if interactive:
manager.start()

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