BEM mesh error while downsampling vertices

Hi,

I got a runtime error while making a BEM model (using mne.make_bem_model) that :
"Surface inner skull has topological defects: 12 / 20484 vertices have fewer than three neighboring triangles [733, 1014, 2068, 7732, 8435, 8489, 10181, 11120, 11121, 11122, 11304, 11788]"

As mentioned in this link- https://github.com/mne-tools/mne-python/issues/6127 I tried to visualize the inner skull surface but didn't know how to find those vertices. I have attached an image of the inner skull surface. I could see some small triangles at places I wouldn't expect them. So I tried to smoothen out any irregularities in Freeview using the smoothing tool. That didn't help. I still got the runtime error but with different vertices:
"RuntimeError: Surface inner skull has topological defects: 12 / 20479 vertices have fewer than three neighboring triangles [733, 1014, 2068, 7730, 8433, 8487, 10179, 11118, 11119, 11120, 11302, 11786]"

Any idea on how to view and edit these vertices?

Thanks,
Manorama
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20200930/fcc3936b/attachment-0001.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: s33vizearlier.png
Type: image/png
Size: 152996 bytes
Desc: s33vizearlier.png
Url : http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20200930/fcc3936b/attachment-0001.png

External Email - Use Caution

I got a runtime error while making a BEM model (using mne.make_bem_model)
that :
"Surface inner skull has topological defects: 12 / 20484 vertices have
fewer than three neighboring triangles [733, 1014, 2068, 7732, 8435, 8489,
10181, 11120, 11121, 11122, 11304, 11788]"

As mentioned in this link-
bem meshes generated by brainsuite cannot be downsampled (mne.make_bem_model)) · Issue #6127 · mne-tools/mne-python · GitHub I tried to visualize
the inner skull surface but didn't know how to find those vertices.

Here is some code to get you started:

import numpy as np
import pyvista
from pyvistaqt import BackgroundPlotter
import mne
fig = BackgroundPlotter()
rr, tris = mne.read_surface(mne.datasets.sample.data_path() +
'/subjects/sample/bem/inner_skull.surf')
tris = np.concatenate([np.full((len(tris), 1), 3), tris], axis=1)
pd = pyvista.PolyData(rr, tris)
fig.add_mesh(pd)
points = pyvista.PolyData(rr[[733, 1014, 2068]])
fig.add_mesh(points, style='points', color='r', point_size=10,
opacity=0.5, render_points_as_spheres=True)

Produces (the third point is out of the current view):

[image: Screenshot from 2020-10-01 11-44-46.png]

I have attached an image of the inner skull surface. I could see some
small triangles at places I wouldn't expect them. So I tried to smoothen
out any irregularities in Freeview using the smoothing tool. That didn't
help.

Interesting, that solution is not listed here:

https://mne.tools/dev/overview/faq.html#my-watershed-bem-meshes-look-incorrect

Would you be up for making a pull request on GitHub to add to the
documentation whatever you did as an option there?

Also feel free to try the other solutions listed there to fix things.

Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20201001/67ffbf56/attachment-0001.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot from 2020-10-01 11-44-46.png
Type: image/png
Size: 82125 bytes
Desc: not available
Url : http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20201001/67ffbf56/attachment-0001.png

Hi Eric,

I forgot to turn off the digest mode, so I can't reply to your email directly.

Thanks for the code.
I could only see a subset of those vertices. Also, couldn't see how to edit those vertices, so I used Blender for editing.
Using the vertices shown in the PyVista plot, I tried to zoom in at the location of those vertices in Blender. But I couldn't find the exact vertex which has fewer than 3 neighbouring triangles.

I found many free-floating vertices, so deleted those. Then the number of vertices in the surface reduced a lot. I have shown an image of those vertices.

Also attached is an image of the area where the Pyvista plot showed a vertex marked in red. All of the vertices have atleast 3 neighbour triangles.

Sure, I can put a Github pull request.

Thanks,
Manorama

Can you share the repo link where I can make a PR?

External Email - Use Caution

Repo: https://github.com/mne-tools/mne-python
Contributing instructions:
https://mne.tools/dev/install/contributing.html#contributing
FAQ file:
https://github.com/mne-tools/mne-python/blob/master/doc/overview/faq.rst#my-watershed-bem-meshes-look-incorrect

Eric

Thanks for the instructions.

Do you know which one is the vertex with less than 3 neighboring triangles?

Manorama

External Email - Use Caution

From the code I pasted above, you should in principle be able to get the
X/Y/Z coordinates of any vertex you need. They are stored in the rows of
"rr". From that vertex number and the X/Y/Z coordinates, Blender probably
provides a way to select (or remove) points, and probably also fix
topological defects. But I don't really use Blender so I'm not sure.

Eric

Ok, thanks!

Manorama

Hi,

I was able to locate the vertices using the "rr" matrix. I dissolved those error-giving vertices in Blender.

But while running the "make_bem_model" function, I got a runtime error message that:
"Surface inner skull is not complete (sum of solid angles yielded 0.999622, should be 1.)"

What's missing in the surface to not have the solid angle as 1?

Thanks,
Manorama

External Email - Use Caution

I was able to locate the vertices using the "rr" matrix. I dissolved those
error-giving vertices in Blender.

But while running the "make_bem_model" function, I got a runtime
error message that:
"Surface inner skull is not complete (sum of solid angles yielded
0.999622, should be 1.)"

My guess is that there is a hole / are some holes in the mesh. We could
probably add some checks for this in our code. In the meantime can you see
if there is a hole / are some holes?

If there are (or if Blender says there are other problems), consider
looking at:

https://docs.blender.org/manual/en/2.80/modeling/meshes/editing/cleanup.html#fill-holes

And again any insights you gain from this process would make for a great
documentation enhancement / pull request!

Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20201010/b5e46889/attachment.html