FEM computation using Brain2mesh

Hello,

I just tried to use Brain2mesh to generate a FEM mesh from a T1 image but run into the following error:

surface mesh generation is complete
cd "/Users/edelaire1/.brainstorm/tmp/" && "/Users/edelaire1/.brainstorm/plugins/iso2mesh/iso2mesh-1.9.6/bin/cork.mexmaci64" -resolve "/Users/edelaire1/.brainstorm/tmp/pre_surfbool1.off" "/Users/edelaire1/.brainstorm/tmp/pre_surfbool2.off" "/Users/edelaire1/.brainstorm/tmp/post_surfbool.off" -1648335518: Illegal instruction


** Error: Line 178: surfboolean (line 178)
** surface boolean command failed:
** cd "/Users/edelaire1/.brainstorm/tmp/" && "/Users/edelaire1/.brainstorm/plugins/iso2mesh/iso2mesh-1.9.6/bin/cork.mexmaci64" -resolve "/Users/edelaire1/.brainstorm/tmp/pre_surfbool1.off" "/Users/edelaire1/.brainstorm/tmp/pre_surfbool2.off" "/Users/edelaire1/.brainstorm/tmp/post_surfbool.off" -1648335518
** ERROR: /bin/bash: line 1: 94119 Illegal instruction: 4 "/Users/edelaire1/.brainstorm/plugins/iso2mesh/iso2mesh-1.9.6/bin/cork.mexmaci64" -resolve "/Users/edelaire1/.brainstorm/tmp/pre_surfbool1.off" "/Users/edelaire1/.brainstorm/tmp/pre_surfbool2.off" "/Users/edelaire1/.brainstorm/tmp/post_surfbool.off" -1648335518
**
**
**
** Call stack:
** >surfboolean.m at 178
** >brain2mesh.m at 312
** >process_fem_mesh.m>Compute at 678
** >process_fem_mesh.m>ComputeInteractive at 1237
** >process_fem_mesh.m at 32
** >bst_call.m at 28
** >tree_callbacks.m>@(h,ev)bst_call(@process_fem_mesh,'ComputeInteractive',iSubject,iAnatomy) at 3034
**

Note: ls /Users/edelaire1/.brainstorm/tmp/ return :

brain2mesh post_vmesh.1.face pre_extract.inr

post_extract.off post_vmesh.1.node pre_surfbool1.off

post_vmesh.1.edge post_vmesh.off pre_surfbool2.off

post_vmesh.1.ele post_vmesh.poly

The main issue seems to be the call to "cork.mexmaci64" :

"/Users/edelaire1/.brainstorm/plugins/iso2mesh/iso2mesh-1.9.6/bin/cork.mexmaci64" -resolve "/Users/edelaire1/.brainstorm/tmp/pre_surfbool1.off" "/Users/edelaire1/.brainstorm/tmp/pre_surfbool2.off" "/Users/edelaire1/.brainstorm/tmp/post_surfbool.off" 
Illegal instruction: 4

Edit: I tried to recompile Cork and now the command "./cork -resolve "/Users/edelaire1/.brainstorm/tmp/pre_surfbool1.off" "/Users/edelaire1/.brainstorm/tmp/pre_surfbool2.off" "/Users/edelaire1/.brainstorm/tmp/post_surfbool.off" " works
(note: this is a binary file, and not a Mex file)

Edit2: Also had to recompile tetgen

So actually, I guess it's mainly linked to Iso2mesh. Will open an issue on Github once I manage to make it work :slight_smile:

Thanks a lot,
Edouard

1 Like

Hi @edelaire

Thanks for reporting this issue.

The Brain2Mesh process relies on the iso2mesh toolbox, and the error you reported is on the binaries. It seems that they are not working on your computer. I tested the process in my computer and it worked (PC windows).

Try first to updated your iso2mesh version.

Tx

Hello,

Yes, I updated iso2mesh before this test. After re-compiling cork, and tetgen, I was able to make the software run a bit further but tegen stop at one point.

Surface Mesh Extraction Utility (Based on CGAL 3.8)
(modified for iso2mesh by Qianqian Fang)
http://iso2mesh.sf.net

RNG seed 1648335518
set initial mesh size to 50
Refining... maximum node number is set to 100000
reach maximum node limit, element angular bound may not satisfied

done.
Final number of points: 100000
surface mesh generation is complete
generating tetrahedral mesh from closed surfaces ...
creating volumetric mesh from a surface mesh ...
 "/Users/edelaire1/Documents/software/iso2mesh/iso2mesh/iso2mesh/tools/tetgen/tetgen" -A -q1.414a500  "/Users/edelaire1/.brainstorm/tmp/post_vmesh.poly"
volume mesh generation is complete
generating tetrahedral mesh from closed surfaces ...
creating volumetric mesh from a surface mesh ...
 "/Users/edelaire1/Documents/software/iso2mesh/iso2mesh/iso2mesh/tools/tetgen/tetgen" -A "/Users/edelaire1/.brainstorm/tmp/post_vmesh.poly"
volume mesh generation is complete
generating tetrahedral mesh from closed surfaces ...
creating volumetric mesh from a surface mesh ...
 "/Users/edelaire1/Documents/software/iso2mesh/iso2mesh/iso2mesh/tools/tetgen/tetgen" -A "/Users/edelaire1/.brainstorm/tmp/post_vmesh.poly"
volume mesh generation is complete
generating tetrahedral mesh from closed surfaces ...
creating volumetric mesh from a surface mesh ...
 "/Users/edelaire1/Documents/software/iso2mesh/iso2mesh/iso2mesh/tools/tetgen/tetgen" -A -pq1.414000a100.000000 "/Users/edelaire1/.brainstorm/tmp/post_vmesh.poly"

***************************************************************************
** Error: Line 120:  surf2mesh (line 120)
** Tetgen command failed

If I run this last command outside matlab, I get :

"/Users/edelaire1/Documents/software/iso2mesh/iso2mesh/iso2mesh/tools/tetgen/tetgen" -A -pq1.414000a100.000000 "/Users/edelaire1/.brainstorm/tmp/post_vmesh.poly"

Opening /Users/edelaire1/.brainstorm/tmp/post_vmesh.poly.

Delaunizing vertices...

Delaunay seconds: 0.192897

Creating surface mesh ...

Surface mesh seconds: 0.084753

Recovering boundaries...

Boundary recovery seconds: 0.274922

Removing exterior tetrahedra ...

Spreading region attributes.

Exterior tets removal seconds: 0.092107

Recovering Delaunayness...

Delaunay recovery seconds: 0.076907

Refining mesh...

76434 insertions, added 24183 points, 4109 subfaces in queue.

25452 insertions, added 11160 points, 548479 tetrahedra in queue.

33928 insertions, added 15549 points, 813703 tetrahedra in queue.

45226 insertions, added 13946 points, 834684 tetrahedra in queue.

Please report this bug to Hang.Si@wias-berlin.de. Include

the message above, your input data set, and the exact

command line you used to run this program, thank you.

Here is the data in .brainstorm/tmp : Archive.zip - Google Drive

Edit: This was linked to surf2mesh/Tetgen v1.9.2: Different behavior with MacOS? · Issue #48 · fangq/iso2mesh · GitHub
By using tegen 1.5, it is generating something. Just not really a brain :

Here is the FEM mesh from fieldtrip :

@edelaire
Can you please:

  1. share the original MRI that you are trying the segment with Brain2mesh
  2. describe exactly how you import and run it in Brainstorm to reproduce the error
  3. copy-paste here the output of the ver command in Matlab

@FangQ Any suggestion?

Hello,

I tried to reproduce the issue on linux but was not able to. SO i guess this is very specific to M1 mac. So i am not sure on how easy it will be to fix.

Will post the data later this week.