Skip to content

Commit

Permalink
Zeffiro developer: A regular push adding the changes made in the curr…
Browse files Browse the repository at this point in the history
…ent local repository to the remote origin. Contents of the folders ./data/ and ./profile/ are ignored. The update necessitates creating a personal access token.
  • Loading branch information
sampsapursiainen committed Oct 9, 2024
1 parent ae2e401 commit 8c90dd6
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 189 deletions.
142 changes: 71 additions & 71 deletions +utilities/+brainstorm2zef/+m/zef_bst_create_compartment_data.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,56 @@
if length(fieldnames(zef_bst.subject_struct)) > 0
subject_struct = zef_bst.subject_struct;
else
subject_struct = bst_get('Subject');
subject_struct = bst_get('Subject');
end
else
subject_struct = bst_get('Subject');
else
subject_struct = bst_get('Subject');
end

if isfield(zef_bst,'subject_folder')
if not(isempty(char(zef_bst.subject_folder)))
subject_folder = zef_bst.subject_folder;
else
subject_folder = bst_get('ProtocolInfo').SUBJECTS;
end
if not(isempty(char(zef_bst.subject_folder)))
subject_folder = zef_bst.subject_folder;
else
subject_folder = bst_get('ProtocolInfo').SUBJECTS;
end
else
subject_folder = bst_get('ProtocolInfo').SUBJECTS;
subject_folder = bst_get('ProtocolInfo').SUBJECTS;
end

if isempty(zef_bst.compartment_files)

aux_type = '';

zef_bst.compartment_files = cell(0);
for i = 1 : length(zef_bst.compartment_list)
if (isfield(subject_struct,['i' zef_bst.compartment_list{i}]))
aux_ind = subject_struct.(['i' zef_bst.compartment_list{i}]);
aux_type = 'Surface';
else
aux_ind = find(ismember({subject_struct.Surface.Comment},zef_bst.compartment_list{i}),1);
aux_type = 'Surface';
if isempty(aux_ind)
aux_ind = find(ismember({subject_struct.Anatomy.Comment},zef_bst.compartment_list{i}),1);
aux_type = 'Anatomy';
end
end
aux_type = '';

zef_bst.compartment_files = cell(0);
for i = 1 : length(zef_bst.compartment_list)
if (isfield(subject_struct,['i' zef_bst.compartment_list{i}]))
aux_ind = subject_struct.(['i' zef_bst.compartment_list{i}]);
aux_type = 'Surface';
else
aux_ind = find(ismember({subject_struct.Surface.Comment},zef_bst.compartment_list{i}),1);
aux_type = 'Surface';

if isempty(aux_ind)
aux_ind = find(ismember({subject_struct.Anatomy.Comment},zef_bst.compartment_list{i}),1);
aux_type = 'Anatomy';
end
end

if not(isempty(aux_ind))
mesh_file_ind = mesh_file_ind + 1;
if isequal(aux_type,'Surface')
zef_bst.compartment_files{mesh_file_ind} = [subject_folder filesep subject_struct.Surface(aux_ind).FileName];
elseif isequal(aux_type,'Anatomy')
zef_bst.compartment_files{mesh_file_ind} = [subject_folder filesep subject_struct.Anatomy(aux_ind).FileName];
end
if not(isempty(aux_ind))
mesh_file_ind = mesh_file_ind + 1;
if isequal(aux_type,'Surface')
zef_bst.compartment_files{mesh_file_ind} = [subject_folder filesep subject_struct.Surface(aux_ind).FileName];
elseif isequal(aux_type,'Anatomy')
zef_bst.compartment_files{mesh_file_ind} = [subject_folder filesep subject_struct.Anatomy(aux_ind).FileName];
end

end
end
end
end

else
for i = 1 : length(zef_bst.compartment_files)
if not(exist(zef_bst.compartment_files{i},'file'))
zef_bst.compartment_files{i} = fullfile(subject_folder,zef_bst.compartment_files{i});
zef_bst.compartment_files{i} = fullfile(subject_folder,zef_bst.compartment_files{i});
end
end
end
Expand All @@ -66,53 +66,53 @@
compartment_types = cell(1,n_surface_meshes);
surface_mesh_type = '';
for i = 1 : n_surface_meshes
surface_mesh_type = load(zef_bst.compartment_files{i},'Comment');
surface_mesh_type = surface_mesh_type.Comment;
if not(ismember(surface_mesh_type,zef_bst.compartment_list))
[subject_struct, ~, surface_index] = bst_get('SurfaceFile', zef_bst.compartment_files{i});
surface_mesh_type = subject_struct.Surface(surface_index).SurfaceType;
end
compartment_types{i} = surface_mesh_type;
surface_mesh_type = load(zef_bst.compartment_files{i},'Comment');
surface_mesh_type = surface_mesh_type.Comment;
if not(ismember(surface_mesh_type,zef_bst.compartment_list))
[subject_struct, ~, surface_index] = bst_get('SurfaceFile', zef_bst.compartment_files{i});
surface_mesh_type = subject_struct.Surface(surface_index).SurfaceType;
end
compartment_types{i} = surface_mesh_type;
end

surface_mesh_order = zeros(n_surface_meshes,1);
surface_counter = 0;
surface_counter = 0;
for i = 1 : length(zef_bst.compartment_list)
I = find(ismember(compartment_types,zef_bst.compartment_list{i}));
n_found = length(I);
surface_mesh_order(I) = [1:n_found]' + surface_counter;
surface_counter = surface_counter + n_found;
I = find(ismember(compartment_types,zef_bst.compartment_list{i}));
n_found = length(I);
surface_mesh_order(I) = [1:n_found]' + surface_counter;
surface_counter = surface_counter + n_found;
end

zef_bst.compartment_files = zef_bst.compartment_files(surface_mesh_order);
compartment_types = compartment_types(surface_mesh_order);

surface_meshes = struct;
for i = 1 : n_surface_meshes

compartment_struct = load(zef_bst.compartment_files{i});

if isfield(compartment_struct, 'Vertices')
surface_meshes(i).Name = compartment_types{i};
surface_meshes(i).Type = compartment_types{i};
surface_meshes(i).Color = [];
surface_meshes(i).Points = zef_bst.unit_conversion*compartment_struct.Vertices;
surface_meshes(i).Triangles = compartment_struct.Faces;
end
if isfield(compartment_struct, 'Vertices')
surface_meshes(i).Name = compartment_types{i};
surface_meshes(i).Type = compartment_types{i};
surface_meshes(i).Color = [];
surface_meshes(i).Points = zef_bst.unit_conversion*compartment_struct.Vertices;
surface_meshes(i).Triangles = compartment_struct.Faces;
end

if isfield(compartment_struct,'Cube')
if not(isempty(compartment_struct.InitTransf))
A = compartment_struct.InitTransf{2};
else
compartment_struct.InitTransf{2} = A;
end
surface_meshes_aux = utilities.brainstorm2zef.m.zef_bst_get_atlas_surfaces(zef,compartment_struct,zef_bst.n_inflation_steps,zef_bst.transform_cell,compartment_types{i});
if length(fieldnames(surface_meshes)) > 0
surface_meshes = [surface_meshes surface_meshes_aux];
else
surface_meshes = surface_meshes_aux;
end
end
if isfield(compartment_struct,'Cube')
if not(isempty(compartment_struct.InitTransf))
A = compartment_struct.InitTransf{2};
else
compartment_struct.InitTransf{2} = A;
end
surface_meshes_aux = utilities.brainstorm2zef.m.zef_bst_get_atlas_surfaces(zef,compartment_struct,zef_bst.n_inflation_steps,zef_bst.transform_cell,compartment_types{i});
if length(fieldnames(surface_meshes)) > 0
surface_meshes = [surface_meshes surface_meshes_aux];
else
surface_meshes = surface_meshes_aux;
end
end

end

Expand All @@ -121,9 +121,9 @@
n_surface_meshes = size(compartment_settings,1);
ind_vec_aux = zeros(n_surface_meshes,1);
for i = 1 : n_surface_meshes
if size(surface_meshes(i).Points,1) >= 4
ind_vec_aux(i) = 1;
end
if size(surface_meshes(i).Points,1) >= 4
ind_vec_aux(i) = 1;
end
end
ind_vec_aux = find(ind_vec_aux);
surface_meshes = surface_meshes(ind_vec_aux);
Expand Down
76 changes: 37 additions & 39 deletions +utilities/+brainstorm2zef/+m/zef_bst_create_project.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@
end

if nargin < 4
input_mode = 1;
input_mode = 1;
end

if nargin < 3
run_type = 1;
run_type = 1;
end

if nargin < 2
project_file_name = '';
project_file_name = '';
end

zef_bst = utilities.brainstorm2zef.m.zef_bst_get_settings(settings_file_name, zef_bst);

zeffiro_path = fileparts(which('zeffiro_interface'));

if evalin("base","exist('zef', 'var');")
run([zeffiro_path filesep 'm' filesep 'zef_close_all.m']);
run([zeffiro_path filesep 'm' filesep 'zef_close_all.m']);
end

if isempty(fieldnames(zef))
zef = zeffiro_interface('start_mode','nodisplay','verbose_mode',zef_bst.verbose_mode,'use_gpu',zef_bst.use_gpu,'parallel_processes',zef_bst.parallel_processes,'always_show_waitbar',zef_bst.always_show_waitbar);
zef = zeffiro_interface('start_mode','nodisplay','verbose_mode',zef_bst.verbose_mode,'use_gpu',zef_bst.use_gpu,'parallel_processes',zef_bst.parallel_processes,'always_show_waitbar',zef_bst.always_show_waitbar);
end

zef = zef_add_bounding_box(zef);
Expand All @@ -44,20 +44,20 @@

[aux_path, aux_file] = fileparts(settings_file_name);
if isequal(run_type,1)
[compartment_settings, surface_meshes, zef] = utilities.brainstorm2zef.m.zef_bst_create_compartment_data(settings_file_name, zef_bst, zef);
writecell(compartment_settings, fullfile(aux_path,[aux_file '_compartment_settings.dat']));
save(fullfile(aux_path,[aux_file '_surface_meshes.mat']),'surface_meshes','-v7.3');
[compartment_settings, surface_meshes, zef] = utilities.brainstorm2zef.m.zef_bst_create_compartment_data(settings_file_name, zef_bst, zef);
writecell(compartment_settings, fullfile(aux_path,[aux_file '_compartment_settings.dat']));
save(fullfile(aux_path,[aux_file '_surface_meshes.mat']),'surface_meshes','-v7.3');
else
compartment_settings = readcell(fullfile(aux_path,[aux_file '_compartment_settings.dat']));
load(fullfile(aux_path,[aux_file '_surface_meshes.mat']));
compartment_settings = readcell(fullfile(aux_path,[aux_file '_compartment_settings.dat']));
load(fullfile(aux_path,[aux_file '_surface_meshes.mat']));
end

n_surface_meshes = size(compartment_settings,1);
ind_vec_aux = zeros(n_surface_meshes,1);
for i = 1 : n_surface_meshes
if size(surface_meshes(i).Points,1) >= 4
ind_vec_aux(i) = 1;
end
if size(surface_meshes(i).Points,1) >= 4
ind_vec_aux(i) = 1;
end
end
ind_vec_aux = find(ind_vec_aux);
surface_meshes = surface_meshes(ind_vec_aux);
Expand All @@ -71,32 +71,30 @@
ind_vec_aux = zeros(n_surface_meshes,1);
h_waitbar = zef_waitbar(0, 'Creating project.');
for i = 1 : n_surface_meshes
zef_waitbar(i/n_surface_meshes,h_waitbar,'Creating project.');
surface_names_aux = {surface_meshes.Name};
i_aux = find(ismember(surface_names_aux,compartment_settings{i,2}),1);
if not(isempty(i_aux))
ind_vec_aux(i) = 1;
zef = zef_add_compartment(zef);
zef.([zef.compartment_tags{1} '_name']) = [compartment_settings{i,4} ' : ' compartment_settings{i,2}];
zef.([zef.compartment_tags{1} '_points']) = surface_meshes(i_aux).Points;
zef.([zef.compartment_tags{1} '_triangles']) = surface_meshes(i_aux).Triangles(:,[1 3 2]);
zef.([zef.compartment_tags{1} '_submesh_ind']) = size(surface_meshes(i_aux).Triangles,1);
zef.([zef.compartment_tags{1} '_sigma']) = compartment_settings{i,10};
zef.([zef.compartment_tags{1} '_activity']) = compartment_settings{i,12};
if not(isempty(surface_meshes(i_aux).Color))
zef.([zef.compartment_tags{1} '_color']) = surface_meshes(i_aux).Color;
end
zef = zef_build_compartment_table(zef);
end
end

ind_vec_aux = find(ind_vec_aux);
zef_waitbar(i/n_surface_meshes,h_waitbar,'Creating project.');
surface_names_aux = {surface_meshes.Name};
i_aux = find(ismember(surface_names_aux,compartment_settings{i,2}),1);
if not(isempty(i_aux))
ind_vec_aux(i) = 1;
zef = zef_add_compartment(zef);
zef.([zef.compartment_tags{1} '_name']) = [compartment_settings{i,4} ' : ' compartment_settings{i,2}];
zef.([zef.compartment_tags{1} '_points']) = surface_meshes(i_aux).Points;
zef.([zef.compartment_tags{1} '_triangles']) = surface_meshes(i_aux).Triangles(:,[1 3 2]);
zef.([zef.compartment_tags{1} '_submesh_ind']) = size(surface_meshes(i_aux).Triangles,1);
zef.([zef.compartment_tags{1} '_sigma']) = compartment_settings{i,10};
zef.([zef.compartment_tags{1} '_activity']) = compartment_settings{i,12};
if not(isempty(surface_meshes(i_aux).Color))
zef.([zef.compartment_tags{1} '_color']) = surface_meshes(i_aux).Color;
end
zef = zef_build_compartment_table(zef);
end
end

I_on = find(zef_bst.compartment_on_vec);
ind_vec_aux = find(ind_vec_aux(I_on));
ref_vec_vol = find(ref_vec_vol(ind_vec_aux));
ref_vec_surf = find(ref_vec_surf(ind_vec_aux));

ref_vec_vol = find(ref_vec_vol);
ref_vec_surf = find(ref_vec_surf);

zef.refinement_on = 1;
zef.mesh_smoothing_on = zef_bst.mesh_smoothing_on;
zef.distance_smoothing_on = zef_bst.distance_smoothing_on;
Expand All @@ -111,18 +109,18 @@
zef.refinement_volume_compartments = ref_vec_vol;
zef.mesh_resolution = zef_bst.mesh_resolution;
zef.use_fem_mesh_inflation = zef_bst.inflation_on;
zef.fem_mesh_inflation_strength = zef_bst.inflation_strength;
zef.fem_mesh_inflation_strength = zef_bst.inflation_strength; if zef.([zef.temp_var_0 '_on'])
zef.max_surface_face_count = zef_bst.surface_mesh_density;
zef.priority_mode = zef_bst.priority_mode;
zef.extensive_relabeling = zef_bst.extensive_relabeling;

run(zef_bst.import_settings);

zef = zef_turn_compartment_onoff(zef,zef_bst.compartment_on_vec)
zef = zef_turn_compartment_onoff(zef,[zef_bst.compartment_on_vec 1]);
zef = zef_process_meshes(zef);

if not(isempty(zef_bst.labeling_priority))
zef = zef_update_labeling_priority(zef,[],zef_bst.labeling_priority);
zef = zef_update_labeling_priority(zef,[],zef_bst.labeling_priority);
end

if not(isempty(char(project_file_name)))
Expand Down
3 changes: 3 additions & 0 deletions m/zef_create_sensors.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
{'visible_list','[]'}
{'names_visible','1'}
{'color_table','[]'}
{'electrode_impedance', '2000'}
{'electrode_inner_radius', '2'}
{'electrode_outer_radius', '5'}
{'get_functions','cell(0)'}};

for i = 1 : length(field_cell_default)
Expand Down
Loading

0 comments on commit 8c90dd6

Please sign in to comment.