📄 rest_sliceviewer.m
字号:
function [varargout]=rest_sliceviewer(AOperation, varargin)
% Show a brain's slice. "rest_sliceviewer" can be opened more than one instance like MRIcro, and supports multi-slice, overlay and so on. by Xiao-Wei Song
%Usage: hFig =rest_sliceviewer('ShowImage', AFilename, CallBack);
% rest_sliceviewer('Delete', AFigHandle);
%Detailed usage is the code file "rest_sliceviewer.m"
%------------------------------------------------------------------------------------------------------------------------------
% Copyright(c) 2007~2010
% State Key Laboratory of Cognitive Neuroscience and Learning in Beijing Normal University
% Written by Xiao-Wei Song
% http://resting-fmri.sourceforge.net
% <a href="Dawnwei.Song@gmail.com">Mail to Author</a>: Xiaowei Song
% Version=1.1;
% Release=20071101;
%------------------------------------------------------------------------------------------------------------------------------
%20071101 Revise: 1. change Position
%
if nargin<1, %No param Launch, 20070918
help(mfilename);
if nargout>=1,
varargout{1}=rest_sliceviewer('ShowImage',''); %by Default, I show a black brain image
else
rest_sliceviewer('ShowImage',''); %by Default, I show a black brain image
end
return;
end
%Initializitation
persistent REST_SliceViewer_Cfg; % run-time persistent config
%if isempty(REST_SliceViewer_Cfg), disp('ko'); end
if ~mislocked(mfilename),mlock; end
%For further Debug, 20070915, to make sure the Config variable exist
% if isempty(REST_SliceViewer_Cfg),
% REST_SliceViewer_Cfg =getappdata(0, 'REST_SliceViewer_Cfg');
% else
% setappdata(0, 'REST_SliceViewer_Cfg', REST_SliceViewer_Cfg);
% end
try
switch upper(AOperation),
case 'SHOWIMAGE', %ShowImage
if nargin==2,
%rest_sliceviewer('ShowImage', theBrainMap); %reho_gui.m 989
AFilename =varargin{1};
ACallback ='';
elseif nargin==3,
%rest_sliceviewer('ShowImage', theBrainMap, [theCallback cmdClearVar], 'Power Spectrum');%reho_gui.m 1010
AFilename =varargin{1};
ACallback =varargin{2};
else
error(sprintf('Usage: hFig =rest_sliceviewer(''ShowImage'', AFilename); \n\t hFig =rest_sliceviewer(''ShowImage'', AFilename, ACallback);'));
end
%Let current handle of the figure be a GUID for the current SliceViewer
% theFig =ExistDisplayFigure(REST_SliceViewer_Cfg, AFilename);
% isExistFig =rest_misc( 'ForceCheckExistFigure' , theFig); %Force check whether the figure exist
% if ~isExistFig
%the specific image didn't exist, so I create one
REST_SliceViewer_Cfg.Config(1+GetDisplayCount(REST_SliceViewer_Cfg)) =InitControls(AFilename, ACallback);
%To Force display following the end of this if-clause
theFig =REST_SliceViewer_Cfg.Config(GetDisplayCount(REST_SliceViewer_Cfg)).hFig;
%I don't display the information defaultly
ToggleInfoDisplay(REST_SliceViewer_Cfg.Config(GetDisplayCount(REST_SliceViewer_Cfg)));
% end
figure(theFig);
varargout{1} =theFig;
case 'UPDATECALLBACK', %UpdateCallback
if nargin==2,
AFigHandle =varargin{1};
ACallback ='';
ACallbackCaption='';
elseif nargin==3,
AFigHandle =varargin{1};
ACallback =varargin{2};
ACallbackCaption='';
elseif nargin==4,
AFigHandle =varargin{1};
ACallback =varargin{2};
ACallbackCaption=varargin{3};
else
error('Usage: rest_sliceviewer(''UpdateCallback'', AFigureHandle, ACallback, ACallbackCaption);');
end
theCardinal =ExistViewer(REST_SliceViewer_Cfg, AFigHandle);
if theCardinal>0,
REST_SliceViewer_Cfg.Config(theCardinal) =UpdateCallback(REST_SliceViewer_Cfg.Config(theCardinal), ACallback, ACallbackCaption);
ResizeFigure(REST_SliceViewer_Cfg.Config(theCardinal));
end
case 'DELETE', % Delete specific figure
if nargin~=2, error('Usage: rest_sliceviewer(''Delete'', AFigHandle);'); end
AFigHandle =varargin{1};
REST_SliceViewer_Cfg =DeleteFigure(REST_SliceViewer_Cfg, AFigHandle);
if ~GetDisplayCount(REST_SliceViewer_Cfg),
rest_sliceviewer('QuitAllSliceViewer');
end
case {'CLICKPOSITION', 'SETPOSITION'}, %ClickPosition %SetPosition
if nargin~=2, error('Usage: rest_sliceviewer(''ClickPosition'', AFigHandle); or rest_sliceviewer(''SetPosition'', AFigHandle);'); end
AFigHandle =varargin{1};
theCardinal =ExistViewer(REST_SliceViewer_Cfg, AFigHandle);
if theCardinal>0
if strcmpi(AOperation, 'ClickPosition'), % for Mouse click
if strcmpi(REST_SliceViewer_Cfg.Config(theCardinal).ViewMode, 'Orthogonal'),
REST_SliceViewer_Cfg.Config(theCardinal) =ClickPositionCrossHair(REST_SliceViewer_Cfg.Config(theCardinal));
elseif strcmpi(REST_SliceViewer_Cfg.Config(theCardinal).ViewMode, 'Sagittal'),
REST_SliceViewer_Cfg.Config(theCardinal) =ClickPositionInSagittalMode(REST_SliceViewer_Cfg.Config(theCardinal));
elseif strcmpi(REST_SliceViewer_Cfg.Config(theCardinal).ViewMode, 'Coronal'),
REST_SliceViewer_Cfg.Config(theCardinal) =ClickPositionInCoronalMode(REST_SliceViewer_Cfg.Config(theCardinal));
elseif strcmpi(REST_SliceViewer_Cfg.Config(theCardinal).ViewMode, 'Transverse'),
REST_SliceViewer_Cfg.Config(theCardinal) =ClickPositionInTransverseMode(REST_SliceViewer_Cfg.Config(theCardinal));
end
elseif strcmpi(AOperation, 'SetPosition'), % for [x y z] manual input
REST_SliceViewer_Cfg.Config(theCardinal) =SetPositionCrossHair(REST_SliceViewer_Cfg.Config(theCardinal));
end
%If yoke, then update all yoked image
isSelfYoked =get(REST_SliceViewer_Cfg.Config(theCardinal).hYoke, 'Value');
if isSelfYoked ,
theDistanceFromOrigin =(REST_SliceViewer_Cfg.Config(theCardinal).LastPosition -REST_SliceViewer_Cfg.Config(theCardinal).Origin) .* REST_SliceViewer_Cfg.Config(theCardinal).VoxelSize;
%Dawnsong 20071102 Revise to make sure the left image/Right brain is +
theDistanceFromOrigin =[-1, 1, 1].* theDistanceFromOrigin;
for x=1:GetDisplayCount(REST_SliceViewer_Cfg),
if x~=theCardinal ,
isYoked =get(REST_SliceViewer_Cfg.Config(x).hYoke, 'Value');
if isYoked,
rest_sliceviewer('SetPhysicalPosition', REST_SliceViewer_Cfg.Config(x).hFig, theDistanceFromOrigin);
end
end
end
end
%Execute the Callback
rest_sliceviewer('RunCallback', AFigHandle);
end
case 'SETPHYSICALPOSITION', %SetPhysicalPosition, for Yoke, the physical position(mm) from the origin
if nargin~=3, error('Usage: rest_sliceviewer(''SetPhysicalPosition'', AFigHandle, ADistanceFromOrigin);'); end
AFigHandle =varargin{1};
ADistanceFromOrigin =varargin{2};
theCardinal =ExistViewer(REST_SliceViewer_Cfg, AFigHandle);
if theCardinal>0,
%Dawnsong 20071102 Revise to make sure the left image/Right brain is +
ADistanceFromOrigin =[-1, 1, 1].* ADistanceFromOrigin;
REST_SliceViewer_Cfg.Config(theCardinal) =SetDistanceFromOrigin(REST_SliceViewer_Cfg.Config(theCardinal), ADistanceFromOrigin);
%Execute the Callback
rest_sliceviewer('RunCallback', AFigHandle);
end
case 'RUNCALLBACK', %RunCallback , 20070625
if nargin~=2, error('Usage: rest_sliceviewer(''RunCallback'', AFigHandle);'); end
AFigHandle =varargin{1};
theCardinal =ExistViewer(REST_SliceViewer_Cfg, AFigHandle);
if theCardinal>0
% Run the Callback
if ~isempty(REST_SliceViewer_Cfg.Config(theCardinal).Callback)
if ischar(REST_SliceViewer_Cfg.Config(theCardinal).Callback),
eval(REST_SliceViewer_Cfg.Config(theCardinal).Callback); %run callback for caller
elseif isa(REST_SliceViewer_Cfg.Config(theCardinal).Callback, 'function_handle')
%I give 2 parameters, 20070624
%1) position: X, Y , Z,
%2) and 3-dim: XSize, YSize, ZSize
thePos =REST_SliceViewer_Cfg.Config(theCardinal).LastPosition;
theSize=size(REST_SliceViewer_Cfg.Config(theCardinal).Volume);
REST_SliceViewer_Cfg.Config(theCardinal).Callback(thePos, theSize);
end
end
end
case 'GETPOSITION', %GetPosition, return Absolute position where current cross-hair stay
if nargin~=2, error('Usage: Position =rest_sliceviewer(''GetPosition'', AFigHandle);'); end
AFigHandle =varargin{1};
theCardinal =ExistViewer(REST_SliceViewer_Cfg, AFigHandle);
if theCardinal>0
varargout{1}=REST_SliceViewer_Cfg.Config(theCardinal).LastPosition;
end
case 'GETPHYSICALPOSITION', %GetPhysicalPosition return Coordinate .* VoxelSize (mm)
if nargin~=2, error('Usage: DistanceFromOrigin =rest_sliceviewer(''GetPhysicalPosition'', AFigHandle);'); end
AFigHandle =varargin{1};
theCardinal =ExistViewer(REST_SliceViewer_Cfg, AFigHandle);
if theCardinal>0
thePosition =REST_SliceViewer_Cfg.Config(theCardinal).LastPosition;
theOrigin =REST_SliceViewer_Cfg.Config(theCardinal).Origin;
theVoxelSize=REST_SliceViewer_Cfg.Config(theCardinal).VoxelSize;
varargout{1} =(thePosition - theOrigin) * theVoxelSize;
end
case 'SETMESSAGE', %SetMessage, update the Message, I don't contain the Copyright any more , 20070915
if nargin~=3, error('Usage: rest_sliceviewer(''SetMessage'', AFigHandle, AMessage);'); end
AFigHandle =varargin{1};
AMessage =varargin{2};
theCardinal =ExistViewer(REST_SliceViewer_Cfg, AFigHandle);
if theCardinal>0
REST_SliceViewer_Cfg.Config(theCardinal).Message =AMessage;
SetMessage(REST_SliceViewer_Cfg.Config(theCardinal));
ResizeFigure(REST_SliceViewer_Cfg.Config(theCardinal));
end
case 'MAGNIFY', %Magnify, x0.5 -x1 -x2 -x3 -x4 -x5 -x6
if nargin~=2, error('Usage: rest_sliceviewer(''Magnify'', AFigHandle);'); end
AFigHandle =varargin{1};
theCardinal =ExistViewer(REST_SliceViewer_Cfg, AFigHandle);
if theCardinal>0
REST_SliceViewer_Cfg.Config(theCardinal) =SetImage(REST_SliceViewer_Cfg.Config(theCardinal));
end
case 'QUITALLSLICEVIEWER', %QuitAllSliceViewer
if nargin~=1, error('Usage: rest_sliceviewer(''QuitAllSliceViewer'');'); end
for x=GetDisplayCount(REST_SliceViewer_Cfg):-1:1, % DawnSong, revised 20070625
rest_sliceviewer('DELETE', REST_SliceViewer_Cfg.Config(x).Filename);
end
if mislocked(mfilename),munlock; end
clear REST_SliceViewer_Cfg;
case 'MONTAGE', %Montage
if nargin~=2, error('Usage: rest_sliceviewer(''Montage'', AFigHandle);'); end
AFigHandle =varargin{1};
theCardinal =ExistViewer(REST_SliceViewer_Cfg, AFigHandle);
if theCardinal>0,
prompt ={'Across: (i.e. the number of columns)', 'Down: (i.e. the number of rows)', 'Spacing(voxels): ', 'Whether to show coordinate''s label: (1=yes and 0=no.)'};
def ={ int2str(REST_SliceViewer_Cfg.Config(theCardinal).Montage.Across), ...
int2str(REST_SliceViewer_Cfg.Config(theCardinal).Montage.Down), ...
int2str(REST_SliceViewer_Cfg.Config(theCardinal).Montage.Spacing), ...
int2str(REST_SliceViewer_Cfg.Config(theCardinal).Montage.WantLabel)};
answer =inputdlg(prompt, 'Montage Set', 1, def);
if numel(answer)==4,
theVal =abs(round(str2num(answer{1})));
if theVal==0, theVal=1; end
REST_SliceViewer_Cfg.Config(theCardinal).Montage.Across = theVal;
theVal =abs(round(str2num(answer{2})));
if theVal==0, theVal=1; end
REST_SliceViewer_Cfg.Config(theCardinal).Montage.Down =theVal;
REST_SliceViewer_Cfg.Config(theCardinal).Montage.Spacing = abs(round(str2num(answer{3})));
REST_SliceViewer_Cfg.Config(theCardinal).Montage.WantLabel = abs(round(str2num(answer{4})));
%Update Image Display
REST_SliceViewer_Cfg.Config(theCardinal) =SetImage(REST_SliceViewer_Cfg.Config(theCardinal));
end
end;
case 'ORTHOGONALVIEW', %OrthogonalView
if nargin~=2, error('Usage: rest_sliceviewer(''OrthogonalView'', AFigHandle);'); end
AFigHandle =varargin{1};
theCardinal =ExistViewer(REST_SliceViewer_Cfg, AFigHandle);
if theCardinal>0,
REST_SliceViewer_Cfg.Config(theCardinal).ViewMode ='Orthogonal';
REST_SliceViewer_Cfg.Config(theCardinal) =SetImage(REST_SliceViewer_Cfg.Config(theCardinal));
end;
case 'TRANSVERSEVIEW', %TransverseView
if nargin~=2, error('Usage: rest_sliceviewer(''TransverseView'', AFigHandle);'); end
AFigHandle =varargin{1};
theCardinal =ExistViewer(REST_SliceViewer_Cfg, AFigHandle);
if theCardinal>0,
REST_SliceViewer_Cfg.Config(theCardinal).ViewMode ='Transverse';
REST_SliceViewer_Cfg.Config(theCardinal) =SetImage(REST_SliceViewer_Cfg.Config(theCardinal));
end;
case 'SAGITTALVIEW', %SagittalView
if nargin~=2, error('Usage: rest_sliceviewer(''SagittalView'', AFigHandle);'); end
AFigHandle =varargin{1};
theCardinal =ExistViewer(REST_SliceViewer_Cfg, AFigHandle);
if theCardinal>0,
REST_SliceViewer_Cfg.Config(theCardinal).ViewMode ='Sagittal';
REST_SliceViewer_Cfg.Config(theCardinal) =SetImage(REST_SliceViewer_Cfg.Config(theCardinal));
end;
case 'CORONALVIEW', %CoronalView
if nargin~=2, error('Usage: rest_sliceviewer(''CoronalView'', AFigHandle);'); end
AFigHandle =varargin{1};
theCardinal =ExistViewer(REST_SliceViewer_Cfg, AFigHandle);
if theCardinal>0,
REST_SliceViewer_Cfg.Config(theCardinal).ViewMode ='Coronal';
REST_SliceViewer_Cfg.Config(theCardinal) =SetImage(REST_SliceViewer_Cfg.Config(theCardinal));
end;
case 'REPAINT', %Repaint
if nargin~=2, error('Usage: rest_sliceviewer(''Repaint'', AFigHandle);'); end
AFigHandle =varargin{1};
theCardinal =ExistViewer(REST_SliceViewer_Cfg, AFigHandle);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -