Skip to content

Commit

Permalink
Report: bst_report(Snapshot) can return image data
Browse files Browse the repository at this point in the history
  • Loading branch information
rcassani committed Aug 21, 2023
1 parent 436aee2 commit 40188c9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion doc/license.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<body alink="#fff000" link="#fff000" vlink="#fff000">
<h4><span style="font-family: Arial Black; color: #ffffff;"><strong>THERE IS NO UNDO BUTTON!<BR>SET UP A <FONT color=red>BACKUP</FONT> OF YOUR DATABASE</strong></span></h4>
<HR>
<!-- LICENCE_START -->Version: 3.230817 (17-Aug-2023)<br>
<!-- LICENCE_START -->Version: 3.230821 (21-Aug-2023)<br>
<span style="font-style: italic;">COPYRIGHT &copy; 2000-2023
USC &amp; McGill University.<br>
</span>
Expand Down
2 changes: 1 addition & 1 deletion doc/version.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
% Brainstorm
% v. 3.230817 (17-Aug-2023)
% v. 3.230821 (21-Aug-2023)
33 changes: 29 additions & 4 deletions toolbox/process/bst_report.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,11 @@ function Info(sProcess, sInputs, strMsg)


%% ===== SNAPSHOT =====
% USAGE: bst_report('Snapshot', 'registration', AnyFile, Comment, Modality, Orientation='left') : left,right,top,bottom,back,front
% USAGE: bst_report('Snapshot', SnapType, FileName, Comment, ...)
% img = bst_report('Snapshot', 'registration', AnyFile, Comment, Modality, Orientation='left') : left,right,top,bottom,back,front
% bst_report('Snapshot', 'ssp', RawFile, Comment)
% bst_report('Snapshot', 'noiscov', AnyFile, Comment)
% bst_report('Snapshot', 'ndatacov', AnyFile, Comment)
% bst_report('Snapshot', 'headmodel', AnyFile, Comment)
% bst_report('Snapshot', 'data', DataFile, Comment, Modality, Time=start, RowName=[All])
% bst_report('Snapshot', 'topo', DataFile, Comment, Modality, Time=start, Freq=0)
Expand All @@ -154,9 +156,13 @@ function Info(sProcess, sInputs, strMsg)
% bst_report('Snapshot', 'spectrum', TimefreqFile, Comment, RowName=[All], Freq=0)
% bst_report('Snapshot', 'dipoles', DipolesFile, Comment, Goodness=0, Orientation='left')
% bst_report('Snapshot', 'timefreq', TimefreqFile, Comment, RowName=[All], Time=start, Freq=0)
% bst_report('Snapshot', 'connectimage', ConnectFile, Comment, Time=start, Freq=0)
% bst_report('Snapshot', 'connectgraph', ConnectFile, Comment, Threshold=0, Time=start, Freq=0)
% bst_report('Snapshot', hFig, AnyFile, Comment, WinPos=[200,200,400,250])
%
% Optional output img is a cell array of cell arrays with image(s) data for each FileName
% Note: All the input files can be either strings (one file) or cell-array of strings (many files)
function Snapshot(SnapType, FileName, Comment, varargin)
function img = Snapshot(SnapType, FileName, Comment, varargin)
% No file in input: nothing to do
if (nargin < 1)
return;
Expand All @@ -169,11 +175,22 @@ function Snapshot(SnapType, FileName, Comment, varargin)
end
% Recustive call if inputs are cell arrays of filenames
if ~isempty(FileName) && iscell(FileName)
for iFile = 1:length(FileName)
Snapshot(SnapType, FileName{iFile}, Comment, varargin{:});
if nargout > 0
% Output: cell array of cell arrays with image(s) for each FileName
imgs = cell(1, length(FileName));
for iFile = 1:length(FileName)
imgs{iFile} = Snapshot(SnapType, FileName{iFile}, Comment, varargin{:});
end
img = imgs;
else
for iFile = 1:length(FileName)
Snapshot(SnapType, FileName{iFile}, Comment, varargin{:});
end
end
return;
end
% Use short file name
FileName = file_short(FileName);

This comment has been minimized.

Copy link
@rcassani

rcassani Aug 22, 2023

Author Member

This was added so the bst_report('Snapshot') works properly with absolute paths:
As functions to get loaded data (e.g bst_memory(GetTimefreqInDataSet) rely on relative paths (which is the way they are stored in GlobalData.Dataset)

% Get current window layout
curLayout = bst_get('Layout', 'WindowManager');
if ~isempty(curLayout)
Expand Down Expand Up @@ -666,6 +683,8 @@ function Snapshot(SnapType, FileName, Comment, varargin)
Error('process_snapshot', FileName, strErr);
hFig = [];
end
% Output images
imgs = cell(1, length(hFig));
% If a figure was created
for i = 1:length(hFig)
drawnow;
Expand All @@ -684,6 +703,10 @@ function Snapshot(SnapType, FileName, Comment, varargin)
end
% Add image to report
Add('image', Comment, FileName, img);
% Append images (only if requested)
if nargout > 0
imgs{i} = img;
end
% Close figure
if ~strcmpi(SnapType, 'figure')
close(hFig(i));
Expand All @@ -705,6 +728,8 @@ function Snapshot(SnapType, FileName, Comment, varargin)
if ~isempty(curLayout)
bst_set('Layout', 'WindowManager', curLayout);
end
% Output: cell array with image(s)
img = imgs;
end


Expand Down

0 comments on commit 40188c9

Please sign in to comment.