Home > functions > plotfunc > vb_select_area.m

vb_select_area

PURPOSE ^

Create area data on brain model.

SYNOPSIS ^

function vb_select_area(parm,plot_parm)

DESCRIPTION ^

 Create area data on brain model.

 [syntax]
 vb_select_area(parm,plot_parm)
 
 [input]
 parm     : <<struct>>
 --- fields of parm
  brainfile: <<string>>
  areafile : <<string>>
  actfile  : <<string>>
 ---
 plot_parm: <<struct>>

 [example]
 >> parm.brainfile = './MS/data/MS.brain.mat';
 >> parm.areafile = './MS/data/MS.area.mat'; 
 >> parm.actfile = './MS/data/MS.act.mat';
 >> parm.mode = 1; % inflate display
 >> plot_parm = vb_set_plot_parm;
 >> vb_select_area(parm,plot_parm);

 [inner functions]
 init_global_variables
 create_display_panel
 create_select_panel
 create_peak_panel
 create_frame
 plot_brain_inner
 create_axes
 create_close_button
 update_listbox_area
 init_stack

 [callback functions]
 callback_return_points
 callback_select_point3d
 callback_radius
 callback_undo
 callback_return_points
 callback_remove_area
 change_modality 
 select_act 
 select_bayesfile 
 vb_select_area
 cancel_all_area
 change_label
 change_transparent
 select_peak_area
 search_peak
 clear_estimation_result
 change_exclude_radius
 select_disp_area
 change_J_ratio
 print_figure
 change_plot_parm 
 change_timewindow

 clear_peak
 close_window

 [global variables in select_area_variables]
 brainfile
 areafile
 inflatefile
 actfile
 plot_parm
 Radius
 ix_peak1
 ix_peak2
 act_keys
 area_keys
 disp_area
 V
 V0
 ix_disp_area
 bayesfile

 F : Inverse filter of the result file
 ix: Indices of the dipoles associated with the inverse filter
 J : Current distribution on all of the dipoles 
 B : MEG time course
 
 [GUI handles]
 rb1 (activityfile/bayesfile)
 lb1 (activity map list)
 lb2 (area list)
 lb3 (display area)
 pb1 (select bayesfile)
 pb2 (cancel all area)
 pb3 (peak1 search)
 pb4 (peak1 select area)
 pb5 (peak2 search)
 pb6 (peak2 select area)
 pb7 (clear estimation result)
 pb8 (select time window)
 pb9 (remove area data)
 tx1 (bayesfile)
 tx2 (peak1 index)
 tx3 (peak2 index)
 tx4 (peak distance)
 ax1 (brain model)
 ed1 (radius)
 ed2 (excluded radius)
 cb2 (transparent)
 jmin_edit   (Jmin_ratio)
 jmin_slider (Jmin_ratio)
 jmax_edit   (Jmax_ratio)
 jmax_slider (Jmax_ratio)

 [history]
 2004-11-11 Taku Yoshioka
 2005-08-19 Taku Yoshioka (for ver 0.3)
 2010-08-26 Taku Yoshioka

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function vb_select_area(parm,plot_parm)
0002 % Create area data on brain model.
0003 %
0004 % [syntax]
0005 % vb_select_area(parm,plot_parm)
0006 %
0007 % [input]
0008 % parm     : <<struct>>
0009 % --- fields of parm
0010 %  brainfile: <<string>>
0011 %  areafile : <<string>>
0012 %  actfile  : <<string>>
0013 % ---
0014 % plot_parm: <<struct>>
0015 %
0016 % [example]
0017 % >> parm.brainfile = './MS/data/MS.brain.mat';
0018 % >> parm.areafile = './MS/data/MS.area.mat';
0019 % >> parm.actfile = './MS/data/MS.act.mat';
0020 % >> parm.mode = 1; % inflate display
0021 % >> plot_parm = vb_set_plot_parm;
0022 % >> vb_select_area(parm,plot_parm);
0023 %
0024 % [inner functions]
0025 % init_global_variables
0026 % create_display_panel
0027 % create_select_panel
0028 % create_peak_panel
0029 % create_frame
0030 % plot_brain_inner
0031 % create_axes
0032 % create_close_button
0033 % update_listbox_area
0034 % init_stack
0035 %
0036 % [callback functions]
0037 % callback_return_points
0038 % callback_select_point3d
0039 % callback_radius
0040 % callback_undo
0041 % callback_return_points
0042 % callback_remove_area
0043 % change_modality
0044 % select_act
0045 % select_bayesfile
0046 % vb_select_area
0047 % cancel_all_area
0048 % change_label
0049 % change_transparent
0050 % select_peak_area
0051 % search_peak
0052 % clear_estimation_result
0053 % change_exclude_radius
0054 % select_disp_area
0055 % change_J_ratio
0056 % print_figure
0057 % change_plot_parm
0058 % change_timewindow
0059 %
0060 % clear_peak
0061 % close_window
0062 %
0063 % [global variables in select_area_variables]
0064 % brainfile
0065 % areafile
0066 % inflatefile
0067 % actfile
0068 % plot_parm
0069 % Radius
0070 % ix_peak1
0071 % ix_peak2
0072 % act_keys
0073 % area_keys
0074 % disp_area
0075 % V
0076 % V0
0077 % ix_disp_area
0078 % bayesfile
0079 %
0080 % F : Inverse filter of the result file
0081 % ix: Indices of the dipoles associated with the inverse filter
0082 % J : Current distribution on all of the dipoles
0083 % B : MEG time course
0084 %
0085 % [GUI handles]
0086 % rb1 (activityfile/bayesfile)
0087 % lb1 (activity map list)
0088 % lb2 (area list)
0089 % lb3 (display area)
0090 % pb1 (select bayesfile)
0091 % pb2 (cancel all area)
0092 % pb3 (peak1 search)
0093 % pb4 (peak1 select area)
0094 % pb5 (peak2 search)
0095 % pb6 (peak2 select area)
0096 % pb7 (clear estimation result)
0097 % pb8 (select time window)
0098 % pb9 (remove area data)
0099 % tx1 (bayesfile)
0100 % tx2 (peak1 index)
0101 % tx3 (peak2 index)
0102 % tx4 (peak distance)
0103 % ax1 (brain model)
0104 % ed1 (radius)
0105 % ed2 (excluded radius)
0106 % cb2 (transparent)
0107 % jmin_edit   (Jmin_ratio)
0108 % jmin_slider (Jmin_ratio)
0109 % jmax_edit   (Jmax_ratio)
0110 % jmax_slider (Jmax_ratio)
0111 %
0112 % [history]
0113 % 2004-11-11 Taku Yoshioka
0114 % 2005-08-19 Taku Yoshioka (for ver 0.3)
0115 % 2010-08-26 Taku Yoshioka
0116 %
0117 % Copyright (C) 2011, ATR All Rights Reserved.
0118 % License : New BSD License(see VBMEG_LICENSE.txt)
0119 
0120 %
0121 % If 'parm' is not a struct, it is regarded as a callback function.
0122 %
0123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0124 if ~isstruct(parm)
0125   eval(parm);
0126   return;
0127 end;
0128 
0129 %
0130 % Initialize global variables
0131 %
0132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0133 clear global select_area_variables
0134 global select_area_variables;
0135 init_global_variables(parm,plot_parm);
0136 
0137 %
0138 % Create GUI
0139 %
0140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0141 figure;
0142 select_area_variables.ax1 = create_axes([0.05 0.45 0.45 0.5]);
0143 create_display_panel([0.55 0.38 0.35 0.52]);
0144 create_select_panel([0.55 0.1 0.35 0.28]);
0145 create_peak_panel([0.1 0.15 0.45 0.23]);
0146 create_close_button([0.1 0.1 0.45 0.05]);
0147 plot_brain_inner;
0148 
0149 %
0150 % Display brain model
0151 % 2010-08-26 Taku Yoshioka
0152 %
0153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0154 function plot_brain_inner(angle)
0155 
0156 global select_area_variables
0157 
0158 plot_parm = select_area_variables.plot_parm;
0159 
0160 % 3D view angle
0161 if nargin==0
0162   axes(select_area_variables.ax1);
0163   [az,el] = view; 
0164   angle = [az el];
0165   cla;
0166 end
0167 
0168 actfile = select_area_variables.actfile;
0169 lb1 = select_area_variables.lb1;
0170 act_keys = select_area_variables.act_keys;
0171 
0172 % which type of the data is selected ?
0173 if get(select_area_variables.rb1(1),'Value')
0174   n = get(lb1,'Value');
0175   if ~isempty(n)
0176     act = vb_get_act(actfile,act_keys(n(1)));
0177     xxP = act.xxP;
0178     plot_parm.J = xxP;
0179   end
0180 elseif get(select_area_variables.rb1(2),'Value')
0181   plot_parm.J = select_area_variables.J_map;
0182 end
0183 
0184 % Display area
0185 plot_parm.area.key = select_area_variables.disp_area;
0186 plot_parm.area.clr = {'b','g','r','c','m','y'};
0187 
0188 % Transparency
0189 cb2 = select_area_variables.cb2;
0190 if get(cb2,'Value')
0191   plot_parm.area.transparent = 1;
0192 else
0193   plot_parm.area.transparent = 0;
0194 end
0195 
0196 % Plotting parameters
0197 %plot_parm.brainfile = select_area_variables.brainfile;
0198 plot_parm.areafile = select_area_variables.areafile;
0199 plot_parm.index = select_area_variables.ix_disp_area;
0200 brain_file = select_area_variables.brainfile;
0201 
0202 %plot_parm.wmin = plot_parm.wmin * plot_parm.Jmin_ratio;
0203 %plot_parm.wmax = plot_parm.wmax * plot_parm.Jmax_ratio;
0204 wmin = plot_parm.wmin * plot_parm.Jmin_ratio;
0205 wmax = plot_parm.wmax * plot_parm.Jmax_ratio;
0206 J = plot_parm.J;
0207 
0208 % Plot
0209 switch select_area_variables.mode
0210  case 0,
0211   % vb_plot_brain(plot_parm);
0212   [V,F] = vb_load_cortex(brain_file);
0213   h = vb_plot_cortex(plot_parm,V,F,[],J,wmin,wmax);
0214   view([0 0]); camlight headlight;
0215   view([0 180]); camlight headlight;
0216   
0217  case 1,
0218   % plot_parm.sulcus = 1;
0219   % vb_plot_brain_inflate(plot_parm);
0220   [V,F,xx,inf_C] = vb_load_cortex(brain_file,'Inflate'); % 'xx' not used
0221   h = vb_plot_cortex(plot_parm,V,F,inf_C,J,wmin,wmax);
0222 end;
0223 
0224 view(angle);
0225 axis equal;
0226 axis off;
0227 if ~isempty(h) & ishandle(h) & strcmp(get(h,'Type'),'light'), 
0228   camlight(h,'headlight');
0229 end;
0230 
0231 % Plot peaks
0232 V = select_area_variables.V;
0233 ix_peak1 = select_area_variables.ix_peak1;
0234 ix_peak2 = select_area_variables.ix_peak2;
0235 ix_disp_area = select_area_variables.ix_disp_area;
0236 
0237 if ~isempty(ix_peak1)
0238   if ~isempty(find(ix_disp_area==ix_peak1)) | ...
0239     isempty(ix_disp_area)
0240     plot3(V(ix_peak1,1),V(ix_peak1,2),V(ix_peak1,3),'rx',...
0241       'MarkerSize',plot_parm.ms,'LineWidth',plot_parm.lw,...
0242       'EraseMode','xor');
0243   end
0244 end
0245 
0246 if ~isempty(ix_peak2) 
0247   if ~isempty(find(ix_disp_area==ix_peak2)) | ...
0248     isempty(ix_disp_area)
0249     plot3(V(ix_peak2,1),V(ix_peak2,2),V(ix_peak2,3),'bx',...
0250       'MarkerSize',plot_parm.ms,'LineWidth',plot_parm.lw,...
0251       'EraseMode','xor');
0252   end
0253 end
0254 
0255 %
0256 % Callback function: select vertices on the plotted model.
0257 %
0258 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0259 function callback_select_point3d
0260 
0261 global select_area_variables;
0262 
0263 plot_parm = select_area_variables.plot_parm;
0264 V = select_area_variables.V;
0265 nextDD = select_area_variables.nextDD;
0266 nextIX = select_area_variables.nextIX;
0267 Radius = select_area_variables.Radius;
0268 stack_points = select_area_variables.stack_points;
0269 ix_stack_points = select_area_variables.ix_stack_points;
0270 
0271 zoom off;
0272 rotate3d off;
0273 
0274 % Disable buttons
0275 h = get(gcf,'Children');
0276 for i = 1:length(h)
0277   if strcmp(get(h(i),'Type'),'uicontrol')
0278     set(h(i),'Enable','off');
0279   end
0280 end
0281 
0282 % Vertex selection
0283 P = [];
0284 h_tmp = [];
0285 while 1
0286   k = waitforbuttonpress;
0287   tmp = (select3d)';
0288   if k ~= 0 | length(tmp) == 0
0289     break;
0290   end
0291   P = [P; tmp];
0292   h_tmp = [h_tmp; plot3(tmp(1),tmp(2),tmp(3),'kx')];
0293 end
0294 
0295 % Clear plots
0296 for i = 1:length(h_tmp)
0297   delete(h_tmp(i));
0298 end
0299 
0300 %
0301 % 選択された点をモデル上の格子点へ変換
0302 % Vはインフレートモデルの頂点座標。Pは選択された点をパッチ上に
0303 % 射影したときの座標。
0304 % ix     : Extracted point index in the whole brain
0305 % h_plot : ixに対応するプロットのグラフィックスハンドル
0306 %
0307 ix = [];
0308 for i = 1:size(P,1)
0309   tmp = repmat(P(i,:), [length(V) 1]);
0310   [tmp tmp2] = min(sum((tmp - V).^2, 2));
0311   ix = [ix; tmp2];
0312 end;
0313 ix
0314 
0315 % Extract area with specified radius
0316 ix = unique(ix);
0317 tmp = [];
0318 for i = 1:length(ix)
0319   ix_tmp = find(nextDD{ix(i)} <= Radius);
0320   tmp = [tmp; nextIX{ix(i)}(ix_tmp)];
0321 end
0322 ix = unique([ix; tmp]);
0323 
0324 % Plot selected vertices
0325 h_plot = plot3(V(ix,1), V(ix,2), V(ix,3), ... 
0326            'r.', 'MarkerSize',plot_parm.ms);
0327 
0328 % Take indices and graphics handles of the selected vertices to
0329 % the stack
0330 tmp = cell(2,1);
0331 tmp{1} = ix;
0332 tmp{2} = h_plot;
0333 ix_stack_points = ix_stack_points + 1;
0334 stack_points{ix_stack_points} = tmp;
0335 
0336 % Enable buttons
0337 for i = 1:length(h)
0338   if strcmp(get(h(i),'Type'),'uicontrol')
0339     set(h(i),'Enable','on');
0340   end
0341 end
0342 
0343 if get(select_area_variables.rb1(1),'Value')
0344   set(select_area_variables.lb1,'Enable','on');
0345   set(select_area_variables.pb1,'Enable','off');
0346   set(select_area_variables.pb7,'Enable','off');
0347   set(select_area_variables.tx1,'Enable','off');
0348 else
0349   set(select_area_variables.lb1,'Enable','off');
0350   set(select_area_variables.pb1,'Enable','on');
0351   set(select_area_variables.pb7,'Enable','on');
0352   set(select_area_variables.tx1,'Enable','inactive');
0353 end
0354 
0355 select_area_variables.stack_points = stack_points;
0356 select_area_variables.ix_stack_points = ix_stack_points;
0357 
0358 return;
0359 
0360 %
0361 % Callback function: select radius
0362 %
0363 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0364 function callback_select_radius
0365 
0366 global select_area_variables;
0367 
0368 select_area_variables.Radius = ...
0369     str2num(get(select_area_variables.ed1,'String'))*1e-3;
0370 
0371 return;
0372 
0373 %
0374 % Undo
0375 %
0376 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0377 function callback_undo
0378 
0379 global select_area_variables;
0380 
0381 ix_stack_points = select_area_variables.ix_stack_points;
0382 stack_points = select_area_variables.stack_points;
0383 
0384 if ix_stack_points > 0
0385   tmp = stack_points{ix_stack_points};
0386   
0387   % Delete points on axis
0388   h = tmp{2};
0389   for i = 1:length(h)
0390     if length(h(i)) ~= 0
0391       delete(h(i));
0392     end
0393   end
0394   
0395   ix_stack_points = ix_stack_points - 1;
0396 end
0397 
0398 select_area_variables.ix_stack_points = ix_stack_points;
0399 select_area_variables.stack_points = stack_points;
0400 
0401 tmp1 = [];
0402 tmp2 = [];
0403 
0404 return;
0405 
0406 %
0407 % Area registration
0408 %
0409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0410 function callback_return_points
0411 
0412 global select_area_variables;
0413 
0414 ix_stack_points = select_area_variables.ix_stack_points;
0415 stack_points = select_area_variables.stack_points;
0416 areafile = select_area_variables.areafile;
0417 
0418 Iextract = [];
0419 Iextract_seq = cell(ix_stack_points,1);
0420 
0421 for i = 1:ix_stack_points
0422   tmp = stack_points{i};
0423   Iextract = [Iextract; tmp{1}];
0424   Iextract_seq{i} = unique(tmp{1});
0425 end
0426 
0427 fprintf('--- %d vertices were selected.\n',...
0428     length(unique(Iextract)));
0429 area_key = inputdlg('Input ID for the selected region: ');
0430 
0431 NewArea.Iextract = unique(Iextract);
0432 NewArea.key = area_key{1};
0433 NewArea.Iextract_seq = Iextract_seq;
0434 
0435 vb_add_area(areafile,NewArea);
0436 
0437 init_stack;
0438 plot_brain_inner;
0439 update_listbox_area;
0440 
0441 return;
0442 
0443 %
0444 % Subfunction: initialize global variables
0445 % 2004-03-14 Taku Yoshioka
0446 %
0447 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0448 function init_global_variables(parm,plot_parm)
0449 
0450 global select_area_variables;
0451 
0452 plot_parm.Jmax_ratio = 1.0;
0453 plot_parm.Jmin_ratio = 1.0;
0454 
0455 select_area_variables.plot_parm = plot_parm;
0456 select_area_variables.brainfile = parm.brainfile;
0457 select_area_variables.areafile = parm.areafile;
0458 select_area_variables.actfile = parm.actfile;
0459 select_area_variables.mode = parm.mode;
0460 select_area_variables.bayesfile = '';
0461 
0462 brainfile = parm.brainfile;
0463 actfile = parm.actfile;
0464 areafile = parm.areafile;
0465 
0466 % brain vertex position
0467 V = vb_load_cortex(brainfile);
0468 select_area_variables.V0 = V;
0469 
0470 if parm.mode == 1, % inflate model
0471   V = vb_load_cortex(brainfile,'Inflate');
0472 end
0473 
0474 select_area_variables.V = V; 
0475 
0476 [nextDD,nextIX] = vb_load_cortex_neighbour(brainfile); 
0477 select_area_variables.nextDD = nextDD;
0478 select_area_variables.nextIX = nextIX;
0479 
0480 % Stack of selected area
0481 init_stack;
0482 
0483 % Radius of selected area
0484 select_area_variables.Radius = 0;
0485 
0486 % Activity map/Area keyset
0487 select_area_variables.act_keys = vb_get_keyset_act(actfile);
0488 select_area_variables.area_keys = vb_get_keyset_area(areafile);
0489 
0490 % Selected area for display
0491 select_area_variables.disp_area = {};
0492 
0493 % Selected peak index
0494 select_area_variables.ix_peak1 = [];
0495 select_area_variables.ix_peak2 = [];
0496 
0497 % Display region
0498 select_area_variables.ix_disp_area = [];
0499 
0500 % Current distribution
0501 select_area_variables.J_map = [];
0502 
0503 return;
0504 
0505 %
0506 % Subfunction: create frame
0507 % 2004-03-14 Taku Yoshioka
0508 %
0509 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0510 function create_frame(pos)
0511 
0512 uicontrol('Style','frame','Units','normalized',...
0513       'Position',pos);
0514 
0515 return;
0516 
0517 %
0518 % Subfunction: create display panel
0519 % 2004-03-14 Taku Yoshioka
0520 %
0521 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0522 function create_display_panel(pos0)
0523 
0524 global select_area_variables
0525 
0526 create_frame(pos0);
0527 
0528 m = 0.03*pos0(3);% margin
0529 x = pos0(1)+m;   % origin (x)
0530 y = pos0(2)+m;   % origin (y)
0531 w = pos0(3)-2*m; % width
0532 h = pos0(4)-2*m; % height
0533 
0534 % Zoom in
0535 pos = [x y+0.9*h 0.5*w 0.1*h];
0536 uicontrol('Style','pushbutton','String','Zoom in/out',...
0537       'Units','normalized','Position',pos,...
0538       'Callback','zoom on');
0539 
0540 % Rotation
0541 pos = [x y+0.8*h 0.5*w 0.1*h];
0542 uicontrol('Style','pushbutton','String','Rotation',...
0543       'Units','normalized','Position',pos,...
0544       'Callback','rotate3d');
0545 %
0546 % rb1: Radio button (1):Activity map (2):Estimation result
0547 %
0548 
0549 % Activity map radio button
0550 pos = [x+0.5*w y+0.9*h 0.5*w 0.1*h]; 
0551 rb1(1) = ...
0552     uicontrol('Style','radiobutton','String','Activity map',...
0553           'Units','normalized','Position',pos,...
0554           'Value',0,'Callback',...
0555           'vb_select_area(''change_modality(1)'')');
0556 set(rb1(1),'Value',1); % Initial value
0557 
0558 % Activity map list
0559 pos = [x+0.5*w y+0.5*h 0.5*w 0.4*h];
0560 str = [];
0561 keys = select_area_variables.act_keys;
0562 for i = 1:length(keys)
0563   str = [str keys{i}];
0564   if i ~= length(keys)
0565     str = [str '|'];
0566   end
0567 end
0568 lb1 = ...
0569     uicontrol('Style','listbox','String',str,...
0570           'Units','normalized','Position',pos,...
0571           'Callback','vb_select_area(''select_act'')',...
0572           'Min',1,'Max',30);
0573 set(lb1,'Value',[1]); % Initial value
0574 
0575 % VB estimation result
0576 pos = [x+0.5*w y+0.4*h 0.5*w 0.1*h];
0577 rb1(2) = ...
0578     uicontrol('Style','radiobutton','String','VB result',...
0579           'Units','normalized','Position',pos,...
0580           'Value',0,'Callback',...
0581           'vb_select_area(''change_modality(2)'')');
0582 set(rb1(2),'Value',0); % Initial value
0583 
0584 % VB result filename
0585 pos = [x+0.5*w y+0.3*h 0.5*w 0.1*h];
0586 tx1 = uicontrol('Style','edit','String','','Enable','off',...
0587         'Units','normalized','Position',pos);
0588 
0589 % Load button
0590 pos = [x+0.5*w y+0.2*h 0.5*w 0.1*h];
0591 pb1 = uicontrol('Style','pushbutton','String','Load result',...
0592         'Units','normalized','Position',pos,...
0593         'Enable','off','Callback',...
0594         'vb_select_area(''select_bayesfile'')');
0595 
0596 % Time window button
0597 pos = [x+0.5*w y+0.1*h 0.5*w 0.1*h];
0598 pb8 = uicontrol('Style','pushbutton','String','Time window',...
0599         'Units','normalized','Position',pos,...
0600         'Enable','off','Callback',...
0601         'vb_select_area(''change_timewindow'')');
0602 
0603 % Clear estimation result
0604 pos = [x+0.5*w y 0.5*w 0.1*h];
0605 pb7 = uicontrol('Style','pushbutton','String','Clear result',...
0606         'Units','normalized','Position',pos,...
0607         'Enable','off','Callback',...
0608         'vb_select_area(''clear_estimation_result'')');
0609 
0610 % Display area
0611 pos = [x y+0.7*h 0.5*w 0.1*h];
0612 uicontrol('Style','text','String','Display',...
0613       'Units','normalized','Position',pos);
0614 
0615 str = [];
0616 keys = select_area_variables.area_keys;
0617 for i = 1:length(keys)
0618   str = [str keys{i}];
0619   if i ~= length(keys)
0620     str = [str '|'];
0621   end
0622 end
0623 
0624 pos = [x y+0.3*h 0.5*w 0.4*h];
0625 lb3 = uicontrol('Style','listbox','String',str,...
0626         'Units','normalized','Position',pos,...
0627         'Callback','vb_select_area(''select_disp_area'')',...
0628         'Min',1,'Max',1);
0629 set(lb3,'Value',length(keys)); % Initial value
0630 
0631 % J Max / Min Ratio
0632 Jmax_ratio = select_area_variables.plot_parm.Jmax_ratio;
0633 Jmin_ratio = select_area_variables.plot_parm.Jmin_ratio;
0634 pos = [x y+0.25*h 0.20*w 0.05*h];
0635 uicontrol('Style', 'text', 'String', 'JMax ratio',...
0636         'Units', 'normalized', 'Position', pos, 'HorizontalAlignment', 'left');
0637 pos = [x+0.15*w y+0.25*h 0.1*w 0.05*h];
0638 jmax_edit = uicontrol('Style', 'edit', 'String', num2str(Jmax_ratio), ...
0639           'Units', 'normalized', 'Position', pos,...
0640           'Callback', 'vb_select_area(''change_J_ratio'')', 'Tag', 'jmax_edit');
0641     
0642 pos = [x+0.25*w y+0.25*h 0.25*w 0.05*h];
0643 jmax_slider = uicontrol('Style', 'slider', 'SliderStep', [0.001, 0.01],...
0644           'Units', 'normalized', 'Position', pos, ...
0645           'Callback', 'vb_select_area(''change_J_ratio'')', 'Tag', 'jmax_slider',...
0646           'Max', 1, 'Min', 0, 'Value', Jmax_ratio);
0647 
0648 pos = [x y+0.2*h 0.20*w 0.05*h];
0649 uicontrol('Style', 'text', 'String', 'JMin ratio',...
0650         'Units', 'normalized', 'Position', pos,...
0651         'HorizontalAlignment', 'left');
0652 pos = [x+0.15*w y+0.2*h 0.1*w 0.05*h];
0653 jmin_edit = uicontrol('Style', 'edit', 'String', num2str(Jmin_ratio), ...
0654           'Units', 'normalized', 'Position', pos,...
0655           'Callback', 'vb_select_area(''change_J_ratio'')', 'Tag', 'jmin_edit');
0656 
0657 pos = [x+0.25*w y+0.2*h 0.25*w 0.05*h];
0658 jmin_slider = uicontrol('Style', 'slider', 'SliderStep', [0.001, 0.01],...
0659           'Units', 'normalized', 'Position', pos,...
0660           'Callback', 'vb_select_area(''change_J_ratio'')', 'Tag', 'jmin_slider',...
0661           'Max', 1, 'Min', 0, 'Value', Jmin_ratio);
0662 
0663 % plot parameter
0664 pos = [x y+0.1*h 0.5*w 0.1*h];
0665 uicontrol('Style','pushbutton','String','Plot parm.',...
0666       'Units','normalized','Position',pos,...
0667       'Callback','vb_select_area(''change_plot_parm'')');
0668 
0669 % print figure
0670 pos = [x y 0.5*w 0.1*h];
0671 uicontrol('Style','pushbutton','String','Print',...
0672       'Units','normalized','Position',pos,...
0673       'Callback','vb_select_area(''print_figure'')');
0674 
0675 %
0676 % GUI handles
0677 %
0678 select_area_variables.rb1 = rb1;
0679 select_area_variables.lb1 = lb1;
0680 select_area_variables.tx1 = tx1;
0681 select_area_variables.pb1 = pb1;
0682 select_area_variables.pb7 = pb7;
0683 select_area_variables.lb3 = lb3;
0684 select_area_variables.pb8 = pb8;
0685 select_area_variables.jmin_edit   = jmin_edit;
0686 select_area_variables.jmin_slider = jmin_slider;
0687 select_area_variables.jmax_edit   = jmax_edit;
0688 select_area_variables.jmax_slider = jmax_slider;
0689 
0690 return;
0691 
0692 %
0693 % Change display activity map and estimation result
0694 % 2004-03-14 Taku Yoshioka
0695 %
0696 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0697 function change_modality(c)
0698 
0699 global select_area_variables;
0700 
0701 switch c
0702  case 1, % display activity map
0703   set(select_area_variables.lb1,'Enable','on');
0704   set(select_area_variables.rb1(1),'Value',1);
0705   set(select_area_variables.pb1,'Enable','off');
0706   set(select_area_variables.pb7,'Enable','off');
0707   set(select_area_variables.tx1,'Enable','off');
0708   set(select_area_variables.rb1(2),'Value',0);
0709   set(select_area_variables.pb8,'Enable','off');
0710   
0711  case 2, % display estimation result
0712   set(select_area_variables.lb1,'Enable','off');
0713   set(select_area_variables.rb1(1),'Value',0);
0714   set(select_area_variables.pb1,'Enable','on');
0715   set(select_area_variables.pb7,'Enable','on');
0716   set(select_area_variables.tx1,'Enable','inactive');
0717   set(select_area_variables.rb1(2),'Value',1);
0718   if isempty(select_area_variables.bayesfile)
0719     set(select_area_variables.pb8,'Enable','off');
0720   else
0721     set(select_area_variables.pb8,'Enable','on');
0722   end
0723 end
0724 
0725 plot_brain_inner;
0726 
0727 return;
0728 
0729 %
0730 % Create axes
0731 % 2004-03-12 Taku Yoshioka
0732 %
0733 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0734 function h = create_axes(pos)
0735 
0736 axes;
0737 set(gca,'Position',pos);
0738 h = gca;
0739 
0740 return;
0741 
0742 %
0743 % Select bayes file
0744 % 2004-03-14 Taku Yoshioka
0745 % change by M. Sato
0746 % load current file
0747 %
0748 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0749 function select_bayesfile
0750 
0751 global select_area_variables;
0752 
0753 [pname,fname] = vb_file_select({'.curr.mat'});
0754 if isempty(fname), return; end
0755 
0756 fname = fname{1};
0757 resultfile = [pname filesep fname];
0758 load(resultfile,'Jact','ix_act','Tstart','Tend','Lact')
0759 select_area_variables.bayesfile = resultfile; 
0760 I = size(select_area_variables.V,1);
0761 
0762 [Nj, T] = size(Jact);
0763 JJ = sqrt(sum(reshape(Jact.^2 , [Nj/Lact Lact*T]), 2)/(Lact*T));
0764 
0765 % Set global variables
0766 select_area_variables.ix = ix_act;
0767 select_area_variables.J_map = zeros(I,1);
0768 select_area_variables.J_map(ix_act) = JJ;
0769 
0770 % Update GUI
0771 set(select_area_variables.tx1,'String',fname);
0772 set(select_area_variables.pb8,'Enable','on');
0773 
0774 % Plot brain
0775 plot_brain_inner;
0776 
0777 return;
0778 
0779 %
0780 % Select activity map
0781 % 2004-03-14 Taku Yoshioka
0782 %
0783 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0784 function select_act
0785 
0786 plot_brain_inner;
0787 
0788 return;
0789 
0790 %
0791 % Create select panel
0792 % 2004-03-14 Taku Yoshioka
0793 %
0794 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0795 function create_select_panel(pos0)
0796 
0797 global select_area_variables
0798 
0799 create_frame(pos0);
0800 
0801 m = 0.04*pos0(4);% margin
0802 x = pos0(1)+m;   % origin (x)
0803 y = pos0(2)+m;   % origin (y)
0804 w = pos0(3)-2*m; % width
0805 h = pos0(4)-2*m; % height
0806 
0807 % Select area
0808 pos = [x+0.5*w y+0.8*h 0.5*w 0.2*h];
0809 uicontrol('Style','pushbutton','String','Select area',...
0810       'Units','normalized','Position',pos,...
0811       'Callback','vb_select_area(''callback_select_point3d'')');
0812 
0813 % Radius
0814 pos = [x y+0.8*h 0.3*w 0.2*h];
0815 uicontrol('Style','text','String','Radius [mm]',...
0816       'Units','normalized','Position',pos);
0817 
0818 pos = [x+0.3*w y+0.8*h 0.2*w 0.2*h];
0819 ed1 = uicontrol('Style','edit','String','0',...
0820         'Units','normalized','Position',pos,...
0821         'Callback', ...
0822         'vb_select_area(''callback_select_radius'')');
0823 
0824 % Undo
0825 pos = [x+0.5*w y+0.6*h 0.5*w 0.2*h];
0826 uicontrol('Style','pushbutton','String','Undo ',...
0827       'Units','normalized','Position',pos,...
0828       'Callback','vb_select_area(''callback_undo'')');
0829 
0830 % Registration
0831 pos = [x+0.5*w y+0.4*h 0.5*w 0.2*h];
0832 uicontrol('Style','pushbutton','String','Registration',...
0833       'Units','normalized','Position',pos,...
0834       'Callback',...
0835       'vb_select_area(''callback_return_points;'')');
0836 
0837 % Area list
0838 pos = [x y+0.2*h 0.5*w 0.6*h];
0839 str = [];
0840 keys = select_area_variables.area_keys;
0841 for i = 1:length(keys)
0842   str = [str keys{i}];
0843   if i ~= length(keys)
0844     str = [str '|'];
0845   end
0846 end
0847 lb2 = uicontrol('Style','listbox','String',str,...
0848         'Units','normalized','Position',pos,...
0849         'Callback','vb_select_area(''select_area_inner'')',...
0850         'Min',1,'Max',30);
0851 set(lb2,'Value',[]); % Initial value
0852 
0853 % Cancel all area
0854 pos = [x y 0.5*w 0.2*h];
0855 pb2 = uicontrol('Style','pushbutton','String','Cancel all',...
0856         'Units','normalized','Position',pos,...
0857         'Enable','on','Callback',...
0858         'vb_select_area(''cancel_all_area'')');
0859 
0860 % Transparent
0861 pos = [x+0.5*w y+0.2*h 0.5*w 0.2*h];
0862 cb2 = uicontrol('Style','checkbox','String','Transparent',...
0863         'Units','normalized','Position',pos,...
0864         'Value',0,'Callback',...
0865         'vb_select_area(''plot_brain_inner'')');
0866 set(cb2,'Value',0); % Initial value
0867 
0868 % Remove area data
0869 pos = [x+0.5*w y 0.5*w 0.2*h];
0870 pb9 = uicontrol('Style','pushbutton','String','Remove',...
0871         'Units','normalized','Position',pos,...
0872         'Callback',...
0873         'vb_select_area(''callback_remove_area'')');
0874 
0875 select_area_variables.lb2 = lb2;
0876 select_area_variables.pb2 = pb2;
0877 select_area_variables.cb2 = cb2;
0878 select_area_variables.ed1 = ed1;
0879 select_area_variables.pb9 = pb9;
0880 
0881 return;
0882 
0883 %
0884 % Select area
0885 % 2004-03-15 Taku Yoshioka
0886 %
0887 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0888 function select_area_inner
0889 
0890 global select_area_variables;
0891 
0892 % indices of selected region
0893 na = get(select_area_variables.lb2,'Value');
0894 
0895 select_area_variables.disp_area = cell(length(na),1);
0896 for i = 1:length(na)
0897   select_area_variables.disp_area{i} = ...
0898       select_area_variables.area_keys{na(i)};
0899 end
0900 
0901 plot_brain_inner;
0902 
0903 return;
0904 
0905 %
0906 % Cancel all area
0907 % 2004-03-15 Taku Yoshioka
0908 %
0909 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0910 function cancel_all_area
0911 
0912 global select_area_variables
0913 
0914 set(select_area_variables.lb2,'Value',[]);
0915 select_area_variables.disp_area = {};
0916 
0917 plot_brain_inner;
0918 
0919 return;
0920 
0921 %
0922 % Create peak panel
0923 % 2004-03-15 Taku Yoshioka
0924 %
0925 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0926 function create_peak_panel(pos0)
0927 
0928 global select_area_variables;
0929 
0930 create_frame(pos0);
0931 
0932 m = 0.04*pos0(4);% margin
0933 x = pos0(1)+m;   % origin (x)
0934 y = pos0(2)+m;   % origin (y)
0935 w = pos0(3)-2*m; % width
0936 h = pos0(4)-2*m; % height
0937 
0938 %
0939 % peak1
0940 %
0941 pos = [x y+0.75*h 0.2*w 0.25*h];
0942 uicontrol('Style','text','String','Peak 1',...
0943       'Units','normalized','Position',pos,...
0944       'ForegroundColor','r');
0945 
0946 pos = [x+0.2*w y+0.75*h 0.2*w 0.25*h];
0947 tx2 = uicontrol('Style','edit','String','','Enable','inactive',...
0948         'Units','normalized','Position',pos);
0949 
0950 pos = [x+0.4*w y+0.75*h 0.3*w 0.25*h];
0951 pb3 = uicontrol('Style','pushbutton','String','Search peak',...
0952         'Units','normalized','Position',pos,...
0953         'Enable','on','Callback',...
0954         'vb_select_area(''search_peak(1)'')');
0955 
0956 pos = [x+0.7*w y+0.75*h 0.3*w 0.25*h];
0957 pb4 = uicontrol('Style','pushbutton','String','Registration',...
0958         'Units','normalized','Position',pos,...
0959         'Enable','off','Callback',...
0960         'vb_select_area(''select_peak_area(1);'')');
0961 
0962 %
0963 % peak2
0964 %
0965 pos = [x y+0.5*h 0.2*w 0.25*h];
0966 uicontrol('Style','text','String','Peak 2',...
0967       'Units','normalized','Position',pos,...
0968       'ForegroundColor','b');
0969 
0970 pos = [x+0.2*w y+0.5*h 0.2*w 0.25*h];
0971 tx3 = uicontrol('Style','edit','String','','Enable','inactive',...
0972         'Units','normalized','Position',pos);
0973 
0974 pos = [x+0.4*w y+0.5*h 0.3*w 0.25*h];
0975 pb5 = uicontrol('Style','pushbutton','String','Search peak',...
0976         'Units','normalized','Position',pos,...
0977         'Enable','on','Callback',...
0978         'vb_select_area(''search_peak(2)'')');
0979 
0980 pos = [x+0.7*w y+0.5*h 0.3*w 0.25*h];
0981 pb6 = uicontrol('Style','pushbutton','String','Registration',...
0982         'Units','normalized','Position',pos,...
0983         'Enable','off','Callback',...
0984         'vb_select_area(''select_peak_area(2);'')');
0985 
0986 %
0987 % Excluded radius
0988 %
0989 pos = [x y+0.25*h 0.6*w 0.25*h];
0990 uicontrol('Style','text','String','Excluded radius [mm]',...
0991       'Units','normalized','Position',pos);
0992 
0993 pos = [x+0.6*w y+0.25*h 0.4*w 0.25*h];
0994 ed2 = uicontrol('Style','edit','String','0',...
0995         'Units','normalized','Position',pos,...
0996         'Callback', ...
0997         'vb_select_area(''change_exclude_radius'')');
0998 
0999 %
1000 % Distance
1001 %
1002 pos = [x y 0.6*w 0.25*h];
1003 uicontrol('Style','text','String','Distance (euclid/cortex)',...
1004       'Units','normalized','Position',pos);
1005 
1006 pos = [x+0.6*w y 0.4*w 0.25*h];
1007 tx4 = uicontrol('Style','edit','String','','Enable','inactive',...
1008         'Units','normalized','Position',pos);
1009 
1010 select_area_variables.tx2 = tx2;
1011 select_area_variables.pb3 = pb3;
1012 select_area_variables.pb4 = pb4;
1013 select_area_variables.tx3 = tx3;
1014 select_area_variables.pb5 = pb5;
1015 select_area_variables.pb6 = pb6;
1016 select_area_variables.tx4 = tx4;
1017 select_area_variables.ed2 = ed2;
1018 
1019 return;
1020 
1021 %
1022 % Create close button
1023 % 2004-03-15 Taku Yoshioka
1024 %
1025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1026 function create_close_button(pos)
1027 
1028 uicontrol('Style','pushbutton','String','Close',...
1029       'Units','normalized','Position',pos,...
1030       'Enable','on','Callback',...
1031       'vb_select_area(''close_window'')');
1032 
1033 return;
1034 
1035 %
1036 % Select area around peak position
1037 % 2004-03-15 Taku Yoshioka
1038 %
1039 function select_peak_area(i)
1040 
1041 global select_area_variables;
1042 
1043 ix_peak1 = select_area_variables.ix_peak1;
1044 ix_peak2 = select_area_variables.ix_peak2;
1045 Radius = select_area_variables.Radius;
1046 nextDD = select_area_variables.nextDD;
1047 nextIX = select_area_variables.nextIX;
1048 
1049 switch i
1050  case 1, 
1051   ix = find(nextDD{ix_peak1}<=Radius);
1052   Iextract = nextIX{ix_peak1}(ix);
1053  case 2,
1054   ix = find(nextDD{ix_peak2}<=Radius);
1055   Iextract = nextIX{ix_peak2}(ix);
1056 end
1057   
1058 areafile = select_area_variables.areafile;
1059 
1060 fprintf('--- %d vertices were selected.\n',...
1061     length(Iextract));
1062 area_key = inputdlg('Input ID for the selected region: ');
1063 
1064 NewArea.Iextract = unique(Iextract);
1065 NewArea.key = area_key{1};
1066 NewArea.Iextract_seq = '';
1067 
1068 vb_add_area(areafile,NewArea);
1069 
1070 init_stack;
1071 plot_brain_inner;
1072 update_listbox_area;
1073 
1074 return;
1075 
1076 %
1077 % Search peak
1078 % 2004-03-15 Taku Yoshioka
1079 %
1080 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1081 function search_peak(ipeak)
1082 
1083 global select_area_variables;
1084 
1085 areafile = select_area_variables.areafile;
1086 area_keys = select_area_variables.area_keys;
1087 nextDD = select_area_variables.nextDD;
1088 nextIX = select_area_variables.nextIX;
1089 ix_peak1 = select_area_variables.ix_peak1;
1090 
1091 % Search region
1092 na = get(select_area_variables.lb2,'Value');
1093 if length(na)==0 % No area selected
1094   ix_search = 1:length(nextDD);
1095 else
1096   ix_search = [];
1097   for i = 1:length(na)
1098     Area = vb_get_area(areafile,area_keys{na(i)});
1099     ix_search = [ix_search; Area.Iextract];
1100   end
1101 end
1102 
1103 ix_search = unique(ix_search);
1104 
1105 % Exclude region around peak 1
1106 if ipeak==2 & ~isempty(ix_peak1)
1107   Radius = get(select_area_variables.ed2,'String');
1108   Radius = str2num(Radius)*1e-3;
1109   ix = find(nextDD{ix_peak1}<=Radius);
1110   ix = nextIX{ix_peak1}(ix);
1111   ix_search = setdiff(ix_search,ix);
1112 end
1113 
1114 ix_mask = zeros(length(nextDD),1);
1115 ix_mask(ix_search) = 1;
1116 
1117 % Find peak from selected modality
1118 if get(select_area_variables.rb1(1),'Value')
1119   na = get(select_area_variables.lb1,'Value');
1120   act = vb_get_act(select_area_variables.actfile,...
1121         select_area_variables.act_keys{na(1)});
1122   act.xxP = act.xxP.*ix_mask;
1123   [tmp,ix_peak] = max(abs(act.xxP));
1124 elseif ~isempty(select_area_variables.J_map)
1125   [tmp,ix_peak] = max(abs(select_area_variables.J_map.*ix_mask));
1126 else
1127   return;
1128 end
1129 
1130 switch ipeak
1131  case 1,
1132   select_area_variables.ix_peak1 = ix_peak;
1133   set(select_area_variables.pb4,'Enable','on');
1134   set(select_area_variables.tx2,'String',num2str(ix_peak));
1135  case 2,
1136   select_area_variables.ix_peak2 = ix_peak;
1137   set(select_area_variables.pb6,'Enable','on');
1138   set(select_area_variables.tx3,'String',num2str(ix_peak));
1139 end
1140 
1141 if ~isempty(select_area_variables.ix_peak1) & ...
1142       ~isempty(select_area_variables.ix_peak2)
1143   ix1 = select_area_variables.ix_peak1;
1144   ix2 = select_area_variables.ix_peak2;
1145   V0 = select_area_variables.V0;
1146   d1 = sqrt(sum((V0(ix1,:)-V0(ix2,:)).^2));
1147   ix = find(nextIX{ix1}==ix2);
1148   if isempty(ix)
1149     str = sprintf('%2.1f/>Rmax',1000*d1);
1150   else
1151     str = sprintf('%2.1f/%2.1f',1000*d1,1000*nextDD{ix1}(ix));
1152   end
1153   set(select_area_variables.tx4,'String',str);
1154 end
1155 
1156 plot_brain_inner;
1157 
1158 return;
1159 
1160 %
1161 % Clear estimation result
1162 % 2004-03-15 Taku Yoshioka
1163 %
1164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1165 function clear_estimation_result
1166 
1167 global select_area_variables;
1168 
1169 % Clear filename on GUI
1170 set(select_area_variables.tx1,'String','');
1171 set(select_area_variables.pb8,'Enable','off');
1172 
1173 % Clear global variables
1174 select_area_variables.J_map = [];
1175 select_area_variables.F = [];
1176 select_area_variables.ix = [];
1177 select_area_variables.B = [];
1178 
1179 % Plot brain model
1180 plot_brain_inner;
1181 
1182 return;
1183 
1184 %
1185 % Change exluded radius
1186 % 2004-03-15 Taku Yoshioka
1187 %
1188 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1189 function change_exclude_radius
1190 
1191 return;
1192 
1193 %
1194 % Select display area
1195 % 2004-03-15 Taku Yoshioka
1196 %
1197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1198 function select_disp_area
1199 
1200 global select_area_variables;
1201 
1202 area_keys = select_area_variables.area_keys;
1203 
1204 na = get(select_area_variables.lb3,'Value');
1205 Area = vb_get_area(select_area_variables.areafile,area_keys{na(1)});
1206 select_area_variables.ix_disp_area = Area.Iextract;
1207 plot_brain_inner;
1208 
1209 return;
1210 
1211 %
1212 % Update listbox of areas
1213 % 2004-03-15 Taku Yoshioka
1214 %
1215 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1216 function update_listbox_area
1217 
1218 global select_area_variables;
1219 
1220 area_old = select_area_variables.area_keys;
1221 area_new = vb_get_keyset_area(select_area_variables.areafile);
1222 
1223 if length(area_old)~=length(area_new)
1224   select_area_variables.area_keys = area_new;
1225 
1226   % Listbox string table
1227   str = [];
1228   for i = 1:length(area_new)
1229     str = [str area_new{i}];
1230     if i~=length(area_new)
1231       str = [str '|'];
1232     end
1233   end
1234   set(select_area_variables.lb2,'String',str);
1235   set(select_area_variables.lb3,'String',str);
1236 
1237   % Re-select area for lb2
1238   ix_old = get(select_area_variables.lb2,'Value');
1239   ix_new = [];
1240   for i=1:length(ix_old)
1241     key_old = area_old{ix_old(i)};
1242     j = strmatch(key_old,area_new,'exact');
1243     if ~isempty(j)
1244       ix_new = [ix_new; j(1)];
1245     end
1246   end
1247   set(select_area_variables.lb2,'Value',ix_new);
1248   
1249   % Re-select area for lb3
1250   ix_old = get(select_area_variables.lb3,'Value');
1251   ix_new = [];
1252   for i=1:length(ix_old)
1253     key_old = area_old{ix_old(i)};
1254     j = strmatch(key_old,area_new,'exact');
1255     if ~isempty(j)
1256       ix_new = [ix_new; j(1)];
1257     end
1258   end
1259   set(select_area_variables.lb3,'Value',ix_new);
1260 end
1261 
1262 return;
1263 
1264 %
1265 % Change J Max/Min ratio
1266 % 2006-09-27 rhayashi
1267 %
1268 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1269 function change_J_ratio
1270 
1271 global select_area_variables
1272 plot_parm = select_area_variables.plot_parm;
1273 
1274 err = false;
1275 hObj = gcbo; % current action object
1276 
1277 switch(hObj)
1278     case select_area_variables.jmin_edit
1279         Jmin_ratio = str2double(get(hObj, 'String'));
1280         if ~(0<= Jmin_ratio && Jmin_ratio <= 1.0)
1281             errordlg('Jmin ratio should be from 0 to 1.0', 'error');
1282             % set previous value
1283             set(hObj, 'String', num2str(plot_parm.Jmin_ratio));
1284             err = true;
1285             return;
1286         end
1287         set(select_area_variables.jmin_slider, 'Value', Jmin_ratio);
1288         plot_parm.Jmin_ratio = Jmin_ratio;
1289     case select_area_variables.jmax_edit
1290         Jmax_ratio = str2double(get(hObj, 'String'));
1291         if ~(0<= Jmax_ratio && Jmax_ratio <= 1.0)
1292             errordlg('Jmax ratio should be from 0 to 1.0', 'error');
1293             % set previous value
1294             set(hObj, 'String', num2str(plot_parm.Jmax_ratio));
1295             err = true;
1296             return;
1297         end
1298         set(select_area_variables.jmax_slider, 'Value', Jmax_ratio);
1299         plot_parm.Jmax_ratio = Jmax_ratio;
1300     case select_area_variables.jmin_slider
1301         Jmin_ratio = get(hObj, 'Value');
1302         set(select_area_variables.jmin_edit, 'String', num2str(Jmin_ratio));
1303         plot_parm.Jmin_ratio = Jmin_ratio;
1304     case select_area_variables.jmax_slider
1305         Jmax_ratio = get(hObj, 'Value');
1306         set(select_area_variables.jmax_edit, 'String', num2str(Jmax_ratio));
1307         plot_parm.Jmax_ratio = Jmax_ratio;
1308     otherwise
1309         % Reset value
1310         Jmax_ratio = plot_parm.Jmax_ratio;
1311         Jmin_ratio = plot_parm.Jmin_ratio;
1312         set(select_area_variables.jmax_slider, 'Value', Jmax_ratio);
1313         set(select_area_variables.jmin_slider, 'Value', Jmin_ratio);
1314         set(select_area_variables.jmax_edit, 'String', num2str(Jmax_ratio));
1315         set(select_area_variables.jmin_edit, 'String', num2str(Jmin_ratio));
1316 end
1317 
1318 select_area_variables.plot_parm = plot_parm;
1319 plot_brain_inner;
1320 
1321 return;
1322 
1323 %
1324 % Initialize stack of selected points
1325 % 2004-03-15 Taku Yoshioka
1326 %
1327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1328 function init_stack
1329 
1330 global select_area_variables;
1331 
1332 select_area_variables.stack_points = cell(256,1); % buffer size: 256
1333 select_area_variables.ix_stack_points = 0;
1334 
1335 return;
1336 
1337 %
1338 % Print figure
1339 % 2004-03-16 Taku Yoshioka
1340 %
1341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1342 function print_figure
1343 
1344 global select_area_variables;
1345 
1346 plot_parm = select_area_variables.plot_parm;
1347 
1348 axes(select_area_variables.ax1);
1349 [az,el] = view;
1350 angle = [az el];
1351 
1352 h = figure; 
1353 set(gcf,'Renderer','zbuffer');
1354 plot_brain_inner(angle);
1355 
1356 material dull;
1357 camlight headlight;
1358 
1359 vb_epsfig(h,plot_parm.print_ratio,plot_parm.print_size);
1360 axis tight;
1361 if plot_parm.light==2, 
1362   camlight headlight;
1363 end
1364 [fname,pname] = uiputfile({'*.eps';'EPS-file(*.eps)'}, 'Save as', 'Untitled.eps');
1365 if (isnumeric(fname) && fname == 0 )
1366     % cancel
1367     return;
1368 else
1369     print(h, '-depsc2',[pname fname]);
1370     disp(['Output epsfile as ' [pname fname]]);
1371     msgbox('File saved.', 'msg');
1372 end
1373     
1374 close(h);
1375 
1376 return;
1377 
1378 %
1379 % Change plot parameters
1380 % 2004-03-25 Taku Yoshioka
1381 %
1382 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1383 function change_plot_parm
1384 
1385 global select_area_variables;
1386 
1387 axes(select_area_variables.ax1);
1388 [az,el] = view; 
1389 select_area_variables.plot_parm.angle = [az el];
1390 
1391 plot_parm = vb_plotparmdlg(select_area_variables.plot_parm);
1392 select_area_variables.plot_parm = plot_parm;
1393 change_J_ratio;
1394 axes(select_area_variables.ax1);
1395 view(plot_parm.angle);
1396 plot_brain_inner;
1397 
1398 return;
1399 
1400 %
1401 % Change time window
1402 % 2004-04-01 Taku Yoshioka
1403 %
1404 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1405 function change_timewindow
1406 
1407 global select_area_variables;
1408 
1409 ix = select_area_variables.ix;
1410 J_map = select_area_variables.J_map;
1411 resultfile = select_area_variables.bayesfile;
1412 plot_parm  = select_area_variables.plot_parm;
1413 
1414 if ~isempty(resultfile)  
1415   load(resultfile, 'Jact','ix_act','Tstart','Tend','Lact', 'MEGinfo');
1416   t = [Tstart:Tend];
1417   [Nj, T] = size(Jact);
1418   
1419   if isfield(select_area_variables, 'Twin_from')
1420       Twin_from = select_area_variables.Twin_from;
1421   else
1422       Twin_from = Tstart;
1423   end
1424   
1425   if isfield(select_area_variables, 'Twin_to')
1426       Twin_to = select_area_variables.Twin_to;
1427   else
1428       Twin_to = Tend;
1429   end
1430   
1431   [Twin_from, Twin_to, cancelled] = ...
1432     select_time_window(MEGinfo.Pretriger, Tstart, Tend, ...
1433                     MEGinfo.SampleFreq, ...
1434                     Twin_from, Twin_to); % initial value
1435   if cancelled, return; end
1436   
1437   Twin = [Twin_from Twin_to];
1438   
1439   tix  = find( t >= Twin(1) & t <= Twin(2) );
1440 
1441   Jact = Jact(:,tix);
1442   T  = length(tix);
1443   
1444   JJ = sqrt(sum(reshape(Jact, [Nj/Lact Lact*T]).^2, 2)/(Lact*T));
1445   
1446   % Update current distribution
1447   J_map = zeros(length(J_map),1);
1448   J_map(ix) = JJ;
1449   select_area_variables.J_map = J_map;
1450   select_area_variables.Twin_from = Twin_from;
1451   select_area_variables.Twin_to   = Twin_to;
1452 
1453   % Plot brain model
1454   plot_brain_inner;
1455 end
1456 
1457 return;
1458 
1459 %
1460 % Close this window
1461 % 2004-04-02 Taku Yoshioka
1462 %
1463 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1464 function close_window
1465 
1466 close;
1467 
1468 return;
1469 
1470 %
1471 % Remove selected area data
1472 % 2004-06-18 Taku Yoshioka
1473 %
1474 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1475 function callback_remove_area
1476 
1477 global select_area_variables;
1478 
1479 lb2 = select_area_variables.lb2; 
1480 areafile = select_area_variables.areafile;
1481 
1482 ix_key = get(lb2,'Value');
1483 area_key = vb_get_keyset_area(areafile);
1484 
1485 for i=length(ix_key):-1:1
1486   vb_rm_area(areafile,area_key{ix_key(i)});
1487 end
1488 
1489 update_listbox_area;
1490 
1491 return;

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005