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

MRG: Recreate our helmet graphic #8116

Merged
merged 13 commits into from
Sep 8, 2020
Merged

MRG: Recreate our helmet graphic #8116

merged 13 commits into from
Sep 8, 2020

Conversation

larsoner
Copy link
Member

I tried to recreate our helmet:

Using Mayavi I get this output for the new example:

Screenshot from 2020-08-11 13-56-44

If I switch to PyVista, I get:

Screenshot from 2020-08-11 13-56-58

Problems thus far:

  1. The coincident topology is not resolved for mayavi or PyVista (if you rotate the scene, PyVista also cuts off parts of the yellow). Perhaps if plot_evoked_field could set the polygon_offset it could be fixed?
  2. The coincident topology for the field lines is wrong for PyVista -- they should be on top.
  3. The camera systems are not equivalent between PyVista and Mayavi.

@GuillaumeFavelier can you look into these when you get a chance? Feel free to push directly here

@larsoner larsoner added this to the 0.21 milestone Aug 11, 2020
@larsoner larsoner changed the title WIP: Recreate our helmet WIP: Recreate our helmet graphic Aug 21, 2020
@GuillaumeFavelier GuillaumeFavelier self-assigned this Aug 24, 2020
@GuillaumeFavelier
Copy link
Contributor

GuillaumeFavelier commented Aug 24, 2020

The camera settings are better IMO. It's good enough for me but I let you try @larsoner

I use a fixed width for the tubes, it would be better to find a suitable value automatically.

The coincident topology still needs to be fixed.

@larsoner
Copy link
Member Author

Indeed it is getting closer:

@larsoner
Copy link
Member Author

For coindicent topology, can we have something like polygon_offset=0 in some mesh call? Then it sets the appropriate Mayavi and PyVista properties under the hood (use polygon offset resolution + set polygon offset)? Assuming it fixes the problem then it's okay to make use of this in the example, and we can use it in _Brain, too. (I've noticed some coincident topology problems there, too, from time to time when rotating a brain.) We probably need to enable the polygon offset for all meshes for it to work (?).

@GuillaumeFavelier
Copy link
Contributor

GuillaumeFavelier commented Aug 28, 2020

I added polygon_offset in mesh() and surface() and updated the docstrings. It also replaces resolve_coincident_topology in _Brain. I'm not sure what is the best strategy to resolve those issues. For now, I just set some fixed values that give the best result based on what I observe.

We probably need to enable the polygon offset for all meshes for it to work (?)

That I don't know. I did some experiments locally and it does not seem necessary but it may be in the future once we have a definitive solution.

Also about Mayavi, I did not find any alternative to SetRelativeCoincidentTopologyPolygonOffsetParameters. Here are some relevant default values that I found:

...
'resolve_coincident_topology': 'polygon_offset',
'resolve_coincident_topology_': 1,
'resolve_coincident_topology_polygon_offset_faces': 1,
'resolve_coincident_topology_z_shift': 0.01,
...

@GuillaumeFavelier
Copy link
Contributor

This is the helmet I have with the new changes:

image

@GuillaumeFavelier
Copy link
Contributor

GuillaumeFavelier commented Aug 28, 2020

By letting the contour filter detect the range of scalar values, I get the same result (talking about the lines):

PyVista Mayavi
image image

@larsoner
Copy link
Member Author

  • Can you try playing with the Mayavi parameters window (leftmost icon in the toolbar) to see if you can find the right button to tweak there to fix the coincident topology? If you can't get it to work I can try.
  • Should we add a parameter for the line width of the contours? It looks like mayavi defaults to 1 and PyVista doesn't

@GuillaumeFavelier
Copy link
Contributor

  1. I can try
  2. For PyVista these are tubes now, I will render again using just the lines. To tweak that, there is the width parameter.

This is what I use:

        # And the field lines on top
        renderer.contour(surface=surf, scalars=data, contours=n_contours,
                         vmin=-vmax, vmax=vmax, opacity=alpha,
                         colormap=colormap_lines, kind='tube',
                         width=0.0005)

@larsoner
Copy link
Member Author

Do the lines also require a polygon_offset tweak?

@larsoner
Copy link
Member Author

(The tubes presumably do not because they actually protrude from the surface; the lines OTOH will be coincident)

@GuillaumeFavelier
Copy link
Contributor

GuillaumeFavelier commented Aug 28, 2020

Seems like it does not matter it it's just a screenshot. The difference is more visible when you interact with the scene:

line tube
image image

Do the lines also require a polygon_offset tweak?

Apparently they don't need the modification.

@larsoner
Copy link
Member Author

Okay, feel free to choose either one based on which one you think looks better / more like the original. I guess the only remaining issue is the Mayavi coincident topology, right?

@GuillaumeFavelier
Copy link
Contributor

I guess the only remaining issue is the Mayavi coincident topology, right?

Yes indeed

@GuillaumeFavelier
Copy link
Contributor

I have pretty much the same mapper options:

image

I tried z-shift but there is some noise remaining near the cell edges:

image

The best solution I found was to "Force translucent" the white surface (that way, the colors blend):

image

Result:

image

@larsoner
Copy link
Member Author

pip-pre errors/segfaults are numpy/numpy#17198 and can be ignored for now

@GuillaumeFavelier
Copy link
Contributor

Update after #8182 :

Mayavi PyVista
image image

@GuillaumeFavelier
Copy link
Contributor

Also we should consider making PyVista the default backend. It's an item of #7162

@agramfort
Copy link
Member

agramfort commented Sep 8, 2020 via email

@GuillaumeFavelier
Copy link
Contributor

@agramfort I opened #8220 :)

@@ -304,7 +304,8 @@ def _set_aspect_equal(ax):

@verbose
def plot_evoked_field(evoked, surf_maps, time=None, time_label='t = %0.0f ms',
n_jobs=1, fig=None, verbose=None):
n_jobs=1, fig=None, vmax=None, n_contours=21,
Copy link
Member

Choose a reason for hiding this comment

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

21 was the mayavi default?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, IIRC

Copy link
Contributor

@GuillaumeFavelier GuillaumeFavelier Sep 8, 2020

Choose a reason for hiding this comment

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

My bad, it's actually 10 but 21 was the default number of contours used in the function. I will change that

@agramfort
Copy link
Member

agramfort commented Sep 8, 2020 via email

@GuillaumeFavelier GuillaumeFavelier changed the title WIP: Recreate our helmet graphic MRG: Recreate our helmet graphic Sep 8, 2020
@GuillaumeFavelier
Copy link
Contributor

I pushed a commit to tweak the distance too:

Before After
image image

WDYT @larsoner ?

@agramfort
Copy link
Member

perfect on my side !

@larsoner larsoner merged commit 13a5ea4 into mne-tools:master Sep 8, 2020
@larsoner
Copy link
Member Author

larsoner commented Sep 8, 2020

Thanks @GuillaumeFavelier !

@larsoner larsoner deleted the field branch September 8, 2020 16:39
larsoner added a commit to libertyh/mne-python that referenced this pull request Sep 9, 2020
* upstream/master: (489 commits)
  MRG, DOC: Fix ICA docstring, add whitening (mne-tools#8227)
  MRG: Extract measurement date and age for NIRX files (mne-tools#7891)
  Nihon Kohden EEG file reader WIP (mne-tools#6017)
  BUG: Fix scaling for src_mri_t in coreg (mne-tools#8223)
  MRG: Set pyvista as default 3d backend (mne-tools#8220)
  MRG: Recreate our helmet graphic (mne-tools#8116)
  [MRG] Adding get_montage for montage to BaseRaw objects (mne-tools#7667)
  ENH: Allow setting tqdm backend (mne-tools#8177)
  [MRG, IO] Persyst reader into Raw object (mne-tools#8176)
  MRG, BUG: Fix errors in IO/loading/projectors (mne-tools#8210)
  MAINT: vectorize _read_annotations_edf (mne-tools#8214)
  FIX : events_from_annotation when annotations.orig_time is None and f… (mne-tools#8209)
  FIX: do not project to sphere; DOC - explain how to get EEGLAB-like topoplots (mne-tools#7455)
  [MRG, DOC] Added linear algebra of transform to doc (mne-tools#7087)
  FIX: Travis failure on python3.8.1 (mne-tools#8207)
  BF: String formatting in exception message (mne-tools#8206)
  BUG: Fix STC limit bug (mne-tools#8202)
  MRG, DOC: fix ica tutorial (mne-tools#8175)
  CSP component order selection (mne-tools#8151)
  MRG, ENH: Add on_missing to plot_events (mne-tools#8198)
  ...
marsipu pushed a commit to marsipu/mne-python that referenced this pull request Oct 14, 2020
* WIP: Recreate our helmet

* Fix roll

* Use https://github.com/mne-tools/mne-python/pull/7147\#issuecomment-566963090

* Change width slightly

* Add polygon_offset parameter to surface()

* Add polygon_offset parameter to mesh()

* Use polygon_offset to resolve coincident topology

* Fix contour()

* Use lines instead of tubes

* Fix pickable issue

* Fix cropped helmet with pyvista

Co-authored-by: Guillaume Favelier <guillaume.favelier@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants