Skip to content

MNT: Depth-peeling 3d option - #10319

Merged
hoechenberger merged 12 commits into
mne-tools:mainfrom
GuillaumeFavelier:mnt/depth_peeling
Feb 11, 2022
Merged

hoechenberger merged 12 commits into
mne-tools:mainfrom
GuillaumeFavelier:mnt/depth_peeling

Conversation

@GuillaumeFavelier

@GuillaumeFavelier GuillaumeFavelier commented Feb 10, 2022 •

Copy link
Copy Markdown
Contributor

This PR adds a 3d option to control depth peeling to address issues with X forwarding.

It is still work in progress:

  • should depth peeling be enabled by default?
  • should it be disabled on CircleCI?

In another PR, I plan to refactor the properties of _PyVistaRenderer and move them into _Figure where I think they should live (the store attribute serves this purpose).

cc @hoechenberger

@GuillaumeFavelier GuillaumeFavelier self-assigned this Feb 10, 2022
@GuillaumeFavelier GuillaumeFavelier changed the title MNT: Depth-peeling 3d option WIP,MNT: Depth-peeling 3d option Feb 10, 2022
@larsoner

Copy link
Copy Markdown
Member

+1 for enabling by default and allowing a way to turn it off.

@GuillaumeFavelier you might want to git grep enable_depth_peeling, hopefully you can get rid of the ones we do internall (e.g., in vector STC plotting, in coreg) and the ones in tutorials. Ideally we would just always turn it on after this PR (unless someone config-vars it off)

@larsoner

Copy link
Copy Markdown
Member

should it be disabled on CircleCI?

I think CircleCI might actually support depth peeling...? In any case, if you touch a few translucent geometry examples then we'll be able to see if CircleCI renders them properly

@hoechenberger

Copy link
Copy Markdown
Member

@GuillaumeFavelier Thanks for working on this! I agree with @larsoner that it should be ON by default so everything looks nice, and only if this breaks stuff for users, they can turn it off. We can document the steps necessary if one experiences odd behavior or crashes (like I did with X2go on NeuroSpin infrastructure)

Comment thread mne/viz/_3d.py Outdated

_3d_options = dict()
_3d_default = dict(antialias='true')
_3d_default = dict(antialias='true', depth_peeling='true')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd turn this into a dataclass to increase robustness against typos :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used it in e4550bf. Is it what you had in mind?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Richard means: depth_peeling=True

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I had an Outdated view of the PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, thanks for taking the time 👌

Comment thread mne/viz/_3d.py Outdated
MESA renderers). This option can also be controlled using an
environment variable, e.g., ``MNE_3D_OPTION_ANTIALIAS=false``.
depth_peeling : bool | None
If not None, set the default setting for accurate transparency.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh I hate the phrasing, "not None", I always have to do massive mental gymnastics to understand what it means (I think we discussed this the other day 🙈) Do you think you could turn this around?

@GuillaumeFavelier GuillaumeFavelier Feb 11, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reworked it in 3b06ba5. What do you think?

Comment thread mne/viz/_3d.py Resolved
@agramfort

agramfort commented Feb 10, 2022 via email

Copy link
Copy Markdown
Member

Comment thread mne/viz/_brain/_brain.py Resolved
@agramfort

Copy link
Copy Markdown
Member

tell us when it's good to go @GuillaumeFavelier

self.antialias = _get_3d_option('antialias') and \
not MNE_3D_BACKEND_TESTING
self.depth_peeling = _get_3d_option('depth_peeling') and \
not MNE_3D_BACKEND_TESTING

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this stuff, in conftest.py we should maybe just have a session-level fixture that picks up on MNE_3D_BACKEND_TESTING and monkeypatch.setenv('MNE_3D_OPTION_ANTIALIAS', 'false'). Then we don't need code here, just in our tests...

@GuillaumeFavelier GuillaumeFavelier Feb 11, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value still needs to be tested in the code right? However the variable is set

@larsoner larsoner Feb 11, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean.

Currently, MNE_3D_BACKEND_TESTING=true is always set if and only if testing is done, right?

If that's the case, then instead of even having this MNE_3D_BACKEND_TESTING env var used here, we should monkeypatch.setattr('MNE_3D_OPTION_ANTIALIAS', 'false') in a fixture that pytest uses for the entire session. That way the code here can just be:

self.antialias = _get_3d_option('antialias')

And the _get_3d_option will get_config('MNE_3D_OPTION_ANTIALIAS'), which will pick up the env var that we set in the fixture via monkeypatch. The effect ends up being the same: we turn off antialiasing (and depth peeling) in all our tests, and we only mess with the value the user has set during testing.

It helps keep testing-related stuff in conftest.py and out of places it doesn't belong (like _pyvista.py)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... if it's not clear what I mean by this, I can push a quick commit to do what I suggest and you can see if it makes sense

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh now I get it, thanks for the explanation.

Of course you can commit in here @larsoner

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GuillaumeFavelier can you open a follow-up PR for this?

@GuillaumeFavelier
GuillaumeFavelier marked this pull request as ready for review February 11, 2022 14:24
@GuillaumeFavelier GuillaumeFavelier changed the title WIP,MNT: Depth-peeling 3d option MNT: Depth-peeling 3d option Feb 11, 2022
@GuillaumeFavelier

Copy link
Copy Markdown
Contributor Author

That's the one I had locally @larsoner

 =================================== FAILURES ===================================
__________________________ test_docstring_parameters ___________________________
mne/tests/test_docstring_parameters.py:156: in test_docstring_parameters
    raise AssertionError(msg)
E   AssertionError: 
E   mne.viz._brain._brain.Brain.enable_depth_peeling : GL02 : Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
E   1 error

https://github.com/mne-tools/mne-python/runs/5157397856?check_suite_focus=true#step:9:3337

@larsoner

Copy link
Copy Markdown
Member

I noticed some differences here

I think it actually is more accurate! You can clearly tell what is totally inside the brain and what is not

That's the one I had locally @larsoner

Yikes, me too! Feel free to put it back in

This reverts commit 8c611f8.
@larsoner larsoner added this to the 1.0 milestone Feb 11, 2022
@hoechenberger
hoechenberger merged commit a5f8d0b into mne-tools:main Feb 11, 2022
@hoechenberger

hoechenberger commented Feb 11, 2022 •

Copy link
Copy Markdown
Member

Thank you, @GuillaumeFavelier!! and @larsoner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants