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

Error when calling brain2mesh #13

Open
tmedani opened this issue Apr 3, 2021 · 15 comments
Open

Error when calling brain2mesh #13

tmedani opened this issue Apr 3, 2021 · 15 comments
Assignees

Comments

@tmedani
Copy link

tmedani commented Apr 3, 2021

Hi @fangq,

I'm trying to run the bran2mesh function on a segmented MRI into 5 tissues,
but I'm not able to make it work as expected, here is my example :

the link below contains the "tissues" data which is the segmentation of the MRI into 5 main tissues, ordered from inner to outer (label 1 to 5)
wm(1), gm(2), csf(3), skull(4) and scalp(5)

here is the code

load('tissues') % download from this link https://www.dropbox.com/t/XBpvzMCBg9acTGTB
seg2 = [];
names={'wm','gm','csf','skull','scalp'};
for i = 5:-1:1
    seg2.(names{i}) = uint8(tissues.Cube==i);
end

cfg.dotruncate = 1;
[node,elem,face] = brain2mesh(seg2,cfg);

here is the output

>> cfg.dotruncate = 1;
[node,elem,face] = brain2mesh(seg2,cfg);
95  segname=fieldnames(density);
extracting surfaces from a volume ...
region 1 centroid :	130.000000 91.666667 1.333333

processing threshold level 1...
Surface Mesh Extraction Utility (Based on CGAL 3.6) 
(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
extracting surfaces from a volume ...
region 1 centroid :	119.500000 21.666667 1.333333

processing threshold level 1...
Surface Mesh Extraction Utility (Based on CGAL 3.6) 
(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 
 
done. 
Final number of points: 40491 
surface mesh generation is complete
extracting surfaces from a volume ...
region 1 centroid :	117.500000 18.666667 1.333333

processing threshold level 1...
Surface Mesh Extraction Utility (Based on CGAL 3.6) 
(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
extracting surfaces from a volume ...
region 1 centroid :	116.000000 16.666667 1.333333

processing threshold level 1...
Surface Mesh Extraction Utility (Based on CGAL 3.6) 
(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 
 
done. 
Final number of points: 19658 
surface mesh generation is complete
generating tetrahedral mesh from closed surfaces ...
creating volumetric mesh from a surface mesh ...
volume mesh generation is complete
extracting surfaces from a volume ...
region 1 centroid :	114.000000 14.666667 1.333333

processing threshold level 1...
Surface Mesh Extraction Utility (Based on CGAL 3.6) 
(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 
 
done. 
Final number of points: 1835 
surface mesh generation is complete
generating tetrahedral mesh from closed surfaces ...
creating volumetric mesh from a surface mesh ...
volume mesh generation is complete
Error using surfboolean (line 188)
surface boolean command failed:
cd "C:\Users\33649\AppData\Local\Temp\iso2mesh-medani\" && "G:\My Drive\GitFolders\GitHub\iso2mesh\bin\cork.exe" -first
"C:\Users\33649\AppData\Local\Temp\iso2mesh-medani\pre_surfbool1.off" "C:\Users\33649\AppData\Local\Temp\iso2mesh-medani\pre_surfbool2.off"
"C:\Users\33649\AppData\Local\Temp\iso2mesh-medani\post_surfbool.off" -1648335518
ERROR: error at c:\users\fangq\cork\src\mesh\mesh.isct.tpp, line #1063: Ran out of tries to perturb the mesh



Error in brain2mesh (line 235)
        [final_surf_n,final_surf_f] = surfboolean(nbox,fbox(:,[1 3 2]),'first',surf_n,surf_f);

As usual, I will appreciate it If you can orient me to solve this issue.

Thank you in advance for your help.

best,

@fangq
Copy link
Owner

fangq commented Apr 11, 2022

this is embarrassing - I did not notice this question posted over a year ago. looks like the dropbox link has expired - let me know if this still an issue.

@ftadel
Copy link

ftadel commented Apr 11, 2022

@tmedani Can you please check that this is not an issue anymore?
Otherwise, can you post the data again?
Thanks

@tmedani
Copy link
Author

tmedani commented Apr 13, 2022

Hi @fangq,

this is embarrassing - I did not notice this question posted over a year ago. looks like the dropbox link has expired - let me know if this still an issue.

no problem, we moved to another task in meantime and this one was not the top priority.

@tmedani Can you please check that this is not an issue anymore?

so the issue is still, I generated an equivalent data, here is the link to it: https://www.dropbox.com/s/57nyv6nz6xi6qwf/tissues.mat?dl=0

load('tissues') % download from this link https://www.dropbox.com/s/57nyv6nz6xi6qwf/tissues.mat?dl=0
seg2 = [];
names={'wm','gm','csf','skull','scalp'};
for i = 5:-1:1
    seg2.(names{i}) = uint8(tissues.Cube==i);
end

cfg.dotruncate = 1;
[node,elem,face] = brain2mesh(seg2,cfg);

Thanks again for your help :)

@fangq fangq self-assigned this Apr 13, 2022
@fangq
Copy link
Owner

fangq commented Apr 14, 2022

I am able to reproduce this issue on my Linux desktop.

I believe the issue is caused by csf and gm surfaces are touching each-other. see this plot, where the red/black lines are gm surface poking outside of csf surface, and most of these are either co-planar or intersecting.

csf_surf

because cork, the surface boolean code only supports limited precision, it is insufficient to resolve co-planar surfaces/features.

there is a decouple option with surfboolean that can be used to push apart two surfaces that enclosing each other, but it is not used in the initial pass of the brain2mesh workflow. I will see what I can do to avoid this.

@DerfelLee
Copy link

Hi
I was running the example script SPM_example_brain.m and SPM_example_wholehad.m, but it reported that 'valface cannot be recognized'. Ive already run the checkdependency file, the error still occurred. I wonder where i can find the valface.m file?
Thanks and best regards

@fangq
Copy link
Owner

fangq commented May 2, 2022

@DerfelLee, volface is a function in iso2mesh - I suppose you did not add path to iso2mesh, can you verify?

https://github.com/fangq/iso2mesh/blob/master/volface.m

@DerfelLee
Copy link

DerfelLee commented May 3, 2022 via email

@fangq
Copy link
Owner

fangq commented May 3, 2022

@DerfelLee, you were right, there is a typo in a recent update to meshabox.m in iso2mesh. now it should be fixed. please redownload iso2mesh from github.

@fangq fangq reopened this May 3, 2022
@DerfelLee
Copy link

DerfelLee commented May 3, 2022 via email

@fangq
Copy link
Owner

fangq commented May 6, 2022

@DerfelLee, did you see the index at position 1 is out of boundary using the built in examples or one of your datasets? if the latter, I would like to get a small script to reproduce, can you share?

@tmedani
Copy link
Author

tmedani commented May 10, 2022

@fangq thanks for checking,
This is confusing me now, the tissues that I shared are the outputs of the headreco process from simnibs.
and these tissues should be free from any intersections. I will check that again and I will let you know.

btw, could we use these tissue with vol2mesh?

Thanks again for your support,

Best

@tmedani
Copy link
Author

tmedani commented May 10, 2022

I am able to reproduce this issue on my Linux desktop.

I believe the issue is caused by csf and gm surfaces are touching each-other. see this plot, where the red/black lines are gm surface poking outside of csf surface, and most of these are either co-planar or intersecting.

csf_surf

is there a way to refine the surface extraction process from the volume,
I think that the tissue volumes are free from the intersection, but the extracted surfaces are intersecting, if we refine the size of the triangles we can avoid the intersections.

@DerfelLee
Copy link

DerfelLee commented Oct 11, 2022 via email

@fangq
Copy link
Owner

fangq commented Dec 20, 2023

@DerfelLee and @tmedani, I am sorry that I haven't had chance working on brain2mesh for a while.

I am no longer able to download the dropbox sample data that previously failed. I am wondering if you can send me an updated link, I will have some time to take a deeper dive.

Update: never mind, I found a previously downloaded tissues.mat, and was able to reproduce the problem. let me find a workaround.

@iamrblc
Copy link

iamrblc commented Apr 16, 2024

Hey,

I am a complete newbie MATLAB user, sorry if some of my description is trivial. I ran into a few issues (on Mac M1, all necessary folders are added to the path).

(0th issue:

  • the brain2mesh function didn't run because it was looking for a bunch of files with .mexmaca64 extention in the bin folder of iso2mesh. I found only .mexmaci64, so i simply renamed them. This seemingly solved the issue. I just mention this in case you think this can cause issues at the future steps.)

1st issue:

seg = cat(4, scalp, skull, csf, gm, wm, air); [node, elem, face] = brain2mesh(seg);

Error: Index exceeds the number of array elements. Index must not exceed 5.

Fine, I removed 'air', although the documentation says it shouldn't be an issue, but for now let's try without it. Then it ran smoothly until...

2nd issue

Error using surfboolean
surface boolean command failed:
cd "<path>/iso2mesh-rblc/" &&
"<path>iso2mesh/bin/cork.mexmaca64" -resolve
"<path>/T/iso2mesh-rblc/pre_surfbool1.off"
"<path>T/iso2mesh-rblc/pre_surfbool2.off"
"<path>/T/iso2mesh-rblc/post_surfbool.off"
-1648335518
ERROR:


Error in brain2mesh (line 309)
        [surf_n,surf_f] = surfboolean(wm_n(:,1:3),wm_f(:,1:3),'resolve',pial_n,pial_f);

Error in mesh_creator (line 11)
[node, elem, face] = brain2mesh(seg);

I saw that a similar issue was reported before with this comment
_"because cork, the surface boolean code only supports limited precision, it is insufficient to resolve co-planar surfaces/features.

there is a decouple option with surfboolean that can be used to push apart two surfaces that enclosing each other, but it is not used in the initial pass of the brain2mesh workflow. I will see what I can do to avoid this."_

Looking at the brain2mesh source code it seems like that the second loop with the decouple option is not reached despite of this fail, but I have no clue if this is really the issue, and if so, how I can overcome this.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants