Home > bioelectromagnetism > gui_mri_open.m

gui_mri_open

PURPOSE ^

gui_mri_open - Load & Display an Analyze volume

SYNOPSIS ^

function [p] = gui_mri_open(p,command,parent)

DESCRIPTION ^

 gui_mri_open - Load & Display an Analyze volume
 
 Usage: [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.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [p] = gui_mri_open(p,command,parent)
0002 
0003 % gui_mri_open - Load & Display an Analyze volume
0004 %
0005 % Usage: [p] = gui_mri_open(p,[command],[parent])
0006 %
0007 % p is a structure, generated by 'eeg_toolbox_defaults'
0008 % command is either 'init' or 'load'
0009 % parent is a handle to the gui that calls this gui, useful
0010 % for updating the UserData field of the parent from this gui.
0011 % The p structure is returned to the parent when the parent
0012 % handle is given.
0013 %
0014 
0015 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:35 $
0016 
0017 % Licence:  GNU GPL, no express or implied warranties
0018 % History:  08/2002, Darren.Weber_at_radiology.ucsf.edu
0019 %
0020 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0021 
0022 
0023 if ~exist('p','var'),
0024    [p] = eeg_toolbox_defaults;
0025 elseif isempty(p),
0026    [p] = eeg_toolbox_defaults;
0027 end
0028 
0029 if ~exist('command','var'),
0030     command = 'init';
0031 elseif isempty(command),
0032     command = 'init';
0033 end
0034 
0035 command = lower(command);
0036 
0037 switch command,
0038 case 'init',
0039     if exist('parent','var'),
0040         MRIOpen = INIT(p,parent);
0041     else
0042         MRIOpen = INIT(p,'');
0043     end
0044 otherwise,
0045     MRIOpen = get(gcbf,'Userdata');
0046     set(MRIOpen.gui,'Pointer','watch');
0047 end
0048 
0049 
0050 switch command,
0051     
0052 case 'plot',
0053     
0054     MRIOpen.p.mri.plot = 1;
0055     MRIOpen.p = mri_open(MRIOpen.p);
0056     
0057 case 'return',
0058     
0059     MRIOpen.p.mri.plot = 0;
0060     MRIOpen.p = mri_open(MRIOpen.p);
0061     
0062 case 'save',
0063     
0064     fprintf('\ngui_mri_OPEN: Save As not implemented yet.\n');
0065     
0066 otherwise,
0067     
0068 end
0069 
0070 
0071 % -- tidy up & return
0072 
0073 switch command,
0074 case 'init',
0075 case 'cancel',
0076     GUI.parent = MRIOpen.parent;
0077     gui_updateparent(GUI);
0078     close gcbf;
0079 otherwise,
0080     set(MRIOpen.gui,'Pointer','arrow');
0081     set(MRIOpen.gui,'Userdata',MRIOpen);
0082     
0083    [p] = gui_updateparent(MRIOpen,0);
0084     
0085     if isequal(get(MRIOpen.handles.Bhold,'Value'),0),
0086         close gcbf;
0087         if isfield(MRIOpen,'parent'),
0088             parent = MRIOpen.parent.gui;
0089         else
0090             parent = [];
0091         end
0092     else
0093         parent = MRIOpen.gui;
0094     end
0095 end
0096 
0097 
0098 return
0099 
0100 
0101 
0102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0104 function [MRIOpen] = INIT(p,parent)
0105     % GUI General Parameters
0106     
0107     GUIwidth  = 500;
0108     GUIheight = 120;
0109     
0110     version = '$Revision: 1.1 $';
0111     name = sprintf('MRI File Open [v %s]\n',version(11:15));
0112     
0113     GUI = figure('Name',name,'Tag','MRI_OPEN',...
0114                  'NumberTitle','off',...
0115                  'MenuBar','none','Position',[1 1 GUIwidth GUIheight]);
0116     movegui(GUI,'center');
0117     
0118     Font.FontName   = 'Helvetica';
0119     Font.FontUnits  = 'Pixels';
0120     Font.FontSize   = 12;
0121     Font.FontWeight = 'normal';
0122     Font.FontAngle  = 'normal';
0123     
0124     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0125     % Voltage Data Selection and Parameters
0126 
0127     G.Title_data = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
0128         'Position',[.01 .75 .17 .2],...
0129         'String','Data Type:','HorizontalAlignment','left');
0130     
0131     switch p.mri.type
0132         case 'Analyze', mriType = 1;
0133         case 'COR',     mriType = 2;
0134         case 'Matlab',  mriType = 3;
0135         otherwise,      mriType = 1;
0136     end
0137     G.PmriType = uicontrol('Tag','PmriType','Parent',GUI,'Style','popupmenu',...
0138         'Units','Normalized',Font,  ...
0139         'Position',[.20 .75 .25 .2],...
0140         'String',{'Analyze' 'FreeSurfer COR' 'Matlab'},'Value',mriType,...
0141         'Callback',strcat('MRIOpen = get(gcbf,''Userdata'');',...
0142                           'MRIOpen.p.mri.type = popupstr(MRIOpen.handles.PmriType);',...
0143                           'set(gcbf,''Userdata'',MRIOpen); clear MRIOpen;'));
0144     
0145     switch p.mri.orient
0146         case 'auto',                mriOrient = 1;
0147         case 'axial unflipped',     mriOrient = 2;
0148         case 'coronal unflipped',   mriOrient = 3;
0149         case 'sagittal unflipped',  mriOrient = 4;
0150         case 'axial flipped',       mriOrient = 5;
0151         case 'coronal flipped',     mriOrient = 6;
0152         case 'sagittal flipped',    mriOrient = 7;
0153         otherwise,                  mriOrient = 1;
0154     end
0155     
0156     G.PmriOrient = uicontrol('Tag','PmriOrient','Parent',GUI,'Style','popupmenu',...
0157         'Units','Normalized',Font,  ...
0158         'Position',[.50 .75 .25 .2],...
0159         'TooltipString','Force loading with this orientation, otherwise use auto detection',...
0160         'String',{'auto' 'axial unflipped' 'coronal unflipped' 'sagittal unflipped' ...
0161                   'axial flipped'  'coronal flipped'  'sagittal flipped'},'Value',mriOrient,...
0162         'Callback',strcat('MRIOpen = get(gcbf,''Userdata'');',...
0163                           'MRIOpen.p.mri.orient = popupstr(MRIOpen.handles.PmriOrient);',...
0164                           'set(gcbf,''Userdata'',MRIOpen); clear MRIOpen;'));
0165     
0166     G.Title_path = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
0167         'Position',[.01 .50 .17 .2],...
0168         'String','Path','HorizontalAlignment','left');
0169     G.EmriPath = uicontrol('Parent',GUI,'Style','edit','Units','Normalized',Font,  ...
0170         'Position',[.20 .50 .58 .2], 'String',p.mri.path,...
0171         'Callback',strcat('MRIOpen = get(gcbf,''Userdata'');',...
0172                           'MRIOpen.p.mri.path = get(MRIOpen.handles.EmriPath,''String'');',...
0173                           'set(gcbf,''Userdata'',MRIOpen); clear MRIOpen;'));
0174     
0175     G.Title_file = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
0176         'Position',[.01 .25 .17 .2],...
0177         'String','File','HorizontalAlignment','left');
0178     G.EmriFile = uicontrol('Parent',GUI,'Style','edit','Units','Normalized',Font,  ...
0179         'Position',[.20 .25 .58 .2], 'String',p.mri.file,...
0180         'Callback',strcat('MRIOpen = get(gcbf,''Userdata'');',...
0181                           'MRIOpen.p.mri.file = get(MRIOpen.handles.EmriFile,''String'');',...
0182                           'set(gcbf,''Userdata'',MRIOpen); clear MRIOpen;'));
0183     
0184     Font.FontWeight = 'bold';
0185     
0186     % BROWSE: Look for the data
0187     browsecommand = strcat('MRIOpen = get(gcbf,''Userdata'');',...
0188         'cd(MRIOpen.p.mri.path);',...
0189         '[file, path] = uigetfile(',...
0190         '{''*.hdr;*.img'', ''Analyze Files (*.hdr,*.img)'';', ...
0191         ' ''COR*'', ''FreeSurfer COR-??? files'';', ...
0192         ' ''*.mat'', ''MATLAB Files (*.mat)'';', ...
0193         ' ''*.*'',   ''All Files (*.*)''},', ...
0194         '''Select MRI File'');',...
0195         'if ~isequal(path,0), MRIOpen.p.mri.path = path; end;',...
0196         'if ~isequal(file,0), MRIOpen.p.mri.file = file; end;',...
0197         'set(MRIOpen.handles.EmriPath,''String'',MRIOpen.p.mri.path);',...
0198         'set(MRIOpen.handles.EmriFile,''String'',MRIOpen.p.mri.file);',...
0199         'if ~isempty(findstr(file,''.hdr'')) | ~isempty(findstr(file,''.img'')), ',...
0200             'set(MRIOpen.handles.PmriType,''Value'',1); ',...
0201             'MRIOpen.p.mri.type = popupstr(MRIOpen.handles.PmriType);',...
0202         'elseif ~isempty(findstr(file,''COR'')), ',...
0203             'set(MRIOpen.handles.PmriType,''Value'',2); ',...
0204             'MRIOpen.p.mri.type = popupstr(MRIOpen.handles.PmriType);',...
0205         'else, ',...
0206             'set(MRIOpen.handles.PmriType,''Value'',3); ',...
0207             'MRIOpen.p.mri.type = popupstr(MRIOpen.handles.PmriType);',...
0208         'end;',...
0209         'set(gcbf,''Userdata'',MRIOpen); clear MRIOpen file path;');
0210     G.BmriFile = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized',Font, ...
0211         'Position',[.01 .01 .17 .2], 'String','BROWSE',...
0212         'BackgroundColor',[0.8 0.8 0.0],...
0213         'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
0214         'Callback', browsecommand );
0215     
0216     % PLOT: Load & plot the data!
0217     G.Bplot = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
0218         'Position',[.20 .01 .18 .2],...
0219         'String','PLOT','BusyAction','queue',...
0220         'TooltipString','Plot the MRI data and return p struct.',...
0221         'BackgroundColor',[0.0 0.5 0.0],...
0222         'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
0223         'Callback',strcat('MRIOpen = get(gcbf,''Userdata'');',...
0224                           'p = gui_mri_open(MRIOpen.p,''plot'');',...
0225                           'clear MRIOpen;'));
0226 
0227     % Save As
0228     G.Bsave = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
0229         'Position',[.40 .01 .18 .2],'HorizontalAlignment', 'center',...
0230         'String','SAVE AS','TooltipString','MRI File Conversion Tool (not implemented yet)',...
0231         'BusyAction','queue',...
0232         'Visible','on',...
0233         'BackgroundColor',[0.0 0.0 0.75],...
0234         'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
0235         'Callback',strcat('MRIOpen = get(gcbf,''Userdata'');',...
0236                           'p = gui_mri_open(MRIOpen.p,''save'');',...
0237                           'clear MRIOpen;'));
0238 
0239     % Quit, return file parameters
0240     G.Breturn = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
0241         'Position',[.60 .01 .18 .2],...
0242         'String','RETURN','BusyAction','queue',...
0243         'TooltipString','Return p struct to workspace and parent GUI.',...
0244         'BackgroundColor',[0.75 0.0 0.0],...
0245         'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
0246         'Callback',strcat('MRIOpen = get(gcbf,''Userdata'');',...
0247                           'p = gui_mri_open(MRIOpen.p,''return'');',...
0248                           'clear MRIOpen;'));
0249     
0250     % Cancel
0251     G.Bcancel = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
0252         'Position',[.80 .01 .18 .2],...
0253         'String','CANCEL','BusyAction','queue',...
0254         'TooltipString','Close, do not return parameters.',...
0255         'BackgroundColor',[0.75 0.0 0.0],...
0256         'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
0257         'Callback',strcat('MRIOpen = get(gcbf,''Userdata'');',...
0258                           'p = gui_mri_open(MRIOpen.p,''cancel'');',...
0259                           'clear MRIOpen;'));
0260     
0261     
0262     % Help
0263     G.Bhelp = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
0264         'Position',[.80 .25 .18 .2],'String','Help','BusyAction','queue',...
0265         'BackgroundColor',[1 1 0],...
0266         'ForegroundColor',[0 0 0], 'HorizontalAlignment', 'center',...
0267         'Callback','doc mri_toolbox;');
0268     
0269     % Hold GUI Open checkbox
0270     G.Bhold = uicontrol('Parent',GUI,'Style','checkbox','Units','Normalized', Font, ...
0271         'Position',[.80 .50 .18 .2],'String','Hold GUI','BusyAction','queue',...
0272         'TooltipString','MRI File Load GUI remains open after ''Plot'' or ''Return'' commands.',...
0273         'Value',p.hold,'HorizontalAlignment', 'center');
0274     
0275     
0276     % Store userdata
0277     if exist('parent','var'), MRIOpen.parent.gui = parent; end
0278     MRIOpen.gui = GUI;          
0279     MRIOpen.handles = G;
0280     MRIOpen.p = p;
0281     set(GUI,'Userdata',MRIOpen);
0282     set(GUI,'HandleVisibility','callback');
0283     
0284 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003