⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gui_mri_open.m

📁 Matlab下的EEG处理程序库
💻 M
字号:
function [p] = gui_mri_open(p,mri_open_command,parent)

% GUI_MRI_OPEN - Load & Display an Analyze volume
% 
% Useage: [p] = gui_mri_open(p,[command],[parent])
% 
% p is a structure, generated by 'eeg_toolbox_defaults'
% command is either 'init' or 'load'
% parent is a handle to the gui that calls this gui, useful
% for updating the UserData field of the parent from this gui.
% The p structure is returned to the parent when the parent 
% handle is given.
%

% $Revision: 1.3 $ $Date: 2003/04/07 06:12:02 $

% Licence:  GNU GPL, no express or implied warranties
% History:  08/2002, Darren.Weber@flinders.edu.au
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if ~exist('mri_open_command','var'), mri_open_command = 'init'; end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Paint the GUI
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

switch mri_open_command,
    
case 'init',

    if exist('parent','var'),
        MRIOpen = INIT(p,parent);
    else
        MRIOpen = INIT(p,'');
    end
    
case 'plot',

    MRIOpen = get(gcbf,'Userdata');
    
    MRIOpen.p.mri.plot = 1;
    
    MRIOpen.p = mri_open(MRIOpen.p);
    
    set(MRIOpen.gui,'Userdata',MRIOpen); % update GUI with MRI data
    
    p = gui_updateparent(MRIOpen,0);
    
    if isequal(get(MRIOpen.handles.Bhold,'Value'),0),
        close gcbf;
        if isfield(MRIOpen,'parent'),
            parent = MRIOpen.parent.gui;
        else
            parent = [];
        end
    else
        parent = MRIOpen.gui;
    end
    
    
case 'save',
    
    fprintf('\ngui_mri_OPEN: Save As not implemented yet.\n');
    
case 'return',
    
    MRIOpen = get(gcbf,'Userdata');
    
    MRIOpen.p.mri.plot = 0;
    
    MRIOpen.p = mri_open(MRIOpen.p);
    
    p = gui_updateparent(MRIOpen);
    
    if isequal(get(MRIOpen.handles.Bhold,'Value'),0),
        close gcbf;
    end
    
otherwise,
    
    MRIOpen = get(gcbf,'Userdata');
    GUI.parent = MRIOpen.parent;
    gui_updateparent(GUI);
    close gcbf;
    
end

return



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [MRIOpen] = INIT(p,parent)
    % GUI General Parameters
    
    GUIwidth  = 500;
    GUIheight = 120;
    
    GUI = figure('Name','MRI File Open','Tag','MRI_OPEN',...
                 'NumberTitle','off',...
                 'MenuBar','none','Position',[1 1 GUIwidth GUIheight]);
    movegui(GUI,'center');
    
    Font.FontName   = 'Helvetica';
    Font.FontUnits  = 'Pixels';
    Font.FontSize   = 12;
    Font.FontWeight = 'normal';
    Font.FontAngle  = 'normal';
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Voltage Data Selection and Parameters

    G.Title_data = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
        'Position',[.01 .75 .17 .2],...
        'String','Data Type:','HorizontalAlignment','left');
    
    switch p.mri.type
        case 'Analyze', mriType = 1;
        case 'COR',     mriType = 2;
        case 'Matlab',  mriType = 3;
        otherwise,      mriType = 1;
    end
    G.PmriType = uicontrol('Tag','PmriType','Parent',GUI,'Style','popupmenu',...
        'Units','Normalized',Font,  ...
        'Position',[.20 .75 .25 .2],...
        'String',{'Analyze' 'FreeSurfer COR' 'Matlab'},'Value',mriType,...
        'Callback',strcat('MRIOpen = get(gcbf,''Userdata'');',...
                          'MRIOpen.p.mri.type = popupstr(MRIOpen.handles.PmriType);',...
                          'set(gcbf,''Userdata'',MRIOpen); clear MRIOpen;'));
    
    switch p.mri.orient
        case 'auto',                mriOrient = 1;
        case 'axial unflipped',     mriOrient = 2;
        case 'coronal unflipped',   mriOrient = 3;
        case 'sagittal unflipped',  mriOrient = 4;
        case 'axial flipped',       mriOrient = 5;
        case 'coronal flipped',     mriOrient = 6;
        case 'sagittal flipped',    mriOrient = 7;
        otherwise,                  mriOrient = 1;
    end
    
    G.PmriOrient = uicontrol('Tag','PmriOrient','Parent',GUI,'Style','popupmenu',...
        'Units','Normalized',Font,  ...
        'Position',[.50 .75 .25 .2],...
        'TooltipString','Force loading with this orientation, otherwise use auto detection',...
        'String',{'auto' 'axial unflipped' 'coronal unflipped' 'sagittal unflipped' ...
                  'axial flipped'  'coronal flipped'  'sagittal flipped'},'Value',mriOrient,...
        'Callback',strcat('MRIOpen = get(gcbf,''Userdata'');',...
                          'MRIOpen.p.mri.orient = popupstr(MRIOpen.handles.PmriOrient);',...
                          'set(gcbf,''Userdata'',MRIOpen); clear MRIOpen;'));
    
    G.Title_path = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
        'Position',[.01 .50 .17 .2],...
        'String','Path','HorizontalAlignment','left');
    G.EmriPath = uicontrol('Parent',GUI,'Style','edit','Units','Normalized',Font,  ...
    	'Position',[.20 .50 .58 .2], 'String',p.mri.path,...
        'Callback',strcat('MRIOpen = get(gcbf,''Userdata'');',...
                          'MRIOpen.p.mri.path = get(MRIOpen.handles.EmriPath,''String'');',...
                          'set(gcbf,''Userdata'',MRIOpen); clear MRIOpen;'));
    
    G.Title_file = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
        'Position',[.01 .25 .17 .2],...
        'String','File','HorizontalAlignment','left');
    G.EmriFile = uicontrol('Parent',GUI,'Style','edit','Units','Normalized',Font,  ...
    	'Position',[.20 .25 .58 .2], 'String',p.mri.file,...
        'Callback',strcat('MRIOpen = get(gcbf,''Userdata'');',...
                          'MRIOpen.p.mri.file = get(MRIOpen.handles.EmriFile,''String'');',...
                          'set(gcbf,''Userdata'',MRIOpen); clear MRIOpen;'));
    
    Font.FontWeight = 'bold';
    
    % BROWSE: Look for the data
    browsecommand = strcat('MRIOpen = get(gcbf,''Userdata'');',...
        'cd(MRIOpen.p.mri.path);',...
        '[file, path] = uigetfile(',...
        '{''*.hdr;*.img'', ''Analyze Files (*.hdr,*.img)'';', ...
        ' ''COR*'', ''FreeSurfer COR-??? files'';', ...
        ' ''*.mat'', ''MATLAB Files (*.mat)'';', ...
        ' ''*.*'',   ''All Files (*.*)''},', ...
        '''Select MRI File'');',...
        'if ~isequal(path,0), MRIOpen.p.mri.path = path; end;',...
        'if ~isequal(file,0), MRIOpen.p.mri.file = file; end;',...
        'set(MRIOpen.handles.EmriPath,''String'',MRIOpen.p.mri.path);',...
        'set(MRIOpen.handles.EmriFile,''String'',MRIOpen.p.mri.file);',...
        'if ~isempty(findstr(file,''.hdr'')) | ~isempty(findstr(file,''.img'')), ',...
            'set(MRIOpen.handles.PmriType,''Value'',1); ',...
            'MRIOpen.p.mri.type = popupstr(MRIOpen.handles.PmriType);',...
        'elseif ~isempty(findstr(file,''COR'')), ',...
            'set(MRIOpen.handles.PmriType,''Value'',2); ',...
            'MRIOpen.p.mri.type = popupstr(MRIOpen.handles.PmriType);',...
        'else, ',...
            'set(MRIOpen.handles.PmriType,''Value'',3); ',...
            'MRIOpen.p.mri.type = popupstr(MRIOpen.handles.PmriType);',...
        'end;',...
        'set(gcbf,''Userdata'',MRIOpen); clear MRIOpen file path;');
    G.BmriFile = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized',Font, ...
        'Position',[.01 .01 .17 .2], 'String','BROWSE',...
        'BackgroundColor',[0.8 0.8 0.0],...
        'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
        'Callback', browsecommand );
    
    % PLOT: Load & plot the data!
    G.Bplot = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
        'Position',[.20 .01 .18 .2],...
        'String','PLOT','BusyAction','queue',...
        'TooltipString','Plot the MRI data and return p struct.',...
        'BackgroundColor',[0.0 0.5 0.0],...
        'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
        'Callback',strcat('MRIOpen = get(gcbf,''Userdata'');',...
                          'p = gui_mri_open(MRIOpen.p,''plot'');',...
                          'clear MRIOpen;'));

    % Save As
	G.Bsave = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
        'Position',[.40 .01 .18 .2],'HorizontalAlignment', 'center',...
        'String','SAVE AS','TooltipString','MRI File Conversion Tool (not implemented yet)',...
        'BusyAction','queue',...
        'Visible','on',...
        'BackgroundColor',[0.0 0.0 0.75],...
        'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
        'Callback',strcat('MRIOpen = get(gcbf,''Userdata'');',...
                          'p = gui_mri_open(MRIOpen.p,''save'');',...
                          'clear MRIOpen;'));

    % Quit, return file parameters
    G.Breturn = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
        'Position',[.60 .01 .18 .2],...
        'String','RETURN','BusyAction','queue',...
        'TooltipString','Return p struct to workspace and parent GUI.',...
        'BackgroundColor',[0.75 0.0 0.0],...
        'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
        'Callback',strcat('MRIOpen = get(gcbf,''Userdata'');',...
                          'p = gui_mri_open(MRIOpen.p,''return'');',...
                          'clear MRIOpen;'));
    
    % Cancel
    G.Bcancel = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
        'Position',[.80 .01 .18 .2],...
        'String','CANCEL','BusyAction','queue',...
        'TooltipString','Close, do not return parameters.',...
        'BackgroundColor',[0.75 0.0 0.0],...
        'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
        'Callback','gui_mri_open([],''cancel'');');
    
    
	% Help
	G.Bhelp = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
        'Position',[.80 .25 .18 .2],'String','Help','BusyAction','queue',...
        'BackgroundColor',[1 1 0],...
        'ForegroundColor',[0 0 0], 'HorizontalAlignment', 'center',...
        'Callback','doc mri_toolbox;');
    
    % Hold GUI Open checkbox
	G.Bhold = uicontrol('Parent',GUI,'Style','checkbox','Units','Normalized', Font, ...
        'Position',[.80 .50 .18 .2],'String','Hold GUI','BusyAction','queue',...
        'TooltipString','MRI File Load GUI remains open after ''Plot'' or ''Return'' commands.',...
        'Value',p.hold,'HorizontalAlignment', 'center');
    
    
    % Store userdata
    if exist('parent','var'), MRIOpen.parent.gui = parent; end
    MRIOpen.gui = GUI;          
    MRIOpen.handles = G;
    MRIOpen.p = p;
    set(GUI,'Userdata',MRIOpen);
    set(GUI,'HandleVisibility','callback');
    
return

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -