Skip to content

Commit

Permalink
Scouts: Get correct surface with scouts, if figure surface is 'anatomy'
Browse files Browse the repository at this point in the history
* Improve initial behaviour of volume atlases
* Changes in scout selection update all figures using the same surface
  • Loading branch information
rcassani committed Jun 4, 2024
1 parent e165251 commit e3ba57e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 40 deletions.
77 changes: 40 additions & 37 deletions toolbox/gui/panel_scout.m
Original file line number Diff line number Diff line change
Expand Up @@ -928,40 +928,12 @@ function CurrentFigureChanged_Callback(oldFig, hFig)
GlobalData.CurrentScoutsSurface = '';
return
end
% Get surfaces in new figure
TessInfo = getappdata(hFig, 'Surface');
iTess = getappdata(hFig, 'iSurface');
if isempty(iTess) || isempty(TessInfo)
SurfaceFile = [];
else
SurfaceFile = TessInfo(iTess).SurfaceFile;
end
% Get scout surface in new figure
SurfaceFile = GetScoutSurface(hFig);
% If the current surface didn't change: nothing to do
if file_compare(GlobalData.CurrentScoutsSurface, SurfaceFile)
return;
end
% If surface file is an MRI or fibers
if ~isempty(iTess) && ismember(lower(TessInfo(iTess).Name), {'anatomy', 'fibers'})
% By default: no attached surface
SurfaceFile = [];
% If there are some data associated with this file: get the associated scouts
if ~isempty(TessInfo(iTess).DataSource) && ~isempty(TessInfo(iTess).DataSource.FileName)
FileMat.SurfaceFile = [];
if strcmpi(TessInfo(iTess).DataSource.Type, 'Source')
FileMat = in_bst_results(TessInfo(iTess).DataSource.FileName, 0, 'SurfaceFile');
elseif strcmpi(TessInfo(iTess).DataSource.Type, 'Timefreq')
FileMat = in_bst_timefreq(TessInfo(iTess).DataSource.FileName, 0, 'SurfaceFile', 'DataFile', 'DataType');
if isempty(FileMat.SurfaceFile) && ~isempty(FileMat.DataFile) && strcmpi(FileMat.DataType, 'results')
FileMat = in_bst_results(FileMat.DataFile, 0, 'SurfaceFile');
end
elseif strcmpi(TessInfo(iTess).DataSource.Type, 'HeadModel')
FileMat = in_bst_headmodel(TessInfo(iTess).DataSource.FileName, 0, 'SurfaceFile');
end
if ~isempty(FileMat.SurfaceFile) % && strcmpi(file_gettype(FileMat.SurfaceFile), 'cortex')
SurfaceFile = FileMat.SurfaceFile;
end
end
end
% Update current surface
SetCurrentSurface(SurfaceFile);

Expand Down Expand Up @@ -1105,6 +1077,41 @@ function SetCurrentAtlas(iAtlas, isForced)
end


%% ===== GET SCOUT SURFACE FOR FIGURE =====
function SurfaceFile = GetScoutSurface(hFig)
% Get surface in new figure
TessInfo = getappdata(hFig, 'Surface');
iTess = getappdata(hFig, 'iSurface');
SurfaceFile = [];
if isempty(iTess) || isempty(TessInfo)
return
% If surface file is an MRI or fibers
elseif ismember(lower(TessInfo(iTess).Name), {'anatomy', 'fibers'})
% By default: no attached surface
SurfaceFile = [];
% If there are some data associated with this file: get the associated scouts
if ~isempty(TessInfo(iTess).DataSource) && ~isempty(TessInfo(iTess).DataSource.FileName)
FileMat.SurfaceFile = [];
if strcmpi(TessInfo(iTess).DataSource.Type, 'Source')
FileMat = in_bst_results(TessInfo(iTess).DataSource.FileName, 0, 'SurfaceFile');
elseif strcmpi(TessInfo(iTess).DataSource.Type, 'Timefreq')
FileMat = in_bst_timefreq(TessInfo(iTess).DataSource.FileName, 0, 'SurfaceFile', 'DataFile', 'DataType');
if isempty(FileMat.SurfaceFile) && ~isempty(FileMat.DataFile) && strcmpi(FileMat.DataType, 'results')
FileMat = in_bst_results(FileMat.DataFile, 0, 'SurfaceFile');
end
elseif strcmpi(TessInfo(iTess).DataSource.Type, 'HeadModel')
FileMat = in_bst_headmodel(TessInfo(iTess).DataSource.FileName, 0, 'SurfaceFile');
end
if ~isempty(FileMat.SurfaceFile) % && strcmpi(file_gettype(FileMat.SurfaceFile), 'cortex')
SurfaceFile = FileMat.SurfaceFile;
end
end
else
SurfaceFile = TessInfo(iTess).SurfaceFile;
end
end


%% ===== SET CURRENT SURFACE =====
function SetCurrentSurface(newSurfaceFile)
global GlobalData;
Expand Down Expand Up @@ -4752,7 +4759,7 @@ function ReloadScouts(hFig)
% Plot all scouts again
PlotScouts([], hFig);
% Update selected/displayed scouts
UpdateScoutsDisplay(hFig);
UpdateScoutsDisplay('current');
end


Expand Down Expand Up @@ -4950,13 +4957,9 @@ function UpdateScoutsDisplay(target)
% Get target scouts
if ~ischar(target)
hFigTarget = target;
TessInfo = getappdata(hFigTarget, 'Surface');
iTess = getappdata(hFigTarget, 'iSurface');
if isempty(TessInfo) || isempty(iTess)
SurfaceFile = GetScoutSurface(hFigTarget);
if isempty(SurfaceFile)
hFigTarget = [];
SurfaceFile = [];
else
SurfaceFile = TessInfo(iTess).SurfaceFile;
end
elseif strcmpi(target, 'all')
SurfaceFile = [];
Expand Down
12 changes: 9 additions & 3 deletions toolbox/gui/view_surface_data.m
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,16 @@


%% ===== DISPLAY SCOUTS =====
% If the default atlas is "Source model" or "Structures": Switch it back to "User scouts"
SurfaceFile = panel_scout('GetScoutSurface', hFig);
sAtlas = panel_scout('GetAtlas', SurfaceFile);
if ~isempty(sAtlas) && ismember(sAtlas.Name, {'Structures', 'Source model'})
panel_scout('SetCurrentAtlas', 1);
if ~isempty(sAtlas)
% Check if default atlas matches grid type (surface or volume)
isVolumeAtlas = panel_scout('ParseVolumeAtlas', sAtlas.Name);
isSameGridType = ~xor(isVolumeAtlas, ismember(lower(SurfaceType), {'anatomy', 'fibers'}));
% Switch atlas to "User scouts" when for "Source model" or "Structures" atlases or atlas does not match grid type
if ismember(sAtlas.Name, {'Structures', 'Source model'}) || ~isSameGridType
panel_scout('SetCurrentAtlas', 1);
end
end
% If there are some loaded scouts available for this figure
if ShowScouts && (isResults || isTimefreq)
Expand Down

0 comments on commit e3ba57e

Please sign in to comment.