Skip to content

Commit

Permalink
Anatomy: FEM mesh generation with SimNIBS4/CHARM
Browse files Browse the repository at this point in the history
  • Loading branch information
ftadel committed Feb 22, 2023
1 parent 24a55b3 commit a270ac0
Show file tree
Hide file tree
Showing 10 changed files with 381 additions and 100 deletions.
4 changes: 3 additions & 1 deletion doc/updates.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
February 2023
- Stat: Added FieldTrip threshold-free cluster enhancement (TFCE)
- Anatomy: Compute FEM mesh statistics
- Anatomy: FEM mesh generation with SimNIBS4/CHARM
- Anatomy: Fixes in template ICBM152 2023 (T1 contrast & tissue labels)
- Bugfix: Error in data covariance computation: Baseline not removed
| when baseline time window was not included in data time window
--------------------------------------------------------------
January 2023
- Anatomy: New template ICBM152 2022
- Anatomy: New template ICBM152 2023
- Anatomy: Remove selection of fiducials when setting anatomy template
- Anatomy: Project scouts between hemispheres using the anatomy template
- Distrib: Enable compilation on Linux and MacOS
Expand Down
32 changes: 22 additions & 10 deletions toolbox/anatomy/mri_getlabels.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,23 @@
if (any(MriFile == '.') || (length(MriFile) > maxNameLength)) && file_exist(MriFile)
% Get file name
[fPath, fBase, fExt] = bst_fileparts(MriFile);
% LABELS: Try to get a side .txt with the labels
% LABELS MRIcron: Try to get a side .txt with the labels
LabelsFile = bst_fullfile(fPath, [fBase, '.txt']);
if file_exist(LabelsFile)
Labels = in_label_mricron(LabelsFile);
end
fBase = strrep(fBase, '.nii', '');
% LABELS: Try to get a side .csv with the labels
% LABELS CAT12: Try to get a side .csv with the labels
LabelsFile = bst_fullfile(fPath, [fBase, '.csv']);
if file_exist(LabelsFile)
Labels = in_label_cat12(LabelsFile);
end
% LABELS SimNIBS4: Try to get a side _LUT.txt with the labels
LabelsFile = bst_fullfile(fPath, [fBase, '_LUT.txt']);
if file_exist(LabelsFile)
Labels = in_label_simnibs(LabelsFile);
end

% If labels were read: use the filename as the atlas name
fBase = lower(fBase);
if ~isempty(Labels)
Expand All @@ -77,7 +83,7 @@
AtlasName = 'freesurfer';
elseif ~isempty(strfind(fBase, '.svreg.label')) % *.svreg.label.nii.gz
AtlasName = 'svreg';
elseif ~isempty(strfind(fBase, '_final_contr'))
elseif ~isempty(strfind(fBase, '_final_contr')) || ~isempty(strfind(fBase, 'final_tissues')) % SimNIBS3/headreco & SimnNIBS4/charm
AtlasName = 'simnibs';
end
end
Expand Down Expand Up @@ -118,13 +124,19 @@
5, 'Scalp', [255, 205, 184]};
case 'simnibs'
Labels = {...
0, 'Background', [ 0, 0, 0]; ...
1, 'White', [220, 220, 220]; ...
2, 'Gray', [130, 130, 130]; ...
3, 'CSF', [ 44, 152, 254]; ...
4, 'Skull', [255, 255, 255]; ...
5, 'Scalp', [255, 205, 184]; ...
6, 'Eyes', [255, 0, 255]};
0, 'Background', [ 0, 0, 0]; ...
1, 'White', [220, 220, 220]; ...
2, 'Gray', [130, 130, 130]; ...
3, 'CSF', [ 44, 152, 254]; ...
4, 'Skull', [255, 255, 255]; ...
5, 'Scalp', [255, 205, 184]; ...
6, 'Eyes', [255, 0, 255]; ...
7, 'Compact_bone', [255, 239, 179]; ...
8, 'Spongy_bone', [255, 138, 57]; ...
9, 'Blood', [ 0, 65, 142]; ...
10, 'Muscle', [ 0, 118, 14]; ...
100, 'Electrode', [ 37, 79, 255]; ...
500, 'Saline_or_gel', [103, 255, 226]};
end
end

Expand Down
3 changes: 2 additions & 1 deletion toolbox/core/bst_get.m
Original file line number Diff line number Diff line change
Expand Up @@ -3466,7 +3466,8 @@
{'.gii'}, 'GIfTI / World coordinates (*.gii)', 'GII-WORLD'; ...
{'.fif'}, 'MNE (*.fif)', 'FIF'; ...
{'.obj'}, 'MNI OBJ (*.obj)', 'MNIOBJ'; ...
{'.msh'}, 'SimNIBS Gmsh4 (*.msh)', 'SIMNIBS'; ...
{'.msh'}, 'SimNIBS3/headreco Gmsh4 (*.msh)', 'SIMNIBS3'; ...
{'.msh'}, 'SimNIBS4/charm Gmsh4 (*.msh)', 'SIMNIBS4'; ...
{'.tri'}, 'TRI (*.tri)', 'TRI'; ...
{'.mri', '.fif', '.img', '.ima', '.nii', '.mgh', '.mgz', '.mnc', '.mni', '.gz', '_subjectimage'}, 'Volume mask or atlas (subject space)', 'MRI-MASK'; ...
{'.mri', '.fif', '.img', '.ima', '.nii', '.mgh', '.mgz', '.mnc', '.mni', '.gz'}, 'Volume mask or atlas (MNI space)', 'MRI-MASK-MNI'; ...
Expand Down
9 changes: 7 additions & 2 deletions toolbox/gui/view_surface_fem.m
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
% Transparency and color
if (size(SurfColor,2) ~= Ntissue)
ColorOrder = panel_scout('GetScoutsColorTable');
SurfColor = ColorOrder(1:Ntissue, :);
SurfColor = ColorOrder(mod((1:Ntissue)-1, length(ColorOrder)) + 1, :);
labels = lower(FemMat.TissueLabels);
% Get default color for each layer
for iTissue = 1:Ntissue
Expand Down Expand Up @@ -181,6 +181,7 @@
Resect = [0, 0.01, 0];
end
% Plot each tissue as a patch object
iTess = 0;
for iTissue = 1:Ntissue
% Progress bar
MeshName = [SurfaceFile, '(', FemMat.TissueLabels{iTissue}, ')'];
Expand All @@ -190,6 +191,9 @@
end
% Select elements of this tissue
Elements = FemMat.Elements(FemMat.Tissue == iTissue, 1:4);
if isempty(Elements)
continue;
end
% Create a surface for the outside surface of this tissue
Faces = tess_voledge(FemMat.Vertices, Elements, Resect);
% Plot as a new surface
Expand All @@ -203,7 +207,8 @@
'SpecularExponent', 0.3, ...
'UserData', Elements);
% Show edges
panel_surface('SetSurfaceEdges', hFig, iTissue, 1);
iTess = iTess + 1;
panel_surface('SetSurfaceEdges', hFig, iTess, 1);
end
if isProgress
bst_progress('text', 'Creating figure...');
Expand Down
2 changes: 1 addition & 1 deletion toolbox/io/import_anatomy_fs.m
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@
oldCortexLowFile = file_fullpath(CortexLowFile);
CortexLowFile = bst_fullfile(bst_fileparts(oldCortexLowFile), 'tess_cortex_pial_low.mat');
file_move(oldCortexLowFile, CortexLowFile);
CortexHiFile = file_short(CortexHiFile);
CortexLowFile = file_short(CortexLowFile);
else
CortexHiFile = [];
CortexLowFile = [];
Expand Down

1 comment on commit a270ac0

@tmedani
Copy link
Collaborator

@tmedani tmedani commented on a270ac0 Mar 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome!!

Please sign in to comment.