FEM-meshing and FEM head model

Dear brainstorm team,

I am currently trying the newly implemented FEM-modeling functions and I have run into the following problems:

  1. After I generated a FEM mesh (with iso2mesh) I can't display it and I get the following error:
  2. When trying to compute the head model, I get this error: (which might be connected to the first problem, I am not sure)

Any help is highly appreciated!

Best regards,
Yvonne

These tools are still under active developments, please give us a few more weeks before they are ready to used publicly...

Hello,

Thank you, Yvonne, for reaching us from here.

@Francois : Yvonne is our "beta" tester of the Bst-Duneuro, she is from Carsten's group.

To come back to your error, it seems the the FEM mesh is not correct,
could you check the data of the structure "FEM 41605 V' by right click > view file contents

You should have a similar structure as in this image :

Let us know how it goes.

A+

Cher Takfa, cher Francois,

Thanks for you replies! See here the file contents:

I can't spot a major difference to yours, but maybe you see something in here. It might be a mac-related problem; I now set up brainstorm on a windows aswell and there it worked fine. I had to manually download the iso2mesh toolbox on my mac, because the automatic installation didn't work properly, but i assume that shouldn't be the issue.
If that's not in your focus right now, don't worry! I know you have a lot on your agenda and I will work on the windows version for now!

Merci beaucoup à vous,
Yvonne

1 Like

Dear Yvonne,

The problem comes from the fact that the indices in the array "Tissue" are not matching the number of tissues defined by "TissueLabels" (= 3). There are some elements that have a Tissue index > 3, which is not supposed to happen with today's version of Brainstorm.

Can you please try to update Brainstorm to today's version, and recompute you FEM meshes.
Then, if you still get the same error, it means that there is something wrong in the mesh generation. In that case, could you send me a minimal dataset to reproduce this error?

  • Right-click on the subject > File > Duplicate subject
  • Delete all the files that are not needed to reproduce the behavior:
    • in the anatomy, delete the ASEG atlas, all the FEM meshes, and all the surfaces but the low-resolution cortex (= source space) and the surfaces you use for computing the FEM mesh,
    • in the functional data, keep only one channel file and one short block of imported data (1s long or less) - delete forward and inverse models
    • Make sure you can still reproduce the error with this minimal dataset
  • Right-click on the subject > File > Export subject
  • Upload the zip file somewhere (dropbox, google drive...) and share the download link here
  • Describe exactly how you generate the faulty FEM mesh (exactly where you click and in which order)

I had to manually download the iso2mesh toolbox on my mac, because the automatic installation didn't work properly, but i assume that shouldn't be the issue.

It could: Could you please help me debug and fix this issue?
Please describe any issue you have if you let the automatic installer download iso2mesh in $HOME/.brainstorm/iso2mesh. (copy-paste the full error messages)

Dear Francois,

I updated brainstorm to yesterday's version, but I still get the same error. I sent you the link to the minimal dataset via private message (for data security reasons).

In order to generate the FEM mesh I select the anatomy view and activate the files, that you find in the minimal dataset. I manually add the iso2mesh-master toolbox to the path (downloaded from https://github.com/fangq/iso2mesh).

  • right click on the subject
  • "generate FEM mesh"
  • select "Iso2mesh"
  • select "MershMesh"
  • keeping default settings (max tetrahedal volume: 0.1; Percentage of elements kept: 100)
    *select OK

The Mesh is then created and saved without any bug, but then I can't open it (see error in my original post). MergeSurf leads to the same problem.

For the automatic installation:
If I do not add the manually downloaded iso2mesh toolbox to my matlab path and i repeat the steps above, I agree to let brainstorm download the latest version of iso2mesh, it downloads, tries to install and then I get the following error:

** Error: Iso2mesh could not be installed in: /Users/yvonnebuschermohle/.brainstorm/iso2mesh/mac64

When I check the .brainstorm folder, I find the iso2mesh toolbox, but it is not properly installed; when repeating the FEM generation now, I get the error:


** Error: Line 117: surf2mesh (line 117)
** Tetgen command failed
**
** Call stack:
** >surf2mesh.m at 117
** >process_generate_fem.m>Compute at 377
** >process_generate_fem.m>ComputeInteractive at 950
** >process_generate_fem.m at 33
** >bst_call.m at 28
** >tree_callbacks.m>@(h,ev)bst_call(@process_generate_fem,'ComputeInteractive',iSubject,[]) at 583
**



** Error: The FEM mesh generation failed.
** Check the Matlab command window for additional information.
**


I hope that helps! Let me know if you have further questions!

Best,
Yvonne

What do you mean by "it is not properly installed"?
What do you have in the folder /Users/yvonnebuschermohle/.brainstorm/iso2mesh/mac64 ?

If you remove iso2mesh from the Matlab path, and execute the following command, what do you obtain?
process_generate_fem('InstallIso2mesh', 1)

@MartinC Could you try to execute the same command on your Mac?

Regarding your example dataset:

  • I downloaded the file on a Windows 10 laptop (using the iso2mesh package downloaded automatically by Brainstorm),
  • loaded it with the menu File > Load protocol > Load from zip file
  • right-clicked on the subject > Generate FEM mesh > Iso2mesh > MergeMesh > Default settings
  • it takes about 5 seconds to create a FEM mesh file with 14254 nodes
    image

If this does not work on your mac, there is maybe something wrong with iso2mesh on MacOS?
I'll ask the iso2mesh developers if there is any reason for this difference.

@MartinC Could you quickly check if it works on your Mac?
(I'll forward you the example file in a separate email)

PS: I tested on a Ubuntu 18 system, and it works correctly as well.

Issue posted on iso2mesh github:

1 Like

@yvonnebuschermoehle
This seems to be working on MacOS: https://github.com/fangq/iso2mesh/issues/48#issuecomment-629241832

Could you please reproduce what is shown on that github issue and post a similar screen capture there?

I think I have found the problem with the automatic installer, I posted a bug fix:
https://github.com/brainstorm-tools/brainstorm3/commit/083fa2b2147e00f7eb59c887a3e6badf425ffb82

For testing the installer again:

  • Update Brainstorm
  • Remove the iso2mesh folder from the Matlab path
  • Delete the .brainstorm/iso2mesh folder
  • Start again the FEM mesh computation

Thank you for your patience... :slight_smile:

Yes, the automatic download seems good now! Thanks a lot! :slight_smile:

When trying to compute the head model, I get this error: (which might be connected to the first problem, I am not sure)

I've also fixed this error occurring when running duneuro for MEG+EEG:
https://github.com/brainstorm-tools/brainstorm3/commit/3f175a6e43f2cc5d0da15fc8b60b5319c3804490
Update Brainstorm to get this fix.

For now you should be able to work with the version of iso2mesh you manually downloaded, until we figure out what's wrong with the version downloaded automatically by Brainstorm.

Thanks a lot! I think we finally found the problem in the automatically downloaded version (see github discussion).

The problem comes from the fact that the indices in the array "Tissue" are not matching the number of tissues defined by "TissueLabels" (= 3). There are some elements that have a Tissue index > 3, which is not supposed to happen with today's version of Brainstorm.

However, this problem is not yet solved, I still get the same error when trying to open the generated meshes

1 Like

Yes, I can reproduce the second error now as well, when enforcing the use of Tetgen 1.5 on my Windows laptop (which was defaulted to use 1.4).
Waiting for so input on fixing this.

In the meantime, you could modify the line 378 of process_generate_fem.m to enforce the use of the older Tetgen version (option method='tetgen'), and now you would finally get what I obtained on Windows:

        [node,elem] = surf2mesh(newnode, newelem, min(newnode), max(newnode),...
            OPTIONS.KeepRatio, factor_bst .* OPTIONS.MaxVol, regions, [], [], 'tetgen');

Additional fix to get the same output with Tetget 1.4 and 1.5:
https://github.com/brainstorm-tools/brainstorm3/commit/0c4b6527062b186e7c252fd1a83d166982ea40bb

@tmedani @yvonnebuschermoehle
Can you please update Brainstorm and check that now it works correctly with Tetgen 1.5?

1 Like

Yes, it works now!

Thanks a lot, @Francois :slight_smile:

1 Like