0001 function [p] = gui_mesh_open(p,command,parent)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
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
0039 case 'init',
0040
0041 if exist('parent','var'),
0042 MESHOpen = INIT(p,parent);
0043 else
0044 MESHOpen = INIT(p);
0045 end
0046
0047
0048 case 'plot',
0049
0050 MESHOpen = get(gcbf,'Userdata');
0051
0052 MESHOpen.p = mesh_open(MESHOpen.p);
0053
0054 set(MESHOpen.gui,'Userdata',MESHOpen);
0055
0056 if isequal(get(MESHOpen.handles.Bhold,'Value'),1),
0057
0058 [p] = gui_updateparent(MESHOpen,0);
0059 [p] = gui_mesh_plot(p,'init',MESHOpen.gui);
0060
0061 else
0062
0063 [p] = gui_updateparent(MESHOpen);
0064 if isfield(MESHOpen,'parent'),
0065 if ~isempty(MESHOpen.parent),
0066 gui_mesh_plot(MESHOpen.p,'init',MESHOpen.parent.gui);
0067 end
0068 else
0069 gui_mesh_plot(MESHOpen.p,'init','');
0070 end
0071 close gcbf;
0072 end
0073
0074
0075 case 'save',
0076
0077 MESHOpen = get(gcbf,'Userdata');
0078 gui_mesh_write(MESHOpen.p);
0079
0080 if isequal(get(MESHOpen.handles.Bhold,'Value'),1),
0081 [p] = gui_updateparent(MESHOpen,0);
0082 else
0083 [p] = gui_updateparent(MESHOpen);
0084 close gcbf;
0085 end
0086
0087
0088 case 'return',
0089
0090 MESHOpen = get(gcbf,'Userdata');
0091
0092 set(MESHOpen.gui,'Pointer','watch');
0093
0094 MESHOpen.p = mesh_open(MESHOpen.p);
0095
0096 set(MESHOpen.gui,'Userdata',MESHOpen);
0097
0098 set(MESHOpen.gui,'Pointer','arrow');
0099
0100 if isequal(get(MESHOpen.handles.Bhold,'Value'),1),
0101 [p] = gui_updateparent(MESHOpen,0);
0102 else
0103 [p] = gui_updateparent(MESHOpen);
0104 close gcbf;
0105 end
0106
0107
0108 otherwise,
0109
0110 close gcbf;
0111
0112 end
0113
0114 return
0115
0116
0117
0118
0119 function [MESHOpen] = INIT(p,parent),
0120
0121
0122
0123 GUIwidth = 500;
0124 GUIheight = 120;
0125
0126 version = '$Revision: 1.1 $';
0127 name = sprintf('MESH File Open [v %s]\n',version(11:15));
0128
0129 GUI = figure('Name',name,'Tag','MESH_OPEN',...
0130 'NumberTitle','off',...
0131 'MenuBar','none','Position',[1 1 GUIwidth GUIheight]);
0132 movegui(GUI,'center');
0133
0134 MESHOpen.gui = GUI;
0135
0136 Font.FontName = 'Helvetica';
0137 Font.FontUnits = 'Pixels';
0138 Font.FontSize = 12;
0139 Font.FontWeight = 'normal';
0140 Font.FontAngle = 'normal';
0141
0142
0143
0144
0145 G.Title_data = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
0146 'Position',[.01 .75 .17 .2],...
0147 'TooltipString','Mesh/Tesselation Formats (see, ''help mesh_open'')',...
0148 'String','Mesh Type:','HorizontalAlignment','left');
0149
0150 switch lower(p.mesh.type),
0151 case 'brainstorm', meshType = 1;
0152 case 'emse', meshType = 2;
0153 case 'ascii', meshType = 3;
0154 case 'freesurfer_ascii', meshType = 4;
0155 case 'freesurfer_surf', meshType = 5;
0156 case 'freesurfer_curv', meshType = 6;
0157 case 'freesurfer_overlay', meshType = 7;
0158 otherwise, meshType = 1;
0159 end
0160
0161 meshtypes = {'BrainStorm' 'EMSE' 'ASCII' ...
0162 'FreeSurfer_ascii' 'FreeSurfer_surf' 'FreeSurfer_curv' 'FreeSurfer_overlay' };
0163 G.PmeshType = uicontrol('Tag','PmeshType','Parent',GUI,'Style','popupmenu',...
0164 'Units','Normalized',Font, ...
0165 'Position',[.20 .75 .28 .2],...
0166 'String',meshtypes,'Value',meshType,...
0167 'TooltipString','Mesh/Triangulation Formats (see, ''help mesh_open'', FS = FreeSurfer)',...
0168 'Callback',strcat('MESHOpen = get(gcbf,''Userdata'');',...
0169 'MESHOpen.p.mesh.type = popupstr(MESHOpen.handles.PmeshType);',...
0170 'set(gcbf,''Userdata'',MESHOpen); clear MESHOpen;'));
0171
0172 G.BmeshReplace = uicontrol('Tag','BmeshReplace','Parent',GUI,'Style','checkbox',...
0173 'Units','Normalized',Font,...
0174 'Position',[.40 .75 .18 .2],...
0175 'String','Replace','Value',1,...
0176 'TooltipString','Reload current mesh, if any?',...
0177 'Visible','off',...
0178 'Callback',strcat('MESHOpen = get(gcbf,''Userdata'');',...
0179 'MESHOpen.p.mesh.reload = get(MESHOpen.handles.BmeshReplace,''Value'');',...
0180 'set(gcbf,''Userdata'',MESHOpen); clear MESHOpen;'));
0181
0182 G.Title_path = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
0183 'Position',[.01 .50 .17 .2],...
0184 'String','Path','HorizontalAlignment','left');
0185 G.EmeshPath = uicontrol('Parent',GUI,'Style','edit','Units','Normalized',Font, ...
0186 'Position',[.20 .50 .58 .2], 'String',p.mesh.path,...
0187 'Callback',strcat('MESHOpen = get(gcbf,''Userdata'');',...
0188 'MESHOpen.p.mesh.path = get(MESHOpen.handles.EmeshPath,''String'');',...
0189 'set(gcbf,''Userdata'',MESHOpen); clear MESHOpen;'));
0190
0191 G.Title_file = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
0192 'Position',[.01 .25 .17 .2],...
0193 'String','File','HorizontalAlignment','left');
0194 G.EmeshFile = uicontrol('Parent',GUI,'Style','edit','Units','Normalized',Font, ...
0195 'Position',[.20 .25 .58 .2], 'String',p.mesh.file,...
0196 'Callback',strcat('MESHOpen = get(gcbf,''Userdata'');',...
0197 'MESHOpen.p.mesh.file = get(MESHOpen.handles.EmeshFile,''String'');',...
0198 'set(gcbf,''Userdata'',MESHOpen); clear MESHOpen;'));
0199
0200 Font.FontWeight = 'bold';
0201
0202
0203 browsecommand = strcat('MESHOpen = get(gcbf,''Userdata'');',...
0204 'cd(MESHOpen.p.mesh.path);',...
0205 '[file, path] = uigetfile(',...
0206 '{''*.dat;*.txt'', ''ASCII Tesselations (*.dat,*.txt)'';', ...
0207 ' ''*.asc;*.tri'', ''FreeSurfer Tesselations (*.asc,*.tri)'';', ...
0208 ' ''*.orig;*.smoothwm;*.white;*.pial'', ''FreeSurfer Surfaces'';', ...
0209 ' ''*.wfr'', ''EMSE Tesselations (*.wfr)'';', ...
0210 ' ''*.mat'', ''BrainStorm Tesselations (*.mat)'';', ...
0211 ' ''*.*'', ''All Files (*.*)''},', ...
0212 '''Select Mesh/Tesselation File'');',...
0213 'if ~isequal(path,0), MESHOpen.p.mesh.path = path; end;',...
0214 'if ~isequal(file,0), MESHOpen.p.mesh.file = file; end;',...
0215 'set(MESHOpen.handles.EmeshPath,''String'',MESHOpen.p.mesh.path);',...
0216 'set(MESHOpen.handles.EmeshFile,''String'',MESHOpen.p.mesh.file);',...
0217 'if findstr(file,''.mat''), value = 1; ',...
0218 'elseif findstr(file,''.wfr''), value = 2; ',...
0219 'elseif findstr(file,''.dat''), value = 3; ',...
0220 'elseif findstr(file,''.txt''), value = 3; ',...
0221 'elseif findstr(file,''.asc''), value = 3; ',...
0222 'elseif findstr(file,''.tri''), value = 4; ',...
0223 'elseif findstr(file,''.orig''), value = 5; ',...
0224 'elseif findstr(file,''.smoothwm''), value = 5; ',...
0225 'elseif findstr(file,''.white''), value = 5; ',...
0226 'elseif findstr(file,''.pial''), value = 5; ',...
0227 'else, value = 3; ',...
0228 'end;',...
0229 'set(MESHOpen.handles.PmeshType,''Value'',value); ',...
0230 'MESHOpen.p.mesh.type = popupstr(MESHOpen.handles.PmeshType);',...
0231 'set(gcbf,''Userdata'',MESHOpen); clear value file path MESHOpen;');
0232 G.BmeshFile = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized',Font, ...
0233 'Position',[.01 .01 .17 .2], 'String','BROWSE',...
0234 'BackgroundColor',[0.8 0.8 0.0],...
0235 'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
0236 'Callback', browsecommand );
0237
0238
0239 G.Bplot = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
0240 'Position',[.20 .01 .18 .2],...
0241 'String','PLOT','BusyAction','queue',...
0242 'TooltipString','Plot the mesh and return the file parameters.',...
0243 'BackgroundColor',[0.0 0.5 0.0],...
0244 'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
0245 'Callback',strcat('MESHOpen = get(gcbf,''Userdata'');',...
0246 'p = gui_mesh_open(MESHOpen.p,''plot'');',...
0247 'clear MESHOpen;'));
0248
0249
0250 G.Bsave = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
0251 'Position',[.40 .01 .18 .2],...
0252 'String','SAVE AS','BusyAction','queue',...
0253 'TooltipString','Load and convert the mesh.',...
0254 'BackgroundColor',[0.0 0.0 0.5],...
0255 'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
0256 'Callback',strcat('MESHOpen = get(gcbf,''Userdata'');',...
0257 'p = gui_mesh_open(MESHOpen.p,''save'');',...
0258 'clear MESHOpen;'));
0259
0260
0261 G.Breturn = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
0262 'Position',[.60 .01 .18 .2],...
0263 'String','RETURN','BusyAction','queue',...
0264 'TooltipString','Close and return the file parameters.',...
0265 'BackgroundColor',[0.75 0.0 0.0],...
0266 'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
0267 'Callback',strcat('MESHOpen = get(gcbf,''Userdata'');',...
0268 'p = gui_mesh_open(MESHOpen.p,''return'');',...
0269 'clear MESHOpen;'));
0270
0271
0272 G.Bcancel = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
0273 'Position',[.80 .01 .18 .2],...
0274 'String','CANCEL','BusyAction','queue',...
0275 'TooltipString','Close, do not return the p struct.',...
0276 'BackgroundColor',[0.75 0.0 0.0],...
0277 'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
0278 'Callback',strcat('MESHOpen = get(gcbf,''Userdata'');',...
0279 'p = gui_mesh_open(MESHOpen.p,''cancel'');',...
0280 'clear MESHOpen;'));
0281
0282
0283 G.Bhelp = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
0284 'Position',[.80 .25 .18 .2],'String','Help','BusyAction','queue',...
0285 'BackgroundColor',[1 1 0],...
0286 'ForegroundColor',[0 0 0], 'HorizontalAlignment', 'center',...
0287 'Callback','doc mesh_open;');
0288
0289
0290 G.Bhold = uicontrol('Parent',GUI,'Style','checkbox','Units','Normalized', Font, ...
0291 'Position',[.80 .50 .18 .2],'String','Hold GUI','BusyAction','queue',...
0292 'TooltipString','MESH File Load GUI remains open after ''Plot'' and ''Return'' commands.',...
0293 'Value',p.hold,'HorizontalAlignment', 'center');
0294
0295
0296 if exist('parent','var'), MESHOpen.parent.gui = parent; end
0297 MESHOpen.handles = G;
0298 MESHOpen.p = p;
0299 set(GUI,'HandleVisibility','callback');
0300 set(GUI,'Userdata',MESHOpen);
0301
0302 return