Error while using ISO2MESH - "A self-intersection was detected. Program stopped"

Hi!
I was trying to recompute the FEM model with ISO2MESH for a subject in which DUNEURO keeps failing, as suggested here https://neuroimage.usc.edu/brainstorm/Tutorials/FemMedianNerveCharm#Remesh_with_Iso2mesh

However I am getting the following error:

***************************************************************************
** Error: Line 117:  surf2mesh (line 117)
** Tetgen command failed
** 
** Call stack:
** >surf2mesh.m at 117
** >process_fem_mesh.m>Compute at 404
** >process_fem_mesh.m>ComputeInteractive at 1283
** >process_fem_mesh.m at 31
** >bst_call.m at 28
** >tree_callbacks.m>@(h,ev)bst_call(@process_fem_mesh,'ComputeInteractive',iSubject,[],GetAllFilenames(bstNodes)) at 1194
** 
***************************************************************************


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

the error in surf2mesh.m at line 117 is related to the following (cmdout)

cmdout =

    'Opening C:\Users\ALIEN_ANALYSIS_ONE\AppData\Local\Temp\iso2mesh-ALIEN ANALYSIS ONE\post_vmesh.poly.
     Delaunizing vertices...
     Warning:  Point #329258 is coincident with #384897. Ignored!
     Warning:  Point #384637 is coincident with #329028. Ignored!
     Warning:  Point #384426 is coincident with #328817. Ignored!
     Warning:  Point #384432 is coincident with #328823. Ignored!
     Warning:  Point #384797 is coincident with #329179. Ignored!

goes on for 1355 lines

     Warning:  Point #329672 is coincident with #287302. Ignored!
     Warning:  Point #329777 is coincident with #291930. Ignored!
     Warning:  Point #329668 is coincident with #287299. Ignored!
     Delaunay seconds:  3.796
     Creating surface mesh ...
     Found two overlapping facets.
       1st: [329302, 87842, 234574] #1
       2nd: [329302, 87842, 234574] #2
     A self-intersection was detected. Program stopped.
     Hint: use -d option to detect all self-intersections.

If I try to add the -d option as suggested, such as line 111 in surf2mesh.m is now
[status, cmdout]=system([' "' mcpath(method,exesuff) '" -A -q1.414a -d' num2str(maxvol) ' ' moreopt ' "' mwpath('post_vmesh.poly') '"']);

I get the following error:

***************************************************************************
** Error: Line 38:  fscanf
** Invalid file identifier. Use fopen to generate a valid file identifier.
** 
** Call stack:
** >readtetgen.m at 38
** >surf2mesh.m at 121
** >process_fem_mesh.m>Compute at 404
** >process_fem_mesh.m>ComputeInteractive at 1283
** >process_fem_mesh.m at 31
** >bst_call.m at 28
** >tree_callbacks.m>@(h,ev)bst_call(@process_fem_mesh,'ComputeInteractive',iSubject,[],GetAllFilenames(bstNodes)) at 1194
** 
***************************************************************************

This is due to the fact that readtetgen.m at line 38 tries to
[dim,count] = fscanf(fp,'%d',3);
but fb is -1 because at line 34 it fp=fopen([fstub,'.ele'],'rt'); but the file fopen is looking for (.ele) does not exist.

Is there any solution to this?
Thanks in advance for your support

1 Like

Hi @GiacomoBertazzoli,

Can you share the steps that you followed and how you got these errors?

There are two possible issues:

  • either the surfaces are intersecting
  • or you selected a very high resolution and then Tetgen fails.

Can you share the surfaces that you use then I can have a look?

Best,
Takfarinas

1 Like

Sure! Here the steps:

  1. Import anatomy (auto) with SimNIBS
  2. Resect neck and merge layers of the FEM model from 12 to 5 as here https://neuroimage.usc.edu/brainstorm/Tutorials/FemMedianNerveCharm#Merge_tissues
  3. Compute FEM tensors (with DTI)
  4. (Try to generate DUNEuro head model, which fails)
  5. Extract surfaces from FEM
  6. Generate FEM mesh from [white, gray, csf, skull, scalp] > Iso2mesh-2021 > MergeMesh > Max volume = 0.001, Percentage kept = 100

I have tried to lower the resolution of the surfaces to 15000 but I still get a similar error in surf2mesh:

cmdout =

    'Opening C:\Users\ALIEN_ANALYSIS_ONE\.brainstorm\tmp\post_vmesh.poly.
     Delaunizing vertices...
     Warning:  Point #59583 is coincident with #70847. Ignored!
     Warning:  Point #60289 is coincident with #51543. Ignored!
     Warning:  Point #29809 is coincident with #44828. Ignored!
     Warning:  Point #59830 is coincident with #29830. Ignored!
     Warning:  Point #10474 is coincident with #59811. Ignored!

[...]

     Warning:  Point #59684 is coincident with #70955. Ignored!
     Warning:  Point #59676 is coincident with #70947. Ignored!
     Warning:  Point #51223 is coincident with #60267. Ignored!
     Delaunay seconds:  2.007
     Creating surface mesh ...
     Found two nearly self-intersecting facets.
       1st: [10981, 10984, 10985] #1
       2nd: [10981, 10984, 11593] #1
     The dihedral angle between them is 0.0981737 degree.
     Hint:  You may use -p/# to decrease the dihedral angle  tolerance 0.1 (degree).
     A self-intersection was detected. Program stopped.
     Hint: use -d option to detect all self-intersections.
     '

So now the algorithm is suggesting to use the -p/# argument
Here the subject (psw for the file in pm): https://drive.google.com/drive/folders/1e-BYUqBk7jWrVQRyEBnd8BF9PulcEEOC?usp=share_link
I have included both the original and downsampled surfaces + the orginal and modified FEM model.
Thank you for your help!

Hey @GiacomoBertazzoli;

Thanks for the detailed step.

I believe that the issue is due to the neck resection step.

Can you avoid this step and work with the whole model?

When you resect the FEM mesh, you cut all the head's bottom parts; therefore, some of the extracted surfaces are open, and iso2mesh/tetgen can't handle the open surfaces. Moreover, all the bottom parts of the tissues will intersect when you merge these surfaces.

  • re-do the process without step 2, and let me know.
    If all works fine, you can continue with this model without cutting the neck.

If you want to cut the neck, I recommend doing it after step 6.

Let me know how it goes, if the problem is still here, I will check the data that you shared.

Best,
Takfarinas

1 Like

Thank you @tmedani! That actually solved the problem. ISO2MESH runs without problems with the surfaces extracted from the orginal FEM.

Best!
Giacmo

1 Like