0001 function h = vb_plot_cortex(plot_parm,V,F,inf_C,J,Jmin,Jmax,ix_area)
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
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
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
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
0117 if isfield(plot_parm, 'edgecolor') & ~isempty(plot_parm.edgecolor)
0118 edgecolor = plot_parm.edgecolor;
0119 else
0120 edgecolor = 'none';
0121 end
0122
0123
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
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
0147 h = gcf;
0148 set(h, 'renderer', 'zbuffer');
0149 if isempty(inf_C)
0150
0151 patch('Faces',FF,'Vertices',Vshrink,'FaceColor',fclr, ...
0152 'FaceLighting','phong','EdgeColor',edgecolor, ...
0153 'Tag', 'vb_plot_cortex_brain');
0154
0155
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
0170 if plot_parm.isact & ~isempty(J),
0171 plot_value(plot_parm,V,F0,J,index,Jmin,Jmax);
0172 end
0173
0174
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
0187 if vb_matlab_version('>=', '8.4') && vb_matlab_version('<=', '8.6')
0188
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
0198 function plot_value(plot_parm,V,F0,J,index,wmin,wmax);
0199
0200 if length(J) == 0
0201 return;
0202 end
0203
0204
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
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
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
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
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
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
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)));
0303
0304
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
0318 if isfield(plot_parm.area,'str') & ...
0319 ~isempty(plot_parm.area.str) & length(FF) > 0,
0320 V0 = mean(V);
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;