-
Notifications
You must be signed in to change notification settings - Fork 182
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
JoaoDell
wants to merge
43
commits into
fury-gl:master
Choose a base branch
from
JoaoDell:feat/api-kde
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 37 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
35bbb98
Post processing functions file
JoaoDell ef06af3
docs?
JoaoDell 110ad6b
feat: Introduces EffectManager Class
JoaoDell a09e262
feat: Opacity inclusion
JoaoDell bec5f0e
fix: Fixed sigma scale and spelling issues
JoaoDell b572b4b
fix: Usage of native colormap function and cleanups
JoaoDell 269c4de
feat: Added remove_effect feature
JoaoDell fae89e1
feat: Added gaussian and laplacian filters
JoaoDell 39f43b4
feat: Added grayscale effect and changed laplacian and gaussian calcu…
JoaoDell 13687be
fix: Fixed gaussian blur issues
JoaoDell 6be3ddc
fix!: Experimenting with multiple effects on the same render and some…
JoaoDell 6dedaec
fix: Fixed textured_billboard positioning issues
JoaoDell bf1503c
fix: Fixed bugs and cleaned EffectManager class
JoaoDell fb024d8
refactor!: Refactored and cleaned the whole PR
JoaoDell edd06e8
Merge branch 'fury-gl:master' into feat/api-kde
JoaoDell 7ecefeb
feat: Added 5 more kernels for the KDE rendering
JoaoDell 68e520e
fix: Added sigma restraining condition
JoaoDell f0a3d6d
feat: Testing renormalization approaches to KDE
JoaoDell f35626e
fix!: Stabilizing approaches to renormalization
JoaoDell 9ad1501
fix: Minor refactoring on effect manager
JoaoDell 0ffaf28
feat!: Experimenting with intensity slider (unstable)
JoaoDell 03299b1
Merge branch 'fury-gl:master' into feat/api-kde
JoaoDell 2c1685a
fix: Deleted effects testing file
JoaoDell 73dfc3f
fix: Deleted experimental files
JoaoDell bacae2e
fix: Improved ui and cleaned the code (deleted other effects)
JoaoDell 80acf71
fix: Added ui tracking inside class
JoaoDell 4490950
fix: Fixed formatting issues and removed UI
JoaoDell 51ae7a6
feat: Initial draft of testing script
JoaoDell e153297
test: Completed testing scripts
JoaoDell 10bcb90
refactor: Written and relocated file to examples
JoaoDell e4612b5
style: Formatted some codes to pep8 and improved example text
JoaoDell 0e475f6
fix: Fixing view up vector
JoaoDell 70d911b
fix: Adressing style issues
JoaoDell 734e8e7
fix: Fixed major scaling issue, sigmas bug, and adressed style issues
JoaoDell 1722b2e
doc: minor doc fix
JoaoDell c54c97f
refactor: use callable approach
devmessias 3f7d335
refactor: effects module
devmessias f996852
refactor: Cleaning refactored API
JoaoDell daa810b
test: Added tests for effects module and tweaked multiple effects han…
JoaoDell f0d855c
test: Implemented the features from last commit
JoaoDell 700e010
fix: Fixed KDE description and set interactive to False
JoaoDell f03bd6a
style: Fixing upper case in shaders.base
JoaoDell ac2ce0d
style: Added Union of float and np.ndarray in bandwidth
JoaoDell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.effects import EffectManager, KDE | ||
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. | ||
|
||
size = (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, 1.0)) | ||
|
||
manager = ShowManager( | ||
scene, | ||
"KDE Render", | ||
(size[0], | ||
size[1])) | ||
|
||
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 bandwidths, | ||
# generated with ``numpy.random.rand`` as well, which are also | ||
# remapped to the range of ``[0.05, 0.2]``. | ||
|
||
bandwidths = 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, bandwidth, 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, bandwidths, kernel="gaussian", colormap="inferno") | ||
kde_effect = KDE(points, bandwidths, kernel="gaussian", colormap="inferno") | ||
effects.add(kde_effect) | ||
|
||
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)) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can directly use
size