Home > functions > plotfunc > vb_plot_cortex.m

vb_plot_cortex

PURPOSE ^

Plot cortical surface model.

SYNOPSIS ^

function h = vb_plot_cortex(plot_parm,V,F,inf_C,J,Jmin,Jmax,ix_area)

DESCRIPTION ^

 Plot cortical surface model. 
 (VBMEG public function)

 [syntax]
 vb_plot_cortex(plot_parm,V,F)
 vb_plot_cortex(plot_parm,V,F,inf_C)
 vb_plot_cortex(plot_parm,V,F,inf_C,J)
 vb_plot_cortex(plot_parm,V,F,inf_C,J,Jmin)
 vb_plot_cortex(plot_parm,V,F,inf_C,J,Jmin,Jmax)
 vb_plot_cortex(plot_parm,V,F,inf_C,J,Jmin,Jmax,ix_area)

 [input]
 plot_parm: <<struct>> Plotting parameters.
 --- fields of plot_parm
  LRflag: <<string>> Specifying hemisphere for plotting. 
   'LR' for both hemishepre
   'L' for left hemisphere
   'R' for both hemisphere
  wmode : <<bool>> If true, absolute value of 'J' is shown. 
  paint : <<bool>> If true, 
  cmap  : <<int>> Colormap (1: hot, otherwise: jet). 
  isact : <optional> <<bool>> If true, activity map is superimposed on
         cortical surface.
  color : <optional> <<vector>> 
  index : <optional> <<vector>>
  area  : <optional> <<struct>>
  --- fields of plot_parm.area
   area_file: <<string>>
   key      : <<cell string>>
   clr      : <<cell string/3d vector>>
   str      : <optional> <<cell string>>
   Rlabel   : <optional> <<double>> Distance between string and area.
  ---
 ---
 V        : <<matrix>> Vertices of cortical surface model.
 F        : <<matrix>> Faces of cortical surface model.
 inf_C    : <<vector>> Color of sulcus/gyrus. It should be empty when
                       plotting folded surface model. 

 [output]
 h: Handle of light.

 [example]
 >> [V,F,xx,inf_C] = vb_load_cortex(brainfile,'Inflate');
 >> J = zeros(size(V,1),1);
 >> J(ix_act_ex) = sqrt(sum((W*Z).*(W*Z),2));
 >> plot_parm = vb_set_plot_parm;
 >> vb_plot_cortex(plot_parm,V,F,inf_C,J);

 [history]
 2009-01-26 taku-y
 2010-12-27 taku-y
  [minor] Not superimpose activity (not invoke patch fnc) if all values
  do not exceed threshold. 
 2012-02-09 taku-y
  [enhancement] If isfield(area,'clr'), plor_parm.area{i}.clr is
  replaced with a.clr, where a=vb_get_area(area_file,area_key{i}). 
 2012-03-14 taku-y
  [minor] Check color value in a.clr, where
  a=vb_get_area(area_file,area_key). 

 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 h = vb_plot_cortex(plot_parm,V,F,inf_C,J,Jmin,Jmax,ix_area)
0002 % Plot cortical surface model.
0003 % (VBMEG public function)
0004 %
0005 % [syntax]
0006 % vb_plot_cortex(plot_parm,V,F)
0007 % vb_plot_cortex(plot_parm,V,F,inf_C)
0008 % vb_plot_cortex(plot_parm,V,F,inf_C,J)
0009 % vb_plot_cortex(plot_parm,V,F,inf_C,J,Jmin)
0010 % vb_plot_cortex(plot_parm,V,F,inf_C,J,Jmin,Jmax)
0011 % vb_plot_cortex(plot_parm,V,F,inf_C,J,Jmin,Jmax,ix_area)
0012 %
0013 % [input]
0014 % plot_parm: <<struct>> Plotting parameters.
0015 % --- fields of plot_parm
0016 %  LRflag: <<string>> Specifying hemisphere for plotting.
0017 %   'LR' for both hemishepre
0018 %   'L' for left hemisphere
0019 %   'R' for both hemisphere
0020 %  wmode : <<bool>> If true, absolute value of 'J' is shown.
0021 %  paint : <<bool>> If true,
0022 %  cmap  : <<int>> Colormap (1: hot, otherwise: jet).
0023 %  isact : <optional> <<bool>> If true, activity map is superimposed on
0024 %         cortical surface.
0025 %  color : <optional> <<vector>>
0026 %  index : <optional> <<vector>>
0027 %  area  : <optional> <<struct>>
0028 %  --- fields of plot_parm.area
0029 %   area_file: <<string>>
0030 %   key      : <<cell string>>
0031 %   clr      : <<cell string/3d vector>>
0032 %   str      : <optional> <<cell string>>
0033 %   Rlabel   : <optional> <<double>> Distance between string and area.
0034 %  ---
0035 % ---
0036 % V        : <<matrix>> Vertices of cortical surface model.
0037 % F        : <<matrix>> Faces of cortical surface model.
0038 % inf_C    : <<vector>> Color of sulcus/gyrus. It should be empty when
0039 %                       plotting folded surface model.
0040 %
0041 % [output]
0042 % h: Handle of light.
0043 %
0044 % [example]
0045 % >> [V,F,xx,inf_C] = vb_load_cortex(brainfile,'Inflate');
0046 % >> J = zeros(size(V,1),1);
0047 % >> J(ix_act_ex) = sqrt(sum((W*Z).*(W*Z),2));
0048 % >> plot_parm = vb_set_plot_parm;
0049 % >> vb_plot_cortex(plot_parm,V,F,inf_C,J);
0050 %
0051 % [history]
0052 % 2009-01-26 taku-y
0053 % 2010-12-27 taku-y
0054 %  [minor] Not superimpose activity (not invoke patch fnc) if all values
0055 %  do not exceed threshold.
0056 % 2012-02-09 taku-y
0057 %  [enhancement] If isfield(area,'clr'), plor_parm.area{i}.clr is
0058 %  replaced with a.clr, where a=vb_get_area(area_file,area_key{i}).
0059 % 2012-03-14 taku-y
0060 %  [minor] Check color value in a.clr, where
0061 %  a=vb_get_area(area_file,area_key).
0062 %
0063 % Copyright (C) 2011, ATR All Rights Reserved.
0064 % License : New BSD License(see VBMEG_LICENSE.txt)
0065 
0066 %
0067 % Check input arguments
0068 %
0069 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0070 if nargin<8, ix_area = []; end
0071 if nargin<5, 
0072   J = [];
0073   Jmin = [];
0074   Jmax = [];
0075 else
0076   if nargin<7, Jmax = max(abs(J)); end
0077   if nargin<6, Jmin = max(abs(J))*0.1; end
0078 end
0079 if nargin<4, inf_C = []; end; 
0080 
0081 if isfield(plot_parm,'color') & ~isempty(plot_parm.color)
0082   fclr = plot_parm.color;
0083 else
0084   fclr = [0.8 0.8 0.8];
0085 end
0086 
0087 if ~isfield(plot_parm,'isact'), 
0088   plot_parm.isact = true;
0089 end
0090 
0091 %
0092 % Left/Right hemisphere
0093 %
0094 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0095 switch plot_parm.LRflag
0096  case 'L'
0097   F0 = F.F3L;
0098  case 'R'
0099   F0 = F.F3R;
0100  case 'LR'
0101   F0 = F.F3;
0102 end
0103 
0104 %
0105 % Select visible patches
0106 %
0107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0108 if ~isfield(plot_parm,'index'), index = [];
0109 else index = plot_parm.index; end
0110 if length(index) == 0, FF = F0;
0111 else FF = vb_patch_select2(index,F0,size(V,1)); end
0112 
0113 %
0114 % Plot cortical surface
0115 %
0116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0117 h = gcf; 
0118 set(h, 'renderer', 'zbuffer');
0119 if isempty(inf_C)
0120   % Display patches
0121   patch('Faces',FF,'Vertices',V,'FaceColor',fclr, ...
0122     'FaceLighting','phong','EdgeColor','none', ...
0123         'FaceAlpha',0.99);
0124   
0125   % Light
0126   h = camlight('headlight');
0127 else
0128   c = repmat(fclr,[length(inf_C) 1]) ...
0129       -0.4*[fclr(1)*inf_C fclr(2)*inf_C fclr(3)*inf_C];
0130   patch('Faces',FF,'Vertices',V,'FaceColor','interp',...
0131     'EdgeColor','none','FaceVertexCData',c, ...
0132         'FaceAlpha',0.99);
0133   h = [];
0134 end
0135 
0136 material dull;
0137 hold on;
0138 
0139 %
0140 % Superimpose activity
0141 %
0142 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0143 if plot_parm.isact & ~isempty(J), 
0144   plot_value(plot_parm,V,F0,J,index,Jmin,Jmax);
0145 end
0146 
0147 %
0148 % Superimpose area
0149 %
0150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0151 if ~isempty(ix_area),
0152   if ~isempty(index), ix_area = intersect(index,ix_area); end
0153   FF = vb_patch_select2(ix_area,F0,size(V,1));
0154   patch('Faces',FF,'Vertices',V,'FaceColor','b',...
0155     'EdgeColor','none','EraseMode','xor', ...
0156         'FaceAlpha',0.99);
0157 end
0158 
0159 plot_area(plot_parm,V,F0);
0160 
0161 return; 
0162 
0163 %
0164 % Subfunction: plot cortical activity
0165 %
0166 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0167 function plot_value(plot_parm,V,F0,J,index,wmin,wmax);
0168 
0169 if length(J) == 0
0170   return;
0171 end
0172 
0173 % Select vertices
0174 if length(index) == 0
0175   tmp = ones(length(J),1);
0176 else  
0177   tmp = zeros(length(J),1);
0178   tmp(index) = 1;
0179 end
0180 
0181 % Left/Right hemisphere
0182 tmp2 = zeros(length(J),1);
0183 tmp2(unique(F0(:))) = 1;
0184 
0185 tmp = J.*tmp.*tmp2;
0186 ix = find(abs(tmp) >= wmin);
0187 if plot_parm.wmode==1
0188   J = abs(J);
0189 end
0190 
0191 % Superimpose activity on cortical surface
0192 if plot_parm.paint==1
0193   h = scatter3(V(ix,1),V(ix,2),V(ix,3),1,J(ix),'.','filled');
0194   set(h,'MarkerSize',plot_parm.ms);
0195 else  
0196   FF = vb_patch_select2(ix,F0,size(V,1));
0197   if ~isempty(FF), 
0198     patch('Faces',FF,'Vertices',V,'FaceColor','interp',...
0199           'FaceVertexCData',J,'EdgeColor','none',...
0200           'FaceLighting','none','FaceAlpha',0.99);
0201     material dull;
0202   end
0203 end
0204 
0205 if plot_parm.wmode==1
0206   caxis([0 wmax]);
0207 else
0208   caxis([-wmax wmax]);
0209 end
0210   
0211 if plot_parm.cmap==1
0212   colormap(hot);
0213 else
0214   colormap(jet);
0215 end
0216 
0217 return; 
0218 
0219 %
0220 % Subfunction: plot cortical area
0221 %
0222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0223 function plot_area(plot_parm,V,F0);
0224 
0225 if isfield(plot_parm,'area'), 
0226   if ~isfield(plot_parm,'index') | isempty(plot_parm.index), 
0227     tmp = ones(size(V,1),1);
0228   else
0229     tmp = zeros(size(V,1),1);
0230     tmp(plot_parm.index) = 1;
0231   end
0232   
0233   % For compatibility with old format
0234   if isfield(plot_parm,'Rlabel'), 
0235     plot_parm.area.Rlabel = plot_parm.Rlabel;
0236   elseif ~isfield(plot_parm.area,'Rlabel'), 
0237     plot_parm.area.Rlabel = 1;
0238   end
0239   
0240   if isfield(plot_parm,'areafile'), 
0241     plot_parm.area.area_file = plot_parm.areafile;
0242   end
0243 
0244   % Transparency
0245   if isfield(plot_parm.area,'transparent') & plot_parm.area.transparent, 
0246     alpha = 0.5;
0247   else
0248     alpha = 1.0;
0249   end
0250 
0251   % Plot area
0252   area_file = plot_parm.area.area_file;
0253   for i = 1:length(plot_parm.area.key)
0254     Area = vb_get_area(area_file,plot_parm.area.key{i});
0255     if isfield(Area,'clr'), 
0256       clr = Area.clr;
0257       if max(clr)>1 | min(clr)<0, 
0258         vb_disp(['Invalid color value of cortical region. area.clr must ' ...
0259                  'be in range [0 1], where area = vb_get_area(area_file,' ...
0260                  'area_key). Normalized in ' ...
0261                  'vb_plot_cortex.']);        
0262         clr = abs(clr)./max(abs(clr));
0263       end
0264     else
0265       Nclr = length(plot_parm.area.clr);
0266       clr = plot_parm.area.clr{1+mod(i-1,Nclr)};
0267     end
0268     ix = Area.Iextract;
0269     ix = ix(:);
0270     ix = ix(find(ix.*tmp(ix))); % Union
0271 
0272     % Dot/Face plot
0273     if plot_parm.paint==1
0274       ix2 = intersect(ix,unique(F0(:)));
0275       plot3(V(ix2,1),V(ix2,2),V(ix2,3),'.',...
0276         'MarkerFaceColor',clr,'MarkerEdgeColor',clr, ...
0277         'MarkerSize',plot_parm.ms);
0278     else
0279       FF = vb_patch_select2(ix,F0,size(V,1));
0280       patch('Faces',FF,'Vertices',V,...
0281             'FaceColor',clr,'EdgeColor','none', ...
0282             'FaceLighting','gouraud','FaceAlpha',alpha);
0283     end
0284 
0285     % Display name of cortical area
0286     if isfield(plot_parm.area,'str') & ...
0287           ~isempty(plot_parm.area.str) & length(FF) > 0, 
0288       V0 = mean(V); % Center of cortical model
0289       pos = median(V(ix,:))-V0;
0290       [theta,phi,r] = cart2sph(pos(1),pos(2),pos(3));
0291       r = plot_parm.area.Rlabel*r;
0292 
0293       [x,y,z] = sph2cart(theta,phi,r);
0294       x = x+V0(1);
0295       y = y+V0(2);
0296       z = z+V0(3);
0297       pos = pos+V0;
0298       plot3([pos(1) x],[pos(2) y],[pos(3) z]);
0299       h = text(x,y,z,plot_parm.area.str{i},...
0300            'Interpreter','none','FontSize',plot_parm.fs,...
0301            'HorizontalAlignment','center');
0302     end
0303   end
0304 end
0305 
0306 return;

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