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
Show spheres with different radii, colors and opacities + add timers + add exit a + resolve issue with imread #1528
Conversation
Hello @Garyfallidis, Thank you for updating ! Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on September 01, 2018 at 02:13 Hours UTC |
dipy/viz/actor.py
Outdated
|
||
glyph = vtk.vtkGlyph3D() | ||
glyph.SetSourceConnection(src.GetOutputPort()) | ||
if major_version <= 5: |
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.
As mentioned by @nilgoyette in #1522, we should decide on an alternate name for this variable. Like vtk_major_version
.
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.
Sure but this is a topic for a different PR and see here #1544 Support of old vtk versions should be removed all together. More of a problem than a solution.
Looks good! A couple of points:
|
85e360d
to
ea653be
Compare
iniital changes extra env files deleted input parametrs changed doc changed unnecessary venv files removed NF: added timer callback in ShowManager TEST: added test for timer callbacks TEST: Corrected execution order in test_timer DOC: new example showing the use of timer callbacks Minor changes DOC: correcting figure output Bad indent removed
58316d2
to
20e9d65
Compare
Codecov Report
@@ Coverage Diff @@
## master #1528 +/- ##
==========================================
+ Coverage 87.33% 87.34% +0.01%
==========================================
Files 246 246
Lines 32164 32244 +80
Branches 3497 3500 +3
==========================================
+ Hits 28089 28163 +74
- Misses 3242 3246 +4
- Partials 833 835 +2
Continue to review full report at Codecov.
|
After travis passes @ranveeraggarwal, @karandeepSJ, @dmreagan and @MarcCote this should be ready to be merged. |
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.
I like the new timer feature. I've added some comments related to that.
showm.initialize() | ||
|
||
def timer_callback(obj, event): | ||
global cnt, sphere_actor, showm, tb |
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.
Do you really need global here? Since timer_callback
is a nested function, those variables should be in the scope.
|
||
showm.initialize() | ||
|
||
def timer_callback(obj, event): |
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.
What's obj
here? What kind of VTK object should we expect?
doc/examples/viz_timers.py
Outdated
|
||
|
||
def timer_callback(obj, event): | ||
global cnt, sphere_actor, showm, tb |
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.
I think we should avoid globals whenever it is possible. Here you can safely remove all globals and make cnt
a mutable variable (e.g. a list). Even better, declare a counter = itertools.count()
instead of cnt = 0
(at line 40), then replace cnt += 1
with cnt = next(counter)
(at line 46).
# Run every 200 milliseconds | ||
showm.add_timer_callback(True, 200, timer_callback) | ||
|
||
showm.start() |
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.
This should be commented?
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.
Nope, start does not need to be commented @MarcCote :) That is the great thing here we can close the application whenever we want from inside the timer callback. Perfect for testing viz, building animations etc. This is a really nice new feature. Don't you agree? :)
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.
Oh nice!
@@ -0,0 +1,69 @@ | |||
""" | |||
=============== | |||
Using a timer |
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.
Go this warning when running the example.
/home/macote/.local/venvs/dipy/lib/python3.6/site-packages/vtk/util/numpy_support.py:137: FutureWarning: Conversion of the second argument of issubdtype from `complex` to `np.complexfloating` is deprecated. In future, it will be treated as `np.complex128 == np.dtype(complex).type`.
assert not numpy.issubdtype(z.dtype, complex), \
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.
Interesting. As far as I know we do not use complex numbers
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.
@skoudoro would be great if we can track down these FutureWarnings appearing when running this example.
|
||
showm.start() | ||
|
||
window.record(showm.ren, size=(900, 768), out_path="viz_timer.png") |
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.
The screenshot recorded says Let's count up to 100 and exit: 101
. I would have expected to see 100 instead of 101.
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.
lol okay sure. Will fix that. Sharp eyes @MarcCote!
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.
;)
@@ -591,6 +586,28 @@ def add_window_callback(self, win_callback): | |||
self.window.AddObserver(vtk.vtkCommand.ModifiedEvent, win_callback) | |||
self.window.Render() | |||
|
|||
def add_timer_callback(self, repeat, duration, timer_callback): | |||
self.iren.AddObserver("TimerEvent", timer_callback) |
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.
Rather than using timer_callback
directly, we could wrap it with our own method/function that way we can control what arguments will be provided to timer_callback
.
For instance, at the moment timer_callback
is a function that expects two arguments: a vtkRenderWindowInteractor
and a str
(the event's name). I doubt common users would use them but they are still forced to provide a callback function that accepts those two arguments. What I propose is the following:
def _wrap_timer_callback(self, timer_callback):
def _wrapped_timer_callback(iren, event):
timer_callback(self, ...)
return _wrapped_timer_callback
then replace line 590 with
self.iren.AddObserver("TimerEvent", self._wrap_timer_callback(timer_callback))
Note ...
means we could provide any Python object we deem relevant in addition to the ShowManager
instance (i.e. self
).
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.
Okay, this is an important point. But does not make much sense changing that in this PR. We need to make decisions about callbacks in a developers meeting. I know that each one of us @karandeepSJ, @dmreagan, @ranveeraggarwal and myself have different suggestions of what will be the optimal strategy with callbacks. My plan is to have that discussion as soon as possible. Possibly after the first split of viz modules. Will send a doodle about that. But for now I suggest moving ahead with this PR. Let me know if you disagree.
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.
I agree.
LGTM |
@skoudoro this is ready to be merged. Please do merge it. Also, we should check why codecov/patch reports coverage on tests. That looks incorrect. Thanks all for reviewing. |
After some tests, LGTM too. merging |
Nice and simple to use function for visualizing many spheres with different radii and colors. RGB and RGBA colors are allowed. A (opacity) component can be different for each sphere.
Adding timers in ShowManager for building animations.
Allowing exiting (closing) a window from inside ShowManager.
Resolving issue with imread as it is not available anymore in scipy.misc.