0001 function job_view_leadfield(basisfile,brainfile,model)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 if nargin<3, model = 1; end
0044 if nargin<2, brainfile = []; end
0045 if nargin<1, basisfile = []; end
0046
0047 inst_id = create_instance;
0048 if isempty(inst_id), return; end;
0049
0050
0051
0052
0053
0054 create_GUI(inst_id,basisfile,brainfile,model);
0055 job_view_lf_update_cortexpattern(inst_id);
0056 job_view_lf_update_sensorpattern(inst_id);
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 function inst_id = create_instance
0067
0068 global vbmeg_inst
0069
0070 if isfield(vbmeg_inst,'viewlf'),
0071 for inst_id=1:vbmeg_inst.const.VIEWLF_MAX
0072 if isempty(vbmeg_inst.viewlf{inst_id}), return; end;
0073 end
0074 fprintf(['The number of instances of ''job_view_leadfield''' ...
0075 ' GUIs reaches the maximum number.\n']);
0076 inst_id = [];
0077 elseif isfield(vbmeg_inst,'const'),
0078 vbmeg_inst.viewlf = cell(vbmeg_inst.const.VIEWLF_MAX,1);
0079 inst_id = 1;
0080 else
0081 fprintf(['''vbmeg_inst'' was not correct. You have to invoke' ...
0082 '''vbmeg'' to create an instance of VBMEG.\n']);
0083 inst_id = [];
0084 end
0085
0086
0087
0088
0089 function create_GUI(inst_id,basisfile,brainfile,model)
0090
0091 global vbmeg_inst;
0092
0093
0094
0095
0096
0097
0098
0099 viewlf.brainfile = brainfile;
0100 viewlf.V = [];
0101 viewlf.Vinf = [];
0102 viewlf.F = [];
0103 viewlf.inf_C = [];
0104 viewlf.xxA = [];
0105 viewlf.nextDD = [];
0106 viewlf.nextIX = [];
0107
0108
0109
0110
0111 viewlf.basisfile = [];
0112 viewlf.basis_org = [];
0113 viewlf.basis_org_smoothed = [];
0114 viewlf.pick = [];
0115 viewlf.MEGinfo = [];
0116
0117
0118 viewlf.ix_selected_vertex = 1;
0119 viewlf.Jmin_plot = -1;
0120 viewlf.Jmax_plot = 1;
0121 viewlf.Bmin_plot = -100;
0122 viewlf.Bmax_plot = 100;
0123 viewlf.sensor_type = 2;
0124 viewlf.plot_parm = vb_set_plot_parm;
0125 viewlf.plot_parm.index = [];
0126 viewlf.plot_parm.LRflag = 'LR';
0127
0128
0129
0130
0131
0132
0133 h_fig = open('job_view_leadfield.fig');
0134 set(h_fig,'HandleVisibility','on');
0135 drawnow;
0136 set(h_fig,'Pointer','watch');
0137
0138
0139 viewlf.model_type = model;
0140
0141
0142
0143
0144
0145
0146 viewlf.h_fig = h_fig;
0147 viewlf.h_cortex = get_child_handle(h_fig,'plot_cortex');
0148
0149 viewlf.h_sensor = get_child_handle(h_fig,'plot_sensor');
0150
0151
0152
0153 viewlf.ed1 = get_child_handle(h_fig,'vertex_index');
0154 viewlf.ed2 = get_child_handle(h_fig,'lf_power');
0155 viewlf.ed3 = get_child_handle(h_fig,'filter_radius');
0156
0157
0158 viewlf.pb1 = get_child_handle(h_fig,'left_button');
0159 viewlf.pb2 = get_child_handle(h_fig,'right_button');
0160 viewlf.pb3 = get_child_handle(h_fig,'top_button');
0161 viewlf.pb4 = get_child_handle(h_fig,'bottom_button');
0162 viewlf.pb5 = get_child_handle(h_fig,'rotate');
0163 viewlf.pb6 = get_child_handle(h_fig,'select_vertex');
0164 viewlf.pb7 = get_child_handle(h_fig,'print');
0165
0166
0167 viewlf.rb1 = get_child_handle(h_fig,'model_type_original_rb');
0168 viewlf.rb2 = get_child_handle(h_fig,'model_type_inflate_rb');
0169
0170
0171 viewlf.cb1 = get_child_handle(h_fig,'left_brain');
0172 viewlf.cb2 = get_child_handle(h_fig,'right_brain');
0173 viewlf.cb3 = get_child_handle(h_fig,'fix_cortex_colorbar');
0174 viewlf.cb4 = get_child_handle(h_fig,'fix_sensor_colorbar');
0175
0176
0177 viewlf.load_cortex_menu ...
0178 = get_child_handle(get_child_handle(h_fig,'file_menu'), ...
0179 'load_cortex_menu');
0180 viewlf.load_leadfield_menu ...
0181 = get_child_handle(get_child_handle(h_fig,'file_menu'),...
0182 'load_leadfield_menu');
0183 viewlf.loaded_files_menu ...
0184 = get_child_handle(get_child_handle(h_fig,'file_menu'), ...
0185 'loaded_files_menu');
0186 viewlf.close_menu ...
0187 = get_child_handle(get_child_handle(h_fig,'file_menu'), ...
0188 'close_menu');
0189
0190
0191 set(viewlf.ed1,'String','1');
0192
0193
0194
0195
0196
0197 inst_str = num2str(inst_id);
0198 viewlf_str = ['vbmeg_inst.viewlf{' inst_str '}'];
0199
0200
0201 command = ['global vbmeg_inst; '...
0202 'vbmeg_inst.viewlf{' inst_str '}=[];'];
0203 set(h_fig,'DeleteFcn',command);
0204
0205
0206 command = ['global vbmeg_inst;' ...
0207 viewlf_str '.ix_selected_vertex = ' ...
0208 'str2num(get(' viewlf_str '.ed1,''String''));' ...
0209 'job_view_lf_update_cortexpattern(' inst_str ');' ...
0210 'job_view_lf_update_sensorpattern(' inst_str ');'];
0211 set(viewlf.ed1,'Callback',command);
0212
0213
0214 command = ['job_view_lf_change_filter_radius(' inst_str ');'];
0215 set(viewlf.ed3,'Callback',command);
0216
0217
0218 command = ['job_view_lf_change_angle(' inst_str ',''left'');'];
0219 set(viewlf.pb1,'Callback',command);
0220 command = ['job_view_lf_change_angle(' inst_str ',''right'');'];
0221 set(viewlf.pb2,'Callback',command);
0222 command = ['job_view_lf_change_angle(' inst_str ',''top'');'];
0223 set(viewlf.pb3,'Callback',command);
0224 command = ['job_view_lf_change_angle(' inst_str ',''bottom'');'];
0225 set(viewlf.pb4,'Callback',command);
0226
0227
0228 command = ['job_view_lf_push_rotate_button(' inst_str ');'];
0229 set(viewlf.pb5,'Callback',command);
0230
0231
0232 command = ['job_view_lf_selvertex(' inst_str ');'];
0233 set(viewlf.pb6,'Callback',command);
0234
0235
0236 command = ['job_view_lf_print(' inst_str ');'];
0237 set(viewlf.pb7,'Callback',command);
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248 model_type_group = [viewlf.rb1, viewlf.rb2];
0249 command = ['job_view_lf_change_modeltype(' inst_str ');'];
0250 set(model_type_group, 'Callback', command);
0251 set(model_type_group, 'Value',get(viewlf.rb1,'Min'));
0252 if model == 0, set(viewlf.rb1,'Value',get(viewlf.rb1,'Max'));
0253 else set(viewlf.rb2,'Value',get(viewlf.rb2,'Max')); end
0254
0255
0256 command = ['job_view_lf_update_cortexpattern(' inst_str ');'];
0257 set(viewlf.cb1,'Callback',command);
0258 set(viewlf.cb2,'Callback',command);
0259
0260
0261 command = ['job_view_lf_update_cortexpattern(' inst_str ');'];
0262 set(viewlf.cb3,'Callback',command);
0263 command = ['job_view_lf_update_sensorpattern(' inst_str ');'];
0264 set(viewlf.cb4,'Callback',command);
0265
0266
0267 set(h_fig,'WindowButtonUpFcn','rotate3d off;');
0268
0269
0270 command = ['[brain_dir,brain_file] = vb_file_select' ...
0271 '({''.brain.mat''},''Load cortical surface model'');' ...
0272 'if ~isempty(brain_file), ' ...
0273 'job_view_lf_load_cortex(' inst_str ',' ...
0274 '[brain_dir filesep brain_file{1}]); end'];
0275 set(viewlf.load_cortex_menu, 'Callback', command);
0276
0277
0278 command = ['[basis_dir,basis_file] = vb_file_select' ...
0279 '({''.basis.mat''},''Load leadfield data'');' ...
0280 'if ~isempty(basis_file), ' ...
0281 'job_view_lf_load_leadfield(' inst_str ',' ...
0282 '[basis_dir filesep basis_file{1}]); end'];
0283 set(viewlf.load_leadfield_menu, 'Callback', command);
0284
0285
0286 command = ['job_view_lf_show_loaded_files(' inst_str ');'];
0287 set(viewlf.loaded_files_menu, 'Callback', command);
0288
0289
0290 command = 'close;';
0291 set(viewlf.close_menu,'Callback',command);
0292
0293
0294
0295
0296
0297 set(h_fig,'Renderer','zbuffer');
0298 set(h_fig,'CurrentAxes',viewlf.h_cortex);
0299 axis off;
0300 set(h_fig,'CurrentAxes',viewlf.h_sensor);
0301 axis off;
0302
0303
0304
0305
0306
0307
0308
0309
0310 vbmeg_inst.viewlf{inst_id} = viewlf;
0311
0312
0313 set(h_fig,'Pointer','arrow');
0314
0315
0316
0317
0318
0319 if ~isempty(brainfile),
0320 job_view_lf_load_cortex(inst_id,brainfile);
0321 end
0322
0323
0324
0325
0326
0327 if ~isempty(basisfile),
0328 job_view_lf_load_leadfield(inst_id,basisfile);
0329 end