-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[GUI] Support saving image without GUI showing a window #1817
[GUI] Support saving image without GUI showing a window #1817
Conversation
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.
Thank you so much! This mostly looks good to me. I only left a few minor comments.
Hey @yuanming-hu, how do I fix this warning? Here's the relevant snippet:
|
python/taichi/misc/gui.py
Outdated
show_gui=True, | ||
res=512, |
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.
show_gui=True, | |
res=512, | |
res=512, | |
show_gui=True, |
Some examples wil break by the argument order.
while (last_frame_interval.size() > 30) { | ||
last_frame_interval.erase(last_frame_interval.begin()); | ||
} | ||
auto real_fps = last_frame_interval.size() / | ||
(std::accumulate(last_frame_interval.begin(), | ||
last_frame_interval.end(), 0.0_f)); | ||
if (show_gui) { |
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.
In fact, we can ignore the FPS-saving sleep
procedure when we just want to save images.
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.
@archibate actually should I also move taichi::Time::wait_until(last_frame_time + frame_delta_limit)
to under the if (show_gui)
?
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.
Yes, I think actually we can move all the codes to update_gui()
? Or simply add if (!show_gui) return;
to the first line of update()
?
tests/python/test_gui.py
Outdated
for i, j, k in pixels: | ||
pixels[i, j, k] = c | ||
|
||
gui = ti.GUI("Test", show_gui=False, res=(n, n)) |
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.
gui = ti.GUI("Test", show_gui=False, res=(n, n)) | |
gui = ti.GUI("Test", (n, n), show_gui=False) |
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 it would be a good idea to keep the named argument for res
in case of constructor order changing?
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.
For example, examples/stable_fluid.py
is using ti.GUI('Stable Fluid', (res, res))
, so it's already broken by this change. I believe many end-users are using res
as positional argument too.
No matter if positional argument is a good design or not, we always want to enforce backward compatibility as much as possible.
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.
Here, I've moved show_gui
to the last argument in the constructor now so that the original order is preserved:
def __init__(self,
name='Taichi',
res=512,
background_color=0x0,
show_gui=True):
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.
Also add if (show_gui)
guard to cocoa.cpp
?
Since all the OS X window resources/functions are called in
, it seems to be okay for now. I added |
Codecov Report
@@ Coverage Diff @@
## master #1817 +/- ##
==========================================
+ Coverage 43.35% 44.09% +0.74%
==========================================
Files 43 44 +1
Lines 5995 6064 +69
Branches 1040 1084 +44
==========================================
+ Hits 2599 2674 +75
+ Misses 3246 3221 -25
- Partials 150 169 +19
Continue to review full report at Codecov.
|
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.
Awesome! LGTM now. Just a final nit. I can merge if that suggestion is adopted and CI passes.
Fixes #1616. cc @archibate @yuanming-hu.
Description
As mentioned in #1616 by @ehannigan, saving the screenshot of a GUI without an actual window will throw
"RuntimeError: [x11.cpp:create_window@139] Taichi fails to create a window. This is probably due to the lack of an X11 GUI environment. If you are using ssh, try ssh -XY."
It is possible to do this with
matplotlib
however it would be better to have a native solution. This PR provides the functionality to save an image without showing a GUI as well as correcting instances ofidendity
.Concerns
Since I'm putting a
if
statement aroundself.core.update()
, is it a concern that the internalGUI
class has a different state fromti.GUI
class?Original version is shown here:
taichi/python/taichi/misc/gui.py
Lines 358 to 363 in 6052a54
I made a
test_gui.py
but there is also anothertest_gui.py
inmisc/
.It could be better to recommend that if
show_GUI
isFalse
, that users usegui.core.screenshot("filename.jpg")
instead of altering theshow
function.