Home > vbmeg > 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 plotted. Otherwise,
          raw value of 'J' is plotted. 
  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>>
  edgecolor : <optional> <<vector>> Color of edges (default: 'none')
  --- fields of plot_parm.area
   area_file          : <<string>> cortical area file(.area.mat)
   key                : <<cell string>> area key name list.
   transparent        : = true  : area tranceparent plot ON
                      : = false : area tranceparent plot OFF <<default>>
   tranceparent_value : from 0 to 1.0 (0.5 is default).
                        If you set 0, area will disappear.
   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]
 % Load inflated standard brain model
 [V,F,xx,inf_C] = vb_load_cortex(brainfile,'Inflate');
 
 % Load current and current information
 [Jinfo, J] = vb_load_current(currentfile);
 
 % get loaded data index between 80[msec] to 120[msec]
 ix = intersect(find(Jinfo.Tmsec>80), find(Jinfo.Tmsec<120));
 
 % Average current between 80msec to 120msec
 Jplot = mean(J(:, ix), 2);
 
 % set viewpoint
 view([10, -2]);
 
 % plot current on cortical inflate model
 plot_parm = vb_set_plot_parm;
 vb_plot_cortex(plot_parm,V,F,inf_C,Jplot);
 
 axis equal;
 axis off;
 
 [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). 
 2022-03-14 rhayashi
  [enhancement] area transparent valueis  added.
  - plot_parm.area.transparent_value
 2022-04-26 Y. Takeda
  [minor] Added option to set edge color

 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 plotted. Otherwise,
0021 %          raw value of 'J' is plotted.
0022 %  paint : <<bool>> If true,
0023 %  cmap  : <<int>> Colormap (1: hot, otherwise: jet).
0024 %  isact : <optional> <<bool>> If true, activity map is superimposed on
0025 %         cortical surface.
0026 %  color : <optional> <<vector>>
0027 %  index : <optional> <<vector>>
0028 %  area  : <optional> <<struct>>
0029 %  edgecolor : <optional> <<vector>> Color of edges (default: 'none')
0030 %  --- fields of plot_parm.area
0031 %   area_file          : <<string>> cortical area file(.area.mat)
0032 %   key                : <<cell string>> area key name list.
0033 %   transparent        : = true  : area tranceparent plot ON
0034 %                      : = false : area tranceparent plot OFF <<default>>
0035 %   tranceparent_value : from 0 to 1.0 (0.5 is default).
0036 %                        If you set 0, area will disappear.
0037 %   clr                : <<cell string/3d vector>>
0038 %   str                : <optional> <<cell string>>
0039 %   Rlabel             : <optional> <<double>> Distance between string and area.
0040 %  ---
0041 % ---
0042 % V        : <<matrix>> Vertices of cortical surface model.
0043 % F        : <<matrix>> Faces of cortical surface model.
0044 % inf_C    : <<vector>> Color of sulcus/gyrus. It should be empty when
0045 %                       plotting folded surface model.
0046 %
0047 % [output]
0048 % h: Handle of light.
0049 %
0050 % [example]
0051 % % Load inflated standard brain model
0052 % [V,F,xx,inf_C] = vb_load_cortex(brainfile,'Inflate');
0053 %
0054 % % Load current and current information
0055 % [Jinfo, J] = vb_load_current(currentfile);
0056 %
0057 % % get loaded data index between 80[msec] to 120[msec]
0058 % ix = intersect(find(Jinfo.Tmsec>80), find(Jinfo.Tmsec<120));
0059 %
0060 % % Average current between 80msec to 120msec
0061 % Jplot = mean(J(:, ix), 2);
0062 %
0063 % % set viewpoint
0064 % view([10, -2]);
0065 %
0066 % % plot current on cortical inflate model
0067 % plot_parm = vb_set_plot_parm;
0068 % vb_plot_cortex(plot_parm,V,F,inf_C,Jplot);
0069 %
0070 % axis equal;
0071 % axis off;
0072 %
0073 % [history]
0074 % 2009-01-26 taku-y
0075 % 2010-12-27 taku-y
0076 %  [minor] Not superimpose activity (not invoke patch fnc) if all values
0077 %  do not exceed threshold.
0078 % 2012-02-09 taku-y
0079 %  [enhancement] If isfield(area,'clr'), plor_parm.area{i}.clr is
0080 %  replaced with a.clr, where a=vb_get_area(area_file,area_key{i}).
0081 % 2012-03-14 taku-y
0082 %  [minor] Check color value in a.clr, where
0083 %  a=vb_get_area(area_file,area_key).
0084 % 2022-03-14 rhayashi
0085 %  [enhancement] area transparent valueis  added.
0086 %  - plot_parm.area.transparent_value
0087 % 2022-04-26 Y. Takeda
0088 %  [minor] Added option to set edge color
0089 %
0090 % Copyright (C) 2011, ATR All Rights Reserved.
0091 % License : New BSD License(see VBMEG_LICENSE.txt)
0092 
0093 % --- Check input arguments
0094 if nargin<8, ix_area = []; end
0095 if nargin<5, 
0096   J = [];
0097   Jmin = [];
0098   Jmax = [];
0099 else
0100   if nargin<7, Jmax = max(abs(J)); end
0101   if nargin<6, Jmin = max(abs(J))*0.1; end
0102 end
0103 if nargin<4, inf_C = []; end; 
0104 
0105 % color of cortical surface
0106 if isfield(plot_parm,'color') & ~isempty(plot_parm.color)
0107   fclr = plot_parm.color;
0108 else
0109   fclr = [0.8 0.8 0.8];
0110 end
0111 
0112 if ~isfield(plot_parm,'isact'), 
0113   plot_parm.isact = true;
0114 end
0115 
0116 % Color of edges
0117 if isfield(plot_parm, 'edgecolor') & ~isempty(plot_parm.edgecolor)
0118     edgecolor = plot_parm.edgecolor;
0119 else
0120     edgecolor = 'none';
0121 end
0122 
0123 % Left/Right hemisphere
0124 switch plot_parm.LRflag
0125  case 'L'
0126   F0 = F.F3L;
0127  case 'R'
0128   F0 = F.F3R;
0129  case 'LR'
0130   F0 = F.F3;
0131 end
0132 
0133 if isempty(inf_C)
0134     inflate = false;
0135 else
0136     inflate = true;
0137 end
0138 Vshrink = vb_shrink_cortex_for_plot(V, F0, inflate);
0139 
0140 % --- Select visible patches
0141 if ~isfield(plot_parm,'index'), index = [];
0142 else index = plot_parm.index; end
0143 if length(index) == 0, FF = F0;
0144 else FF = vb_patch_select2(index,F0,size(V,1)); end
0145 
0146 % --- Plot cortical surface
0147 h = gcf; 
0148 set(h, 'renderer', 'zbuffer');
0149 if isempty(inf_C)
0150   % Display patches
0151   patch('Faces',FF,'Vertices',Vshrink,'FaceColor',fclr, ...
0152     'FaceLighting','phong','EdgeColor',edgecolor, ...
0153         'Tag', 'vb_plot_cortex_brain');
0154   
0155   % Light
0156   h = camlight('headlight');
0157 else
0158   c = repmat(fclr,[length(inf_C) 1]) ...
0159       -0.4*[fclr(1)*inf_C fclr(2)*inf_C fclr(3)*inf_C];
0160   patch('Faces',FF,'Vertices',Vshrink,'FaceColor','interp',...
0161     'EdgeColor',edgecolor,'FaceVertexCData',c, ...
0162         'Tag', 'vb_plot_cortex_brain');
0163   h = [];
0164 end
0165 
0166 material dull;
0167 hold on;
0168 
0169 % --- Superimpose activity
0170 if plot_parm.isact & ~isempty(J), 
0171   plot_value(plot_parm,V,F0,J,index,Jmin,Jmax);
0172 end
0173 
0174 % --- Superimpose area
0175 if ~isempty(ix_area),
0176   if ~isempty(index), ix_area = intersect(index,ix_area); end
0177   FF = vb_patch_select2(ix_area,F0,size(V,1));
0178   patch('Faces',FF,'Vertices',V,'FaceColor','b',...
0179     'EdgeColor','none','EraseMode','xor', ...
0180         'FaceAlpha',1);
0181 end
0182 
0183 plot_area(plot_parm,V,F0);
0184 
0185 
0186 % To avoid MATLAB alpha bug(R2014b to R2015b)
0187 if vb_matlab_version('>=', '8.4') && vb_matlab_version('<=', '8.6')
0188     % reset alpha value of brain to 0.99
0189     t = timer('Name', 'vb_plot_cortex', 'StartDelay', 1, ...
0190           'TimerFcn', 'alpha(findobj(gca, ''Tag'', ''vb_plot_cortex_brain''), 0.99);', ...
0191           'ExecutionMode', 'singleshot');
0192     start(t);
0193 end
0194 
0195 return; 
0196 
0197 % --- Inner function: plot cortical activity
0198 function plot_value(plot_parm,V,F0,J,index,wmin,wmax);
0199 
0200 if length(J) == 0
0201   return;
0202 end
0203 
0204 % Select vertices
0205 if length(index) == 0
0206   tmp = ones(length(J),1);
0207 else  
0208   tmp = zeros(length(J),1);
0209   tmp(index) = 1;
0210 end
0211 
0212 % Left/Right hemisphere
0213 tmp2 = zeros(length(J),1);
0214 tmp2(unique(F0(:))) = 1;
0215 
0216 tmp = J.*tmp.*tmp2;
0217 ix = find(abs(tmp) >= wmin);
0218 if plot_parm.wmode==1
0219   J = abs(J);
0220 end
0221 
0222 % Superimpose activity on cortical surface
0223 if plot_parm.paint==1
0224   h = scatter3(V(ix,1),V(ix,2),V(ix,3),1,J(ix),'.','filled');
0225   set(h,'MarkerSize',plot_parm.ms);
0226 else  
0227   FF = vb_patch_select2(ix,F0,size(V,1));
0228   if ~isempty(FF), 
0229     patch('Faces',FF,'Vertices',V,'FaceColor','interp',...
0230           'FaceVertexCData',J,'EdgeColor','none',...
0231           'FaceLighting','none','FaceAlpha',1);
0232     material dull;
0233   end
0234 end
0235 
0236 if plot_parm.wmode==1
0237   caxis([0 wmax]);
0238 else
0239   caxis([-wmax wmax]);
0240 end
0241   
0242 if plot_parm.cmap==1
0243   colormap(hot);
0244 else
0245   colormap(jet);
0246 end
0247 
0248 return; 
0249 
0250 % --- Inner function: plot cortical area
0251 function plot_area(plot_parm,V,F0);
0252 
0253 if isfield(plot_parm,'area'), 
0254   if ~isfield(plot_parm,'index') | isempty(plot_parm.index), 
0255     tmp = ones(size(V,1),1);
0256   else
0257     tmp = zeros(size(V,1),1);
0258     tmp(plot_parm.index) = 1;
0259   end
0260   
0261   % For compatibility with old format
0262   if isfield(plot_parm,'Rlabel'), 
0263     plot_parm.area.Rlabel = plot_parm.Rlabel;
0264   elseif ~isfield(plot_parm.area,'Rlabel'), 
0265     plot_parm.area.Rlabel = 1;
0266   end
0267   
0268   if isfield(plot_parm,'areafile'), 
0269     plot_parm.area.area_file = plot_parm.areafile;
0270   end
0271 
0272   % Transparency
0273   if isfield(plot_parm.area,'transparent') & plot_parm.area.transparent, 
0274     if isfield(plot_parm.area, 'tranceparent_value')
0275         alpha = plot_parm.area.tranceparent_value;
0276     else
0277         alpha = 0.5;
0278     end
0279   else
0280     alpha = 1.0;
0281   end
0282 
0283   % Plot area
0284   area_file = plot_parm.area.area_file;
0285   for i = 1:length(plot_parm.area.key)
0286     Area = vb_get_area(area_file,plot_parm.area.key{i});
0287     if isfield(Area,'clr'), 
0288       clr = Area.clr;
0289       if max(clr)>1 | min(clr)<0, 
0290         vb_disp(['Invalid color value of cortical region. area.clr must ' ...
0291                  'be in range [0 1], where area = vb_get_area(area_file,' ...
0292                  'area_key). Normalized in ' ...
0293                  'vb_plot_cortex.']);        
0294         clr = abs(clr)./max(abs(clr));
0295       end
0296     else
0297       Nclr = length(plot_parm.area.clr);
0298       clr = plot_parm.area.clr{1+mod(i-1,Nclr)};
0299     end
0300     ix = Area.Iextract;
0301     ix = ix(:);
0302     ix = ix(find(ix.*tmp(ix))); % Union
0303 
0304     % Dot/Face plot
0305     if plot_parm.paint==1
0306       ix2 = intersect(ix,unique(F0(:)));
0307       plot3(V(ix2,1),V(ix2,2),V(ix2,3),'.',...
0308         'MarkerFaceColor',clr,'MarkerEdgeColor',clr, ...
0309         'MarkerSize',plot_parm.ms);
0310     else
0311       FF = vb_patch_select2(ix,F0,size(V,1));
0312       patch('Faces',FF,'Vertices',V,...
0313             'FaceColor',clr,'EdgeColor','none', ...
0314             'FaceLighting','gouraud','FaceAlpha',alpha);
0315     end
0316 
0317     % Display name of cortical area
0318     if isfield(plot_parm.area,'str') & ...
0319           ~isempty(plot_parm.area.str) & length(FF) > 0, 
0320       V0 = mean(V); % Center of cortical model
0321       pos = median(V(ix,:))-V0;
0322       [theta,phi,r] = cart2sph(pos(1),pos(2),pos(3));
0323       r = plot_parm.area.Rlabel*r;
0324 
0325       [x,y,z] = sph2cart(theta,phi,r);
0326       x = x+V0(1);
0327       y = y+V0(2);
0328       z = z+V0(3);
0329       pos = pos+V0;
0330       plot3([pos(1) x],[pos(2) y],[pos(3) z]);
0331       h = text(x,y,z,plot_parm.area.str{i},...
0332            'Interpreter','none','FontSize',plot_parm.fs,...
0333            'HorizontalAlignment','center');
0334     end
0335   end
0336 end
0337 
0338 return;

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005