0001 function[p] = eeg_plot_surf(p)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 fprintf('\nEEG_PLOT_SURF...\n'); tic;
0026
0027
0028
0029 if isfield(p,'mesh'),
0030 if isfield(p.mesh,'data'),
0031 if isfield(p.mesh.data,'timeseries'),
0032 if isempty(p.mesh.data.Cdata{p.mesh.current}),
0033 msg = sprintf('...p.mesh.data.Cdata{%d} is empty\n',p.mesh.current);
0034 error(msg);
0035 end
0036 end
0037 end
0038 else
0039 error('...p.mesh.data is empty - load mesh first\n');
0040 end
0041
0042
0043
0044
0045
0046
0047
0048
0049 switch p.mesh.data.meshtype{p.mesh.current},
0050 case {'scalp','elec'},
0051 samplePoint = p.volt.samplePoint;
0052 sampleTime = p.volt.sampleTime;
0053 otherwise
0054 samplePoint = p.mesh.samplePoint;
0055 sampleTime = p.mesh.sampleTime;
0056 end
0057
0058
0059 nvert = size(p.mesh.data.vertices{p.mesh.current},1);
0060
0061 [s1,s2] = size(p.mesh.data.Cdata{p.mesh.current});
0062 if isequal(nvert,s1),
0063 meshCdata = p.mesh.data.Cdata{p.mesh.current}(:,samplePoint);
0064 else,
0065 meshCdata = p.mesh.data.Cdata{p.mesh.current}(samplePoint,:)';
0066 end
0067
0068
0069 switch p.mesh.data.meshtype{p.mesh.current},
0070 case {'scalp','elec'},
0071 otherwise
0072 meshCdata = abs(meshCdata);
0073 end
0074
0075
0076 switch p.rangeMethod
0077 case 'minmaxall',
0078 fprintf('...estimating color data range, min/max all time points.\n');
0079 p.maximumIntensity = max(max(p.mesh.data.Cdata{p.mesh.current}));
0080 p.minimumIntensity = min(min(p.mesh.data.Cdata{p.mesh.current}));
0081 case 'minmaxone',
0082 fprintf('...estimating color data range, min/max single time point.\n');
0083
0084 p.maximumIntensity = max(max(meshCdata));
0085 p.minimumIntensity = min(min(meshCdata));
0086 case 'minmaxabs',
0087 fprintf('...estimating color data range, abs min/max single time point.\n');
0088 absmax = max(max(abs(meshCdata)));
0089 p.maximumIntensity = absmax;
0090 p.minimumIntensity = -absmax;
0091 otherwise
0092
0093 fprintf('...checking predefined color data range.\n');
0094 if isempty(p.maximumIntensity),
0095 fprintf('...estimating color data range, min/max single time point.\n');
0096 p.maximumIntensity = max(max(meshCdata)); end
0097 if isempty(p.minimumIntensity),
0098 fprintf('...estimating color data range, min/max single time point.\n');
0099 p.minimumIntensity = min(min(meshCdata)); end
0100 end
0101
0102
0103
0104
0105
0106
0107
0108 fprintf('...plotting the surface.\n');
0109
0110
0111
0112 if sampleTime,
0113 if p.volt.data,
0114 data = sprintf('%s %s',p.volt.file,p.mesh.data.meshtype{p.mesh.current});
0115 name = sprintf('Surface: %s @ %8.2f msec',data, sampleTime);
0116 else
0117 data = sprintf('%s',p.mesh.data.meshtype{p.mesh.current});
0118 name = sprintf('Surface: %s @ %8.2f msec',data, sampleTime);
0119 end
0120 else
0121 if p.volt.data,
0122 data = sprintf('%s %s',p.volt.file,p.mesh.data.meshtype{p.mesh.current});
0123 name = sprintf('Surface: %s',data);
0124 else
0125 data = sprintf('%s',p.mesh.data.meshtype{p.mesh.current});
0126 name = sprintf('Surface: %s',data);
0127 end
0128 end
0129
0130
0131
0132
0133
0134
0135 H.gui = figure('NumberTitle','off','Name',name,'color',[0 0 0]);
0136
0137
0138 p.mesh.patch = patch('vertices',p.mesh.data.vertices{p.mesh.current},...
0139 'faces',p.mesh.data.faces{p.mesh.current},...
0140 'facevertexCdata',meshCdata,...
0141 'facecolor','interp','EdgeColor','none',...
0142 'FaceLighting','phong');
0143
0144
0145
0146
0147 set(gca,'Projection','perspective')
0148 set(gca,'DataAspectRatio',[1 1 1]);
0149 axis off tight vis3d
0150
0151
0152
0153
0154 lighting phong
0155 set(H.gui,'RendererMode','auto')
0156
0157
0158
0159
0160 H.light(1) = camlight(-20, 30,'infinite');
0161 H.light(2) = camlight( 20, 30,'infinite');
0162 H.light(3) = camlight(-20,-30,'infinite');
0163 for i = 1:length(H.light),
0164
0165 set(H.light(i),'color',[.8 1 1]/length(H.light)/1.2);
0166 end
0167
0168
0169
0170
0171
0172
0173 meshtype = lower(p.mesh.data.meshtype{p.mesh.current});
0174 switch meshtype,
0175 case 'scalp',
0176 set(gca,'AmbientLightColor',[.9 .8 .7]);
0177 colormap(p.colorMap.map);
0178 case {'cortex','pial','white','smoothwm','orig'},
0179
0180
0181
0182
0183 if exist('bluehot'),
0184 p.colorMap.map = grayish(bluehot(128),.33);
0185 p.colorMap.map = grayish(hot(128),.33);
0186 p.colorMap.map = hot(128);
0187 colormap(p.colorMap.map);
0188 else
0189 set(gca,'AmbientLightColor',[.6 .6 .6]);
0190 colormap(p.colorMap.map);
0191 end
0192
0193 otherwise
0194 set(gca,'AmbientLightColor',[.9 .9 .9]);
0195 end
0196
0197 caxis([p.minimumIntensity p.maximumIntensity]);
0198 colorbar
0199
0200
0201
0202
0203
0204 p.reflect{1} = 0.9;
0205 p.reflect{2} = 0.2;
0206 p.reflect{3} = 0.0;
0207 p.reflect{4} = 500;
0208 p.reflect{5} = 0;
0209 set(p.mesh.patch,'AmbientStrength',p.reflect{1});
0210 set(p.mesh.patch,'DiffuseStrength',p.reflect{2});
0211 set(p.mesh.patch,'SpecularStrength',p.reflect{3});
0212 set(p.mesh.patch,'SpecularExponent',p.reflect{4});
0213 set(p.mesh.patch,'SpecularColorReflectance',p.reflect{5});
0214
0215
0216
0217
0218
0219 if (p.contour.plot3D == 1),
0220 [p] = eeg_plot_surf_contours(p);
0221 end
0222
0223
0224
0225
0226
0227 H.p = p;
0228
0229 set(H.gui,'userdata',H);
0230 set(gca,'Visible','off');
0231
0232 if isequal(exist('mouse_rotate'),2),
0233 mouse_rotate('init',H);
0234 else
0235 rotate3d on;
0236 end
0237 if isequal(exist('gui_topo_animate'),2),
0238 gui_topo_animate('init',p);
0239 end
0240
0241
0242 t = toc;
0243 fprintf('...done (%6.2f sec).\n\n',t);
0244
0245 return